Skip to content

Commit

Permalink
spinny bois
Browse files Browse the repository at this point in the history
  • Loading branch information
GoldenStarGamer committed Oct 6, 2024
1 parent 9fb40c3 commit 6d66ddd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Arqeta/Arqeta.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
4 changes: 3 additions & 1 deletion Arqeta/BaseCube.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using OpenTK.Mathematics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -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;
}
}
}
17 changes: 11 additions & 6 deletions Arqeta/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -62,6 +65,8 @@ protected override void OnUpdateFrame(FrameEventArgs args)
{
base.OnUpdateFrame(args);

DeltaT = args.Time;

var input = KeyboardState;

if (input.IsKeyDown(Keys.Escape))
Expand All @@ -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;
Expand Down
29 changes: 15 additions & 14 deletions Arqeta/RenderMng.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down

0 comments on commit 6d66ddd

Please sign in to comment.