slight code improvements. Still didn't fix cube sphere shading
All checks were successful
Gitea Actions Demo / Scan the project (push) Successful in 22s

This commit is contained in:
Daniel 2024-03-04 21:33:46 +01:00
parent 3912f2bd9a
commit 36ae444574
2 changed files with 14 additions and 20 deletions

View File

@ -32,7 +32,7 @@ public static class Program
private static Camera _cam;
private static Vector2 _lastMousePosition;
private static uint _vao, _vbo;
private static IcoSphere sphere;
private static Sphere sphere;
public static void Main(string[] args)
{
@ -140,7 +140,7 @@ public static class Program
// Sphere
sphere = new IcoSphere(10);
sphere = new Sphere(10);
sphere.CreateSphere();
_sphereShader =
new Nebulix.Rendering.Shader(_gl, "./Shaders/Sphere/sphere.vert", "./Shaders/Sphere/sphere.frag");

View File

@ -6,9 +6,11 @@ using Silk.NET.OpenGL;
namespace Engine_silk.NET
{
// also maybe make an ISphere and call this class "CubeSphere"?
// Also look into this way of generating a cube sphere: http://www.songho.ca/opengl/gl_sphere.html
public class Sphere
{
private readonly Mesh mesh = new();
private readonly Mesh[] mesh = new Mesh[6];
private readonly Face[] faces = new Face[6];
private readonly uint resolution;
public Sphere(uint resolution)
@ -21,7 +23,6 @@ namespace Engine_silk.NET
public void CreateSphere()
{
// TODO: merge the individual meshes to one mesh
Vector3[] directions =
[
Vector3.UnitZ, -Vector3.UnitZ,
@ -29,25 +30,15 @@ namespace Engine_silk.NET
Vector3.UnitX, -Vector3.UnitX
];
List<Vector3> vertices = new();
List<uint> indices = new();
for (int i = 0; i < directions.Length; i++)
{
Mesh m = new();
Face f = new(directions[i], m, resolution);
f.GenerateMesh();
vertices.AddRange(m.Vertices);
for (int j = 0; j < m.Indices.Length; j++)
if (mesh[i] is null) // linting not working here. mesh[i] can actually be null
{
indices.Add(m.Indices[j] + (uint)(m.Vertices.Length * i));
mesh[i] = new Mesh();
faces[i] = new Face(directions[i], mesh[i], resolution);
}
faces[i].GenerateMesh();
}
// TODO get rid of overlapping vertices maybe
mesh.Clear();
mesh.Vertices = vertices.ToArray();
mesh.Indices = indices.ToArray();
mesh.CalculateNormals();
}
/// <summary>
@ -55,11 +46,14 @@ namespace Engine_silk.NET
/// </summary>
public void RenderSphere(GL gl) // Will not be needed
{
mesh.Render(gl);
for (int i = 0; i < mesh.Length; i++)
{
faces[i].Mesh.Render(gl);
}
}
}
internal record struct Face
internal readonly record struct Face
{
public Mesh Mesh => _mesh;