From e94d544043de04e4009f9a476e9e09dbe0d99f33 Mon Sep 17 00:00:00 2001 From: daniel Date: Sat, 3 Jan 2026 19:35:33 +0100 Subject: [PATCH] small improvements and test code for manipulating vertices --- .../EngineSharp.Core/OpenGLEngine.cs | 3 +++ src/EngineSharp.Core/EngineSharp.Core/Time.cs | 12 ++++++++++++ src/EngineSharp/PlanetGenerator.cs | 12 ++++++++---- 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 src/EngineSharp.Core/EngineSharp.Core/Time.cs diff --git a/src/EngineSharp.Core/EngineSharp.Core/OpenGLEngine.cs b/src/EngineSharp.Core/EngineSharp.Core/OpenGLEngine.cs index 2ec8a94..b630469 100644 --- a/src/EngineSharp.Core/EngineSharp.Core/OpenGLEngine.cs +++ b/src/EngineSharp.Core/EngineSharp.Core/OpenGLEngine.cs @@ -110,6 +110,9 @@ internal class OpenGLEngine : Engine { _window.Close(); } + + Time._secondsSinceStart = _window.Time; + Time._deltaTime = deltaTime; TemporaryMovementProcessing((float)deltaTime); TemporaryMouseProcessing(); diff --git a/src/EngineSharp.Core/EngineSharp.Core/Time.cs b/src/EngineSharp.Core/EngineSharp.Core/Time.cs new file mode 100644 index 0000000..e4369a2 --- /dev/null +++ b/src/EngineSharp.Core/EngineSharp.Core/Time.cs @@ -0,0 +1,12 @@ +namespace EngineSharp.Core; + +public static class Time +{ + internal static double _deltaTime; + internal static double _secondsSinceStart; + + public static double DeltaTime => _deltaTime; + public static float DeltaTimeF => (float)_deltaTime; + public static double SecondsSinceStart => _secondsSinceStart; + public static float SecondsSinceStartF => (float)_secondsSinceStart; +} \ No newline at end of file diff --git a/src/EngineSharp/PlanetGenerator.cs b/src/EngineSharp/PlanetGenerator.cs index cefb998..00400d6 100644 --- a/src/EngineSharp/PlanetGenerator.cs +++ b/src/EngineSharp/PlanetGenerator.cs @@ -1,9 +1,12 @@ +using EngineSharp.Core; using EngineSharp.Core.Rendering; +using Silk.NET.Maths; namespace EngineSharp; public class PlanetGenerator : Core.ECS.LogicComponent { + private MeshRenderer _planetMesh = null!; public override void Initialise() { var shader = Shader.GetShader("./assets/shaders/sphere.vert"); @@ -17,17 +20,18 @@ public class PlanetGenerator : Core.ECS.LogicComponent Material = material, }; - // TODO: MeshRenderer should probably not have the mesh as a required property. - var planetMesh = new MeshRenderer + _planetMesh = new MeshRenderer { Mesh = sphereGenerator.CreateSphere(), }; - Entity.AddComponent(planetMesh); + Entity.AddComponent(_planetMesh); } public override void OnUpdate(double deltaTime) { - // Nothing to do at the moment + // TODO: Now that vertices can be manipulated, I now need to implement the infrastructure to support compute shaders for planet generation + var time = (float)Time.SecondsSinceStart; + _planetMesh.Mesh.Vertices[0] = new Vector3D(MathF.Sin(time), MathF.Cos(time), MathF.Sin(time)); } } \ No newline at end of file