Reputation: 143
I am trying to make something like - lets call it flight simulator using modern OpenGL. I am trying to use yaw, pitch and roll to rotate my plane object. But it seems object rotates around global coordinate system (I mean if my object faces vector (0,0,1) roll operation works like it should but if i turn it to face for example (1,0,0) it behaves like pitch)
my transformation matrix is calculated like this:
transformation_matrix = perspective_projection_matrix *
camera_rotation_matrix *
camera_translation_matrix *
translation_matrix *
rotation_matrix *
scale_matrix;
Rotation matrix is
rotation_matrix = rotation_z * rotation_y * rotation_x;
I tried to add local rotation matrix before translation one but it looks even worse (object now flies around some point in space facing always default)
What should I do to rotate object like typical plane with yaw, pitch and roll in local coordinates system?
EDIT
I also noticed that rotation is performed in global coordinate system with camera position as (0,0,0)
Not the case, my bad
Upvotes: 0
Views: 949
Reputation: 16582
The plane's orientation will ultimately be the concatenation of many discrete rotations around different axes. This is not the same as simply summing the individual rotations. They are not independent.
For example, if you pitch up 90 degrees, roll 90 degrees, and then pitch down 90 degrees, the resulting orientation will not be a roll of 90 degrees, but instead a yaw of 90 degrees.
Instead, keep a persistant matrix which represents the orientation of your plane, and then apply roll, pitch, and yaw rotations to it as appropriate.
Upvotes: 1