* Inverts a 4x4 matrix. * * This function can currently handle only pure translation-rotation matrices. * Read http://www.gamedev.net/community/forums/topic.asp?topic_id=425118 * for an explanation. */
| 409 | * for an explanation. |
| 410 | */ |
| 411 | static void |
| 412 | invert(GLfloat *m) |
| 413 | { |
| 414 | GLfloat t[16]; |
| 415 | identity(t); |
| 416 | |
| 417 | // Extract and invert the translation part 't'. The inverse of a |
| 418 | // translation matrix can be calculated by negating the translation |
| 419 | // coordinates. |
| 420 | t[12] = -m[12]; t[13] = -m[13]; t[14] = -m[14]; |
| 421 | |
| 422 | // Invert the rotation part 'r'. The inverse of a rotation matrix is |
| 423 | // equal to its transpose. |
| 424 | m[12] = m[13] = m[14] = 0; |
| 425 | transpose(m); |
| 426 | |
| 427 | // inv(m) = inv(r) * inv(t) |
| 428 | multiply(m, t); |
| 429 | } |
| 430 | |
| 431 | /** |
| 432 | * Calculate a perspective projection transformation. |