diff --git a/src/core.c b/src/core.c index e84d82c49..720fd2c5e 100644 --- a/src/core.c +++ b/src/core.c @@ -434,6 +434,9 @@ typedef struct CoreData { Vector2 offset; // Mouse offset Vector2 scale; // Mouse scaling + Vector2 delta; // Mouse movement per frame + Vector2 previousPosition; // Previus frame position + int cursor; // Tracks current mouse cursor bool cursorHidden; // Track if cursor is hidden bool cursorOnScreen; // Tracks if cursor is inside client area @@ -3387,6 +3390,12 @@ Vector2 GetMousePosition(void) return position; } +// Mouse movement per frame XY +RLAPI Vector2 GetDeltaMouse(void) +{ + return CORE.Input.Mouse.delta; +} + // Set mouse position XY void SetMousePosition(int x, int y) { @@ -4856,6 +4865,10 @@ static void PollInputEvents(void) // NOTE: Mouse input events polling is done asynchronously in another pthread - EventThread() // NOTE: Gamepad (Joystick) input events polling is done asynchonously in another pthread - GamepadThread() #endif + + CORE.Input.Mouse.delta.x = CORE.Input.Mouse.position.x - CORE.Input.Mouse.previousPosition.x; + CORE.Input.Mouse.delta.y = CORE.Input.Mouse.position.y - CORE.Input.Mouse.previousPosition.y; + CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.position; } // Copy back buffer to front buffers diff --git a/src/raylib.h b/src/raylib.h index 67fde1574..4efa944af 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1102,6 +1102,7 @@ RLAPI bool IsMouseButtonUp(int button); // Detect if a mou RLAPI int GetMouseX(void); // Returns mouse position X RLAPI int GetMouseY(void); // Returns mouse position Y RLAPI Vector2 GetMousePosition(void); // Returns mouse position XY +RLAPI Vector2 GetDeltaMouse(void); // Mouse movement per frame XY RLAPI void SetMousePosition(int x, int y); // Set mouse position XY RLAPI void SetMouseOffset(int offsetX, int offsetY); // Set mouse offset RLAPI void SetMouseScale(float scaleX, float scaleY); // Set mouse scaling