View Full Version : vetors, angles, YPR

Been some years since i last did this sort of calculations, so please help.

I have a vector that is normalized(-0.70016, -0.140028, -0.70016). This is the sun looking down on the ground. I want to place my camera in the suns position, and look down in the vector direction. I must somehow translate my vector to yaw and pitch so I can rotate my camera.

I assume you can't calculate roll on camera with only one vector(that is not important)

I also know I will need to take my yaw and pitch and make a vector out of it(one way will probably explain the other way though).

Please give me an example of how this is done.

pythagoras

10-08-2001, 10:49 AM

Can't you use glRotate?

No, I can't because I got to do the calculations myself.

I think maybe I know a way to calcualte the pitch and yaw... I take the original vector, and make two new ones moved down to the zx-plane and the xy-plane. Calculate the angle between the new vectors and the original(dotproduct), and the two angles I get is yaw and pitch...

I'm not sure if this will work, but I still don't know how to i the opposite way, from yaw and pitch to a vector...

well, it kind of worked, the angles I calculate is correct, but now I have to recalculate my angles to check what direction it stood before my calculation(my answer is always positive pitch and yaw). This means my picht can be:

p=p, p=-p or p=p-pi

the same is for yaw. Now my problem is the rules for these 3 answers.

What I really think is that I'm doing alot of work that I'm sure can be done in a easier way. Still.. how to get yaw and pitch back to it's vector form

Coconut

10-09-2001, 05:45 AM

The mapping between YPR and the xform is NOT as nice as you might think.

Given a 3x3 orthonormal matrix for rotation, generally, you have two YPR solutions. In some special cases, you can have infinite solutions, for example, when pitch is 90 degrees.

In your case, if you enforce roll is always zero, pick a pitch that correspending to the sign of Y in the original vector. That is pitch is +ve if and only if Y is +ve. Your yaw should then be uniquely found.

Why don't you use gluLookAt(eye_x, eye_y, eye_z, target_x, target_y, target_z, upvector_x, upvector_y, upvector_z)

the upvector can be calculated via the cross product of your vector from the "sun" to your target and the vector <1,0,0>.

Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.