To main page | 3dengine.org

Roll (as in yaw/heading, pitch, roll) is the angle that makes vertical lines non-vertical from "camera" point-of-view. Note that only lines going through the camera center should be vertical, others won't be exactly vertical due to perspective projection caused by camera's angle-of-view).

Note, that roll is rotation around local camera's z-axis, not ANY OF global axes.

## Compensating roll in OpenGL

Roll is the main annoyance why many resort to storing heading, pitch, roll angles or any of other Euler angles.

After you camera is set up in space: in most cases roll can be calculated as
roll = atan2(-modelview[4], modelview[5]); // modelview matrix
OpenGL operates with angles in degress, not in radians. Then you can issue
glRotate(roll, 0,0,1);
thereby making vertical lines vertical again. The only problem is when camera looks exactly up or down (pitch=90 or -90), then there is no difference between heading and pitch, in that case it's best to NOT compensate the angle, cause the camera would be rotating wildly, but if you need to know:
roll = acos(-m[15]);
[!] use only when abs(m[2])<0.001 and abs(m[4])<0.001
You might need to multiply your roll value by degrees-to-radians or radians-to-degrees constants depending on what unit system your programming language use. OpenGL uses angles; C++ for example, uses radians [Note: OpenGL under C++ still uses angles for input, and atan2 call in C++ still returns radians].