PDA

View Full Version : Compositing a camera matrix...



zen
04-29-2001, 06:26 AM
I'm trying to implement a camera model using a 3x3 matrix for camera roation and a 3-vector for camera translation/position.I want to keep it simple for now so I only want to implement camera translation and rotation around it's own(the camera's coordinate system)axes.Supposing I have a camera position vector cam_pos[3] and a camera rotation matrix cam_rot[9],how can I compose a 4x4 homogenous camera matrix(for use with glLoadMatrixf or glMultMatrixf) so that the camera is first translated to cam_pos and the rotated in place(around this new position/coord. system) according to cam_rot?Thanx in advance for any help...

Korval
04-29-2001, 08:45 AM
I'd go back to your original data (the position and orientation of the camera) and use gluLookAt.

zen
04-29-2001, 01:20 PM
I'd prefer to use my own functions.By now I can make the camera rotate around it's on ccord. system but the translation seems to take place(as it should) according to the worlds coord. system.What I do is simply multiply the camera matrix first by the rotation and then by the translation matrix so that the translation is carrited out first.Yet I want the tranlation to be carried out int the camera's coord. system.So given the translation amount in each axis of the camera's coord. system how can I find translation values that'l give me the same effect when the translation is carried out in the world's coord.system?
I'll give gluLookAt a try though anyway until I find a way to do it myself.

jwatte
04-29-2001, 04:53 PM
If you want the world to move to the right as seen from the camera, you can move the camera to the left as seen from the world. Thus, your modelview transform should be the negative of whatever you want your "camera transform" to be (as far as translation goes).

And you are right that you need to rotate (around the origin) first and then translate to where you want to go, as all rotation happens around the origin. If you draw it out on paper, you'll quickly see why :-)

zen
04-30-2001, 03:30 AM
The problem is that if the camera gets rotated then the axes of the camera nad world coordinate system don't align any more.If I translate in the world coord. system(even the other way round as you correctly noted)I won't be translating along the camera's axes.
Today though I noticed that the rotations don't seem to happen entirely along the local coord. system as well.The rotation seems to happen along the worlds coord. system translated to the camera's point.

So say I have a 3x3 matrix representing cmaera rotation and a 3-vector for camera position.Out of these I can create 4x4 homogenous rotation and translation matrices respectively.What do I have to do so that by multiplying the matrix by a rotation matrix(like:

|1 0 0 |
|0 cos(a) -sin(a)|
|0 sin(a) cos(a)|)

the view gets rotated around the camera's coord. system?The camera also has to be positioned at the point with coords. these of the 3-vector in WORLD coordinates.

zen
04-30-2001, 12:34 PM
I'm starting a new topic so anyone who want's to post should do it there...