Sign in to follow this  
gamen00b

calculate x and y rotations from a 3D vector...

Recommended Posts

I have found it easy to calculate the y-rotation from a vector. For some reason, I've been having a hard time calculating the x-rotation. Anyone have an idea how to do this. No z-rotations are possible in my game. Assume OpenGL Coordinate system and that (0, 0, -1) implies 0 x-rotation Thanks [Edited by - gamen00b on November 13, 2008 12:19:52 AM]

Share this post


Link to post
Share on other sites
Hmm... am I correct in guessing that your problem is in, given one direction vector, finding the x- and y- angles that it describes, as opposed, for example, to calculating the angles from two different vectors?

If the former, and you've calculated y-rotation (by which I'm guessing that you mean elevation above the horizontal), you should be able to apply trigonometry to find the x-rotation.

Specifically, use the y-angle, the length of the original vector and the cosine function (I think) to find the length of the vector along the ground. You should then, if I'm not much mistaken, be able to use that length along with the component of the same ground vector that lies on whichever axis is appropriate (that is, the one that would correspond to a direction of zero) to find the x-angle, again using the appropriate trigonometric function (sine in this case, I think).

Good luck! ^_^

Share this post


Link to post
Share on other sites
using asin(vector.y) should get you an x rotation.

in this case if vector y is 0, we get 0 x axis rotation (rotation about the x-axis), if vector.y is 1 then we get 90 degrees, this will make us look top down essentially on our scene.

I use this for my camera system so just get the camera position vector, normalize it and use asin.

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