Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get camera up vector from roll, pitch, and yaw?

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!

like image 978
Polaris878 Avatar asked Oct 15 '09 21:10

Polaris878


2 Answers

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
like image 190
shoosh Avatar answered Oct 11 '22 11:10

shoosh


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_debug_terminal

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.

like image 21
BluePlateSpecial Avatar answered Oct 11 '22 12:10

BluePlateSpecial