To main page
Roll (in heading-pitch-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, modelview); // modelview matrix
OpenGL operates with angles in degress, not in radians. Then you can issue
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
, 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);
[!] use only when abs(m)<0.001 and abs(m)<0.001
You might need to multiply your roll value by degrees-to-radians
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].
code - looking around the scene without storing heading, pitch, roll
Yaw/heading, pitch, roll