I have an object traveling along a 3D vector in terms of X, Y, Z... I need to rotate the object according to each axis (x-axis, y-axis, and z-axis).
How do I get these measurements in terms of degrees?
(I am using OpenGL and only know of glRotatef(...)
) [glRotatef(...) documentation here]
Looking at this question, the answer gives
viewvector =
<x, y, z>
r = sqrt(x² + y² + z²)
phi = arctan2(y, x)
theta = arccos(z / r)
but from this wiki page I understand that:
[Edit from Ignacio Vazquez-Abrams]
phi => angle around Z-axis
theta => angle between x/y plane
but how do I find Y? or do I need to?
The real question is, How do I represent this in terms of glRotatef(...)
?
glRotatef(theta, 1.0, 1.0, 0.0)
and glRotatef(phi, 0.0, 0.0, 1.0)
will work - Wallter 2012-04-05 03:22
Theta is the angle above the XY plane. Phi is the angle around the Z axis. In general, polar coordinates in n dimensions have n-1 angle components and 1 radius component.
glRotate*()
takes the vector, not the angles. As for the roll, that's something you'll need to determine for yourself - Ignacio Vazquez-Abrams 2012-04-04 05:02