51 lines
1.8 KiB
C#
51 lines
1.8 KiB
C#
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using System;
|
|
|
|
namespace RecrownedAthenaeum.Camera
|
|
{
|
|
/// <summary>
|
|
/// A virtual 2D camera that wraps the normal <see cref="Camera3D"/>. Default projection is orthographic.
|
|
/// </summary>
|
|
public class Camera2D : Camera3D
|
|
{
|
|
|
|
/// <summary>
|
|
/// The 2D position.
|
|
/// </summary>
|
|
public Vector2 Position { get { return new Vector2(position.X, position.Y); } set { position.X = value.X; position.Y = value.Y; } }
|
|
|
|
/// <summary>
|
|
/// A 2D camera from the generic <see cref="Camera3D"/>.
|
|
/// </summary>
|
|
/// <param name="graphicsDevice">The graphics device to use if not using the one in <see cref="Configuration"/>.</param>
|
|
public Camera2D(GraphicsDevice graphicsDevice = null) : base(graphicsDevice)
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lerps to the given position.
|
|
/// </summary>
|
|
/// <param name="alpha">The multiplier for difference in distance.</param>
|
|
/// <param name="targetPosition">The target position to lerp to.</param>
|
|
/// <param name="delta">Time between this frame and the previous frame.</param>
|
|
public void LinearInterpolationToPosition(float alpha, Vector2 targetPosition, float delta)
|
|
{
|
|
if (alpha <= 0 && alpha > 1f) throw new ArgumentException("Alpha can't be greater than 1f, less than or equal to 0.");
|
|
|
|
Vector2 distance = targetPosition - Position;
|
|
distance *= (float)(1.0f - Math.Pow(1 - alpha, delta / 0.02f));
|
|
|
|
Position += distance;
|
|
|
|
Apply();
|
|
}
|
|
|
|
private Matrix BasicOrthographic()
|
|
{
|
|
return Matrix.CreateOrthographic(graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height, 0, 1);
|
|
}
|
|
}
|
|
}
|