Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualJohnnyCode

Posted 24 April 2014 - 06:35 AM

void Matrix4f::InitCamera( const Vector3f& forward, const Vector3f& up ) {
Vector3f f = forward.GetNorm(); // actual normalized forward
Vector3f r = up.GetNorm();
r = r.Cross( f ).GetNorm(); // actual right vector
Vector3f u = f.Cross( r ).GetNorm(); // recalculated up



this is gimbal lock. Look at matrix is constructed from lookto direction, up direction, and their cross product, and third cross product of the ones. It is 3 normalized vectors resulting in orthonormal matrix that rotates everything, with possible translation added.

If lookto vector in space "flows through" up vector (getting close enough) their crossproduct is negative, but the same direction pattern on the plane they form. Normalizing this result will still point to the new (negated) direction. Your right vector inverts

In your code I cannot to track the const Vector3f& up. Many camera implementations does not need such gimbal case to handle, up vector stays 0,1,0 constantly throuh program (the one as input, not the one in orthonormal matrix). If you need to eliminate gimbal lock, you have few options. For example to have up vector not constant but kept as a vector in the plane that cuts verticaly through the camera and always with the same moment towards lookat vector (not necesarilly angle, only moment)

#1JohnnyCode

Posted 23 April 2014 - 04:59 PM

    void Matrix4f::InitCamera( const Vector3f& forward, const Vector3f& up ) {
        Vector3f f = forward.GetNorm(); // actual normalized forward
        Vector3f r = up.GetNorm();
        r = r.Cross( f ).GetNorm(); // actual right vector
        Vector3f u = f.Cross( r ).GetNorm(); // recalculated up

 

 

 

this is gimbal lock. Look at matrix is constructed from lookto direction, up direction, and their cross product, and third cross product of the ones. It is 3 normalized vectors resulting in orthonormal matrix that rotates everything, with possible translation added.

 

If lookto vector in space "flows through" up vector (getting close enough) their crossproduct is negative, but the same direction pattern on the plane they form. Normalizing this result will still point to the new (negated) direction. Your right vector inverts

 

In your code I cannot to track the const Vector3f& up. Many camera implementations  does not need such gimbal case to handle, up vector stays 0,1,0 constantly throuh program (the one as input, not the one in orthonormal matrix). If you need to eliminate gimbal lock, you have few options. For example to have up vector not constant but kept  as a vector in the plane that cuts verticaly through the camera and always with the same moment towards lookat vector (not necesarilly angle, only moment)

 

Try this:

get yourself desired lookat vector (x,y,z), and construct up vector such as (x,y+y*y,z) and pass this as the up vector to the InitCamera function, should work as I think about it.


PARTNERS