Added mouse look, fixed WASD bindings

actorid openmw-0.07_Bond_just_Bond
Nicolay Korslund 15 years ago
parent 3a0600b84c
commit 737b29035d

@ -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);

@ -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)

@ -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;

@ -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"),

@ -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)

@ -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,

Loading…
Cancel
Save