OpenGL direction of a vector in degrees (X, Y, Z)

Go To StackoverFlow.com

0

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(...)?

2012-04-04 04:51
by Wallter
The third angle is arbitrary, since it doesn't affect the direction of travel. You'll need another constraint if you want to force a particular value - Vaughn Cato 2012-04-04 04:58
So if I am to understand correctly, 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
glRotatef(phi,0,0,1); glRotatef(theta,1,0,0) - Vaughn Cato 2012-04-05 03:57


1

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.

2012-04-04 04:56
by Ignacio Vazquez-Abrams
thanks for the clarification - Now how do I get it to rotate it with glRotatef(...) - Wallter 2012-04-04 05:00
First, you can stop worrying about theta and phi, since 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
Ads