* 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. */
| 391 | * for an explanation. |
| 392 | */ |
| 393 | static void |
| 394 | invert(GLfloat *m) |
| 395 | { |
| 396 | GLfloat t[16]; |
| 397 | identity(t); |
| 398 | |
| 399 | // Extract and invert the translation part 't'. The inverse of a |
| 400 | // translation matrix can be calculated by negating the translation |
| 401 | // coordinates. |
| 402 | t[12] = -m[12]; t[13] = -m[13]; t[14] = -m[14]; |
| 403 | |
| 404 | // Invert the rotation part 'r'. The inverse of a rotation matrix is |
| 405 | // equal to its transpose. |
| 406 | m[12] = m[13] = m[14] = 0; |
| 407 | transpose(m); |
| 408 | |
| 409 | // inv(m) = inv(r) * inv(t) |
| 410 | multiply(m, t); |
| 411 | } |
| 412 | |
| 413 | /** |
| 414 | * Calculate a perspective projection transformation. |