views:

1233

answers:

2

Hello,

I need to get an up vector for a camera (to get the right look) from a roll, pitch, and yaw angles (in degrees). I've been trying different things for a couple hours and have had no luck :(. Any help here would be appreciated!

+5  A: 

Roll, Pitch and Yaw define a rotation in 3 axis. from these angles you can construct a 3x3 transformation matrix which express this rotation (see here how)
After you have this matrix you take your regular up vector, say (0,1,0) if 'up' is the Y axis and multiply it with the matrix. What you'll get is the transformed up vector.

Edit-
Applying the transformation to (0,1,0) is the same thing as taking the middle row. The 3 rows of the matrix make up an orthogonal base of the rotated system. Mind you that a 3D graphic API uses 4x4 matrices. So to make a 4x4 matrix out of the 3x3 rotation matrix you need to add a '1' at M[3][3] (the corner) and zeros at the rest like so:

r r r 0
r r r 0 
r r r 0
0 0 0 1
shoosh
Shoosh, what if I don't apply the transformation to the (0,1,0)? Can I just pull out one of the rows/columns from the rotation matrix as my up? Thanks
Polaris878
Yes, instead of doing the vector-matrix transformation, you can simplify the equation by leaving out the zero-sums/terms. Also, vectors can be column-major or row-major. Make sure you extract the axis correctly.
Mads Elvheim
+1  A: 

This may not directly answer your question, although it may still help. I have a free open-source project for XNA that creates a debug terminal that overlays your game while it is running. You can use this for looking up values, invoking methods, or whatever. So if you have a transformation matrix and you wanted to extract various parts of it while the game is running, you can do that. The project can be found here: http://www.protohacks.net/xna%5Fdebug%5Fterminal

I don't have much expertise in the kind of math you are using, but hopefully Shoosh's post helps on that. Maybe the debug terminal can help you when trying out his idea or in any other future problems you encounter.

BluePlateSpecial
hah i can't wait to play with this later.It looks like a tool ive wanted for a while ... ive been having to write a console in my projects and output data there ... very very clunky.
John Nicholas