mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-24 03:56:31 +00:00
Adding bounding frustum, projection matrix, inverse view matrix
This commit is contained in:
@@ -61,6 +61,31 @@ namespace MonoGame.Extended
|
||||
public Matrix GetViewMatrix()
|
||||
{
|
||||
return GetViewMatrix(Vector2.One);
|
||||
}
|
||||
|
||||
public Matrix GetInverseViewMatrix()
|
||||
{
|
||||
return Matrix.Invert(GetViewMatrix());
|
||||
}
|
||||
|
||||
private Matrix GetProjectionMatrix(Matrix viewMatrix)
|
||||
{
|
||||
// Note: This projection matrix is the same one used inside of the MonoGame SpriteBatch by default.
|
||||
Matrix projection = Matrix.CreateOrthographicOffCenter(0, _viewportAdapter.VirtualWidth, _viewportAdapter.VirtualHeight, 0, -1, 0);
|
||||
|
||||
// Half pixel offset.
|
||||
projection.M41 += -0.5f * projection.M11;
|
||||
projection.M42 += -0.5f * projection.M22;
|
||||
|
||||
Matrix.Multiply(ref viewMatrix, ref projection, out projection);
|
||||
|
||||
return projection;
|
||||
}
|
||||
|
||||
public BoundingFrustum GetBoundingFrustum()
|
||||
{
|
||||
Matrix viewMatrix = GetViewMatrix();
|
||||
return new BoundingFrustum(viewMatrix * GetProjectionMatrix(viewMatrix));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user