From 6d66dddc8e93375a6d144be11e15dd529fc3ab2d Mon Sep 17 00:00:00 2001 From: Starman Date: Sun, 6 Oct 2024 16:49:02 +0100 Subject: [PATCH] spinny bois --- Arqeta/Arqeta.csproj | 2 +- Arqeta/BaseCube.cs | 4 +++- Arqeta/Game.cs | 17 +++++++++++------ Arqeta/RenderMng.cs | 29 +++++++++++++++-------------- 4 files changed, 30 insertions(+), 22 deletions(-) diff --git a/Arqeta/Arqeta.csproj b/Arqeta/Arqeta.csproj index 7ab2957..311a67f 100644 --- a/Arqeta/Arqeta.csproj +++ b/Arqeta/Arqeta.csproj @@ -1,7 +1,7 @@  - Exe + WinExe net8.0 enable enable diff --git a/Arqeta/BaseCube.cs b/Arqeta/BaseCube.cs index 98c06df..59310e5 100644 --- a/Arqeta/BaseCube.cs +++ b/Arqeta/BaseCube.cs @@ -1,4 +1,5 @@ -using System; +using OpenTK.Mathematics; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -40,6 +41,7 @@ public BaseCube(Game game, Transform tran) : base(game, tran) public async override Task Update() { await base.Update(); + transform.rotation += new Quaternion(1, 1, 1, 1).ToEulerAngles() * (float)game.DeltaT; } } } diff --git a/Arqeta/Game.cs b/Arqeta/Game.cs index 21b6c9b..b9dbba3 100644 --- a/Arqeta/Game.cs +++ b/Arqeta/Game.cs @@ -19,6 +19,9 @@ public class Game : GameWindow Scene scene; ContentMng assets; Camera camera; + + public double DeltaT { get; private set; } + public Game(int width, int height, string title) : base(GameWindowSettings.Default, new() { ClientSize = (width, height), @@ -62,6 +65,8 @@ protected override void OnUpdateFrame(FrameEventArgs args) { base.OnUpdateFrame(args); + DeltaT = args.Time; + var input = KeyboardState; if (input.IsKeyDown(Keys.Escape)) @@ -74,28 +79,28 @@ protected override void OnUpdateFrame(FrameEventArgs args) if (input.IsKeyDown(Keys.W)) { - camera.Position += camera.Front * cameraSpeed * (float)args.Time; // Forward + camera.Position += camera.Front * cameraSpeed * (float)DeltaT; // Forward } if (input.IsKeyDown(Keys.S)) { - camera.Position -= camera.Front * cameraSpeed * (float)args.Time; // Backwards + camera.Position -= camera.Front * cameraSpeed * (float)DeltaT; // Backwards } if (input.IsKeyDown(Keys.A)) { - camera.Position -= camera.Right * cameraSpeed * (float)args.Time; // Left + camera.Position -= camera.Right * cameraSpeed * (float)DeltaT; // Left } if (input.IsKeyDown(Keys.D)) { - camera.Position += camera.Right * cameraSpeed * (float)args.Time; // Right + camera.Position += camera.Right * cameraSpeed * (float)DeltaT; // Right } if (input.IsKeyDown(Keys.Space)) { - camera.Position += camera.Up * cameraSpeed * (float)args.Time; // Up + camera.Position += camera.Up * cameraSpeed * (float)DeltaT; // Up } if (input.IsKeyDown(Keys.LeftShift)) { - camera.Position -= camera.Up * cameraSpeed * (float)args.Time; // Down + camera.Position -= camera.Up * cameraSpeed * (float)DeltaT; // Down } var mouse = MouseState; diff --git a/Arqeta/RenderMng.cs b/Arqeta/RenderMng.cs index efd4828..294b791 100644 --- a/Arqeta/RenderMng.cs +++ b/Arqeta/RenderMng.cs @@ -56,32 +56,33 @@ static void Free(RndrBuffers buffrs) public void Render(Camera cam) { GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); + RndrBuffers buffrs = new(); + shader.Use(); + GL.BindVertexArray(buffrs.VAO); + GL.BindBuffer(BufferTarget.ArrayBuffer, buffrs.VBO); + GL.BindBuffer(BufferTarget.ElementArrayBuffer, buffrs.EBO); + + GL.VertexAttribPointer(shader.GetAttribLocation("pos"), 3, VertexAttribPointerType.Float, false, 5 * sizeof(float), 0); + GL.EnableVertexAttribArray(shader.GetAttribLocation("pos")); + GL.VertexAttribPointer(shader.GetAttribLocation("texcoord"), 2, VertexAttribPointerType.Float, false, 5 * sizeof(float), 3 * sizeof(float)); + GL.EnableVertexAttribArray(shader.GetAttribLocation("tex")); + + shader.SetUniform("view", cam.GetViewMatrix()); + shader.SetUniform("project", cam.GetProjectionMatrix()); + foreach (var item in batch) { - RndrBuffers buffrs = new(); - shader.Use(); - GL.BindVertexArray(buffrs.VAO); - GL.BindBuffer(BufferTarget.ArrayBuffer, buffrs.VBO); GL.BufferData(BufferTarget.ArrayBuffer, item.usable().Length * sizeof(float), item.usable(), BufferUsageHint.StreamDraw); - GL.BindBuffer(BufferTarget.ElementArrayBuffer, buffrs.EBO); GL.BufferData(BufferTarget.ElementArrayBuffer, item.index.Length * sizeof(uint), item.index, BufferUsageHint.StaticDraw); - GL.VertexAttribPointer(shader.GetAttribLocation("pos"), 3, VertexAttribPointerType.Float, false, 5 * sizeof(float), 0); - GL.EnableVertexAttribArray(shader.GetAttribLocation("pos")); - - GL.VertexAttribPointer(shader.GetAttribLocation("texcoord"), 2, VertexAttribPointerType.Float, false, 5 * sizeof(float), 3 * sizeof(float)); - GL.EnableVertexAttribArray(shader.GetAttribLocation("tex")); - shader.SetUniform("model", item.model); - shader.SetUniform("view", cam.GetViewMatrix()); - shader.SetUniform("project", cam.GetProjectionMatrix()); GL.DrawElements(PrimitiveType.Triangles, item.index.Length, DrawElementsType.UnsignedInt, 0); - Free(buffrs); } + Free(buffrs); batch.Clear(); } }