Skip to content

Commit

Permalink
Fixed strange bug with rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
Tornado-Technology committed Jul 16, 2024
1 parent a732c0a commit 914b6e4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Hypercube.Client.Graphics.Texturing;
using Hypercube.Client.Graphics.Windows;
using Hypercube.Client.Resources.Caching;
using Hypercube.Math;
using Hypercube.Math.Matrixs;
using Hypercube.Shared.Runtimes.Loop.Event;
using OpenToolkit.Graphics.OpenGL4;
Expand Down Expand Up @@ -64,7 +65,13 @@ private void OnLoad()
private void OnFrameUpdate(ref UpdateFrameEvent args)
{
#if DEBUG
_windowManager.WindowSetTitle(MainWindow, $"FPS: {_timing.Fps} | RealTime: {_timing.RealTime} | cPos: {_cameraManager.MainCamera?.Position ?? null} | cRot: {_cameraManager.MainCamera?.Rotation ?? null}");
var cameraTitle = string.Empty;
if (_cameraManager.MainCamera is not null)
{
cameraTitle = $"| cPos: {_cameraManager.MainCamera.Position} | cRot: {_cameraManager.MainCamera.Rotation * HyperMathF.RadiansToDegrees}";
}

_windowManager.WindowSetTitle(MainWindow, $"FPS: {_timing.Fps} | RealTime: {_timing.RealTime} {cameraTitle}");
#endif
_windowManager.PollEvents();
_cameraManager.UpdateInput(_cameraManager.MainCamera, args.DeltaSeconds);
Expand Down
1 change: 1 addition & 0 deletions Hypercube.Client/Graphics/Viewports/Camera2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public Camera2D(Vector2Int size, Vector2 position, float zNear, float zFar)
_zFar = zFar;

SetPosition(new Vector3(position));
SetRotation(Vector3.UnitZ * HyperMathF.PI);

UpdateProjection();
}
Expand Down
10 changes: 5 additions & 5 deletions Hypercube.Client/Graphics/Viewports/CameraManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ public void UpdateInput(ICamera? camera, float delta)
var rotation = camera.Rotation;
var scale = camera.Scale;

var speed = 20f;
var speed = 60f;

if (_inputHandler.IsKeyDown(Key.W))
position -= Vector3.UnitY * speed * delta;
position += Vector3.UnitY * speed * delta;

if (_inputHandler.IsKeyDown(Key.S))
position += Vector3.UnitY * speed * delta;
position -= Vector3.UnitY * speed * delta;

if (_inputHandler.IsKeyDown(Key.A))
position += Vector3.UnitX * speed * delta;
position -= Vector3.UnitX * speed * delta;

if (_inputHandler.IsKeyDown(Key.D))
position -= Vector3.UnitX * speed * delta;
position += Vector3.UnitX * speed * delta;

if (_inputHandler.IsKeyDown(Key.Q))
rotation -= Vector3.UnitZ * delta;
Expand Down

0 comments on commit 914b6e4

Please sign in to comment.