Advertisement

quaternion rotation problems

Started by September 16, 2003 02:58 PM
-1 comments, last by Gonosz 21 years, 5 months ago
Hi, I''ve got a problem with 3D rotation. I am writing a small flight simulator (or, to be precise, something like that ), and I''m using quaternions for rotations. But after some yaw/pitch/roll changes the model I''m using is no more pointing in the direction of the velocity. The rotation code is as follows: dir.postMult(f00Quat(-deltadir.y, 1.0f, 0.0f, 0.0f)); dir.postMult(f00Quat(-deltadir.x, 0.0f, 1.0f, 0.0f)); dir.postMult(f00Quat(-deltadir.z, 0.0f, 0.0f, 1.0f)); (dir is a quaternion for storing the plane orientation) glLoadIdentity(); gluLookAt(campoint.x, campoint.y, campoint.z, position.x, position.y, position.z, 0.0, 1.0, 0.0); glTranslated(position.x, position.y, position.z); GLfloat matrix[16]; planeorient->getMatrix(matrix); glMultMatrixf(matrix); DrawShip(); where planeorient is another quaternion, which has the same rotations as ''dir'', but inverted - it works, but it''s kindda strange that I have to transform the plane with the inverted rotations to get it right... (so the physics uses the ''dir'' quaternion, but the graphics needs ''planeorient'') (BTW this is a fly-by-cam) I''m pretty sure that the quaternion class is okay, since it isn''t my code Is there anything wrong in this code ? Or is there an easier way to do three degree of freedom rotations ? I''ve tried some other ways, but only the first rotation worked, the other two seemed to rotate the plane around the _original_ axis instead of the transformed ones. Thanks for your help, Baloo

This topic is closed to new replies.

Advertisement