fixed movement
This commit is contained in:
23
Camera.cs
23
Camera.cs
@@ -9,9 +9,14 @@ namespace Voxel
|
||||
public static float Pitch = -22.5f;
|
||||
public static float Yaw = 0f;
|
||||
public static float FOV = 60f;
|
||||
public static float TargetFOV = FOV;
|
||||
public static float FOVLerpSpeed = 10f;
|
||||
public static float Speed = 5f;
|
||||
public static float ShiftSpeed = 20f;
|
||||
|
||||
private static int _width;
|
||||
private static int _height;
|
||||
|
||||
public static Matrix4 view =>
|
||||
Matrix4.LookAt(Position, Position + Front, Vector3.UnitY);
|
||||
|
||||
@@ -39,14 +44,28 @@ namespace Voxel
|
||||
Pitch = MathHelper.Clamp(Pitch, -89f, 89f);
|
||||
}
|
||||
|
||||
public static void UpdateProjection(int width, int height)
|
||||
public static void UpdateProjection()
|
||||
{
|
||||
float fov = MathHelper.DegreesToRadians(FOV);
|
||||
float aspectRatio = width / (float)height;
|
||||
float aspectRatio = _width / (float)_height;
|
||||
float near = 0.1f;
|
||||
float far = 1000f;
|
||||
|
||||
projection = Matrix4.CreatePerspectiveFieldOfView(fov, aspectRatio, near, far);
|
||||
}
|
||||
|
||||
public static void UpdateSize(int width, int height)
|
||||
{
|
||||
_width = width;
|
||||
_height = height;
|
||||
UpdateProjection();
|
||||
}
|
||||
|
||||
public static void UpdateFOV(float deltaTime, float alpha)
|
||||
{
|
||||
float currentFOV = MathHelper.Lerp(FOV, TargetFOV, FOVLerpSpeed * deltaTime);
|
||||
Camera.FOV = currentFOV;
|
||||
Camera.UpdateProjection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user