I have implemented an orbit camera and it seems to work but there is a strange twitch that happens when I rotate around the Y-axis too fast. I have recorded and posted it to youtube for your viewing pleasure :). If I move slowly it seems okay, but if I move the mouse quickly right/left, the entire scene becomes kind of skewed. The problem is most prominent in the angle recorded on the video and does not happen if the camera direction is parallel with the floor. I am not sure what could be causing it.
The camera code:
void CameraControl::Update(Camera *camera, UserInput *input)
{
// Rotation
// position and previousPosition are the positions of the mouse
float yaw = (input->position.x - input->previousPosition.x) * -0.005f;
float pitch = (input->position.y - input->previousPosition.y) * -0.005f;
Vector3 targetToCameraVector = camera->position - camera->target;
float length = Math::Length(targetToCameraVector);
targetToCameraVector = Math::Normalize(targetToCameraVector);
Vector3 forward = -targetToCameraVector;
Vector3 right = Math::CrossProduct(forward, Vector3(0, 1, 0));
right = Math::Normalize(right);
Vector3 up = Math::CrossProduct(right, forward);
up = Math::Normalize(up);
Vector4 rotatedTargetToCameraVector = Math::GetRotation(pitch, right) *
Math::GetRotation(yaw, Vector3(0, 1, 0)) * Vector4(targetToCameraVector, 0.0f);
camera->position = camera->target + Math::Normalize(Vector3(rotatedTargetToCameraVector)) * length;
camera->viewMatrix = Math::LookAt(camera->position, camera->target, up);
}
I would welcome any suggestions. Thanks.