Home | Gaming | Programming | Play Online | Contact | Keyword Query
Games++ Games & Game Programming

Games++ Home
Games++ Gaming
Games++ Programming
Beta Testing Games
Free Online Games
Hints & Cheats

E-mail This Page
Add to Favorites


Web Games++

Cheat Codes
Trickster Wiki
Game Ratings
Gameboy Cheats
PlayStation Cheats
BlackBerry Games
Photoshop Tutorials
Illustrator Tutorials
ImageReady Tutorials



Inverse Transformations Part 7: Matrix Transformation Tutorial

Table of Contents

  1. Introduction
  2. Math Prerequisites

  3. Importance of Correct Transformations
  4. What a Matrix Represents
  5. Matrix Multiplication
  6. Transforming a Vector by a Matrix
  7. Object Space Transformations
  8. Camera Transformations
  9. Inverse Transformations
  10. Hierarchical Transformations

  11. Precision
  12. Conclusion

Inverse Transformations

Inverse transformations are used to perform hidden surface removal in object space, without transforming any normal vectors. Likewise, the same technique can be used in shading. This method provides some obvious speed increases over transforming normal vectors, the correct culling or shading information can be determined by inversely transforming a view or light vector, then taking the dot product of this inversely transformed vector and the non-transformed normal vectors. In addition to the rendering time saved by not transforming normal vectors, this method can give significant time savings by allowing you to hide points as well as polys. If you determine that only the points contained in visible polygons are visible, you can avoid transforming points contained in those polygons which are not visible. This usually accounts for around half of the points in an object.

Inverse transformation requires an inverse matrix, which is made by negating all of the angles in the constituent rotation matrices and multiplying them together in reverse order. As you can imagine, this is quite a slow process, especially when a camera and hierarchical object are involved! Thankfully though, there is a shortcut.

Certain types of matrices (I believe those that have a determinant of 1) can be inverted by swapping rows and columns. The transformation matrix is this type of matrix. I made a utility to test this property, generating an inverse matrix with the negate and multiply in reverse order algorithm, and comparing it to the original matrix. I found that transformation matrices do fit the pattern of inversion by row and column swapping.

This means that you can inverse transform your view and light vectors with the following formulas (notice that these are identical to the regular transformation formulas, but have the row and column indices swapped):

        x = x0 * matrix[0][0] + y0 * matrix[0][1] + z0 * matrix[0][2];

        y = x0 * matrix[1][0] + y0 * matrix[1][1] + z0 * matrix[1][2];

        z = x0 * matrix[2][0] + y0 * matrix[2][1] + z0 * matrix[2][2];

If you are a smart one, you will also notice that there are only 3 terms in these equations, the w term (translation part of the matrix) is missing. This is because we are inverse transforming, the result is object space. We want all of our vectors to start at the origin for this operation, in object space the origin is [0, 0, 0].

Copyright © 1998-2007, Games++ All rights reserved. | Privacy Policy