diff --git a/backends/events/sdl/sdl-events.cpp b/backends/events/sdl/sdl-events.cpp index 9b0ffcc102f..fcf4163aa99 100644 --- a/backends/events/sdl/sdl-events.cpp +++ b/backends/events/sdl/sdl-events.cpp @@ -92,9 +92,11 @@ int SdlEventSource::mapKey(SDLKey key, SDLMod mod, Uint16 unicode) { return key; } -void SdlEventSource::fillMouseEvent(Common::Event &event, int x, int y) { +void SdlEventSource::fillMouseEvent(Common::Event &event, int x, int y, int relx, int rely) { event.mouse.x = x; event.mouse.y = y; + event.relMouse.x = relx; + event.relMouse.y = rely; // Update the "keyboard mouse" coords _km.x = x; @@ -363,7 +365,7 @@ bool SdlEventSource::handleKeyUp(SDL_Event &ev, Common::Event &event) { bool SdlEventSource::handleMouseMotion(SDL_Event &ev, Common::Event &event) { event.type = Common::EVENT_MOUSEMOVE; - fillMouseEvent(event, ev.motion.x, ev.motion.y); + fillMouseEvent(event, ev.motion.x, ev.motion.y, ev.motion.xrel, ev.motion.yrel); return true; } @@ -386,7 +388,7 @@ bool SdlEventSource::handleMouseButtonDown(SDL_Event &ev, Common::Event &event) else return false; - fillMouseEvent(event, ev.button.x, ev.button.y); + fillMouseEvent(event, ev.button.x, ev.button.y, 0, 0); return true; } @@ -402,7 +404,7 @@ bool SdlEventSource::handleMouseButtonUp(SDL_Event &ev, Common::Event &event) { #endif else return false; - fillMouseEvent(event, ev.button.x, ev.button.y); + fillMouseEvent(event, ev.button.x, ev.button.y, 0, 0); return true; } @@ -410,10 +412,10 @@ bool SdlEventSource::handleMouseButtonUp(SDL_Event &ev, Common::Event &event) { bool SdlEventSource::handleJoyButtonDown(SDL_Event &ev, Common::Event &event) { if (ev.jbutton.button == JOY_BUT_LMOUSE) { event.type = Common::EVENT_LBUTTONDOWN; - fillMouseEvent(event, _km.x, _km.y); + fillMouseEvent(event, _km.x, _km.y, 0, 0); } else if (ev.jbutton.button == JOY_BUT_RMOUSE) { event.type = Common::EVENT_RBUTTONDOWN; - fillMouseEvent(event, _km.x, _km.y); + fillMouseEvent(event, _km.x, _km.y, 0, 0); } else { event.type = Common::EVENT_KEYDOWN; switch (ev.jbutton.button) { @@ -441,10 +443,10 @@ bool SdlEventSource::handleJoyButtonDown(SDL_Event &ev, Common::Event &event) { bool SdlEventSource::handleJoyButtonUp(SDL_Event &ev, Common::Event &event) { if (ev.jbutton.button == JOY_BUT_LMOUSE) { event.type = Common::EVENT_LBUTTONUP; - fillMouseEvent(event, _km.x, _km.y); + fillMouseEvent(event, _km.x, _km.y, 0, 0); } else if (ev.jbutton.button == JOY_BUT_RMOUSE) { event.type = Common::EVENT_RBUTTONUP; - fillMouseEvent(event, _km.x, _km.y); + fillMouseEvent(event, _km.x, _km.y, 0, 0); } else { event.type = Common::EVENT_KEYUP; switch (ev.jbutton.button) { @@ -512,7 +514,7 @@ bool SdlEventSource::handleJoyAxisMotion(SDL_Event &ev, Common::Event &event) { #endif } - fillMouseEvent(event, _km.x, _km.y); + fillMouseEvent(event, _km.x, _km.y, 0, 0); return true; } diff --git a/backends/events/sdl/sdl-events.h b/backends/events/sdl/sdl-events.h index 805b76b108a..b8733eb0258 100644 --- a/backends/events/sdl/sdl-events.h +++ b/backends/events/sdl/sdl-events.h @@ -110,7 +110,7 @@ protected: /** * Assigns the mouse coords to the mouse event */ - virtual void fillMouseEvent(Common::Event &event, int x, int y); + virtual void fillMouseEvent(Common::Event &event, int x, int y, int relx, int rely); /** * Remaps key events. This allows platforms to configure diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp index fc1a25ca31a..3ebc2ee2e8b 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp @@ -68,6 +68,8 @@ SurfaceSdlGraphicsManager::SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSou sdlFlags ^= SDL_INIT_VIDEO; } #endif + + // SDL_ShowCursor(SDL_DISABLE); } SurfaceSdlGraphicsManager::~SurfaceSdlGraphicsManager() { diff --git a/common/events.h b/common/events.h index 371080c1b27..95e4b9a53d4 100644 --- a/common/events.h +++ b/common/events.h @@ -99,6 +99,11 @@ struct Event { */ Common::Point mouse; + /** + * Mouse movement since the last mouse movement event. + */ + Common::Point relMouse; + Event() : type(EVENT_INVALID), synthetic(false) {} }; diff --git a/engines/myst3/myst3.cpp b/engines/myst3/myst3.cpp index 249dab1084d..bcb684260de 100644 --- a/engines/myst3/myst3.cpp +++ b/engines/myst3/myst3.cpp @@ -66,6 +66,7 @@ Common::Error Myst3Engine::run() { } _system->setupScreen(w, h, false, true); + _system->showMouse(false); _scene.init(w, h); @@ -76,8 +77,11 @@ Common::Error Myst3Engine::run() { Common::Event event; while (_system->getEventManager()->pollEvent(event)) { // Check for "Hard" quit" - if (event.type == Common::EVENT_QUIT) + if (event.type == Common::EVENT_QUIT) { return Common::kNoError; + } else if (event.type == Common::EVENT_MOUSEMOVE) { + _scene.updateCamera(event.relMouse); + } } _scene.clear(); diff --git a/engines/myst3/scene.cpp b/engines/myst3/scene.cpp index befd4a9eeb2..291ff01a653 100644 --- a/engines/myst3/scene.cpp +++ b/engines/myst3/scene.cpp @@ -53,8 +53,13 @@ void Scene::setupCamera() { glLoadIdentity(); glRotatef(_cameraPitch, 1.0f, 0.0f, 0.0f); glRotatef(_cameraYaw, 0.0f, 1.0f, 0.0f); - - _cameraYaw += 0.1f; +} + +void Scene::updateCamera(Common::Point &mouse) { + _cameraYaw += mouse.x / 3.0f; + _cameraPitch += mouse.y / 3.0f; + + _cameraPitch = CLIP(_cameraPitch, -90.0f, 90.0f); } } // end of namespace Myst3 diff --git a/engines/myst3/scene.h b/engines/myst3/scene.h index 657d066abc8..5a373f46c99 100644 --- a/engines/myst3/scene.h +++ b/engines/myst3/scene.h @@ -33,17 +33,21 @@ #include #endif +#include "common/rect.h" + namespace Myst3 { class Scene { private: float _cameraPitch; float _cameraYaw; + Common::Point _mouseOld; public: void init(int width, int height); void clear(); void setupCamera(); + void updateCamera(Common::Point &mouse); }; } // end of namespace Myst3