From 5947727f8031db306126c49b9e4b6043da13ea22 Mon Sep 17 00:00:00 2001 From: Muzychenko Andrey <33288308+k4zmu2a@users.noreply.github.com> Date: Sun, 10 Oct 2021 17:13:43 +0300 Subject: [PATCH] Tweaked ball mouse control cheat. --- SpaceCadetPinball/pb.cpp | 8 +++++--- SpaceCadetPinball/pb.h | 2 +- SpaceCadetPinball/winmain.cpp | 15 ++++++++++----- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/SpaceCadetPinball/pb.cpp b/SpaceCadetPinball/pb.cpp index e2eab14..0977fb0 100644 --- a/SpaceCadetPinball/pb.cpp +++ b/SpaceCadetPinball/pb.cpp @@ -201,11 +201,13 @@ void pb::replay_level(int demoMode) MainTable->Message(1014, static_cast(options::Options.Players)); } -void pb::ballset(int x, int y) +void pb::ballset(float dx, float dy) { + // dx and dy are normalized to window, ideally in [-1, 1] + static constexpr float sensitivity = 7000; TBall* ball = MainTable->BallList.at(0); - ball->Acceleration.X = x * 30.0f; - ball->Acceleration.Y = y * 30.0f; + ball->Acceleration.X = dx * sensitivity; + ball->Acceleration.Y = dy * sensitivity; ball->Speed = maths::normalize_2d(&ball->Acceleration); } diff --git a/SpaceCadetPinball/pb.h b/SpaceCadetPinball/pb.h index 2c31c5f..81b2e78 100644 --- a/SpaceCadetPinball/pb.h +++ b/SpaceCadetPinball/pb.h @@ -48,7 +48,7 @@ public: static void mode_change(int mode); static void toggle_demo(); static void replay_level(int demoMode); - static void ballset(int x, int y); + static void ballset(float dx, float dy); static void frame(float dtMilliSec); static void timed_frame(float timeNow, float timeDelta, bool drawBalls); static void window_size(int* width, int* height); diff --git a/SpaceCadetPinball/winmain.cpp b/SpaceCadetPinball/winmain.cpp index eaa9073..f8951e8 100644 --- a/SpaceCadetPinball/winmain.cpp +++ b/SpaceCadetPinball/winmain.cpp @@ -212,10 +212,18 @@ int winmain::WinMain(LPCSTR lpCmdLine) { if (mouse_down) { - int x, y; + int x, y, w, h; SDL_GetMouseState(&x, &y); - pb::ballset(last_mouse_x - x, y - last_mouse_y); + SDL_GetWindowSize(window, &w, &h); + float dx = (last_mouse_x - x) / static_cast(w); + float dy = (y - last_mouse_y) / static_cast(h); + pb::ballset(dx, dy); + SDL_WarpMouseInWindow(window, last_mouse_x, last_mouse_y); + + // Mouse warp does not work over remote desktop or in some VMs + //last_mouse_x = x; + //last_mouse_y = y; } if (!single_step) { @@ -560,7 +568,6 @@ int winmain::event_handler(const SDL_Event* event) if (mouse_down) { mouse_down = 0; - SDL_ShowCursor(SDL_ENABLE); SDL_SetWindowGrab(MainWindow, SDL_FALSE); } switch (event->type) @@ -665,7 +672,6 @@ int winmain::event_handler(const SDL_Event* event) mouse_down = 1; last_mouse_x = event->button.x; last_mouse_y = event->button.y; - SDL_ShowCursor(SDL_DISABLE); SDL_SetWindowGrab(MainWindow, SDL_TRUE); } else @@ -689,7 +695,6 @@ int winmain::event_handler(const SDL_Event* event) if (mouse_down) { mouse_down = 0; - SDL_ShowCursor(SDL_ENABLE); SDL_SetWindowGrab(MainWindow, SDL_FALSE); } if (!pb::cheat_mode)