Skip to main content
gamedev.net
🔒 Locked

Camera matrix composition

Started by kdworld Jan 16, 2008 at 2:55 AM 4 replies 1.4k views
Original Post
kdworld
kdworld
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.
haegarr
haegarr
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.
kdworld
kdworld
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 ?
Gage64
Gage64
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.
kdworld
kdworld
Thank you. I will read that..

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.