protected void UpdateMatrices()
{
// grab a reference to the current render system
RenderSystem renderSystem = Root.Instance.RenderSystem;
if ( ProjectionType == Projection.Perspective )
{
// perspective transform, API specific
Matrix4 tmp;
renderSystem.MakeProjectionMatrix( FieldOfView, AspectRatio, Near, Far, out tmp );
ProjectionMatrix = tmp;
}
else if ( ProjectionType == Projection.Orthographic )
{
// orthographic projection, API specific
Matrix4 tmp;
renderSystem.MakeOrthoMatrix( FieldOfView, AspectRatio, Near, Far, out tmp );
ProjectionMatrix = tmp;
}
// View matrix is:
//
// [ Lx Uy Dz Tx ]
// [ Lx Uy Dz Ty ]
// [ Lx Uy Dz Tz ]
// [ 0 0 0 1 ]
//
// Where T = -(Transposed(Rot) * Pos)
// This is most efficiently done using 3x3 Matrices
// Get orientation from quaternion
Quaternion orientation = lightOrientation;
Vector3 position = lightPosition;
Matrix3 rotation = orientation.ToRotationMatrix();
Vector3 left = rotation.GetColumn( 0 );
Vector3 up = rotation.GetColumn( 1 );
Vector3 direction = rotation.GetColumn( 2 );
// make the translation relative to the new axis
Matrix3 rotationT = rotation.Transpose();
Vector3 translation = -rotationT * position;
// initialize the upper 3x3 portion with the rotation
_viewMatrix = rotationT;
// add the translation portion, add set 1 for the bottom right portion
_viewMatrix.m03 = translation.x;
_viewMatrix.m13 = translation.y;
_viewMatrix.m23 = translation.z;
_viewMatrix.m33 = 1.0f;
}