Kav/Camera.cs

45 lines
1.2 KiB
C#
Raw Normal View History

2020-08-04 09:32:02 +00:00
using Microsoft.Xna.Framework;
namespace Kav
{
public class Camera
{
public Matrix Transform { get; set; }
public Matrix Projection { get; set; }
2020-08-05 19:15:22 +00:00
public Matrix View
{
2020-08-04 09:32:02 +00:00
get
{
return Matrix.CreateLookAt(Transform.Translation, Transform.Forward, Transform.Up);
}
}
2020-08-05 19:15:22 +00:00
public float FOV { get; set; } = MathHelper.PiOver4;
public float AspectRatio { get; set; } = 1920f / 1080f;
2020-08-04 09:32:02 +00:00
public float NearPlane { get; set; } = 0.1f;
public float FarPlane { get; set; } = 200f;
public Camera(Vector3 position, Quaternion orientation)
{
Transform = Matrix.CreateFromQuaternion(orientation) * Matrix.CreateTranslation(position.X, position.Y, position.Z);
Projection = Matrix.CreatePerspectiveFieldOfView(
FOV,
AspectRatio,
2020-08-05 19:15:22 +00:00
NearPlane,
FarPlane
);
}
public Camera(Matrix transform)
{
Transform = transform;
Projection = Matrix.CreatePerspectiveFieldOfView(
FOV,
AspectRatio,
NearPlane,
2020-08-04 09:32:02 +00:00
FarPlane
);
}
}
}