Iceman
Iceman

Reputation: 4362

OpenGL - find rotation vector for glRotate()

I have been working on the problem of implementing roll-, pitch-, and yaw-style rotations in OpenGL for quite some time, with limited relevant material available online. The crux of the problem is finding the updated local axes, as the object is rotating. For example, rotation around X, causes local Y and Z axes to change. Subsequent rotations will be around the updated axes. I have found some mathematical formulas to find the updated vectors here:

http://nehe.gamedev.net/article/camera_class_tutorial/18010/

However, the new vector is given in terms of points, e.g., rotation of 45 degrees around Y-axis changes the X-axis, which now passes through the points (0.71, 0, 0.71). The question now is how to find the (x, y, z) points which can be passed in to glRotatef(angle, x, y, z). Note that x, y, z, lie on a vector which passes through them and the origin.

I am thinking of taking a normal to the line passing through (0.71, 0, 0.71) and origin, and then again taking a normal to get (x, y, z).

Can anyone suggest an improvement to this, or an alternative method?

Upvotes: 0

Views: 1516

Answers (1)

Mathieu St-Louis
Mathieu St-Louis

Reputation: 11

I suggest you to use quaternions. It is somewhat conceptually difficult to grasp at first, but once you get the gist of it, the implementation is quite straight-forward. Moreover, quaternion rotation allows you to avoid the gimbal lock :)

OpenGL Quaternion tutorial site:

http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-17-quaternions/

Upvotes: 1

Related Questions