From 5277638e014715d16c924216eb2a7054b40f93e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Sat, 9 Jan 2021 13:06:08 +0100 Subject: [PATCH] Added simple camera control --- Sandbox/src/SandboxApp.bf | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/Sandbox/src/SandboxApp.bf b/Sandbox/src/SandboxApp.bf index 4a2490c..0022f79 100644 --- a/Sandbox/src/SandboxApp.bf +++ b/Sandbox/src/SandboxApp.bf @@ -160,6 +160,33 @@ namespace Sandbox public override void Update(GameTime gameTime) { + Vector2 movement = .(); + + if(Input.IsKeyPressed(Key.W)) + { + movement.Y += 1; + } + else if(Input.IsKeyPressed(Key.S)) + { + movement.Y -= 1; + } + + if(Input.IsKeyPressed(Key.A)) + { + movement.X -= 1; + } + else if(Input.IsKeyPressed(Key.D)) + { + movement.X += 1; + } + + if(movement != .Zero) + movement.Normalize(); + + movement *= (float)(gameTime.FrameTime.TotalSeconds); + + _camera.Position += .(movement, 0); + _camera.Width = Application.Get().Window.Context.SwapChain.BackbufferViewport.Width / 256; _camera.Height = Application.Get().Window.Context.SwapChain.BackbufferViewport.Height / 256; @@ -175,8 +202,6 @@ namespace Sandbox Application.Get().Window.Context.SetViewport(Application.Get().Window.Context.SwapChain.BackbufferViewport); - RenderCommand.SetViewport(Application.Get().Window.Context.SwapChain.BackbufferViewport); - Renderer.BeginScene(_camera); Renderer.Submit(_geometryBinding, _effect);