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
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using System.Numerics;
|
||||
using Engine.Core;
|
||||
using Engine.Core.Components;
|
||||
using Engine.Graphics;
|
||||
using Engine.Graphics.Vulkan;
|
||||
using Flecs.NET.Core;
|
||||
@@ -9,17 +11,31 @@ class Program
|
||||
{
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Cortex Engine — Vulkan Triangle (pure P/Invoke)...");
|
||||
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;
|
||||
@@ -30,14 +46,20 @@ class Program
|
||||
{
|
||||
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++;
|
||||
|
||||
Reference in New Issue
Block a user