2018-11-11 20:44:30 +00:00
|
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace RhythmBullet.Zer01HD.Utilities.Camera
|
|
|
|
|
{
|
2018-11-12 05:05:51 +00:00
|
|
|
|
public class Camera2D
|
2018-11-11 20:44:30 +00:00
|
|
|
|
{
|
|
|
|
|
public float Zoom;
|
|
|
|
|
public Vector2 Position;
|
2018-11-12 05:05:51 +00:00
|
|
|
|
public Matrix TransformMatrix { get; private set; }
|
|
|
|
|
public GraphicsDevice graphicsDevice;
|
|
|
|
|
|
|
|
|
|
public Camera2D(GraphicsDevice graphicsDevice)
|
|
|
|
|
{
|
|
|
|
|
this.graphicsDevice = graphicsDevice;
|
|
|
|
|
Zoom = 1f;
|
|
|
|
|
Position.X = this.graphicsDevice.Viewport.Width * 0.5f;
|
|
|
|
|
Position.Y = this.graphicsDevice.Viewport.Height * 0.5f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update()
|
2018-11-11 20:44:30 +00:00
|
|
|
|
{
|
2018-11-12 05:05:51 +00:00
|
|
|
|
Rectangle bounds = graphicsDevice.Viewport.Bounds;
|
|
|
|
|
TransformMatrix =
|
|
|
|
|
Matrix.CreateTranslation(new Vector3(-Position.X, -Position.Y, 0)) *
|
2018-11-11 20:44:30 +00:00
|
|
|
|
Matrix.CreateScale(Zoom) *
|
2018-11-12 05:05:51 +00:00
|
|
|
|
Matrix.CreateTranslation(new Vector3(bounds.Width * 0.5f, bounds.Height * 0.5f, 0f));
|
2018-11-11 20:44:30 +00:00
|
|
|
|
}
|
2018-11-12 06:33:40 +00:00
|
|
|
|
|
|
|
|
|
public void LinearInterpolationToPosition(float alpha, Vector2 targetPosition)
|
|
|
|
|
{
|
|
|
|
|
if (alpha < 0 && alpha > 1f) throw new ArgumentException("Alpha can't be greater than 1f, or less than 0.");
|
|
|
|
|
Position.X = MathHelper.Lerp(Position.X, targetPosition.X, alpha);
|
|
|
|
|
Position.Y = MathHelper.Lerp(Position.Y, targetPosition.Y, alpha);
|
|
|
|
|
}
|
2018-11-11 20:44:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|