forked from mirror/openmw-tes3mp
split Player class into a MWWorld and a MWRender component
This commit is contained in:
parent
4f51391003
commit
f01a3d5e35
9 changed files with 99 additions and 42 deletions
|
@ -14,14 +14,18 @@ set(GAMEREND
|
||||||
mwrender/cellimp.cpp
|
mwrender/cellimp.cpp
|
||||||
mwrender/interior.cpp
|
mwrender/interior.cpp
|
||||||
mwrender/exterior.cpp
|
mwrender/exterior.cpp
|
||||||
mwrender/sky.cpp)
|
mwrender/sky.cpp
|
||||||
|
mwrender/player.cpp
|
||||||
|
)
|
||||||
set(GAMEREND_HEADER
|
set(GAMEREND_HEADER
|
||||||
mwrender/cell.hpp
|
mwrender/cell.hpp
|
||||||
mwrender/cellimp.hpp
|
mwrender/cellimp.hpp
|
||||||
mwrender/mwscene.hpp
|
mwrender/mwscene.hpp
|
||||||
mwrender/interior.hpp
|
mwrender/interior.hpp
|
||||||
mwrender/exterior.hpp
|
mwrender/exterior.hpp
|
||||||
mwrender/sky.hpp)
|
mwrender/sky.hpp
|
||||||
|
mwrender/player.hpp
|
||||||
|
)
|
||||||
source_group(apps\\openmw\\mwrender FILES ${GAMEREND} ${GAMEREND_HEADER})
|
source_group(apps\\openmw\\mwrender FILES ${GAMEREND} ${GAMEREND_HEADER})
|
||||||
|
|
||||||
set(GAMEINPUT
|
set(GAMEINPUT
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
|
|
||||||
#include "../mwworld/player.hpp"
|
#include "../mwworld/player.hpp"
|
||||||
|
|
||||||
|
#include "../mwrender/player.hpp"
|
||||||
|
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
#include <OgreRoot.h>
|
#include <OgreRoot.h>
|
||||||
|
@ -165,7 +167,7 @@ namespace MWInput
|
||||||
ogre.getRoot()->addFrameListener(this);
|
ogre.getRoot()->addFrameListener(this);
|
||||||
|
|
||||||
// Set up the mouse handler and tell it about the player camera
|
// Set up the mouse handler and tell it about the player camera
|
||||||
mouse = MouseLookEventPtr(new MouseLookEvent(player.getCamera()));
|
mouse = MouseLookEventPtr(new MouseLookEvent(player.getRenderer()->getCamera()));
|
||||||
|
|
||||||
// This event handler pumps events into MyGUI
|
// This event handler pumps events into MyGUI
|
||||||
guiEvents = EventInjectorPtr(new EventInjector(windows.getGui()));
|
guiEvents = EventInjectorPtr(new EventInjector(windows.getGui()));
|
||||||
|
@ -278,7 +280,7 @@ namespace MWInput
|
||||||
{
|
{
|
||||||
// Start mouse-looking again. TODO: This should also allow
|
// Start mouse-looking again. TODO: This should also allow
|
||||||
// for other ways to disable mouselook, like paralyzation.
|
// for other ways to disable mouselook, like paralyzation.
|
||||||
mouse->setCamera(player.getCamera());
|
mouse->setCamera(player.getRenderer()->getCamera());
|
||||||
|
|
||||||
// Disable GUI events
|
// Disable GUI events
|
||||||
guiEvents->enabled = false;
|
guiEvents->enabled = false;
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
#include "../mwworld/ptr.hpp"
|
#include "../mwworld/ptr.hpp"
|
||||||
#include <components/esm/loadstat.hpp>
|
#include <components/esm/loadstat.hpp>
|
||||||
|
|
||||||
|
#include "player.hpp"
|
||||||
|
|
||||||
using namespace MWRender;
|
using namespace MWRender;
|
||||||
using namespace Ogre;
|
using namespace Ogre;
|
||||||
|
|
||||||
|
@ -38,6 +40,13 @@ MWScene::MWScene(OEngine::Render::OgreRenderer &_rend)
|
||||||
|
|
||||||
//used to obtain ingame information of ogre objects (which are faced or selected)
|
//used to obtain ingame information of ogre objects (which are faced or selected)
|
||||||
mRaySceneQuery = rend.getScene()->createRayQuery(Ray());
|
mRaySceneQuery = rend.getScene()->createRayQuery(Ray());
|
||||||
|
|
||||||
|
mPlayer = new MWRender::Player (getCamera());
|
||||||
|
}
|
||||||
|
|
||||||
|
MWScene::~MWScene()
|
||||||
|
{
|
||||||
|
delete mPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<std::string, float> MWScene::getFacedHandle (MWWorld::World& world)
|
std::pair<std::string, float> MWScene::getFacedHandle (MWWorld::World& world)
|
||||||
|
|
|
@ -20,36 +20,41 @@ namespace MWWorld
|
||||||
|
|
||||||
namespace MWRender
|
namespace MWRender
|
||||||
{
|
{
|
||||||
/** Class responsible for Morrowind-specific interfaces to OGRE.
|
class Player;
|
||||||
|
|
||||||
This might be refactored partially into a non-mw specific
|
/// \brief 3D-scene (rendering and physics)
|
||||||
counterpart in ogre/ at some point.
|
|
||||||
*/
|
|
||||||
class MWScene
|
|
||||||
{
|
|
||||||
OEngine::Render::OgreRenderer &rend;
|
|
||||||
|
|
||||||
// Root node for all objects added to the scene. This is rotated so
|
class MWScene
|
||||||
// that the OGRE coordinate system matches that used internally in
|
{
|
||||||
// Morrowind.
|
OEngine::Render::OgreRenderer &rend;
|
||||||
Ogre::SceneNode *mwRoot;
|
|
||||||
Ogre::RaySceneQuery *mRaySceneQuery;
|
|
||||||
|
|
||||||
public:
|
/// Root node for all objects added to the scene. This is rotated so
|
||||||
MWScene(OEngine::Render::OgreRenderer &_rend);
|
/// that the OGRE coordinate system matches that used internally in
|
||||||
|
/// Morrowind.
|
||||||
|
Ogre::SceneNode *mwRoot;
|
||||||
|
Ogre::RaySceneQuery *mRaySceneQuery;
|
||||||
|
|
||||||
Ogre::Camera *getCamera() { return rend.getCamera(); }
|
MWRender::Player *mPlayer;
|
||||||
Ogre::SceneNode *getRoot() { return mwRoot; }
|
|
||||||
Ogre::SceneManager *getMgr() { return rend.getScene(); }
|
|
||||||
Ogre::Viewport *getViewport() { return rend.getViewport(); }
|
|
||||||
Ogre::RaySceneQuery *getRaySceneQuery() { return mRaySceneQuery; }
|
|
||||||
|
|
||||||
//gets the handle of the object the player is looking at
|
public:
|
||||||
//pair<name, distance>
|
|
||||||
//name is empty and distance = -1 if there is no object which
|
MWScene (OEngine::Render::OgreRenderer &_rend);
|
||||||
//can be faced
|
|
||||||
std::pair<std::string, float> getFacedHandle (MWWorld::World& world);
|
~MWScene();
|
||||||
};
|
|
||||||
|
Ogre::Camera *getCamera() { return rend.getCamera(); }
|
||||||
|
Ogre::SceneNode *getRoot() { return mwRoot; }
|
||||||
|
Ogre::SceneManager *getMgr() { return rend.getScene(); }
|
||||||
|
Ogre::Viewport *getViewport() { return rend.getViewport(); }
|
||||||
|
Ogre::RaySceneQuery *getRaySceneQuery() { return mRaySceneQuery; }
|
||||||
|
MWRender::Player *getPlayer() { return mPlayer; }
|
||||||
|
|
||||||
|
/// Gets the handle of the object the player is looking at
|
||||||
|
/// pair<name, distance>
|
||||||
|
/// name is empty and distance = -1 if there is no object which
|
||||||
|
/// can be faced
|
||||||
|
std::pair<std::string, float> getFacedHandle (MWWorld::World& world);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
8
apps/openmw/mwrender/player.cpp
Normal file
8
apps/openmw/mwrender/player.cpp
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
|
||||||
|
#include "player.hpp"
|
||||||
|
|
||||||
|
namespace MWRender
|
||||||
|
{
|
||||||
|
Player::Player (Ogre::Camera *camera) : mCamera (camera)
|
||||||
|
{}
|
||||||
|
}
|
24
apps/openmw/mwrender/player.hpp
Normal file
24
apps/openmw/mwrender/player.hpp
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#ifndef GAME_MWRENDER_PLAYER_H
|
||||||
|
#define GAME_MWRENDER_PLAYER_H
|
||||||
|
|
||||||
|
namespace Ogre
|
||||||
|
{
|
||||||
|
class Camera;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace MWRender
|
||||||
|
{
|
||||||
|
/// \brief Player character rendering and camera control
|
||||||
|
class Player
|
||||||
|
{
|
||||||
|
Ogre::Camera *mCamera;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
Player (Ogre::Camera *camera);
|
||||||
|
|
||||||
|
Ogre::Camera *getCamera() { return mCamera; }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,12 +1,14 @@
|
||||||
|
|
||||||
#include "player.hpp"
|
#include "player.hpp"
|
||||||
|
|
||||||
|
#include "../mwrender/player.hpp"
|
||||||
|
|
||||||
#include "world.hpp"
|
#include "world.hpp"
|
||||||
|
|
||||||
namespace MWWorld
|
namespace MWWorld
|
||||||
{
|
{
|
||||||
Player::Player (Ogre::Camera *cam, const ESM::NPC *player, MWWorld::World& world) :
|
Player::Player (MWRender::Player *renderer, const ESM::NPC *player, MWWorld::World& world) :
|
||||||
mCellStore (0), camera(cam), mWorld (world), mClass (0)
|
mCellStore (0), mRenderer (renderer), mWorld (world), mClass (0)
|
||||||
{
|
{
|
||||||
mPlayer.base = player;
|
mPlayer.base = player;
|
||||||
mName = player->name;
|
mName = player->name;
|
||||||
|
@ -26,7 +28,7 @@ namespace MWWorld
|
||||||
mWorld.moveObject (getPlayer(), x, y, z);
|
mWorld.moveObject (getPlayer(), x, y, z);
|
||||||
|
|
||||||
if (updateCamera)
|
if (updateCamera)
|
||||||
camera->setPosition (Ogre::Vector3 (
|
mRenderer->getCamera()->setPosition (Ogre::Vector3 (
|
||||||
mPlayer.ref.pos.pos[0],
|
mPlayer.ref.pos.pos[0],
|
||||||
mPlayer.ref.pos.pos[2],
|
mPlayer.ref.pos.pos[2],
|
||||||
-mPlayer.ref.pos.pos[1]));
|
-mPlayer.ref.pos.pos[1]));
|
||||||
|
@ -35,13 +37,13 @@ namespace MWWorld
|
||||||
void Player::moveRel (float &relX, float &relY, float &relZ)
|
void Player::moveRel (float &relX, float &relY, float &relZ)
|
||||||
{
|
{
|
||||||
// Move camera relative to its own direction
|
// Move camera relative to its own direction
|
||||||
camera->moveRelative (Ogre::Vector3(relX,0,relZ));
|
mRenderer->getCamera()->moveRelative (Ogre::Vector3(relX,0,relZ));
|
||||||
|
|
||||||
// Up/down movement is always done relative the world axis.
|
// Up/down movement is always done relative the world axis.
|
||||||
camera->move (Ogre::Vector3(0,relY,0));
|
mRenderer->getCamera()->move (Ogre::Vector3(0,relY,0));
|
||||||
|
|
||||||
// Get new camera position, converting back to MW coords.
|
// Get new camera position, converting back to MW coords.
|
||||||
Ogre::Vector3 pos = camera->getPosition();
|
Ogre::Vector3 pos = mRenderer->getCamera()->getPosition();
|
||||||
relX = pos[0];
|
relX = pos[0];
|
||||||
relY = -pos[2];
|
relY = -pos[2];
|
||||||
relZ = pos[1];
|
relZ = pos[1];
|
||||||
|
|
|
@ -8,18 +8,21 @@
|
||||||
#include "../mwworld/refdata.hpp"
|
#include "../mwworld/refdata.hpp"
|
||||||
#include "../mwworld/ptr.hpp"
|
#include "../mwworld/ptr.hpp"
|
||||||
|
|
||||||
namespace MWWorld
|
namespace MWRender
|
||||||
{
|
{
|
||||||
class World;
|
class Player;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace MWWorld
|
namespace MWWorld
|
||||||
{
|
{
|
||||||
|
class World;
|
||||||
|
|
||||||
|
/// \brief NPC object representing the player and additional player data
|
||||||
class Player
|
class Player
|
||||||
{
|
{
|
||||||
ESMS::LiveCellRef<ESM::NPC, MWWorld::RefData> mPlayer;
|
ESMS::LiveCellRef<ESM::NPC, MWWorld::RefData> mPlayer;
|
||||||
MWWorld::Ptr::CellStore *mCellStore;
|
MWWorld::Ptr::CellStore *mCellStore;
|
||||||
Ogre::Camera *camera;
|
MWRender::Player *mRenderer;
|
||||||
MWWorld::World& mWorld;
|
MWWorld::World& mWorld;
|
||||||
std::string mName;
|
std::string mName;
|
||||||
bool mMale;
|
bool mMale;
|
||||||
|
@ -29,7 +32,7 @@ namespace MWWorld
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Player(Ogre::Camera *cam, const ESM::NPC *player, MWWorld::World& world);
|
Player(MWRender::Player *renderer, const ESM::NPC *player, MWWorld::World& world);
|
||||||
|
|
||||||
~Player();
|
~Player();
|
||||||
|
|
||||||
|
@ -41,8 +44,6 @@ namespace MWWorld
|
||||||
mCellStore = cellStore;
|
mCellStore = cellStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ogre::Camera *getCamera() { return camera; }
|
|
||||||
|
|
||||||
/// Move the player relative to her own position and
|
/// Move the player relative to her own position and
|
||||||
/// orientation. After the call, the new position is returned.
|
/// orientation. After the call, the new position is returned.
|
||||||
void moveRel (float &relX, float &relY, float &relZ);
|
void moveRel (float &relX, float &relY, float &relZ);
|
||||||
|
@ -53,6 +54,8 @@ namespace MWWorld
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MWRender::Player *getRenderer() { return mRenderer; }
|
||||||
|
|
||||||
void setName (const std::string& name)
|
void setName (const std::string& name)
|
||||||
{
|
{
|
||||||
mName = name;
|
mName = name;
|
||||||
|
|
|
@ -329,7 +329,7 @@ namespace MWWorld
|
||||||
mEsm.open (masterPath.file_string());
|
mEsm.open (masterPath.file_string());
|
||||||
mStore.load (mEsm);
|
mStore.load (mEsm);
|
||||||
|
|
||||||
mPlayer = new MWWorld::Player (mScene.getCamera(), mStore.npcs.find ("player"), *this);
|
mPlayer = new MWWorld::Player (mScene.getPlayer(), mStore.npcs.find ("player"), *this);
|
||||||
|
|
||||||
// global variables
|
// global variables
|
||||||
mGlobalVariables = new Globals (mStore);
|
mGlobalVariables = new Globals (mStore);
|
||||||
|
|
Loading…
Reference in a new issue