mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-21 01:39:32 +00:00
Merge pull request #3 from WardBenjamin/feature-camera/utils
Camera utility features
This commit is contained in:
@@ -61,6 +61,61 @@ 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));
|
||||
}
|
||||
|
||||
public bool Contains(Point point)
|
||||
{
|
||||
return GetBoundingFrustum().Contains(new Vector3(point.X, point.Y, 0)) != ContainmentType.Disjoint;
|
||||
}
|
||||
|
||||
public bool Contains(Vector2 point)
|
||||
{
|
||||
return GetBoundingFrustum().Contains(new Vector3(point.X, point.Y, 0)) != ContainmentType.Disjoint;
|
||||
}
|
||||
|
||||
public bool Contains(Rectangle rectangle)
|
||||
{
|
||||
return GetBoundingFrustum().Contains(new BoundingBox(new Vector3(0, 0, 0), new Vector3(15, 15, 0))) != ContainmentType.Disjoint;
|
||||
}
|
||||
|
||||
public ContainmentType Contains(Point point)
|
||||
{
|
||||
return GetBoundingFrustum().Contains(new Vector3(point.X, point.Y, 0));
|
||||
}
|
||||
|
||||
public ContainmentType Contains(Vector2 point)
|
||||
{
|
||||
return GetBoundingFrustum().Contains(new Vector3(point.X, point.Y, 0));
|
||||
}
|
||||
|
||||
public ContainmentType Contains(Rectangle rectangle)
|
||||
{
|
||||
return GetBoundingFrustum().Contains(new BoundingBox(new Vector3(0, 0, 0), new Vector3(15, 15, 0)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user