Question on Matrix concatenation

Started by
5 comments, last by Taralieth 18 years ago
I was designing a scene graph and was thinking about how to concatenate the transformation matrices on the downward pass through the scene graph. I wanted to make the scene graph api independent. But DirectX describes points as row vectors so if I want to apply transformation A, then B to the row vector, I would have to multiply A*B. But I believe that OpenGL describes points as column vectors so for OpenGL, if I want to apply transformation A, then B, I would have to multiply B*A. Am I missing something here? Or if I'm right, is there any way around this?
Advertisement
If v'=A*v, then v'T=vT*AT. In other words, the only thing you need to do differently to go between row and column vectors and switch the order of operands is transpose the matrix before passing it to the graphics API.
My page on matrix layout in DirectX and OpenGL will likely help.

Hint: There are enough differences between the APIs such that they cancel out, and the in-memory representation is actually the same for DirectX and OpenGL WORLD/MODELVIEW matrices. In GL you have to multiply in the VIEW matrix manually, though; that's easily done by starting with it (instead of identity) when traversing for OpenGL.
enum Bool { True, False, FileNotFound };
Thanks for the quick reply.

Quote:Original post by Sneftel
If v'=A*v, then v'T=vT*AT. In other words, the only thing you need to do differently to go between row and column vectors and switch the order of operands is transpose the matrix before passing it to the graphics API.


This seems so unintuitive. So lets say that the matrix A is a concatenation of matrix B and C. Where B is the first transformation I want to do and C is the second one afterwards.

So:
A = B*C
v'=v*A // where v is a row vector

is the same as:
A = C*B // meant to be used with column vector
v'T=vT*AT // v' was a column vector but transposed to make it a row vector

Is this true for all cases? Or is it because these are concatenation of transformation matrices?
You're using A for two different things, though, which is making your notation rather confusing. A=B*C. That's inside your scene graph library, with no regards to whether the graphics API uses row or column vectors. The only important insight is that multiplying a matrix A by a column vector produces the same values as multiplying a row vector by the transposed matrix AT. And yes, this works in all cases.

If you want to do it more verbosely, if A=B*C and v'=A*v, then v'T=vT*CT*BT=vT*(B*C)T. But that's a rather confusing way to state it. At the point where you start to worry about what form of transformation your graphics API does, the components of your final transformation matrix no longer matter.
Quote:Original post by Taralieth
Is this true for all cases? Or is it because these are concatenation of transformation matrices?

It is true for all matrices: (A*B)T = BT*AT.
Quote:Original post by Sneftel
...

If you want to do it more verbosely, if A=B*C and v'=A*v, then v'T=vT*CT*BT=vT*(B*C)T. But that's a rather confusing way to state it. At the point where you start to worry about what form of transformation your graphics API does, the components of your final transformation matrix no longer matter.


Thanks for clearing that up. Yeah the components of the final transformation matrix doesn't matter. But I just like to see the reason why mathematically it makes sense before I use it in my code. I just completely forgot about the property that (B*C)T=CT*BT. So everything works out nicely :).

This topic is closed to new replies.

Advertisement