This commit is contained in:
2024-12-16 04:28:45 +03:00
parent ef922486eb
commit dbe7aebd4f
57 changed files with 895 additions and 374 deletions

View File

@@ -1,21 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Engine\Engine.csproj"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Serilog" Version="4.1.0"/>
<PackageReference Include="Serilog.Enrichers.Thread" Version="4.0.0"/>
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0"/>
<PackageReference Include="System.Drawing.Common" Version="8.0.10"/>
<ProjectReference Include="..\Engine\Engine.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,33 @@
using Engine.Input;
using OpenTK.Mathematics;
namespace DoomDeathmatch.Component;
public class ControllerComponent : Engine.Scene.Component.Component
{
public float Speed { get; set; } = 10.0f;
private readonly IInputHandler _inputHandler = Engine.Engine.Instance.InputHandler!;
public override void Update(double parDeltaTime)
{
var movement = Vector3.Zero;
if (_inputHandler.IsKeyPressed(KeyboardButtonCode.W))
movement.Z += 1;
if (_inputHandler.IsKeyPressed(KeyboardButtonCode.S))
movement.Z -= 1;
if (_inputHandler.IsKeyPressed(KeyboardButtonCode.A))
movement.X -= 1;
if (_inputHandler.IsKeyPressed(KeyboardButtonCode.D))
movement.X += 1;
if (_inputHandler.IsKeyPressed(KeyboardButtonCode.Space))
movement.Y += 1;
if (_inputHandler.IsKeyPressed(KeyboardButtonCode.Shift))
movement.Y -= 1;
if (movement.LengthSquared > 0)
movement.Normalize();
GameObject.Transform.Translation += movement * Speed * (float)parDeltaTime;
}
}

View File

@@ -0,0 +1,22 @@
using Engine.Input;
using OpenTK.Mathematics;
namespace DoomDeathmatch.Component;
public class RotateComponent : Engine.Scene.Component.Component
{
private readonly IInputHandler _inputHandler = Engine.Engine.Instance.InputHandler!;
public override void Update(double parDeltaTime)
{
if (_inputHandler.IsKeyPressed(KeyboardButtonCode.Q))
GameObject.Transform.Rotation *= Quaternion.FromAxisAngle(Vector3.UnitY, (float)parDeltaTime * 0.5f);
else if (_inputHandler.IsKeyPressed(KeyboardButtonCode.E))
GameObject.Transform.Rotation *= Quaternion.FromAxisAngle(Vector3.UnitY, -(float)parDeltaTime * 0.5f);
if (_inputHandler.IsMouseButtonPressed(MouseButtonCode.Left))
GameObject.Transform.Rotation *= Quaternion.FromAxisAngle(Vector3.UnitZ, (float)parDeltaTime * 0.5f);
else if (_inputHandler.IsMouseButtonPressed(MouseButtonCode.Right))
GameObject.Transform.Rotation *= Quaternion.FromAxisAngle(Vector3.UnitZ, -(float)parDeltaTime * 0.5f);
}
}

View File

@@ -0,0 +1,37 @@
using DoomDeathmatch.Component;
using Engine.Asset.Mesh.Loader;
using Engine.Scene;
using Engine.Scene.Component.BuiltIn;
using Engine.Scene.Component.BuiltIn.Renderer;
using OpenTK.Mathematics;
namespace DoomDeathmatch;
public static class DoomDeathmatch
{
public static void Initialize(Engine.Engine parEngine)
{
parEngine.SceneManager.TransitionTo(MainScene());
}
private static Scene MainScene()
{
var cameraObject = new GameObject();
cameraObject.Transform.Translation.Z = -6;
cameraObject.AddComponent<PerspectiveCamera>();
cameraObject.AddComponent<ControllerComponent>();
using var reader = new StreamReader("../DoomDeathmatch/asset/model/test2.obj");
var box2dRenderer = new GameObject();
box2dRenderer.AddComponent(new MeshRenderer { Mesh = ObjMeshLoader.Load(reader) });
box2dRenderer.AddComponent<Box2DRenderer>();
box2dRenderer.AddComponent<RotateComponent>();
var scene = new Scene();
scene.Add(cameraObject);
scene.Add(box2dRenderer);
return scene;
}
}

View File

@@ -1,12 +0,0 @@
using System.Diagnostics;
using System.Drawing;
using System.Runtime.InteropServices;
namespace DoomDeathmatch;
internal abstract class Program
{
public static void Main(string[] args)
{
}
}

View File

@@ -1,17 +0,0 @@
using Engine.Graphics.Buffer.Vertex;
using OpenTK.Graphics.OpenGL;
using OpenTK.Mathematics;
using Half = System.Half;
namespace DoomDeathmatch;
public struct QuadVertex : IVertex
{
[Vertex(VertexAttribType.Float, 2)] public Vector2 Position2;
[Vertex(VertexAttribType.Float, 2)] public Vector2 Position;
[Vertex(VertexAttribType.Float, 2)] public Vector2 Position4;
[Vertex(VertexAttribType.Float, 2)] public Vector2 Position3;
}