OpenGL Question on Matrix concatenation

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

Recommended Posts

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?

Share on other sites
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.

Share on other sites
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.

Share on other sites

Quote:
 Original post by SneftelIf 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?

Share on other sites
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.

Share on other sites
Quote:
 Original post by TaraliethIs 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.

Share on other sites
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 :).

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
18

• 13
• 10
• 12
• 10
• 13
• Forum Statistics

• Total Topics
632998
• Total Posts
3009806
• Who's Online (See full list)

There are no registered users currently online

×

Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!