update
This commit is contained in:
73
Camera.cs
Normal file
73
Camera.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using OpenTK.Mathematics;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Voxel
|
||||
{
|
||||
static class Camera
|
||||
{
|
||||
public static Vector3 Position;
|
||||
|
||||
public static float Pitch = 0f;
|
||||
public static float Yaw = -90f;
|
||||
public static float FOV = 70f;
|
||||
public static float Speed = 0.5f;
|
||||
|
||||
public static Matrix4 view =>
|
||||
Matrix4.LookAt(Position, Position + Front, Vector3.UnitY);
|
||||
|
||||
public static Matrix4 projection;
|
||||
|
||||
public static Vector3 Front
|
||||
{
|
||||
get
|
||||
{
|
||||
Vector3 front;
|
||||
front.X = MathF.Cos(MathHelper.DegreesToRadians(Yaw)) * MathF.Cos(MathHelper.DegreesToRadians(Pitch));
|
||||
front.Y = MathF.Sin(MathHelper.DegreesToRadians(Pitch));
|
||||
front.Z = MathF.Sin(MathHelper.DegreesToRadians(Yaw)) * MathF.Cos(MathHelper.DegreesToRadians(Pitch));
|
||||
return front.Normalized();
|
||||
}
|
||||
}
|
||||
|
||||
public static void Update(float time)
|
||||
{
|
||||
float moveSpeed = Speed * time;
|
||||
if (Input.GetKey(OpenTK.Windowing.GraphicsLibraryFramework.Keys.LeftShift))
|
||||
{
|
||||
moveSpeed *= 10;
|
||||
}
|
||||
if (Input.GetKey(OpenTK.Windowing.GraphicsLibraryFramework.Keys.W))
|
||||
{
|
||||
Position += Front * moveSpeed;
|
||||
}
|
||||
if (Input.GetKey(OpenTK.Windowing.GraphicsLibraryFramework.Keys.S))
|
||||
{
|
||||
Position += Front * -moveSpeed;
|
||||
}
|
||||
if (Input.GetKey(OpenTK.Windowing.GraphicsLibraryFramework.Keys.A))
|
||||
{
|
||||
Position += Vector3.Cross(Front, Vector3.UnitY).Normalized() * -moveSpeed;
|
||||
}
|
||||
if (Input.GetKey(OpenTK.Windowing.GraphicsLibraryFramework.Keys.D))
|
||||
{
|
||||
Position += Vector3.Cross(Front, Vector3.UnitY).Normalized() * moveSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateMouse(Vector2 delta)
|
||||
{
|
||||
float fov = MathHelper.DegreesToRadians(60f);
|
||||
float aspectRatio = 800f / 600f;
|
||||
float near = 0.1f;
|
||||
float far = 100f;
|
||||
|
||||
projection = Matrix4.CreatePerspectiveFieldOfView(fov, aspectRatio, near, far);
|
||||
|
||||
float sensitivity = 0.1f;
|
||||
Yaw += delta.X * sensitivity;
|
||||
Pitch -= delta.Y * sensitivity;
|
||||
|
||||
Pitch = MathHelper.Clamp(Pitch, -89f, 89f);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user