I have some questions that may or may not be entirely related to OpenGL, but certainly are related to graphics programming, so maybe some of you might be able to help me:
1- Is it OK to use glRotatef with quaternions instead of constructing the rotation matrix and loading it manually?
2- Can I call glRotatef twice without fear of something being wrong because of Gimbal Lock?
3- Suppose the following scenario:
- I have a top down view where there is an object in the center of the screen
- I want to rotate my object over the Z axis by using the mouse's position in relation to the middle of the screen. I do this by normalizing the vector and calling atan2 to get the angle needed to rotate the object.
- Then, I also want to rotate the object so that it is parallel to the plane it is sitting on. I do this by constructing a quaternion that shifts the world up vector (0, 0, 1) to the normal of the plane.
- Finally, I came up with the following set of rotations:
| glTranslatef(slime.pos.x, slime.pos.y, slime.pos.z);
// From AllegroGL`s math.c
glRotatef((2*acos(slime.rotation.w)) * 180 / M_PI, slime.rotation.x, slime.rotation.y, slime.rotation.z);
glRotatef(mouse_angle, 0, 0, 1);
|
- Is this right?
- Does the order of rotations matter here?
- If not, what should I be doing instead?