Sign in to follow this  
samgzman

Extracting orientation from scene graph based camera

Recommended Posts

In my engine, the camera is a valid scene graph node. Its stores both local (relative) and global (absolute) transformations. When rendering an object, the matrix transformation i pass into a shader is OBJECT_GLOBAL * CAMERA_GLOBAL_INVERSE * PROJECTION. I still want the camera to be able to strafe, and otherwise move in a simple fashion. Some of these operations that affect camera position (strafe, move foward, move up) require a knowledge of the camera's orientation in world space. This orientation would be most convient in the form of a set of lookat, up, and right vectors. Are these vectors still represented by the column vectors of the camera's global transformation matrix even though this matrix could be composed of much more that just rotations? (Assuming DX-style row major matrices) What is is the cheapest way to recover these vectors given the global tranformation matrix?

Share this post


Link to post
Share on other sites
If you're using a 4x4 homogeneous transformation matrix, then rotation and translation are isolated. I'll assume there's no scaling at the moment, although there are ways to isolate that transformation if it's present. In that case, the "right," "up," and "forward" vectors are just the 3x1 columns of CAMERA_GLOBAL_INVERSE, respectively.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zipster
If you're using a 4x4 homogeneous transformation matrix, then rotation and translation are isolated. I'll assume there's no scaling at the moment, although there are ways to isolate that transformation if it's present. In that case, the "right," "up," and "forward" vectors are just the 3x1 columns of CAMERA_GLOBAL_INVERSE, respectively.


I'm not sure why the right, up, and forward vectors would still be columns of CAMERA_GLOBAL_INVERSE. Correct me if I'm wrong. The camera's rotation matrix would be [R,U,F] where R = right column vector, U = up column vector, F = forward column vector. So after taking the inverse of it, the right, up and forward vectors would no longer be the columns of CAMERA_GLOBAL_INVERSE, right?

Share this post


Link to post
Share on other sites
Quote:
Original post by Taralieth
I'm not sure why the right, up, and forward vectors would still be columns of CAMERA_GLOBAL_INVERSE. Correct me if I'm wrong. The camera's rotation matrix would be [R,U,F] where R = right column vector, U = up column vector, F = forward column vector. So after taking the inverse of it, the right, up and forward vectors would no longer be the columns of CAMERA_GLOBAL_INVERSE, right?
The original post suggests that the OP is using row vectors, so the basis vectors would in fact be in the columns of the inverse camera matrix.

The OP also said something about the camera matrix being composed of 'more than just rotations'; I'm not sure what he means by this, but it may mean that extracting the direction vectors might require some additional steps.

Share this post


Link to post
Share on other sites
What other transformations are happening to the camera? Most camera matrices consist of translations and rotations only. If this is true in your case, then yes, those vectors are still represented by the camera's global transformation matrix. Think of your forward up and right vectors ([1 0 0], [0 1 0] and [0 0 1]) untransformed. Now translations in your camera transformation matrix will do nothing to vectors, which makes sense since no matter where our camera is, if it's only translated, up is still up. So we're left with camera rotation. So muliply your camera matrix by say, the up vector and you will get a rotated up vector which yes, corresponds to the up direction in your camera's space. Since the up vector is [0 1 0] (let's say), then multiplying this by your camera transformation matrix gives the second column of your camera transformation matrix. Like Zipster said, scaling will obviously denormalize your vectors, but camera transformations don't normally include scales.

Also, you don't want to use your inverse camera matrix as was suggested, just use the camera transform matrix.

Share this post


Link to post
Share on other sites
Quote:
Original post by PaulEdwards
Also, you don't want to use your inverse camera matrix as was suggested, just use the camera transform matrix.
Technically speaking, you can get the direction vectors from either the transform or the inverse transform matrix. I agree though that it's conceptually clearer to extract them from the transform matrix, but if for whatever reason that's not an option, you can certainly pull them from the inverse matrix instead.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this