Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualBCullis

Posted 30 January 2013 - 12:17 PM

I see. Now it makes more sense. So, where the look-at vector comes from? It is computed from mouse input?

It depends on your implementation.  I could technically say "yes" when talking about my own code, because mouse movement alters the camera's rotation, and that rotation modifies the camera's "Forward" vector, which is used together with the camera's world position to make my look-at matrix.  But the DirectX LookAt method takes an origin and a destination, and calculates the matrix that would represent a view "looking at" the destination from the origin.

 

The following is C# code, but probably explains better than I just tried to:

(_rotation is a vector representing x, y, and z-axis rotation of the camera)

public virtual void Update(float timeDelta)
        {
            Matrix rotation = Matrix.RotationYawPitchRoll(_rotation.Y, _rotation.X, 0);
            _forward = Vector3.TransformCoordinate(Vector3.UnitZ, rotation);
            _up = Vector3.TransformCoordinate(Vector3.UnitY, rotation);
            _left = Vector3.Normalize(Vector3.Cross(_forward, _up));
            _viewMatrix = Matrix.LookAtLH(_worldPosition, _worldPosition + _forward, _up);
        }

#1BCullis

Posted 30 January 2013 - 12:15 PM

I see. Now it makes more sense. So, where the look-at vector comes from? It is computed from mouse input?

It depends on your implementation.  I could technically say "yes" when talking about my own code, because mouse movement alters the camera's rotation, and that rotation modifies the camera's "Forward" vector, which is used together with the camera's world position to make my look-at matrix.  But the DirectX LookAt method takes an origin and a destination, and calculates the matrix that would represent a view "looking at" the destination from the origin.

 

The following is C# code, but probably explains better than I just tried to:

public virtual void Update(float timeDelta)
        {
            Matrix rotation = Matrix.RotationYawPitchRoll(_rotation.Y, _rotation.X, 0);
            _forward = Vector3.TransformCoordinate(Vector3.UnitZ, rotation);
            _up = Vector3.TransformCoordinate(Vector3.UnitY, rotation);
            _left = Vector3.Normalize(Vector3.Cross(_forward, _up));
            _viewMatrix = Matrix.LookAtLH(_worldPosition, _worldPosition + _forward, _up);
        }

PARTNERS