From 147447b638d5974adb230b51fffb0d6804ce21ed Mon Sep 17 00:00:00 2001 From: Titus Tscharntke Date: Thu, 25 Mar 2010 00:19:49 +0000 Subject: [PATCH] better mouse camera navigation ( missing win32 implementation ) --- source/glest_game/game/game.cpp | 10 +++++++--- source/glest_game/game/game_camera.cpp | 8 ++++---- source/shared_lib/include/platform/sdl/window.h | 2 ++ source/shared_lib/include/platform/win32/window.h | 3 ++- source/shared_lib/sources/platform/sdl/window.cpp | 6 ++++++ 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index e15cc10f..963f6d9c 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiño Figueroa +// Copyright (C) 2001-2008 Marti�o Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -434,6 +434,10 @@ void Game::mouseMove(int x, int y, const MouseState *ms){ float xmult = 0.2f; gameCamera.transitionVH(-(y - lastMousePos.y) * ymult, (lastMousePos.x - x) * xmult); + mouseX=lastMousePos.x; + mouseY=lastMousePos.y; + Window::revertMousePos(); + return; } } else { @@ -479,8 +483,8 @@ void Game::mouseMove(int x, int y, const MouseState *ms){ } } - lastMousePos.x = x; - lastMousePos.y = y; + lastMousePos.x = mouseX; + lastMousePos.y = mouseY; } void Game::eventMouseWheel(int x, int y, int zDelta) { diff --git a/source/glest_game/game/game_camera.cpp b/source/glest_game/game/game_camera.cpp index c15711e7..7b8885dc 100644 --- a/source/glest_game/game/game_camera.cpp +++ b/source/glest_game/game/game_camera.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiño Figueroa +// Copyright (C) 2001-2008 Marti�o Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -232,9 +232,9 @@ void GameCamera::transitionXYZ(float x, float y, float z) { } void GameCamera::transitionVH(float v, float h) { - destAng.x += v; - destPos.y -= v * destPos.y / 100.f; - destAng.y += h; + destAng.x -= v; + //destPos.y -= v * destPos.y / 100.f; + destAng.y -= h; clampAng(); } diff --git a/source/shared_lib/include/platform/sdl/window.h b/source/shared_lib/include/platform/sdl/window.h index 08ffb7a1..3bc7a436 100644 --- a/source/shared_lib/include/platform/sdl/window.h +++ b/source/shared_lib/include/platform/sdl/window.h @@ -126,6 +126,8 @@ protected: public: static bool handleEvent(); + static void revertMousePos(); + Window(); virtual ~Window(); diff --git a/source/shared_lib/include/platform/win32/window.h b/source/shared_lib/include/platform/win32/window.h index 2e2d9f4a..c443252f 100644 --- a/source/shared_lib/include/platform/win32/window.h +++ b/source/shared_lib/include/platform/win32/window.h @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest Shared Library (www.glest.org) // -// Copyright (C) 2001-2008 Martiño Figueroa +// Copyright (C) 2001-2008 Marti�o Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -136,6 +136,7 @@ protected: public: static bool handleEvent(); + static void revertMousePos(); //contructor & destructor Window(); diff --git a/source/shared_lib/sources/platform/sdl/window.cpp b/source/shared_lib/sources/platform/sdl/window.cpp index c2e0d778..1bfe354e 100644 --- a/source/shared_lib/sources/platform/sdl/window.cpp +++ b/source/shared_lib/sources/platform/sdl/window.cpp @@ -32,6 +32,7 @@ namespace Shared{ namespace Platform{ // Matze: hack for now... static Window* global_window = 0; +static int oldX=0,oldY=0; unsigned int Window::lastMouseEvent = 0; /** for use in mouse hover calculations */ Vec2i Window::mousePos; MouseState Window::mouseState; @@ -57,6 +58,7 @@ Window::~Window() { bool Window::handleEvent() { SDL_Event event; + SDL_GetMouseState(&oldX,&oldY); while(SDL_PollEvent(&event)) { try { //printf("START [%d]\n",event.type); @@ -138,6 +140,10 @@ bool Window::handleEvent() { return true; } +void Window::revertMousePos() { + SDL_WarpMouse(oldX, oldY); +} + string Window::getText() { char* c = 0; SDL_WM_GetCaption(&c, 0);