PDA

View Full Version : Calculating the inverse matrix

Exoide
01-25-2010, 05:53 PM
Hi there,

I need to get the inverse matrix of the model-view matrix.

To do it faster can I do it in the following way:

1- Multiply by (-1) the translation vector in the matrix (only X, Y, Z items of the vector)
2- Calculate the transpose of the 3x3 sub matrix that contains the rotation vectors
3- Update the first three items of the diagonal with this 1/m11, 1/m22, 1/m33

Of course that method is only valid for the following transformations:

1- Translation
2- Rotation
3- Scale

Can I calculate the inverse in that way? I mean, is this an accurate way to get the inverse?

Thank you.

PD: I will only do these transformations in the model-view.

Exoide
01-26-2010, 05:26 AM
No, it's not possible to calculate the inverse in that way after a lot of tests I arrive to the conclusion that the rotation is the transpose of the sub matrix 3x3 but the translation vector isn't always its opposite.

Thanks anyway.

Dark Photon
01-26-2010, 06:03 AM
Of course that method is only valid for the following transformations:

1- Translation
2- Rotation
3- Scale
As you said, I think there may be a flaw in your logic. However, if you limit yourself to the first two (translation and rotation -- no scale!), then there is indeed a faster inverse. Transpose the 3x3 rotation part (it's orthogonal -- no scales -- so this is valid). Then to get the translate part: take the original translate, negate it, and then transform it by the inverse rotation.

It's generally bad to put scales in modelview anyway. For instance, doing so means you needlessly have to rescale/normalize normals in your shader. It also complicates culling (your spheres are not spheres anymore...uh oh :( ).

Jedimaster
02-23-2010, 09:21 PM
If you know your transformation sequence, you could build a matrix which is built from inverse of Translate/Rotate/Scale, or else try to use an external library to do that such as cml, nv_math, etc.

Yann LE PETITCORPS
03-07-2010, 07:35 AM
In shaders, they are gl_ModelViewMatrixInverseTranspose and others like gl_ProjectionInverse that can be used for example.

If this have to be used outside the shader, I know that we can import matrix into the shader via glUniformMatrix but don't know how to export this (without write pixels that encode the matrix into a pixel buffer and read this pixel buffer after).

@+
Yannoo