Camera question

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Camera question

      The following is a code snippet from the camera class in my current DX9 terrain engine:

      Source Code

      1. void Camera::rotate(float head, float pitch, float roll)
      2. {
      3. head = D3DXToRadian(head);
      4. pitch = D3DXToRadian(pitch);
      5. roll = D3DXToRadian(roll);
      6. D3DXQUATERNION rot, result;
      7. // Yaw the camera about its local y-axis.
      8. D3DXQuaternionRotationAxis(&rot, &WORLD_YAXIS, -head);
      9. D3DXQuaternionMultiply(&orientation, &orientation, &rot);
      10. // Pitch the camera about its local x-axis.
      11. D3DXQuaternionRotationAxis(&rot, &WORLD_XAXIS, -pitch);
      12. D3DXQuaternionMultiply(&orientation, &orientation, &rot);
      13. // Roll the camera about its local z-axis.
      14. D3DXQuaternionRotationAxis(&rot, &WORLD_ZAXIS, roll);
      15. D3DXQuaternionMultiply(&orientation, &orientation, &rot);
      16. update();
      17. }
      Display All


      The orientation variable is a class member.

      I am using the default D3D left handed coordinate system here. Positive rotations about an axis should result in a clockwise rotation when looking along the axis towards the origin. A positive heading change should rotate the camera to the right. A positive pitch change should rotate the camera downwards. A positive roll change should rotate the camera counter clockwise.

      When testing this code I could only get the expected results by negating the head and pitch angles. That makes sense since rotating a camera left is the same as rotating the world to the right of the camera. If that's the case then why not also negate the roll angle as well? When negating the roll angle as well I get the incorrect result.

      The code seems to work fine...but those two negatives screams HACK to me ?(

      Any ideas?
    • That code makes perfect sense to me. If you were using the righthand coord system the roll and yaw would have to be negative and the pitch would be positive. Just rotate your coordinate system so that the axis you want to turn on is temporarily z, then try your rotation - then translate it back - its hard to visualize at first, but it's right....

      An artifact of an imperfect world....

      Rich
      "Your job is not to die for your country. Your job is to make some other poor sod die for his."