# I need help with understanding Invert vs Transpose

This topic is 3627 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm a little confused by the difference between inverting a matrix versus transposing a matrix. I invert my camera matrix to bring objects into camera space, and transpose my texture matrix to be used for my shadow maps. The two function that I have that invert and transpose matrices are similar, and that's what is confusing me. The xyz rotation axis are being transposed in both, but the forth column, and position, are treated differetly. I guess I understand why the invert function I have works, but I don't understand what the 4x4 transpose is doing with the 4th column and position data. Invert function: b[0]=a[0]; b[1]=a[4]; b[2]=a[8]; b[3]=0.0f; b[4]=a[1]; b[5]=a[5]; b[6]=a[9]; b[7]=0.0f; b[8]=a[2]; b[9]=a[6]; b[10]=a[10]; b[11]=0.0f; b[12]=-(a[12]*a[0])-(a[13]*a[1])-(a[14]*a[2]); b[13]=-(a[12]*a[4])-(a[13]*a[5])-(a[14]*a[6]); b[14]=-(a[12]*a[8])-(a[13]*a[9])-(a[14]*a[10]); b[15]=1.0f; Transpose function: temp[0]=m[0]; temp[1]=m[4]; temp[2]=m[8]; temp[3]=m[12]; temp[4]=m[1]; temp[5]=m[5]; temp[6]=m[9]; temp[7]=m[13]; temp[8]=m[2]; temp[9]=m[6]; temp[10]=m[10]; temp[11]=m[14]; temp[12]=m[3]; temp[13]=m[7]; temp[14]=m[11]; temp[15]=m[15]; -WhatEver

##### Share on other sites
Transposing is a completely different function from inverting, it just happens to be that the transpose of an orthogonal matrix (ie. one that only contains rotations), is the same as the inverse. As soon as your matrix contains things like scaling and sheering/translation, the transpose will be different from the inverse.

What I assume is the case with your code, is that your invert function makes the assumption that your matrix only contains a rotation and a translation. So to calculate the inverse of that, it transposes the rotation part, and calculates the translation part by inverting the translation vec, and rotating it by the matrix' rotation part.

This isn't really a correct way of calculating the inverse, but it will work if your matrix contains only rotation and translation.

##### Share on other sites
I guess so. I have never scaled my camera before...but I do remember having problems with lighting when my objects are scaled. My shaders perform lighting in object space, so I have to multiply the lights by the inverse of the object world matrix.

I pretty much get how the invert matrix works then, but what about the transpose matrix? I get it when it has to do with rotations, but other than that, I'm clueless. Here's the source code that creates my textureMat for shadowing (it's the same as the one in the OpenGL SuperBible but with my functions)

S3Dmat16f textureMat;

s3dMatIdentity16f(textureMat);
s3dMatTranslate16f(textureMat, 0.5f, 0.5f, 0.5f);
s3dMatScale16f(textureMat, 0.5f, 0.5f, 0.5f);
s3dMatMultiply16x16f(textureMat, projection, textureMat);
s3dMatMultiply16x16f(textureMat, modelView, textureMat);

s3dMatTranspose16f(textureMat);

glTexGenfv(GL_S, GL_EYE_PLANE, &textureMat[0]);
glTexGenfv(GL_T, GL_EYE_PLANE, &textureMat[4]);
glTexGenfv(GL_R, GL_EYE_PLANE, &textureMat[8]);
glTexGenfv(GL_Q, GL_EYE_PLANE, &textureMat[12]);

I understand that S, T, R, and Q are holding the results of the textureMat. But what exactly is going on? I was under the impression that the textureMat would need to be inverted not transposed so that S, T, R, and Q would be brought into texture space.

##### Share on other sites
A quick side-note: if you scale your object non-uniformly (i.e. not the same scale factor for all axes) then you'll need to recalculate your normals for the lighting to be correct.

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 10
• 9
• 9
• 11
• 11
• ### Forum Statistics

• Total Topics
633688
• Total Posts
3013328
×