style: apply code-style cleanup (explicit types, this-qualification, switch expressions)
This commit is contained in:
@@ -8,8 +8,8 @@ public sealed class Camera
|
||||
|
||||
public Vector3 Position { get; private set; }
|
||||
public float Yaw { get; private set; } = -90f; // degrees; -90 looks down -Z
|
||||
public float Pitch { get; private set; } = 0f; // degrees
|
||||
public float Fov { get; set; } = 60f; // degrees
|
||||
public float Pitch { get; private set; } // degrees
|
||||
public float Fov { get; set; } = 60f; // degrees
|
||||
public float AspectRatio { get; set; }
|
||||
|
||||
public Vector3 Front { get; private set; } = -Vector3.UnitZ;
|
||||
@@ -18,37 +18,37 @@ public sealed class Camera
|
||||
|
||||
public Camera(Vector3 position, float aspectRatio)
|
||||
{
|
||||
Position = position;
|
||||
AspectRatio = aspectRatio;
|
||||
UpdateVectors();
|
||||
this.Position = position;
|
||||
this.AspectRatio = aspectRatio;
|
||||
this.UpdateVectors();
|
||||
}
|
||||
|
||||
public void Move(Vector3 delta) => Position += delta;
|
||||
public void Move(Vector3 delta) => this.Position += delta;
|
||||
|
||||
public void AddRotation(float yawDelta, float pitchDelta)
|
||||
{
|
||||
Yaw += yawDelta;
|
||||
Pitch = MathHelper.Clamp(Pitch + pitchDelta, -89f, 89f);
|
||||
UpdateVectors();
|
||||
this.Yaw += yawDelta;
|
||||
this.Pitch = MathHelper.Clamp(this.Pitch + pitchDelta, -89f, 89f);
|
||||
this.UpdateVectors();
|
||||
}
|
||||
|
||||
public Matrix4 GetViewMatrix() => Matrix4.LookAt(Position, Position + Front, Up);
|
||||
public Matrix4 GetViewMatrix() => Matrix4.LookAt(this.Position, this.Position + this.Front, this.Up);
|
||||
|
||||
public Matrix4 GetProjectionMatrix() =>
|
||||
Matrix4.CreatePerspectiveFieldOfView(
|
||||
MathHelper.DegreesToRadians(Fov), AspectRatio, 0.1f, 100f);
|
||||
MathHelper.DegreesToRadians(this.Fov), this.AspectRatio, 0.1f, 100f);
|
||||
|
||||
private void UpdateVectors()
|
||||
{
|
||||
float yaw = MathHelper.DegreesToRadians(Yaw);
|
||||
float pitch = MathHelper.DegreesToRadians(Pitch);
|
||||
float yaw = MathHelper.DegreesToRadians(this.Yaw);
|
||||
float pitch = MathHelper.DegreesToRadians(this.Pitch);
|
||||
|
||||
Front = Vector3.Normalize(new Vector3(
|
||||
this.Front = Vector3.Normalize(new Vector3(
|
||||
MathF.Cos(yaw) * MathF.Cos(pitch),
|
||||
MathF.Sin(pitch),
|
||||
MathF.Sin(yaw) * MathF.Cos(pitch)));
|
||||
|
||||
Right = Vector3.Normalize(Vector3.Cross(Front, WorldUp));
|
||||
Up = Vector3.Normalize(Vector3.Cross(Right, Front));
|
||||
this.Right = Vector3.Normalize(Vector3.Cross(this.Front, Camera.WorldUp));
|
||||
this.Up = Vector3.Normalize(Vector3.Cross(this.Right, this.Front));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,14 +12,14 @@ public sealed class ChunkRenderer : IDisposable
|
||||
|
||||
public ChunkRenderer(float[] vertices)
|
||||
{
|
||||
_vertexCount = vertices.Length / FloatsPerVertex;
|
||||
int stride = FloatsPerVertex * sizeof(float);
|
||||
this._vertexCount = vertices.Length / ChunkRenderer.FloatsPerVertex;
|
||||
int stride = ChunkRenderer.FloatsPerVertex * sizeof(float);
|
||||
|
||||
_vao = GL.GenVertexArray();
|
||||
GL.BindVertexArray(_vao);
|
||||
this._vao = GL.GenVertexArray();
|
||||
GL.BindVertexArray(this._vao);
|
||||
|
||||
_vbo = GL.GenBuffer();
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, _vbo);
|
||||
this._vbo = GL.GenBuffer();
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, this._vbo);
|
||||
GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.StaticDraw);
|
||||
|
||||
// location 0: position (vec3) at offset 0
|
||||
@@ -39,14 +39,14 @@ public sealed class ChunkRenderer : IDisposable
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
GL.BindVertexArray(_vao);
|
||||
GL.DrawArrays(PrimitiveType.Triangles, 0, _vertexCount);
|
||||
GL.BindVertexArray(this._vao);
|
||||
GL.DrawArrays(PrimitiveType.Triangles, 0, this._vertexCount);
|
||||
GL.BindVertexArray(0);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GL.DeleteBuffer(_vbo);
|
||||
GL.DeleteVertexArray(_vao);
|
||||
GL.DeleteBuffer(this._vbo);
|
||||
GL.DeleteVertexArray(this._vao);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,38 +10,38 @@ public sealed class Shader : IDisposable
|
||||
|
||||
public Shader(string vertexPath, string fragmentPath)
|
||||
{
|
||||
int vertex = CompileFromFile(ShaderType.VertexShader, vertexPath);
|
||||
int fragment = CompileFromFile(ShaderType.FragmentShader, fragmentPath);
|
||||
int vertex = Shader.CompileFromFile(ShaderType.VertexShader, vertexPath);
|
||||
int fragment = Shader.CompileFromFile(ShaderType.FragmentShader, fragmentPath);
|
||||
|
||||
_handle = GL.CreateProgram();
|
||||
GL.AttachShader(_handle, vertex);
|
||||
GL.AttachShader(_handle, fragment);
|
||||
GL.LinkProgram(_handle);
|
||||
this._handle = GL.CreateProgram();
|
||||
GL.AttachShader(this._handle, vertex);
|
||||
GL.AttachShader(this._handle, fragment);
|
||||
GL.LinkProgram(this._handle);
|
||||
|
||||
GL.GetProgram(_handle, GetProgramParameterName.LinkStatus, out int linked);
|
||||
GL.GetProgram(this._handle, GetProgramParameterName.LinkStatus, out int linked);
|
||||
if (linked == 0)
|
||||
throw new InvalidOperationException($"Program link failed: {GL.GetProgramInfoLog(_handle)}");
|
||||
throw new InvalidOperationException($"Program link failed: {GL.GetProgramInfoLog(this._handle)}");
|
||||
|
||||
GL.DetachShader(_handle, vertex);
|
||||
GL.DetachShader(_handle, fragment);
|
||||
GL.DetachShader(this._handle, vertex);
|
||||
GL.DetachShader(this._handle, fragment);
|
||||
GL.DeleteShader(vertex);
|
||||
GL.DeleteShader(fragment);
|
||||
}
|
||||
|
||||
public void Use() => GL.UseProgram(_handle);
|
||||
public void Use() => GL.UseProgram(this._handle);
|
||||
|
||||
public void SetMatrix4(string name, Matrix4 value) =>
|
||||
GL.UniformMatrix4(Location(name), true, ref value);
|
||||
GL.UniformMatrix4(this.Location(name), true, ref value);
|
||||
|
||||
public void SetInt(string name, int value) =>
|
||||
GL.Uniform1(Location(name), value);
|
||||
GL.Uniform1(this.Location(name), value);
|
||||
|
||||
private int Location(string name)
|
||||
{
|
||||
if (!_uniforms.TryGetValue(name, out int location))
|
||||
if (!this._uniforms.TryGetValue(name, out int location))
|
||||
{
|
||||
location = GL.GetUniformLocation(_handle, name);
|
||||
_uniforms[name] = location;
|
||||
location = GL.GetUniformLocation(this._handle, name);
|
||||
this._uniforms[name] = location;
|
||||
}
|
||||
return location;
|
||||
}
|
||||
@@ -60,5 +60,5 @@ public sealed class Shader : IDisposable
|
||||
return shader;
|
||||
}
|
||||
|
||||
public void Dispose() => GL.DeleteProgram(_handle);
|
||||
public void Dispose() => GL.DeleteProgram(this._handle);
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ public sealed class Texture : IDisposable
|
||||
|
||||
public Texture(string path)
|
||||
{
|
||||
_handle = GL.GenTexture();
|
||||
GL.BindTexture(TextureTarget.Texture2D, _handle);
|
||||
this._handle = GL.GenTexture();
|
||||
GL.BindTexture(TextureTarget.Texture2D, this._handle);
|
||||
|
||||
StbImage.stbi_set_flip_vertically_on_load(1);
|
||||
using FileStream stream = File.OpenRead(path);
|
||||
@@ -28,8 +28,8 @@ public sealed class Texture : IDisposable
|
||||
public void Use(TextureUnit unit = TextureUnit.Texture0)
|
||||
{
|
||||
GL.ActiveTexture(unit);
|
||||
GL.BindTexture(TextureTarget.Texture2D, _handle);
|
||||
GL.BindTexture(TextureTarget.Texture2D, this._handle);
|
||||
}
|
||||
|
||||
public void Dispose() => GL.DeleteTexture(_handle);
|
||||
public void Dispose() => GL.DeleteTexture(this._handle);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user