This is a common problem. You apply many rotations, and over time, the rounding errors sum up. After a while, the three vectors vUp
, vLook
and vRight
are not normalized and orthogonal anymore.
I would use one of two options:
1.
Don't store vLook
and vRight
; instead, just store 2 angles. Assuming x is right, y is top, z is back, store a) the angle between your view axis and the xz-Plane, and b) the angle between the projection of your view axis on the xz-Plane and the z-Axis or x-Axis. Update these angles according to mouse move and calculate vLook
and vRight
from them.
2.
Set the y-component of vRight
to 0, as vRight
should be in the xz-Plane. Then re-orthonormalize the vectors (you know the vectors should be perpendicular to each other and have length 1). So after calculating the new vLook
and vRight
, apply these corrections:
vRight.y = 0
vRight = Normalize(vRight)
vUp = Normalize(Cross(vLook, vRight))
vLook = Normalize(Cross(vRight, vUp))