I'm programming a 3D game where the user controls a first-person camera, and movement is constrained to the inside surface of a sphere. I've managed to constrain the movement, but I'm having trouble figuring out how to manage the camera orientation using quaternions. Ideally the camera up vector should point along the normal of the sphere towards its center, and user should be able to free look around - as if we was always on the bottom of the sphere, no matter where he moves.
A:
Quaternions are normally used to avoid gimbal lock in free space motion (flight sims, etc.). In your case, you actually want the gimbal effect, since a camera that is forced to stay upright will inevitably behave strangely when it has to point almost straight up or down.
You should be able to represent the camera's orientation as just a latitude/longitude pair indicating the direction the camera is pointing.
Marcelo Cantos
2010-10-29 11:33:59
Can you please elaborate? Why will a camera behave strangely when pointing up or down? And how can you find the camera transformation from simply a latitude/longitude pair?
thekidder
2010-10-29 11:41:15
Because a small change in direction may tilt the camera past the pole, requiring a sudden 180° flip in order to keep the camera's "Up" facing north. This is known as gimbal lock.
Marcelo Cantos
2010-10-29 12:00:42
The transform is simply the combination of rotating around the z-axis to produce longitude rotation and around the x-axis to produce latitude rotation (assuming the untransformed camera points along the y-axis).
Marcelo Cantos
2010-10-29 12:03:47