Files
Cortex_Engine/src/CortexEngine.App/Program.cs
T
emil28092005 fcbc42959e feat: FreeFlyCameraController — interactive WASD + mouse look
- Program.cs: create Camera entity in ECS World, FreeFlyCameraController
  with WASD movement, Q/E up/down, Shift boost, right-click mouse look
- VulkanRenderer.RenderWorld: queries Camera from World, computes VP
  from Camera.GetViewMatrix() * GetProjectionMatrix()
- Camera aspect ratio auto-updated on window resize
- Fallback to hardcoded VP if no Camera entity found
- Torus knot still rotating via push constant model matrix
- 0 validation errors
2026-06-18 16:49:54 +03:00

85 lines
2.6 KiB
C#

using System.Numerics;
using Engine.Core;
using Engine.Core.Components;
using Engine.Graphics;
using Engine.Graphics.Vulkan;
using Flecs.NET.Core;
namespace CortexEngine.App;
class Program
{
static async Task Main(string[] args)
{
Console.WriteLine("Cortex Engine — Vulkan (pure P/Invoke)...");
try
{
VulkanBackendRegistrar.EnsureRegistered();
using var renderContext = RenderBackendFactory.Create("vulkan", 1280, 720, enableValidation: true);
var window = renderContext.Window;
var input = window.Input;
using var renderer = renderContext.CreateRenderer();
using var world = World.Create();
var cameraEntity = world.Entity("Camera")
.Set(new Camera(
new Vector3(0, 0, -6),
new Vector3(0, 0, 0),
Vector3.UnitY,
MathF.PI / 4f,
1280f / 720f,
0.1f,
100f));
var cameraController = new FreeFlyCameraController(cameraEntity);
Console.WriteLine("Camera: FreeFly (WASD + right-click mouse look, Q/E up/down, Shift boost)");
var lastWidth = window.Width;
var lastHeight = window.Height;
var frames = 0;
var lastFpsTime = 0.0;
var timing = new Timing();
while (!window.ShouldClose)
{
timing.Tick();
window.PumpEvents();
input.BeginFrame();
if (window.Width != lastWidth || window.Height != lastHeight)
{
lastWidth = window.Width;
lastHeight = window.Height;
renderContext.Resize(lastWidth, lastHeight);
ref var cam = ref cameraEntity.Ensure<Camera>();
cam.AspectRatio = (float)lastWidth / lastHeight;
cameraEntity.Set(cam);
}
cameraController.Update(input, (float)timing.DeltaTime);
renderer.RenderWorld(world);
frames++;
if (timing.TotalTime - lastFpsTime >= 1.0)
{
Console.WriteLine($"FPS: {frames}, Delta: {timing.DeltaTime * 1000.0:F2} ms");
frames = 0;
lastFpsTime = timing.TotalTime;
}
}
Console.WriteLine("Shutting down...");
}
catch (Exception ex)
{
Console.WriteLine($"Fatal error: {ex}");
Environment.Exit(1);
}
await Task.CompletedTask;
}
}