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 Camera3D
{
///
/// The zoom of the camera.
///
public float worldScale = 1f;
///
/// 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; protected set; }
///
/// The projection matrix.
///
public Matrix projectionMatrix;
///
/// The graphics device used
///
protected GraphicsDevice graphicsDevice;
///
/// The basic effect that contains the transformations.
///
public BasicEffect BasicEffect { get; protected set; }
///
/// 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 Camera3D(GraphicsDevice graphicsDevice = null)
{
graphicsDevice = graphicsDevice ?? (Configuration.GraphicsDeviceManager.GraphicsDevice);
this.graphicsDevice = graphicsDevice;
worldMatrix = Matrix.Identity;
lookAt = Vector3.Forward;
upDirection = Vector3.Up;
projectionMatrix = Matrix.Identity;
BasicEffect = new BasicEffect(graphicsDevice);
BasicEffect.TextureEnabled = true;
BasicEffect.VertexColorEnabled = true;
Apply();
}
///
/// Applies the changes to the fields and properties of the camera.
///
public virtual void Apply()
{
ViewMatrix = Matrix.CreateLookAt(position, lookAt, upDirection);
worldMatrix *= Matrix.CreateScale(worldScale);
BasicEffect.World = worldMatrix;
BasicEffect.View = ViewMatrix;
BasicEffect.Projection = projectionMatrix;
}
///
/// Moves camera by the given amount.
///
/// A that contains how much in each direction to move.
public void MoveCamera(Vector3 move)
{
position += move;
Apply();
}
}
}