diff --git a/MonoGame.Extended/MonoGame.Extended/Camera2D.cs b/MonoGame.Extended/MonoGame.Extended/Camera2D.cs index 5f007c30..b96affbf 100644 --- a/MonoGame.Extended/MonoGame.Extended/Camera2D.cs +++ b/MonoGame.Extended/MonoGame.Extended/Camera2D.cs @@ -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)); } } }