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

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

## 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 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 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.

1. 1
2. 2
3. 3
4. 4
Rutin
15
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633724
• Total Posts
3013554
×