Reputation: 123
I am having trouble on how to rotate an object in 3D space, based on the OpenGL rotate function glRotatef(..).
glRotatef ( angle , x , y , z )
My object is traveling from one point to another in 3D space. I want my object to rotate in the direction it is traveling.
How would I find the angle, x, y, z that is needed for the glRotatef(...) function if I know the point where I am starting and the point where I am finishing.
Upvotes: 1
Views: 528
Reputation: 72279
The gluLookAt
function is exactly what you need here. It will save you from calculating the axis and angle manually.
Upvotes: 1
Reputation: 1300
Very crudely, what you need is to get the axis of rotation, which will be normal to both the direction of travel and the surface normal, which would mean a cross product of the direction of travel (T) and surface normal (n) would give you an axis for your rotation. Thus axis(A) would be:
A = norm(T x n) or maybe A = norm(n x T), one of which will let you use a positive angle to "rotate" in the right direction.
However, the positive or negative nature of the angle of rotation needs to be analyzed depending on which one of the above you use, but this should get you started with the axis of rotation :)
Upvotes: 0