Skip to content

Commit

Permalink
Added UE controls
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelBilek committed Jul 21, 2024
1 parent f179c8a commit 1d0bcd9
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions GraphicsApp/GraphicsApp/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ public class Game : GameWindow

private Stopwatch _timer = Stopwatch.StartNew();

private bool _canMove = false;

public Game(int width, int height, string title)
: base(GameWindowSettings.Default, new NativeWindowSettings() { Size = (width, height), Title = title })
{
Expand All @@ -121,8 +123,6 @@ protected override void OnLoad()
{
base.OnLoad();

CursorState = CursorState.Grabbed;

_camera.LookAt(Vector3.Zero);

GL.Enable(EnableCap.DepthTest);
Expand Down Expand Up @@ -267,6 +267,29 @@ protected override void OnFramebufferResize(FramebufferResizeEventArgs e)
GL.Viewport(0, 0, e.Width, e.Height);
}

protected override void OnMouseDown(MouseButtonEventArgs e)
{
base.OnMouseDown(e);

if (e.Button == MouseButton.Right)
{
CursorState = CursorState.Grabbed;
_canMove = true;
_firstMove = true;
}
}

protected override void OnMouseUp(MouseButtonEventArgs e)
{
base.OnMouseUp(e);

if (e.Button == MouseButton.Right)
{
CursorState = CursorState.Normal;
_canMove = false;
}
}

protected override void OnMouseMove(MouseMoveEventArgs e)
{
base.OnMouseMove(e);
Expand All @@ -276,6 +299,11 @@ protected override void OnMouseMove(MouseMoveEventArgs e)
return;
}

if (!_canMove)
{
return;
}

if (_firstMove)
{
_lastPos = new Vector2(e.X, e.Y);
Expand Down Expand Up @@ -307,6 +335,11 @@ protected override void OnUpdateFrame(FrameEventArgs e)
Close();
}

if (!_canMove)
{
return;
}

if (input.IsKeyDown(Keys.W))
{
_camera.Position += _camera.Front * _speed * (float)e.Time; //Forward
Expand Down

0 comments on commit 1d0bcd9

Please sign in to comment.