Jump to content
  • Advertisement
Sign in to follow this  
kdworld

Camera matrix composition

This topic is 3807 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

Hello Friends, I am confused with camera affine matrix composition.For example this is my camera transformation glRotatef(-m_fRotZ,0,0,1); glRotatef(-m_fRotY,0,1,0); glRotatef(-m_fRotX,1,0,0); glTranslatef(-m_Translation.x,-m_Translation.y,-m_Translation.z); So that the object will move according to the camera movement. So How to create the resultant matrix . If R = [RX]*[RY]*[RZ]; And T = [T] is it R*T or T*R ? Thanks kdworld If You can Dream , You can Do it.

Share this post


Link to post
Share on other sites
Advertisement
The resulting matrix will be R*T, just like the order of the function calls. Note, however, that the matrix will be mutiplied by the vertex position on the left, that is, (R*T)*v.

Share this post


Link to post
Share on other sites
To be precise: The formula equivalent to the command order is
Rz * Ry * Rx * T
(i.e. the OP's definition of R is already wrong).

The mathematical way is to define the camera as part of the world as usual
C := T * R
and then to invert it (since we need a global-to-local transformation here)
C-1 = ( T * R )-1
what not only inverts the parts but also reverses the order
  = R-1 * T-1
That is true also for the parts of combined rotation (or any other) matrices, of course. The OP has done part inversion by inverting the parameters to the matrix creation.

Share this post


Link to post
Share on other sites
Thanks all for the reply.

Anyway i don't think the [Rx]* [Ry]* [Rz] order is wrong. because i guess in opengl normally transformation is carried out in the reverse order .
So here it is X*Y*Z .

Right ?

Share this post


Link to post
Share on other sites
Quote:
i don't think the [Rx]* [Ry]* [Rz] order is wrong. because i guess in opengl normally transformation is carried out in the reverse order .
So here it is X*Y*Z .

Right ?


Every time you call a transformation function, you apply that transformation to the current matrix (the matrix on top of the OpenGL matrix stack). This is done by multiplying the current matrix on the right.

Here's how the current matrix looks after each one of your calls (assuming it starts out as identity):

I -> Rz -> Rz * Ry -> Rz * Ry * Rx -> Rz * Ry * Rx * T.

When transforming vertices, the vertex position is multiplied by the current matrix on the left (because OpenGL uses column vectors) like so:

(Rz * Ry * Rx * T) * v.

So actually the transformations are applied in the reverse order than the function calls. Go here and read the section titled "Thinking About Transformations" to better understand this and what to do about it.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!