diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index b9fd3f497..a5e3d525b 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -14,14 +14,18 @@ set(GAMEREND mwrender/cellimp.cpp mwrender/interior.cpp mwrender/exterior.cpp - mwrender/sky.cpp) + mwrender/sky.cpp + mwrender/player.cpp + ) set(GAMEREND_HEADER mwrender/cell.hpp mwrender/cellimp.hpp mwrender/mwscene.hpp mwrender/interior.hpp mwrender/exterior.hpp - mwrender/sky.hpp) + mwrender/sky.hpp + mwrender/player.hpp + ) source_group(apps\\openmw\\mwrender FILES ${GAMEREND} ${GAMEREND_HEADER}) set(GAMEINPUT diff --git a/apps/openmw/mwinput/inputmanager.cpp b/apps/openmw/mwinput/inputmanager.cpp index 11e6cb617..31623fb58 100644 --- a/apps/openmw/mwinput/inputmanager.cpp +++ b/apps/openmw/mwinput/inputmanager.cpp @@ -20,6 +20,8 @@ #include "../mwworld/player.hpp" +#include "../mwrender/player.hpp" + #include #include #include @@ -165,7 +167,7 @@ namespace MWInput ogre.getRoot()->addFrameListener(this); // 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 guiEvents = EventInjectorPtr(new EventInjector(windows.getGui())); @@ -278,7 +280,7 @@ namespace MWInput { // Start mouse-looking again. TODO: This should also allow // for other ways to disable mouselook, like paralyzation. - mouse->setCamera(player.getCamera()); + mouse->setCamera(player.getRenderer()->getCamera()); // Disable GUI events guiEvents->enabled = false; diff --git a/apps/openmw/mwrender/mwscene.cpp b/apps/openmw/mwrender/mwscene.cpp index 133607797..5fff2c295 100644 --- a/apps/openmw/mwrender/mwscene.cpp +++ b/apps/openmw/mwrender/mwscene.cpp @@ -13,6 +13,8 @@ #include "../mwworld/ptr.hpp" #include +#include "player.hpp" + using namespace MWRender; 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) mRaySceneQuery = rend.getScene()->createRayQuery(Ray()); + + mPlayer = new MWRender::Player (getCamera()); +} + +MWScene::~MWScene() +{ + delete mPlayer; } std::pair MWScene::getFacedHandle (MWWorld::World& world) diff --git a/apps/openmw/mwrender/mwscene.hpp b/apps/openmw/mwrender/mwscene.hpp index 9d2a51bae..b4c8357cf 100644 --- a/apps/openmw/mwrender/mwscene.hpp +++ b/apps/openmw/mwrender/mwscene.hpp @@ -20,36 +20,41 @@ namespace MWWorld namespace MWRender { - /** Class responsible for Morrowind-specific interfaces to OGRE. + class Player; - This might be refactored partially into a non-mw specific - counterpart in ogre/ at some point. - */ - class MWScene - { - OEngine::Render::OgreRenderer &rend; + /// \brief 3D-scene (rendering and physics) - // Root node for all objects added to the scene. This is rotated so - // that the OGRE coordinate system matches that used internally in - // Morrowind. - Ogre::SceneNode *mwRoot; - Ogre::RaySceneQuery *mRaySceneQuery; + class MWScene + { + OEngine::Render::OgreRenderer &rend; - public: - MWScene(OEngine::Render::OgreRenderer &_rend); + /// Root node for all objects added to the scene. This is rotated so + /// that the OGRE coordinate system matches that used internally in + /// Morrowind. + Ogre::SceneNode *mwRoot; + Ogre::RaySceneQuery *mRaySceneQuery; - 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 *mPlayer; - //gets the handle of the object the player is looking at - //pair - //name is empty and distance = -1 if there is no object which - //can be faced - std::pair getFacedHandle (MWWorld::World& world); - }; + public: + + MWScene (OEngine::Render::OgreRenderer &_rend); + + ~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 is empty and distance = -1 if there is no object which + /// can be faced + std::pair getFacedHandle (MWWorld::World& world); + }; } #endif diff --git a/apps/openmw/mwrender/player.cpp b/apps/openmw/mwrender/player.cpp new file mode 100644 index 000000000..badc77bda --- /dev/null +++ b/apps/openmw/mwrender/player.cpp @@ -0,0 +1,8 @@ + +#include "player.hpp" + +namespace MWRender +{ + Player::Player (Ogre::Camera *camera) : mCamera (camera) + {} +} diff --git a/apps/openmw/mwrender/player.hpp b/apps/openmw/mwrender/player.hpp new file mode 100644 index 000000000..a8f8d24fe --- /dev/null +++ b/apps/openmw/mwrender/player.hpp @@ -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 diff --git a/apps/openmw/mwworld/player.cpp b/apps/openmw/mwworld/player.cpp index c2dd8ff35..1c27dbe77 100644 --- a/apps/openmw/mwworld/player.cpp +++ b/apps/openmw/mwworld/player.cpp @@ -1,12 +1,14 @@ #include "player.hpp" +#include "../mwrender/player.hpp" + #include "world.hpp" namespace MWWorld { - Player::Player (Ogre::Camera *cam, const ESM::NPC *player, MWWorld::World& world) : - mCellStore (0), camera(cam), mWorld (world), mClass (0) + Player::Player (MWRender::Player *renderer, const ESM::NPC *player, MWWorld::World& world) : + mCellStore (0), mRenderer (renderer), mWorld (world), mClass (0) { mPlayer.base = player; mName = player->name; @@ -26,7 +28,7 @@ namespace MWWorld mWorld.moveObject (getPlayer(), x, y, z); if (updateCamera) - camera->setPosition (Ogre::Vector3 ( + mRenderer->getCamera()->setPosition (Ogre::Vector3 ( mPlayer.ref.pos.pos[0], mPlayer.ref.pos.pos[2], -mPlayer.ref.pos.pos[1])); @@ -35,13 +37,13 @@ namespace MWWorld void Player::moveRel (float &relX, float &relY, float &relZ) { // 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. - camera->move (Ogre::Vector3(0,relY,0)); + mRenderer->getCamera()->move (Ogre::Vector3(0,relY,0)); // Get new camera position, converting back to MW coords. - Ogre::Vector3 pos = camera->getPosition(); + Ogre::Vector3 pos = mRenderer->getCamera()->getPosition(); relX = pos[0]; relY = -pos[2]; relZ = pos[1]; diff --git a/apps/openmw/mwworld/player.hpp b/apps/openmw/mwworld/player.hpp index 0b488116e..27bc3138b 100644 --- a/apps/openmw/mwworld/player.hpp +++ b/apps/openmw/mwworld/player.hpp @@ -8,18 +8,21 @@ #include "../mwworld/refdata.hpp" #include "../mwworld/ptr.hpp" -namespace MWWorld +namespace MWRender { - class World; + class Player; } namespace MWWorld { + class World; + + /// \brief NPC object representing the player and additional player data class Player { ESMS::LiveCellRef mPlayer; MWWorld::Ptr::CellStore *mCellStore; - Ogre::Camera *camera; + MWRender::Player *mRenderer; MWWorld::World& mWorld; std::string mName; bool mMale; @@ -29,7 +32,7 @@ namespace MWWorld public: - Player(Ogre::Camera *cam, const ESM::NPC *player, MWWorld::World& world); + Player(MWRender::Player *renderer, const ESM::NPC *player, MWWorld::World& world); ~Player(); @@ -41,8 +44,6 @@ namespace MWWorld mCellStore = cellStore; } - 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); @@ -53,6 +54,8 @@ namespace MWWorld return ptr; } + MWRender::Player *getRenderer() { return mRenderer; } + void setName (const std::string& name) { mName = name; diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 7ad8afba8..d8d7b3d6a 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -329,7 +329,7 @@ namespace MWWorld mEsm.open (masterPath.file_string()); 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 mGlobalVariables = new Globals (mStore);