My camera has an origin and an orientation (quaternion). The origin and quaternion are lerped and slerped between logical updates. The camera vector components (direction, origin, up, left) are computed every frame for the renderer (in my case it goes directly into a gluLookAt()):
void Camera::update() {
direction = (orientation * Vector<3>(0, 0, 1)).normalize();
up = (Vector<3>(0, 1, 0)).normalize();
left = Vector<3>::cross(up, direction);
}
void Camera::translate(const Vector<3>& amount) {
origin += amount;
}
void Camera::rotate(const Vector<3>& axis, const Angle& angle) {
orientation *= Quaternion<>::fromAxisAngle(axis, angle);
orientation.normalize();
}
This all seems to work fine, but when I rotate the camera by the mouse then I get strange results. Here is the camera rotation code (Lua):
self.camera : rotate(self.camera.left, Angle(self.rotateVelocity.y)) self.camera : rotate(self.camera.up, Angle(self.rotateVelocity.x)) self.camera : translate(self.velocity)
(self.rotateVelocity is the change in mouse coordinates)
At first the rotation appears to be correct, but as I turn the camera around the y-axis rotation inverts (moving mouse up makes camera rotate down) and if I face left the camera does not rotate at all vertically. It seems as though my camera's left vector is incorrect, but I know that it is correct (camera strafing works).
I am also sure that my quaternion rotation is correct, I believe I am just using them incorrectly. Is there anything obviously wrong with my approach?






