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 RecrownedAthenaeum.Camera
{
///
/// A generic 3D camera.
///
public class Camera
{
///
/// Current position in the world.
///
public Vector3 position;
///
/// The place the 3D camera is looking at.
///
public Vector3 lookAt;
///
/// The direction up is for the 3D camera.
///
public Vector3 upDirection;
///
/// The transform matrix representing the world (rotation and translations of the original world).
///
public Matrix worldMatrix;
///
/// The view matrix that describes where the camera looks.
///
public Matrix ViewMatrix { get; private set; }
///
/// The projection matrix.
///
public Matrix projectionMatrix;
///
/// The final transformation matrix.
///
public Matrix TransformationMatrix { get; private set; }
///
/// The graphics device used
///
protected GraphicsDevice graphicsDevice;
///
/// Constructs 3D camera with an orthographic projection matrix with dimensions of graphics devices viewport. All changes to matrices should have apply called after changes.
///
/// The graphics device to use. Will use graphics device from 's graphics device manager if this is null which it is by default.
public Camera(GraphicsDevice graphicsDevice = null)
{
this.graphicsDevice = graphicsDevice ?? (Configuration.GraphicsDeviceManager.GraphicsDevice);
position.Z = 0;
worldMatrix = Matrix.Identity;
lookAt = Vector3.Forward;
upDirection = Vector3.Up;
Center();
projectionMatrix = Matrix.CreateOrthographic(graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height, 0, 1);
Apply();
}
///
/// Applies the changes to the fields and properties of the camera.
///
public virtual void Apply()
{
ViewMatrix = Matrix.CreateLookAt(position, lookAt, upDirection);
TransformationMatrix = worldMatrix * ViewMatrix * projectionMatrix;
}
///
/// Centers the camera to middle of width and height of game window.
///
public void Center()
{
position.X = this.graphicsDevice.Viewport.Width * 0.5f;
position.Y = this.graphicsDevice.Viewport.Height * 0.5f;
}
}
}