Added camera movement (arrows/WASD). No mouse look yet.
parent
af7c87e8dc
commit
6b6f5b95ec
@ -0,0 +1,56 @@
|
||||
#ifndef _MWRENDER_PLAYERPOS_H
|
||||
#define _MWRENDER_PLAYERPOS_H
|
||||
|
||||
#include "OgreCamera.h"
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
// This class keeps track of the player position. It takes care of
|
||||
// camera movement, sound listener updates, and collision handling
|
||||
// (to be done).
|
||||
class PlayerPos
|
||||
{
|
||||
float x, y, z;
|
||||
Ogre::Camera *camera;
|
||||
|
||||
public:
|
||||
PlayerPos(Ogre::Camera *cam) :
|
||||
camera(cam), x(0), y(0), z(0) {}
|
||||
|
||||
// Set the player position. Uses Morrowind coordinates.
|
||||
void setPos(float _x, float _y, float _z)
|
||||
{
|
||||
x = _x;
|
||||
y = _y;
|
||||
z = _z;
|
||||
|
||||
// TODO: Update sound listener
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
using namespace Ogre;
|
||||
|
||||
// Move camera relative to its own direction
|
||||
camera->moveRelative(Vector3(relX,0,relZ));
|
||||
|
||||
// Up/down movement is always done relative the world axis.
|
||||
camera->move(Vector3(0,relY,0));
|
||||
|
||||
// Get new camera position, converting back to MW coords.
|
||||
Vector3 pos = camera->getPosition();
|
||||
relX = pos[0];
|
||||
relY = -pos[2];
|
||||
relZ = pos[1];
|
||||
|
||||
// TODO: Collision detection must be used to find the REAL new
|
||||
// position.
|
||||
|
||||
// Set the position
|
||||
setPos(relX, relY, relZ);
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif
|
@ -0,0 +1,51 @@
|
||||
#ifndef _INPUT_POLLER_H
|
||||
#define _INPUT_POLLER_H
|
||||
|
||||
#include "dispatch_map.hpp"
|
||||
#include "oismanager.hpp"
|
||||
|
||||
namespace Input {
|
||||
|
||||
/** The poller is used to check (poll) for keys rather than waiting
|
||||
for events. TODO: Might make this OIS-independent later. */
|
||||
struct Poller
|
||||
{
|
||||
DispatchMap map;
|
||||
OIS::Keyboard *keyboard;
|
||||
|
||||
Poller(Input::OISManager &ois)
|
||||
{
|
||||
keyboard = ois.keyboard;
|
||||
assert(keyboard);
|
||||
}
|
||||
|
||||
/** Bind or unbind a given action with a key. The action is the first
|
||||
parameter, the key is the second.
|
||||
*/
|
||||
void bind(int in, int out) { map.bind(in, out); }
|
||||
void unbind(int in, int out) { map.unbind(in, out); }
|
||||
bool isBound(int in) const { return map.isBound(in); }
|
||||
|
||||
/// Check whether a given action button is currently pressed.
|
||||
typedef DispatchMap::OutList _O;
|
||||
bool isDown(int index) const
|
||||
{
|
||||
assert(keyboard);
|
||||
|
||||
// No bindings, no action
|
||||
if(!isBound(index))
|
||||
return false;
|
||||
|
||||
// Get all the keys bound to this action, and check them.
|
||||
const _O &list = map.getList(index);
|
||||
_O::const_iterator it;
|
||||
for(it = list.begin(); it != list.end(); it++)
|
||||
// If there's any match, we're good to go.
|
||||
if(keyboard->isKeyDown((OIS::KeyCode)*it)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
Loading…
Reference in New Issue