diff --git a/game/mwinput/inputmanager.hpp b/game/mwinput/inputmanager.hpp index 763d1a487..94b0c915f 100644 --- a/game/mwinput/inputmanager.hpp +++ b/game/mwinput/inputmanager.hpp @@ -54,6 +54,9 @@ namespace MWInput // Add ourselves as a frame listener, to catch movement keys ogre.getRoot()->addFrameListener(this); + // Tell the input listener about the camera + listener.setCamera(player.getCamera()); + // Key bindings disp.bind(KC_Q, A_Quit); disp.bind(KC_ESCAPE, A_Quit); @@ -70,7 +73,7 @@ namespace MWInput poller.bind(A_MoveLeft, KC_A); poller.bind(A_MoveRight, KC_D); poller.bind(A_MoveForward, KC_W); - poller.bind(A_MoveBackward, KC_D); + poller.bind(A_MoveBackward, KC_S); // Use shift and ctrl for up and down poller.bind(A_MoveUp, KC_LSHIFT); diff --git a/game/mwrender/playerpos.hpp b/game/mwrender/playerpos.hpp index 51906aca8..cf1d02092 100644 --- a/game/mwrender/playerpos.hpp +++ b/game/mwrender/playerpos.hpp @@ -27,6 +27,8 @@ namespace MWRender // TODO: Update sound listener } + Ogre::Camera *getCamera() { return camera; } + // Move the player relative to her own position and // orientation. After the call, the new position is returned. void moveRel(float &relX, float &relY, float &relZ) diff --git a/input/listener.hpp b/input/listener.hpp index 4c4b80c56..f2a1bff20 100644 --- a/input/listener.hpp +++ b/input/listener.hpp @@ -33,6 +33,8 @@ namespace Input mMouse -> setEventCallback(this); } + void setCamera(Ogre::Camera *cam) { camera = cam; } + // Call this to exit the main loop void exitNow() { doExit = true; } @@ -62,6 +64,29 @@ namespace Input bool mouseMoved( const OIS::MouseEvent &arg ) { + using namespace Ogre; + assert(camera); + + // Mouse sensitivity. Should be a config option later. + const float MS = 0.2; + + float x = arg.state.X.rel * MS; + float y = arg.state.Y.rel * MS; + + camera->yaw(Degree(-x)); + + // The camera before pitching + Quaternion nopitch = camera->getOrientation(); + + camera->pitch(Degree(-y)); + + // Apply some failsafe measures against the camera flipping + // upside down. Is the camera close to pointing straight up or + // down? + if(camera->getUp()[1] <= 0.1) + // If so, undo the last pitch + camera->setOrientation(nopitch); + return true; } @@ -79,6 +104,7 @@ namespace Input const Dispatcher &disp; Ogre::RenderWindow *mWindow; + Ogre::Camera *camera; OIS::Mouse *mMouse; OIS::Keyboard *mKeyboard; bool doExit; diff --git a/input/oismanager.cpp b/input/oismanager.cpp index 07714da3f..92495f967 100644 --- a/input/oismanager.cpp +++ b/input/oismanager.cpp @@ -30,8 +30,9 @@ OISManager::OISManager(Render::OgreRenderer &rend) windowHndStr << windowHnd; pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); - // Non-exclusive mouse and keyboard input in debug mode - if(true) + // Non-exclusive mouse and keyboard input in debug mode. Debug mode + // isn't implemented yet though. + if(false) { #if defined OIS_WIN32_PLATFORM pl.insert(std::make_pair(std::string("w32_mouse"), diff --git a/old_d_version/input/events.d b/old_d_version/input/events.d index 9273c7129..4c5d570e7 100644 --- a/old_d_version/input/events.d +++ b/old_d_version/input/events.d @@ -57,11 +57,6 @@ import input.ois; bool pause = false; int *guiMode; -void toggleFullscreen() -{ - ogre_toggleFullscreen(); -} - const float volDiff = 0.05; void musVolume(bool increase) @@ -88,16 +83,6 @@ void mainVolume(bool increase) writefln(increase?"Increasing":"Decreasing", " main volume to ", config.getMainVolume); } -void takeScreenShot() -{ - char[] file = format("screenshot_%06d.png", config.screenShotNum++); - ogre_screenshot(toStringz(file)); - writefln("Wrote '%s'", file); -} - -// Mouse sensitivity -float effMX, effMY; - void updateMouseSensitivity() { effMX = *config.mouseSensX; @@ -112,19 +97,6 @@ void togglePause() else writefln("Pause off"); } -extern(C) void d_handleMouseMove(MouseState *state) -{ - debug(printMouseMove) - writefln("handleMouseMove: Abs(%s, %s, %s) Rel(%s, %s, %s)", - state.X.abs, state.Y.abs, state.Z.abs, - state.X.rel, state.Y.rel, state.Z.rel); - - if(*guiMode) return; - - ogre_rotateCamera( state.X.rel * effMX, - state.Y.rel * effMY ); -} - extern(C) void d_handleMouseButton(MouseState *state, int button) { debug(printMouse) diff --git a/old_d_version/ogre/cpp_framelistener.cpp b/old_d_version/ogre/cpp_framelistener.cpp index bd1bf64a4..864153ccb 100644 --- a/old_d_version/ogre/cpp_framelistener.cpp +++ b/old_d_version/ogre/cpp_framelistener.cpp @@ -100,21 +100,6 @@ extern "C" void ogre_screenshot(char* filename) mWindow->writeContentsToFile(filename); } -// Rotate camera as result of mouse movement -extern "C" void ogre_rotateCamera(float x, float y) -{ - mCamera->yaw(Degree(-x)); - - Quaternion nopitch = mCamera->getOrientation(); - - mCamera->pitch(Degree(-y)); - - // Is the camera close to being upside down? - if(mCamera->getUp()[1] <= 0.1) - // If so, undo the last pitch - mCamera->setOrientation(nopitch); -} - // Get current camera orientation, in the form of 'front' and 'up' // vectors. extern "C" void ogre_getCameraOrientation(float *fx, float *fy, float *fz,