Added simple camera control

This commit is contained in:
Simon Lübeß
2021-01-09 13:06:08 +01:00
parent 33f8c86a18
commit 5277638e01
+27 -2
View File
@@ -160,6 +160,33 @@ namespace Sandbox
public override void Update(GameTime gameTime) 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.Width = Application.Get().Window.Context.SwapChain.BackbufferViewport.Width / 256;
_camera.Height = Application.Get().Window.Context.SwapChain.BackbufferViewport.Height / 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); Application.Get().Window.Context.SetViewport(Application.Get().Window.Context.SwapChain.BackbufferViewport);
RenderCommand.SetViewport(Application.Get().Window.Context.SwapChain.BackbufferViewport);
Renderer.BeginScene(_camera); Renderer.BeginScene(_camera);
Renderer.Submit(_geometryBinding, _effect); Renderer.Submit(_geometryBinding, _effect);