How can I transform an object with a given yaw, pitch, and roll?
The upper left 3×3 portion of a transformation matrix is composed of the new X, Y, and Z axes of the post-transformation coordinate space. If the new transform is a roll, compute new local Y and X axes by rotating them “roll” degrees around the local Z axis. Do similar calculations if the transform is a pitch or yaw. Then simply construct your transformation matrix by inserting the new local X, Y, and Z axes into the upper left 3×3 portion of an identity matrix. This matrix can be passed as a parameter to glMultMatrix(). Further rotations should be computed around the new local axes. This will inevitably require rotation about an arbitrary axis, which can be confusing to inexperienced 3D programmers. This is a basic concept in linear algebra. Many programmers apply all three transformations — yaw, pitch, and roll — at once as successive glRotate() calls about the X, Y, and Z axes. This has the disadvantage of creating gimbal lock, in which the result depends on the order of glRotate(