Jump to content
  • Advertisement
Sign in to follow this  
gamen00b

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

This topic is 3599 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!