46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
using OpenTK.Mathematics;
|
|
using VoxelEngine.Core;
|
|
using VoxelEngine.Rendering;
|
|
using VoxelChunk = VoxelEngine.World.Chunk.Chunk;
|
|
|
|
namespace VoxelEngine.Game;
|
|
|
|
public sealed class Player
|
|
{
|
|
private readonly Configuration _cfg;
|
|
|
|
public Camera Camera { get; }
|
|
public Vector3 Position => this.Camera.Position;
|
|
public float MoveSpeed => this._cfg.MoveSpeed;
|
|
public float MouseSensitivity => this._cfg.MouseSensitivity;
|
|
|
|
public Vector3i ChunkPosition
|
|
{
|
|
get
|
|
{
|
|
Vector3 p = this.Position;
|
|
return new Vector3i(
|
|
Player.FloorDiv((int)MathF.Floor(p.X), VoxelChunk.Size),
|
|
Player.FloorDiv((int)MathF.Floor(p.Y), VoxelChunk.Size),
|
|
Player.FloorDiv((int)MathF.Floor(p.Z), VoxelChunk.Size));
|
|
}
|
|
}
|
|
|
|
public Player(Configuration cfg, Vector3 spawnPosition, float aspectRatio)
|
|
{
|
|
this._cfg = cfg;
|
|
this.Camera = new Camera(spawnPosition, aspectRatio) { Fov = cfg.Fov };
|
|
}
|
|
|
|
public void Move(Vector3 delta) => this.Camera.Move(delta);
|
|
|
|
public void AddRotation(float yawDelta, float pitchDelta) => this.Camera.AddRotation(yawDelta, pitchDelta);
|
|
|
|
private static int FloorDiv(int value, int size)
|
|
{
|
|
int q = value / size;
|
|
if (value % size != 0 && value < 0) q--;
|
|
return q;
|
|
}
|
|
}
|