53 lines
1.6 KiB
C#
53 lines
1.6 KiB
C#
using OpenTK.Mathematics;
|
|
|
|
namespace Voxel
|
|
{
|
|
static class Camera
|
|
{
|
|
public static Vector3 Position = new Vector3(-8, 16, -8);
|
|
|
|
public static float Pitch = -22.5f;
|
|
public static float Yaw = 45f;
|
|
public static float FOV = 60f;
|
|
public static float Speed = 5f;
|
|
public static float ShiftSpeed = 20f;
|
|
|
|
public static Matrix4 view =>
|
|
Matrix4.LookAt(Position, Position + Front, Vector3.UnitY);
|
|
|
|
public static Matrix4 projection;
|
|
|
|
public static Vector3 Front
|
|
{
|
|
get
|
|
{
|
|
float yawOffset = Yaw - 90f;
|
|
Vector3 front;
|
|
front.X = MathF.Cos(MathHelper.DegreesToRadians(yawOffset)) * MathF.Cos(MathHelper.DegreesToRadians(Pitch));
|
|
front.Y = MathF.Sin(MathHelper.DegreesToRadians(Pitch));
|
|
front.Z = MathF.Sin(MathHelper.DegreesToRadians(yawOffset)) * MathF.Cos(MathHelper.DegreesToRadians(Pitch));
|
|
return front.Normalized();
|
|
}
|
|
}
|
|
|
|
public static void UpdateMouse(Vector2 delta)
|
|
{
|
|
float sensitivity = 0.1f;
|
|
Yaw += delta.X * sensitivity;
|
|
Pitch -= delta.Y * sensitivity;
|
|
|
|
Pitch = MathHelper.Clamp(Pitch, -89f, 89f);
|
|
}
|
|
|
|
public static void UpdateProjection(int width, int height)
|
|
{
|
|
float fov = MathHelper.DegreesToRadians(FOV);
|
|
float aspectRatio = width / (float)height;
|
|
float near = 0.1f;
|
|
float far = 1000f;
|
|
|
|
projection = Matrix4.CreatePerspectiveFieldOfView(fov, aspectRatio, near, far);
|
|
}
|
|
}
|
|
}
|