1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 17:19:56 +00:00
openmw-tes3mp/apps/openmw/mwrender/playerpos.hpp

87 lines
2.3 KiB
C++
Raw Normal View History

#ifndef _MWRENDER_PLAYERPOS_H
#define _MWRENDER_PLAYERPOS_H
#include "OgreCamera.h"
#include <components/esm_store/cell_store.hpp>
#include "../mwworld/refdata.hpp"
2010-07-26 10:59:50 +00:00
#include "../mwworld/ptr.hpp"
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
{
ESMS::LiveCellRef<ESM::NPC, MWWorld::RefData> mPlayer;
2010-07-26 10:59:50 +00:00
MWWorld::Ptr::CellStore *mCellStore;
Ogre::Camera *camera;
public:
PlayerPos(Ogre::Camera *cam, const ESM::NPC *player) :
2010-07-26 10:59:50 +00:00
mCellStore (0), camera(cam)
{
mPlayer.base = player;
2010-07-22 10:29:23 +00:00
mPlayer.ref.pos.pos[0] = mPlayer.ref.pos.pos[1] = mPlayer.ref.pos.pos[2] = 0;
}
// Set the player position. Uses Morrowind coordinates.
2010-07-22 10:29:23 +00:00
void setPos(float _x, float _y, float _z, bool updateCamera = false)
{
mPlayer.ref.pos.pos[0] = _x;
mPlayer.ref.pos.pos[1] = _y;
mPlayer.ref.pos.pos[2] = _z;
2010-07-22 10:29:23 +00:00
if (updateCamera)
camera->setPosition (Ogre::Vector3 (
mPlayer.ref.pos.pos[0],
mPlayer.ref.pos.pos[2],
mPlayer.ref.pos.pos[1]));
// TODO: Update sound listener
}
2010-07-26 10:59:50 +00:00
void setCell (MWWorld::Ptr::CellStore *cellStore)
{
mCellStore = cellStore;
}
2010-06-22 08:15:22 +00:00
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)
{
// TODO: Update mPlayer state
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);
}
MWWorld::Ptr getPlayer()
{
MWWorld::Ptr ptr (&mPlayer, mCellStore);
return ptr;
}
};
}
#endif