Jump to content
  • Advertisement
Sign in to follow this  
Taralieth

OpenGL Question on Matrix concatenation

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

If you intended to correct an error in the post then please contact us.

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 this post


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

Share this post


Link to post
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 this post


Link to post
Share on other sites
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?

Share this post


Link to post
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 this post


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

Share this post


Link to post
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 :).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

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!