some C# cause why not. C# guy might like this? idk. some python too. mostly simulations. WindowsAPI C# is good i guess
This commit is contained in:
50
simulations/fluids/fluidsC#/Camera.cs
Normal file
50
simulations/fluids/fluidsC#/Camera.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using OpenTK.Mathematics;
|
||||
|
||||
namespace fluidsC_;
|
||||
|
||||
public class Camera
|
||||
{
|
||||
public Vector3 Position;
|
||||
public float AspectRatio;
|
||||
|
||||
public Vector3 Front = -Vector3.UnitZ;
|
||||
public Vector3 Up = Vector3.UnitY;
|
||||
public Vector3 Right = Vector3.UnitX;
|
||||
|
||||
public float Pitch;
|
||||
public float Yaw = -MathHelper.PiOver2;
|
||||
|
||||
public float Speed = 2.5f;
|
||||
public float Sensitivity = 0.002f;
|
||||
|
||||
public Camera(Vector3 position, float aspectRatio)
|
||||
{
|
||||
Position = position;
|
||||
AspectRatio = aspectRatio;
|
||||
UpdateVectors();
|
||||
}
|
||||
|
||||
public Matrix4 GetViewMatrix()
|
||||
{
|
||||
return Matrix4.LookAt(Position, Position + Front, Up);
|
||||
}
|
||||
|
||||
public Matrix4 GetProjectionMatrix()
|
||||
{
|
||||
return Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4, AspectRatio, 0.01f, 100.0f);
|
||||
}
|
||||
|
||||
public void UpdateVectors()
|
||||
{
|
||||
// Calculate the new Front vector
|
||||
Front.X = MathF.Cos(Yaw) * MathF.Cos(Pitch);
|
||||
Front.Y = MathF.Sin(Pitch);
|
||||
Front.Z = MathF.Sin(Yaw) * MathF.Cos(Pitch);
|
||||
|
||||
Front = Vector3.Normalize(Front);
|
||||
|
||||
// Also re-calculate the Right and Up vector
|
||||
Right = Vector3.Normalize(Vector3.Cross(Front, Vector3.UnitY));
|
||||
Up = Vector3.Normalize(Vector3.Cross(Right, Front));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user