The following is a code snippet from the camera class in my current DX9 terrain engine:
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?
Source Code
- void Camera::rotate(float head, float pitch, float roll)
- {
- head = D3DXToRadian(head);
- pitch = D3DXToRadian(pitch);
- roll = D3DXToRadian(roll);
- D3DXQUATERNION rot, result;
- // Yaw the camera about its local y-axis.
- D3DXQuaternionRotationAxis(&rot, &WORLD_YAXIS, -head);
- D3DXQuaternionMultiply(&orientation, &orientation, &rot);
- // Pitch the camera about its local x-axis.
- D3DXQuaternionRotationAxis(&rot, &WORLD_XAXIS, -pitch);
- D3DXQuaternionMultiply(&orientation, &orientation, &rot);
- // Roll the camera about its local z-axis.
- D3DXQuaternionRotationAxis(&rot, &WORLD_ZAXIS, roll);
- D3DXQuaternionMultiply(&orientation, &orientation, &rot);
- update();
- }
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?