PDA

View Full Version : How to Get the Camera Up Vector from its transform matrix ?


Floating_Inkpot
02-08-2009, 11:05 AM
Hi, i am a bit confused with transforms, angles, vectors & company...

Lets say i have a camera that is pointing towards a direction.
Mycam.Transform returns :
(matrix3 [0.604205,-0.796829,0] [0,0,1] [-0.796829,-0.604205,0] [-61.4619,-46.6042,0])
So if i need the vector of the direction i will type :
Mycam.dir
which returns :
[-0.796829,-0.604205,0]

What i am trying to find, is the Up Vector of the camera. because i want to use the cross product on the Camera Direction to find a Perpendicular vector.

But the Cross product need two vectors forming a plane.
I have the first, which is Mycam.dir and i need a second, wich would be the Camera Up.

Cross MyCam.dir MyCamUp i would find a vector perpendicular to this plane ^^

How to calculate this Camera Up Vector ?
I tryed some vector multiplications, additions etc.... but i think i am a little bit confused with all that mathematics^^ and i need your help i think :p
I searched into the tranform matrix, but there is one thing i dont understand, it is that it contains 4 elements , but it is a matrix3... ?
(matrix3 [0.604205,-0.796829,0] [0,0,1] [-0.796829,-0.604205,0] [-61.4619,-46.6042,0])
What does that stand for ? position, rotation, scale and ?

i tryed also Mycam.transform.rotation
(quat -0.633286 0.314561 0.314561 0.633286)
but a i am not familiar with quaternions, i think i could get the Up vector of the rotation or something like that ?

Thanks for your clarification i hope i will understand it better after that^^

gan0nia
02-08-2009, 11:48 AM
I guessthe up vector is one of the elements of that camera's transformation matrix

(
matrix3
[0.604205,-0.796829,0] -- row 1 ...
[0,0,1] -- row2 the up vector
[-0.796829,-0.604205,0] -- row3 , the dir which is camera's local z axis
[-61.4619,-46.6042,0] -- row4 , same as the position value
)

cheers~

Bobo
02-08-2009, 02:45 PM
I guessthe up vector is one of the elements of that camera's transformation matrix

(
matrix3
[0.604205,-0.796829,0] -- row 1 ...
[0,0,1] -- row2 the up vector
[-0.796829,-0.604205,0] -- row3 , the dir which is camera's local z axis
[-61.4619,-46.6042,0] -- row4 , same as the position value
)

cheers~

This is correct, .row1 is the X axis, .row2 is the Y (equivalent to Up vector), row3 is the Z axis (and keep in mind that the camera looks at the scene with the NEGATIVE Z axis!) and row4 is the position.

Btw, the inverse of this matrix equals the viewport transformation matrix.

Floating_Inkpot
02-08-2009, 07:56 PM
It was sitting under my nose but i could'nt see it ^^
Thanks a lot!

CGTalk Moderation
02-08-2009, 07:57 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.