Camera in functional state.

This commit is contained in:
2018-11-11 23:05:51 -06:00
parent 3c44a52a8f
commit a2defc5d11
6 changed files with 40 additions and 21 deletions

View File

@@ -8,18 +8,28 @@ using System.Threading.Tasks;
namespace RhythmBullet.Zer01HD.Utilities.Camera
{
class Camera2D
public class Camera2D
{
public float Zoom;
public Vector2 Position;
public Matrix Transform { get; private set; }
public void Update(Viewport viewport)
public Matrix TransformMatrix { get; private set; }
public GraphicsDevice graphicsDevice;
public Camera2D(GraphicsDevice graphicsDevice)
{
Transform =
Matrix.CreateTranslation(new Vector3(Position.X, Position.Y, 0)) *
this.graphicsDevice = graphicsDevice;
Zoom = 1f;
Position.X = this.graphicsDevice.Viewport.Width * 0.5f;
Position.Y = this.graphicsDevice.Viewport.Height * 0.5f;
}
public void Update()
{
Rectangle bounds = graphicsDevice.Viewport.Bounds;
TransformMatrix =
Matrix.CreateTranslation(new Vector3(-Position.X, -Position.Y, 0)) *
Matrix.CreateScale(Zoom) *
Matrix.CreateTranslation(new Vector3(viewport.Width/2f, viewport.Height/2f, 0f));
Matrix.CreateTranslation(new Vector3(bounds.Width * 0.5f, bounds.Height * 0.5f, 0f));
}
}
}