From 4b846a54f1ea67afa637cecbe5f19088aef6b9be Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Mon, 1 Aug 2011 15:55:36 +0200 Subject: [PATCH] PhysicsSystem --- apps/openmw/CMakeLists.txt | 2 + apps/openmw/mwrender/exterior.cpp | 10 +- apps/openmw/mwrender/exterior.hpp | 4 +- apps/openmw/mwrender/interior.cpp | 6 +- apps/openmw/mwrender/interior.hpp | 9 +- apps/openmw/mwrender/mwscene.cpp | 115 ----------------- apps/openmw/mwrender/mwscene.hpp | 24 ---- apps/openmw/mwworld/physicssystem.cpp | 171 ++++++++++++++++++++++++++ apps/openmw/mwworld/physicssystem.hpp | 45 +++++++ apps/openmw/mwworld/physikssystem.cpp | 7 -- apps/openmw/mwworld/physikssystem.hpp | 4 - apps/openmw/mwworld/scene.cpp | 10 +- apps/openmw/mwworld/scene.hpp | 4 +- apps/openmw/mwworld/world.cpp | 13 +- apps/openmw/mwworld/world.hpp | 2 + 15 files changed, 256 insertions(+), 170 deletions(-) create mode 100644 apps/openmw/mwworld/physicssystem.cpp create mode 100644 apps/openmw/mwworld/physicssystem.hpp delete mode 100644 apps/openmw/mwworld/physikssystem.cpp delete mode 100644 apps/openmw/mwworld/physikssystem.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 8fc10079c..6322c4080 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -140,6 +140,7 @@ source_group(apps\\openmw\\mwsound FILES ${GAMESOUND} ${GAMESOUND_HEADER}) set(GAMEWORLD mwworld/world.cpp mwworld/scene.cpp + mwworld/physicssystem.cpp mwworld/globals.cpp mwworld/class.cpp mwworld/actionteleport.cpp @@ -152,6 +153,7 @@ set(GAMEWORLD set(GAMEWORLD_HEADER mwworld/refdata.hpp mwworld/world.hpp + mwworld/physicssystem.hpp mwworld/scene.hpp mwworld/environment.hpp mwworld/globals.hpp diff --git a/apps/openmw/mwrender/exterior.cpp b/apps/openmw/mwrender/exterior.cpp index 513fdac2a..6e6908a62 100644 --- a/apps/openmw/mwrender/exterior.cpp +++ b/apps/openmw/mwrender/exterior.cpp @@ -34,8 +34,8 @@ bool ExteriorCellRender::lightOutQuadInLin = false; int ExteriorCellRender::uniqueID = 0; ExteriorCellRender::ExteriorCellRender(ESMS::CellStore &_cell, MWWorld::Environment& environment, - MWScene &_scene) - : mCell(_cell), mEnvironment (environment), mScene(_scene), mBase(NULL), mInsert(NULL), mAmbientMode (0) + MWScene &_scene, MWWorld::PhysicsSystem *physics) + : mCell(_cell), mEnvironment (environment), mScene(_scene), mBase(NULL), mInsert(NULL), mAmbientMode (0), mPhysics(physics) { uniqueID = uniqueID +1; sg = mScene.getMgr()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID)); @@ -233,13 +233,15 @@ void ExteriorCellRender::insertMesh(const std::string &mesh) void ExteriorCellRender::insertObjectPhysics() { if (!mInsertMesh.empty()) - mScene.addObject (mInsert->getName(), mInsertMesh, mInsert->getOrientation(), + { + mPhysics->addObject (mInsert->getName(), mInsertMesh, mInsert->getOrientation(), mInsert->getScale().x, mInsert->getPosition()); + } } void ExteriorCellRender::insertActorPhysics() { - mScene.addActor (mInsert->getName(), mInsertMesh, mInsert->getPosition()); + mPhysics->addActor (mInsert->getName(), mInsertMesh, mInsert->getPosition()); } // insert a light related to the most recent insertBegin call. diff --git a/apps/openmw/mwrender/exterior.hpp b/apps/openmw/mwrender/exterior.hpp index 6c7f6effc..d8f6b9b96 100644 --- a/apps/openmw/mwrender/exterior.hpp +++ b/apps/openmw/mwrender/exterior.hpp @@ -3,6 +3,7 @@ #include "cell.hpp" #include "cellimp.hpp" +#include "../mwworld/physicssystem.hpp" #include "OgreColourValue.h" #include @@ -49,6 +50,7 @@ namespace MWRender ESMS::CellStore &mCell; MWWorld::Environment &mEnvironment; MWScene &mScene; + MWWorld::PhysicsSystem *mPhysics; /// The scene node that contains all objects belonging to this /// cell. @@ -101,7 +103,7 @@ namespace MWRender public: ExteriorCellRender(ESMS::CellStore &_cell, MWWorld::Environment& environment, - MWScene &_scene); + MWScene &_scene, MWWorld::PhysicsSystem *physics); virtual ~ExteriorCellRender() { destroy(); } diff --git a/apps/openmw/mwrender/interior.cpp b/apps/openmw/mwrender/interior.cpp index 02bed0898..bfde4b04e 100644 --- a/apps/openmw/mwrender/interior.cpp +++ b/apps/openmw/mwrender/interior.cpp @@ -195,13 +195,15 @@ void InteriorCellRender::insertMesh(const std::string &mesh) void InteriorCellRender::insertObjectPhysics() { if (!mInsertMesh.empty()) - scene.addObject (insert->getName(), mInsertMesh, insert->getOrientation(), + { + mPhysics->addObject (insert->getName(), mInsertMesh, insert->getOrientation(), insert->getScale().x, insert->getPosition()); + } } void InteriorCellRender::insertActorPhysics() { - scene.addActor (insert->getName(), mInsertMesh, insert->getPosition()); + mPhysics->addActor (insert->getName(), mInsertMesh, insert->getPosition()); } // insert a light related to the most recent insertBegin call. diff --git a/apps/openmw/mwrender/interior.hpp b/apps/openmw/mwrender/interior.hpp index 295eaa475..16fca0898 100644 --- a/apps/openmw/mwrender/interior.hpp +++ b/apps/openmw/mwrender/interior.hpp @@ -3,6 +3,7 @@ #include "cell.hpp" #include "cellimp.hpp" +#include "../mwworld/physicssystem.hpp" #include "OgreColourValue.h" #include @@ -48,6 +49,7 @@ namespace MWRender ESMS::CellStore &cell; MWWorld::Environment &mEnvironment; MWScene &scene; + MWWorld::PhysicsSystem *mPhysics; /// The scene node that contains all objects belonging to this /// cell. @@ -93,8 +95,11 @@ namespace MWRender public: InteriorCellRender(ESMS::CellStore &_cell, MWWorld::Environment& environment, - MWScene &_scene) - : cell(_cell), mEnvironment (environment), scene(_scene), base(NULL), insert(NULL), ambientMode (0) {} + MWScene &_scene, MWWorld::PhysicsSystem *physics) + : cell(_cell), mEnvironment (environment), scene(_scene), base(NULL), insert(NULL), ambientMode (0) + { + mPhysics = physics; + } virtual ~InteriorCellRender() { destroy(); } diff --git a/apps/openmw/mwrender/mwscene.cpp b/apps/openmw/mwrender/mwscene.cpp index e4d449bf2..a1d4aed03 100644 --- a/apps/openmw/mwrender/mwscene.cpp +++ b/apps/openmw/mwrender/mwscene.cpp @@ -76,121 +76,6 @@ std::pair MWScene::getFacedHandle (MWWorld::World& world) return eng->rayTest(from,to); } -void MWScene::doPhysics (float duration, MWWorld::World& world, - const std::vector >& actors) -{ - // stop changes to world from being reported back to the physics system - MWWorld::DoingPhysics scopeGuard; - - //set the DebugRenderingMode. To disable it,set it to 0 - //eng->setDebugRenderingMode(1); - - //set the walkdirection to 0 (no movement) for every actor) - for(std::map::iterator it = eng->PhysicActorMap.begin(); it != eng->PhysicActorMap.end();it++) - { - OEngine::Physic::PhysicActor* act = it->second; - act->setWalkDirection(btVector3(0,0,0)); - } - - for (std::vector >::const_iterator iter (actors.begin()); - iter!=actors.end(); ++iter) - { - OEngine::Physic::PhysicActor* act = eng->getCharacter(iter->first); - - //dirty stuff to get the camera orientation. Must be changed! - - Ogre::SceneNode *sceneNode = rend.getScene()->getSceneNode (iter->first); - Ogre::Vector3 dir; - Ogre::Node* yawNode = sceneNode->getChildIterator().getNext(); - Ogre::Node* pitchNode = yawNode->getChildIterator().getNext(); - if(mFreeFly) - { - Ogre::Quaternion yawQuat = yawNode->getOrientation(); - Ogre::Quaternion pitchQuat = pitchNode->getOrientation(); - Ogre::Vector3 dir1(iter->second.x,iter->second.z,-iter->second.y); - dir = 0.07*(yawQuat*pitchQuat*dir1); - } - else - { - Ogre::Quaternion quat = yawNode->getOrientation(); - Ogre::Vector3 dir1(iter->second.x,iter->second.z,-iter->second.y); - dir = 0.025*(quat*dir1); - } - - //set the walk direction - act->setWalkDirection(btVector3(dir.x,-dir.z,dir.y)); - } - eng->stepSimulation(duration); - - for(std::map::iterator it = eng->PhysicActorMap.begin(); it != eng->PhysicActorMap.end();it++) - { - OEngine::Physic::PhysicActor* act = it->second; - btVector3 newPos = act->getPosition(); - MWWorld::Ptr ptr = world.getPtrViaHandle (it->first); - world.moveObject (ptr, newPos.x(), newPos.y(), newPos.z()); - } -} - -void MWScene::addObject (const std::string& handle, const std::string& mesh, - const Ogre::Quaternion& rotation, float scale, const Ogre::Vector3& position) -{ - OEngine::Physic::RigidBody* body = eng->createRigidBody(mesh,handle); - eng->addRigidBody(body); - btTransform tr; - tr.setOrigin(btVector3(position.x,position.y,position.z)); - tr.setRotation(btQuaternion(rotation.x,rotation.y,rotation.z,rotation.w)); - body->setWorldTransform(tr); -} - -void MWScene::addActor (const std::string& handle, const std::string& mesh, - const Ogre::Vector3& position) -{ - //TODO:optimize this. Searching the std::map isn't very efficient i think. - eng->addCharacter(handle); - OEngine::Physic::PhysicActor* act = eng->getCharacter(handle); - act->setPosition(btVector3(position.x,position.y,position.z)); -} - -void MWScene::removeObject (const std::string& handle) -{ - //TODO:check if actor??? - eng->removeCharacter(handle); - eng->removeRigidBody(handle); - eng->deleteRigidBody(handle); -} - -void MWScene::moveObject (const std::string& handle, const Ogre::Vector3& position, bool updatePhysics) -{ - rend.getScene()->getSceneNode(handle)->setPosition(position); - - if(updatePhysics)//TODO: is it an actor? Done? - { - if (OEngine::Physic::RigidBody* body = eng->getRigidBody(handle)) - { - // TODO very dirty hack to avoid crash during setup -> needs cleaning up to allow - // start positions others than 0, 0, 0 - btTransform tr = body->getWorldTransform(); - tr.setOrigin(btVector3(position.x,position.y,position.z)); - body->setWorldTransform(tr); - } - if (OEngine::Physic::PhysicActor* act = eng->getCharacter(handle)) - { - // TODO very dirty hack to avoid crash during setup -> needs cleaning up to allow - // start positions others than 0, 0, 0 - act->setPosition(btVector3(position.x,position.y,position.z)); - } - } -} - -void MWScene::rotateObject (const std::string& handle, const Ogre::Quaternion& rotation) -{ -} - -void MWScene::scaleObject (const std::string& handle, float scale) -{ - -} - bool MWScene::toggleCollisionMode() { for(std::map::iterator it = eng->PhysicActorMap.begin(); it != eng->PhysicActorMap.end();it++) diff --git a/apps/openmw/mwrender/mwscene.hpp b/apps/openmw/mwrender/mwscene.hpp index 7429ff21e..a9dfad7b5 100644 --- a/apps/openmw/mwrender/mwscene.hpp +++ b/apps/openmw/mwrender/mwscene.hpp @@ -65,30 +65,6 @@ namespace MWRender /// can be faced std::pair getFacedHandle (MWWorld::World& world); - /// Run physics simulation and modify \a world accordingly. - void doPhysics (float duration, MWWorld::World& world, - const std::vector >& actors); - - /// Add object to physics system. - void addObject (const std::string& handle, const std::string& mesh, - const Ogre::Quaternion& rotation, float scale, const Ogre::Vector3& position); - - /// Add actor to physics system. - void addActor (const std::string& handle, const std::string& mesh, - const Ogre::Vector3& position); - - /// Remove object from physic systems. - void removeObject (const std::string& handle); - - /// Move object. - void moveObject (const std::string& handle, const Ogre::Vector3& position, bool updatePhysics); - - /// Change object's orientation. - void rotateObject (const std::string& handle, const Ogre::Quaternion& rotation); - - /// Change object's scale. - void scaleObject (const std::string& handle, float scale); - /// Toggle collision mode for player. If disabled player object should ignore /// collisions and gravity. /// \return Resulting mode diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp new file mode 100644 index 000000000..07a822ffa --- /dev/null +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -0,0 +1,171 @@ +#include "physicssystem.hpp" +#include "../mwworld/doingphysics.hpp" +#include "../mwworld/ptr.hpp" +#include "../mwworld/world.hpp" // FIXME + +#include "OgreRoot.h" +#include "OgreRenderWindow.h" +#include "OgreSceneManager.h" +#include "OgreViewport.h" +#include "OgreCamera.h" +#include "OgreTextureManager.h" + + +namespace MWWorld +{ + + PhysicsSystem::PhysicsSystem(OEngine::Render::OgreRenderer &_rend , OEngine::Physic::PhysicEngine* physEng) : + mRender(_rend), mEngine(physEng) + { + + } + + PhysicsSystem::~PhysicsSystem() + { + + } + + void PhysicsSystem::doPhysics (float duration, MWWorld::World& world, + const std::vector >& actors) + { + // stop changes to world from being reported back to the physics system + MWWorld::DoingPhysics scopeGuard; + + //set the DebugRenderingMode. To disable it,set it to 0 + //eng->setDebugRenderingMode(1); + + //set the walkdirection to 0 (no movement) for every actor) + for(std::map::iterator it = mEngine->PhysicActorMap.begin(); it != mEngine->PhysicActorMap.end();it++) + { + OEngine::Physic::PhysicActor* act = it->second; + act->setWalkDirection(btVector3(0,0,0)); + } + + for (std::vector >::const_iterator iter (actors.begin()); + iter!=actors.end(); ++iter) + { + OEngine::Physic::PhysicActor* act = mEngine->getCharacter(iter->first); + + //dirty stuff to get the camera orientation. Must be changed! + + Ogre::SceneNode *sceneNode = mRender.getScene()->getSceneNode (iter->first); + Ogre::Vector3 dir; + Ogre::Node* yawNode = sceneNode->getChildIterator().getNext(); + Ogre::Node* pitchNode = yawNode->getChildIterator().getNext(); + if(mFreeFly) + { + Ogre::Quaternion yawQuat = yawNode->getOrientation(); + Ogre::Quaternion pitchQuat = pitchNode->getOrientation(); + Ogre::Vector3 dir1(iter->second.x,iter->second.z,-iter->second.y); + dir = 0.07*(yawQuat*pitchQuat*dir1); + } + else + { + Ogre::Quaternion quat = yawNode->getOrientation(); + Ogre::Vector3 dir1(iter->second.x,iter->second.z,-iter->second.y); + dir = 0.025*(quat*dir1); + } + + //set the walk direction + act->setWalkDirection(btVector3(dir.x,-dir.z,dir.y)); + } + mEngine->stepSimulation(duration); + + for(std::map::iterator it = mEngine->PhysicActorMap.begin(); it != mEngine->PhysicActorMap.end();it++) + { + OEngine::Physic::PhysicActor* act = it->second; + btVector3 newPos = act->getPosition(); + MWWorld::Ptr ptr = world.getPtrViaHandle (it->first); + world.moveObject (ptr, newPos.x(), newPos.y(), newPos.z()); + } + } + + void PhysicsSystem::addObject (const std::string& handle, const std::string& mesh, + const Ogre::Quaternion& rotation, float scale, const Ogre::Vector3& position) + { + OEngine::Physic::RigidBody* body = mEngine->createRigidBody(mesh,handle); + mEngine->addRigidBody(body); + btTransform tr; + tr.setOrigin(btVector3(position.x,position.y,position.z)); + tr.setRotation(btQuaternion(rotation.x,rotation.y,rotation.z,rotation.w)); + body->setWorldTransform(tr); + } + + void PhysicsSystem::addActor (const std::string& handle, const std::string& mesh, + const Ogre::Vector3& position) + { + //TODO:optimize this. Searching the std::map isn't very efficient i think. + mEngine->addCharacter(handle); + OEngine::Physic::PhysicActor* act = mEngine->getCharacter(handle); + act->setPosition(btVector3(position.x,position.y,position.z)); + } + + void PhysicsSystem::removeObject (const std::string& handle) + { + //TODO:check if actor??? + mEngine->removeCharacter(handle); + mEngine->removeRigidBody(handle); + mEngine->deleteRigidBody(handle); + } + + void PhysicsSystem::moveObject (const std::string& handle, const Ogre::Vector3& position, bool updatePhysics) + { + mRender.getScene()->getSceneNode(handle)->setPosition(position); + + if(updatePhysics)//TODO: is it an actor? Done? + { + if (OEngine::Physic::RigidBody* body = mEngine->getRigidBody(handle)) + { + // TODO very dirty hack to avoid crash during setup -> needs cleaning up to allow + // start positions others than 0, 0, 0 + btTransform tr = body->getWorldTransform(); + tr.setOrigin(btVector3(position.x,position.y,position.z)); + body->setWorldTransform(tr); + } + if (OEngine::Physic::PhysicActor* act = mEngine->getCharacter(handle)) + { + // TODO very dirty hack to avoid crash during setup -> needs cleaning up to allow + // start positions others than 0, 0, 0 + act->setPosition(btVector3(position.x,position.y,position.z)); + } + } + } + + void PhysicsSystem::rotateObject (const std::string& handle, const Ogre::Quaternion& rotation) + { + } + + void PhysicsSystem::scaleObject (const std::string& handle, float scale) + { + + } + + bool PhysicsSystem::toggleCollisionMode() + { + for(std::map::iterator it = mEngine->PhysicActorMap.begin(); it != mEngine->PhysicActorMap.end();it++) + { + OEngine::Physic::PhysicActor* act = it->second; + bool cmode = act->getCollisionMode(); + if(cmode) + { + act->enableCollisions(false); + act->setGravity(0.); + act->setVerticalVelocity(0); + mFreeFly = true; + return false; + } + else + { + mFreeFly = false; + act->enableCollisions(true); + act->setGravity(4.); + act->setVerticalVelocity(0); + return true; + } + } + + return false; // This should never happen, but it shall not bother us now, since + // this part of the code needs a rewrite anyway. + } + +} diff --git a/apps/openmw/mwworld/physicssystem.hpp b/apps/openmw/mwworld/physicssystem.hpp new file mode 100644 index 000000000..3465c0eae --- /dev/null +++ b/apps/openmw/mwworld/physicssystem.hpp @@ -0,0 +1,45 @@ +#ifndef GAME_MWWORLD_PHYSICSSYSTEM_H +#define GAME_MWWORLD_PHYSICSSYSTEM_H + +#include +#include +#include + +namespace MWWorld +{ + + class PhysicsSystem + { + public: + PhysicsSystem (OEngine::Render::OgreRenderer &_rend , OEngine::Physic::PhysicEngine* physEng); + ~PhysicsSystem (); + + void doPhysics (float duration, MWWorld::World& world, + const std::vector >& actors); + + void addObject (const std::string& handle, const std::string& mesh, + const Ogre::Quaternion& rotation, float scale, const Ogre::Vector3& position); + + void addActor (const std::string& handle, const std::string& mesh, + const Ogre::Vector3& position); + + void removeObject (const std::string& handle); + + void moveObject (const std::string& handle, const Ogre::Vector3& position, bool updatePhysics); + + void rotateObject (const std::string& handle, const Ogre::Quaternion& rotation); + + void scaleObject (const std::string& handle, float scale); + + bool toggleCollisionMode(); + + private: + OEngine::Render::OgreRenderer &mRender; + OEngine::Physic::PhysicEngine* mEngine; + bool mFreeFly; + + }; + +} + +#endif diff --git a/apps/openmw/mwworld/physikssystem.cpp b/apps/openmw/mwworld/physikssystem.cpp deleted file mode 100644 index 5e2042937..000000000 --- a/apps/openmw/mwworld/physikssystem.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "physikssystem.hpp" - - -namespace MWWorld -{ - -} diff --git a/apps/openmw/mwworld/physikssystem.hpp b/apps/openmw/mwworld/physikssystem.hpp deleted file mode 100644 index 450f630b5..000000000 --- a/apps/openmw/mwworld/physikssystem.hpp +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef GAME_MWWORLD_PHYSIKSSYSTEM_H -#define GAME_MWWORLD_PHYSIKSSYSTEM_H - -#endif diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 2080653fa..d9ce68dcd 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -27,7 +27,7 @@ namespace MWWorld { // silence annoying g++ warning for (std::vector::const_iterator iter (functor.mHandles.begin()); iter!=functor.mHandles.end(); ++iter) - mScene.removeObject (*iter); + mPhysics->removeObject (*iter); } mWorld->removeScripts (iter->first); @@ -113,7 +113,7 @@ namespace MWWorld mWorld->getExterior(x, y)->loadExt (x, y, mWorld->getStore(), mWorld->getEsmReader()); Ptr::CellStore *cell = mWorld->getExterior(x, y); - loadCell (cell, new MWRender::ExteriorCellRender (*cell, mEnvironment, mScene)); + loadCell (cell, new MWRender::ExteriorCellRender (*cell, mEnvironment, mScene, mPhysics)); } } @@ -144,9 +144,9 @@ namespace MWWorld mCellChanged = true; } - Scene::Scene (Environment& environment, World *world, MWRender::MWScene& scene) + Scene::Scene (Environment& environment, World *world, MWRender::MWScene& scene, PhysicsSystem *physics) : mScene (scene), mCurrentCell (0), - mCellChanged (false), mEnvironment (environment), mWorld(world) + mCellChanged (false), mEnvironment (environment), mWorld(world), mPhysics(physics) { } @@ -184,7 +184,7 @@ namespace MWWorld mWorld->getInterior(cellName)->loadInt (cellName, mWorld->getStore(), mWorld->getEsmReader()); Ptr::CellStore *cell = mWorld->getInterior(cellName); - loadCell (cell, new MWRender::InteriorCellRender (*cell, mEnvironment, mScene)); + loadCell (cell, new MWRender::InteriorCellRender (*cell, mEnvironment, mScene, mPhysics)); // adjust player mCurrentCell = cell; diff --git a/apps/openmw/mwworld/scene.hpp b/apps/openmw/mwworld/scene.hpp index bfb7a5537..c6d996364 100644 --- a/apps/openmw/mwworld/scene.hpp +++ b/apps/openmw/mwworld/scene.hpp @@ -9,6 +9,7 @@ #include #include "../mwrender/mwscene.hpp" +#include "physicssystem.hpp" #include "refdata.hpp" #include "ptr.hpp" @@ -62,13 +63,14 @@ namespace MWWorld bool mCellChanged; Environment& mEnvironment; World *mWorld; + PhysicsSystem *mPhysics; void playerCellChange (Ptr::CellStore *cell, const ESM::Position& position, bool adjustPlayerPos = true); public: - Scene (Environment& environment, World *world, MWRender::MWScene& scene); + Scene (Environment& environment, World *world, MWRender::MWScene& scene, PhysicsSystem *physics); ~Scene(); diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 0e9f65e8c..17830248f 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -283,6 +283,8 @@ namespace MWWorld mSky (false), mEnvironment (environment), mNextDynamicRecord (0) { mPhysEngine = physEng; + + mPhysics = new PhysicsSystem(renderer, physEng); boost::filesystem::path masterPath (fileCollections.getCollection (".esm").getPath (master)); @@ -294,7 +296,7 @@ namespace MWWorld mStore.load (mEsm); mPlayer = new MWWorld::Player (mScene.getPlayer(), mStore.npcs.find ("player"), *this); - mScene.addActor (mPlayer->getPlayer().getRefData().getHandle(), "", Ogre::Vector3 (0, 0, 0)); + mPhysics->addActor (mPlayer->getPlayer().getRefData().getHandle(), "", Ogre::Vector3 (0, 0, 0)); // global variables mGlobalVariables = new Globals (mStore); @@ -310,7 +312,7 @@ namespace MWWorld mPhysEngine = physEng; - mWorldScene = new Scene(environment, this, mScene); + mWorldScene = new Scene(environment, this, mScene, mPhysics); } World::~World() @@ -319,6 +321,7 @@ namespace MWWorld delete mSkyManager; delete mGlobalVariables; delete mWorldScene; + delete mPhysics; } const ESM::Cell *World::getExterior (const std::string& cellName) const @@ -635,7 +638,7 @@ namespace MWWorld mEnvironment.mSoundManager->stopSound3D (ptr); if (!DoingPhysics::isDoingPhysics()) - mScene.removeObject (ptr.getRefData().getHandle()); + mPhysics->removeObject (ptr.getRefData().getHandle()); } render->deleteObject (ptr.getRefData().getHandle()); @@ -672,7 +675,7 @@ namespace MWWorld } } - mScene.moveObject (ptr.getRefData().getHandle(), Ogre::Vector3 (x, y, z), + mPhysics->moveObject (ptr.getRefData().getHandle(), Ogre::Vector3 (x, y, z), !DoingPhysics::isDoingPhysics()); // TODO cell change for non-player ref @@ -710,7 +713,7 @@ namespace MWWorld void World::doPhysics (const std::vector >& actors, float duration) { - mScene.doPhysics (duration, *this, actors); + mPhysics->doPhysics (duration, *this, actors); } bool World::toggleCollisionMode() diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index a9e2668db..045d37aac 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -14,6 +14,7 @@ #include "ptr.hpp" #include "globals.hpp" #include "scene.hpp" +#include "physicssystem.hpp" #include @@ -73,6 +74,7 @@ namespace MWWorld ESMS::ESMStore mStore; ScriptList mLocalScripts; MWWorld::Globals *mGlobalVariables; + MWWorld::PhysicsSystem *mPhysics; bool mSky; Environment& mEnvironment; int mNextDynamicRecord;