diff --git a/apps/openmw/mwclass/activator.cpp b/apps/openmw/mwclass/activator.cpp index e815549d8e..1f5c7c2174 100644 --- a/apps/openmw/mwclass/activator.cpp +++ b/apps/openmw/mwclass/activator.cpp @@ -30,9 +30,8 @@ namespace MWClass void Activator::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const { const std::string model = getModel(ptr); - if(!model.empty()) { - physics.insertObjectPhysics(ptr, model); - } + if(!model.empty()) + physics.addObject(ptr); } std::string Activator::getModel(const MWWorld::Ptr &ptr) const @@ -94,7 +93,7 @@ namespace MWClass return info; } - + MWWorld::Ptr Activator::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const { diff --git a/apps/openmw/mwclass/apparatus.cpp b/apps/openmw/mwclass/apparatus.cpp index a05c24e864..7205ab3955 100644 --- a/apps/openmw/mwclass/apparatus.cpp +++ b/apps/openmw/mwclass/apparatus.cpp @@ -33,9 +33,8 @@ namespace MWClass void Apparatus::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const { const std::string model = getModel(ptr); - if(!model.empty()) { - physics.insertObjectPhysics(ptr, model); - } + if(!model.empty()) + physics.addObject(ptr); } std::string Apparatus::getModel(const MWWorld::Ptr &ptr) const diff --git a/apps/openmw/mwclass/armor.cpp b/apps/openmw/mwclass/armor.cpp index 7254c37f8a..906d880709 100644 --- a/apps/openmw/mwclass/armor.cpp +++ b/apps/openmw/mwclass/armor.cpp @@ -36,9 +36,8 @@ namespace MWClass void Armor::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const { const std::string model = getModel(ptr); - if(!model.empty()) { - physics.insertObjectPhysics(ptr, model); - } + if(!model.empty()) + physics.addObject(ptr); } std::string Armor::getModel(const MWWorld::Ptr &ptr) const diff --git a/apps/openmw/mwclass/book.cpp b/apps/openmw/mwclass/book.cpp index 4a2ad1dcb9..b994634d86 100644 --- a/apps/openmw/mwclass/book.cpp +++ b/apps/openmw/mwclass/book.cpp @@ -32,9 +32,8 @@ namespace MWClass void Book::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const { const std::string model = getModel(ptr); - if(!model.empty()) { - physics.insertObjectPhysics(ptr, model); - } + if(!model.empty()) + physics.addObject(ptr); } std::string Book::getModel(const MWWorld::Ptr &ptr) const diff --git a/apps/openmw/mwclass/clothing.cpp b/apps/openmw/mwclass/clothing.cpp index d746350dfe..c902e8e8f0 100644 --- a/apps/openmw/mwclass/clothing.cpp +++ b/apps/openmw/mwclass/clothing.cpp @@ -34,9 +34,8 @@ namespace MWClass void Clothing::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const { const std::string model = getModel(ptr); - if(!model.empty()) { - physics.insertObjectPhysics(ptr, model); - } + if(!model.empty()) + physics.addObject(ptr); } std::string Clothing::getModel(const MWWorld::Ptr &ptr) const diff --git a/apps/openmw/mwclass/container.cpp b/apps/openmw/mwclass/container.cpp index 237f451f33..0d75b653d7 100644 --- a/apps/openmw/mwclass/container.cpp +++ b/apps/openmw/mwclass/container.cpp @@ -65,9 +65,8 @@ namespace MWClass void Container::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const { const std::string model = getModel(ptr); - if(!model.empty()) { - physics.insertObjectPhysics(ptr, model); - } + if(!model.empty()) + physics.addObject(ptr); } std::string Container::getModel(const MWWorld::Ptr &ptr) const diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index e4ff3c95ba..fce9511165 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -94,9 +94,8 @@ namespace MWClass void Creature::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const { const std::string model = getModel(ptr); - if(!model.empty()){ - physics.insertActorPhysics(ptr, model); - } + if(!model.empty()) + physics.addActor(ptr); MWBase::Environment::get().getMechanicsManager()->addActor (ptr); } diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp index f944391e12..b03db4ec7d 100644 --- a/apps/openmw/mwclass/door.cpp +++ b/apps/openmw/mwclass/door.cpp @@ -35,9 +35,8 @@ namespace MWClass void Door::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const { const std::string model = getModel(ptr); - if(!model.empty()) { - physics.insertObjectPhysics(ptr, model); - } + if(!model.empty()) + physics.addObject(ptr); } std::string Door::getModel(const MWWorld::Ptr &ptr) const diff --git a/apps/openmw/mwclass/ingredient.cpp b/apps/openmw/mwclass/ingredient.cpp index 45779287f4..e322fa3b8f 100644 --- a/apps/openmw/mwclass/ingredient.cpp +++ b/apps/openmw/mwclass/ingredient.cpp @@ -41,9 +41,8 @@ namespace MWClass void Ingredient::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const { const std::string model = getModel(ptr); - if(!model.empty()) { - physics.insertObjectPhysics(ptr, model); - } + if(!model.empty()) + physics.addObject(ptr); } std::string Ingredient::getModel(const MWWorld::Ptr &ptr) const diff --git a/apps/openmw/mwclass/light.cpp b/apps/openmw/mwclass/light.cpp index 6ae9ed6615..fc545abaf8 100644 --- a/apps/openmw/mwclass/light.cpp +++ b/apps/openmw/mwclass/light.cpp @@ -53,12 +53,11 @@ namespace MWClass const std::string &model = ref->base->mModel; - if(!model.empty()) { - physics.insertObjectPhysics(ptr, "meshes\\" + model); - } - if (!ref->base->mSound.empty()) { + if(!model.empty()) + physics.addObject(ptr); + + if (!ref->base->mSound.empty()) MWBase::Environment::get().getSoundManager()->playSound3D(ptr, ref->base->mSound, 1.0, 1.0, MWBase::SoundManager::Play_Loop); - } } std::string Light::getModel(const MWWorld::Ptr &ptr) const diff --git a/apps/openmw/mwclass/lockpick.cpp b/apps/openmw/mwclass/lockpick.cpp index a0ec65c988..71e2dbb12f 100644 --- a/apps/openmw/mwclass/lockpick.cpp +++ b/apps/openmw/mwclass/lockpick.cpp @@ -34,9 +34,8 @@ namespace MWClass void Lockpick::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const { const std::string model = getModel(ptr); - if(!model.empty()) { - physics.insertObjectPhysics(ptr, model); - } + if(!model.empty()) + physics.addObject(ptr); } std::string Lockpick::getModel(const MWWorld::Ptr &ptr) const diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp index edcfc7daa7..ca7e073b1e 100644 --- a/apps/openmw/mwclass/misc.cpp +++ b/apps/openmw/mwclass/misc.cpp @@ -37,9 +37,8 @@ namespace MWClass void Miscellaneous::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const { const std::string model = getModel(ptr); - if(!model.empty()) { - physics.insertObjectPhysics(ptr, model); - } + if(!model.empty()) + physics.addObject(ptr); } std::string Miscellaneous::getModel(const MWWorld::Ptr &ptr) const diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 2e21f8f63f..7e554ee8af 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -138,7 +138,7 @@ namespace MWClass void Npc::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const { - physics.insertActorPhysics(ptr, getModel(ptr)); + physics.addActor(ptr); MWBase::Environment::get().getMechanicsManager()->addActor(ptr); } diff --git a/apps/openmw/mwclass/potion.cpp b/apps/openmw/mwclass/potion.cpp index f641cc7199..6403765366 100644 --- a/apps/openmw/mwclass/potion.cpp +++ b/apps/openmw/mwclass/potion.cpp @@ -34,9 +34,8 @@ namespace MWClass void Potion::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const { const std::string model = getModel(ptr); - if(!model.empty()) { - physics.insertObjectPhysics(ptr, model); - } + if(!model.empty()) + physics.addObject(ptr); } std::string Potion::getModel(const MWWorld::Ptr &ptr) const diff --git a/apps/openmw/mwclass/probe.cpp b/apps/openmw/mwclass/probe.cpp index 39472f2ec4..8961b8007f 100644 --- a/apps/openmw/mwclass/probe.cpp +++ b/apps/openmw/mwclass/probe.cpp @@ -34,9 +34,8 @@ namespace MWClass void Probe::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const { const std::string model = getModel(ptr); - if(!model.empty()) { - physics.insertObjectPhysics(ptr, model); - } + if(!model.empty()) + physics.addObject(ptr); } std::string Probe::getModel(const MWWorld::Ptr &ptr) const diff --git a/apps/openmw/mwclass/repair.cpp b/apps/openmw/mwclass/repair.cpp index 7ccb34913d..3c0361b0be 100644 --- a/apps/openmw/mwclass/repair.cpp +++ b/apps/openmw/mwclass/repair.cpp @@ -32,9 +32,8 @@ namespace MWClass void Repair::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const { const std::string model = getModel(ptr); - if(!model.empty()) { - physics.insertObjectPhysics(ptr, model); - } + if(!model.empty()) + physics.addObject(ptr); } std::string Repair::getModel(const MWWorld::Ptr &ptr) const diff --git a/apps/openmw/mwclass/static.cpp b/apps/openmw/mwclass/static.cpp index 07ab54256e..099b096572 100644 --- a/apps/openmw/mwclass/static.cpp +++ b/apps/openmw/mwclass/static.cpp @@ -24,9 +24,8 @@ namespace MWClass void Static::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const { const std::string model = getModel(ptr); - if(!model.empty()) { - physics.insertObjectPhysics(ptr, model); - } + if(!model.empty()) + physics.addObject(ptr); } std::string Static::getModel(const MWWorld::Ptr &ptr) const diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index fee0dfdf14..52dc91205d 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -34,9 +34,8 @@ namespace MWClass void Weapon::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const { const std::string model = getModel(ptr); - if(!model.empty()) { - physics.insertObjectPhysics(ptr, model); - } + if(!model.empty()) + physics.addObject(ptr); } std::string Weapon::getModel(const MWWorld::Ptr &ptr) const diff --git a/apps/openmw/mwrender/player.hpp b/apps/openmw/mwrender/player.hpp index b4d8983e4e..29a68ca693 100644 --- a/apps/openmw/mwrender/player.hpp +++ b/apps/openmw/mwrender/player.hpp @@ -48,16 +48,6 @@ namespace MWRender /// Updates sound manager listener data void updateListener(); - void rotateCamera(const Ogre::Vector3 &rot, bool adjust); - - float getYaw(); - void setYaw(float angle); - - float getPitch(); - void setPitch(float angle); - - void compensateYaw(float diff); - void setLowHeight(bool low = true); public: @@ -69,7 +59,17 @@ namespace MWRender /// \param rot Rotation angles in radians /// \return true if player object needs to bo rotated physically bool rotate(const Ogre::Vector3 &rot, bool adjust); + + void rotateCamera(const Ogre::Vector3 &rot, bool adjust); + float getYaw(); + void setYaw(float angle); + + float getPitch(); + void setPitch(float angle); + + void compensateYaw(float diff); + std::string getHandle() const; /// Attach camera to object diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index bcc3a311d9..1b9f46781a 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -237,8 +237,8 @@ void RenderingManager::addObject (const MWWorld::Ptr& ptr){ const MWWorld::Class& class_ = MWWorld::Class::get (ptr); class_.insertObjectRendering(ptr, *this); - } + void RenderingManager::removeObject (const MWWorld::Ptr& ptr) { if (!mObjects.deleteObject (ptr)) @@ -258,39 +258,44 @@ void RenderingManager::moveObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& setPosition (position); } -void RenderingManager::scaleObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& scale){ - +void RenderingManager::scaleObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& scale) +{ + ptr.getRefData().getBaseNode()->setScale(scale); } -bool -RenderingManager::rotateObject( - const MWWorld::Ptr &ptr, - Ogre::Vector3 &rot, - bool adjust) +bool RenderingManager::rotateObject( const MWWorld::Ptr &ptr, Ogre::Vector3 &rot, bool adjust) { bool isActive = ptr.getRefData().getBaseNode() != 0; bool isPlayer = isActive && ptr.getRefData().getHandle() == "player"; bool force = true; - if (isPlayer) { + if (isPlayer) force = mPlayer->rotate(rot, adjust); - } + MWWorld::Class::get(ptr).adjustRotation(ptr, rot.x, rot.y, rot.z); - if (adjust) { + if (!isPlayer && isActive) + { + Ogre::Quaternion xr(Ogre::Radian(rot.x), Ogre::Vector3::UNIT_X); + Ogre::Quaternion yr(Ogre::Radian(rot.y), Ogre::Vector3::UNIT_Y); + Ogre::Quaternion zr(Ogre::Radian(rot.z), Ogre::Vector3::UNIT_Z); + Ogre::Quaternion newo = adjust ? (xr * yr * zr) * ptr.getRefData().getBaseNode()->getOrientation() : xr * yr * zr; + rot.x = newo.x; + rot.y = newo.y; + rot.z = newo.z; + ptr.getRefData().getBaseNode()->setOrientation(newo); + } + else if(isPlayer) + { + rot.x = mPlayer->getPitch(); + rot.z = mPlayer->getYaw(); + } + else if (adjust) + { /// \note Stored and passed in radians float *f = ptr.getRefData().getPosition().rot; rot.x += f[0], rot.y += f[1], rot.z += f[2]; } - - if (!isPlayer && isActive) { - Ogre::Quaternion xr(Ogre::Radian(rot.x), Ogre::Vector3::UNIT_X); - Ogre::Quaternion yr(Ogre::Radian(rot.y), Ogre::Vector3::UNIT_Y); - Ogre::Quaternion zr(Ogre::Radian(rot.z), Ogre::Vector3::UNIT_Z); - - ptr.getRefData().getBaseNode()->setOrientation(xr * yr * zr); - } - return force; } diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index 3be85c7f3d..5359c4eb27 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -12,6 +12,7 @@ #include //#include "../mwbase/world.hpp" // FIXME +#include "../mwbase/environment.hpp" #include "ptr.hpp" #include "class.hpp" @@ -249,31 +250,36 @@ namespace MWWorld mEngine->removeHeightField(x, y); } - void PhysicsSystem::addObject (const std::string& handle, const std::string& mesh, - const Ogre::Quaternion& rotation, float scale, const Ogre::Vector3& position) + void PhysicsSystem::addObject (const Ptr& ptr) { - handleToMesh[handle] = mesh; - OEngine::Physic::RigidBody* body = mEngine->createAndAdjustRigidBody(mesh,handle,scale, position, rotation); + std::string mesh = MWWorld::Class::get(ptr).getModel(ptr); + Ogre::SceneNode* node = ptr.getRefData().getBaseNode(); + handleToMesh[node->getName()] = mesh; + OEngine::Physic::RigidBody* body = mEngine->createAndAdjustRigidBody(mesh, node->getName(), node->getScale().x, node->getPosition(), node->getOrientation()); mEngine->addRigidBody(body); } - void PhysicsSystem::addActor (const std::string& handle, const std::string& mesh, - const Ogre::Vector3& position, float scale, const Ogre::Quaternion& rotation) + void PhysicsSystem::addActor (const Ptr& ptr) { + std::string mesh = MWWorld::Class::get(ptr).getModel(ptr); + Ogre::SceneNode* node = ptr.getRefData().getBaseNode(); //TODO:optimize this. Searching the std::map isn't very efficient i think. - mEngine->addCharacter(handle, mesh, position, scale, rotation); + mEngine->addCharacter(node->getName(), mesh, node->getPosition(), node->getScale().x, node->getOrientation()); } 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, Ogre::SceneNode* node) + void PhysicsSystem::moveObject (const Ptr& ptr) { + Ogre::SceneNode* node = ptr.getRefData().getBaseNode(); + std::string handle = node->getName(); Ogre::Vector3 position = node->getPosition(); if (OEngine::Physic::RigidBody* body = mEngine->getRigidBody(handle)) { @@ -307,8 +313,10 @@ namespace MWWorld } } - void PhysicsSystem::rotateObject (const std::string& handle, Ogre::SceneNode* node) + void PhysicsSystem::rotateObject (const Ptr& ptr) { + Ogre::SceneNode* node = ptr.getRefData().getBaseNode(); + std::string handle = node->getName(); Ogre::Quaternion rotation = node->getOrientation(); if (OEngine::Physic::PhysicActor* act = mEngine->getCharacter(handle)) { @@ -324,23 +332,18 @@ namespace MWWorld } } - void PhysicsSystem::scaleObject (const std::string& handle, Ogre::SceneNode* node) + void PhysicsSystem::scaleObject (const Ptr& ptr) { + Ogre::SceneNode* node = ptr.getRefData().getBaseNode(); + std::string handle = node->getName(); if(handleToMesh.find(handle) != handleToMesh.end()) { removeObject(handle); - - float scale = node->getScale().x; - Ogre::Quaternion quat = node->getOrientation(); - Ogre::Vector3 vec = node->getPosition(); - addObject(handle, handleToMesh[handle], quat, scale, vec); + addObject(ptr); } if (OEngine::Physic::PhysicActor* act = mEngine->getCharacter(handle)) - { - float scale = node->getScale().x; - act->setScale(scale); - } + act->setScale(node->getScale().x); } bool PhysicsSystem::toggleCollisionMode() @@ -371,23 +374,6 @@ namespace MWWorld throw std::logic_error ("can't find player"); } - void PhysicsSystem::insertObjectPhysics(const MWWorld::Ptr& ptr, const std::string model){ - - Ogre::SceneNode* node = ptr.getRefData().getBaseNode(); - - addObject( - node->getName(), - model, - node->getOrientation(), - node->getScale().x, - node->getPosition()); - } - - void PhysicsSystem::insertActorPhysics(const MWWorld::Ptr& ptr, const std::string model){ - Ogre::SceneNode* node = ptr.getRefData().getBaseNode(); - addActor (node->getName(), model, node->getPosition(), node->getScale().x, node->getOrientation()); - } - bool PhysicsSystem::getObjectAABB(const MWWorld::Ptr &ptr, Ogre::Vector3 &min, Ogre::Vector3 &max) { std::string model = MWWorld::Class::get(ptr).getModel(ptr); diff --git a/apps/openmw/mwworld/physicssystem.hpp b/apps/openmw/mwworld/physicssystem.hpp index 1427060f6a..8bd73fd6cb 100644 --- a/apps/openmw/mwworld/physicssystem.hpp +++ b/apps/openmw/mwworld/physicssystem.hpp @@ -20,11 +20,9 @@ namespace MWWorld std::vector< std::pair > doPhysicsFixed (const std::vector >& actors); ///< do physics with fixed timestep - Usage: first call doPhysics with frame dt, then call doPhysicsFixed as often as time steps have passed - void addObject (const std::string& handle, const std::string& mesh, - const Ogre::Quaternion& rotation, float scale, const Ogre::Vector3& position); + void addObject (const MWWorld::Ptr& ptr); - void addActor (const std::string& handle, const std::string& mesh, - const Ogre::Vector3& position, float scale, const Ogre::Quaternion& rotation); + void addActor (const MWWorld::Ptr& ptr); void addHeightField (float* heights, int x, int y, float yoffset, @@ -32,13 +30,14 @@ namespace MWWorld void removeHeightField (int x, int y); + // have to keep this as handle for now as unloadcell only knows scenenode names void removeObject (const std::string& handle); - void moveObject (const std::string& handle, Ogre::SceneNode* node); + void moveObject (const MWWorld::Ptr& ptr); - void rotateObject (const std::string& handle, Ogre::SceneNode* node); + void rotateObject (const MWWorld::Ptr& ptr); - void scaleObject (const std::string& handle, Ogre::SceneNode* node); + void scaleObject (const MWWorld::Ptr& ptr); bool toggleCollisionMode(); @@ -60,10 +59,6 @@ namespace MWWorld std::pair castRay(float mouseX, float mouseY); ///< cast ray from the mouse, return true if it hit something and the first result (in OGRE coordinates) - void insertObjectPhysics(const MWWorld::Ptr& ptr, std::string model); - - void insertActorPhysics(const MWWorld::Ptr&, std::string model); - OEngine::Physic::PhysicEngine* getEngine(); void setCurrentWater(bool hasWater, int waterHeight); diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 37cc23f5ff..881b090fa5 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -41,6 +41,8 @@ namespace { rendering.addObject(ptr); class_.insertObject(ptr, physics); + MWBase::Environment::get().getWorld()->rotateObject(ptr, 0, 0, 0, true); + MWBase::Environment::get().getWorld()->scaleObject(ptr, ptr.getCellRef().mScale); } catch (const std::exception& e) { @@ -417,6 +419,8 @@ namespace MWWorld { mRendering.addObject(ptr); MWWorld::Class::get(ptr).insertObject(ptr, *mPhysics); + MWBase::Environment::get().getWorld()->rotateObject(ptr, 0, 0, 0, true); + MWBase::Environment::get().getWorld()->scaleObject(ptr, ptr.getCellRef().mScale); } void Scene::removeObjectFromScene (const Ptr& ptr) diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 2304576ec7..d90a43f581 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -189,10 +189,8 @@ namespace MWWorld mPlayer = new MWWorld::Player (mStore.npcs.find ("player"), *this); mRendering->attachCameraTo(mPlayer->getPlayer()); - std::string playerCollisionFile = "meshes\\base_anim.nif"; //This is used to make a collision shape for our player - //We will need to support the 1st person file too in the future - mPhysics->addActor (mPlayer->getPlayer().getRefData().getHandle(), playerCollisionFile, Ogre::Vector3 (0, 0, 0), 1, Ogre::Quaternion::ZERO); - + mPhysics->addActor(mPlayer->getPlayer()); + // global variables mGlobalVariables = new Globals (mStore); @@ -580,39 +578,48 @@ namespace MWWorld CellStore *currCell = ptr.getCell(); bool isPlayer = ptr == mPlayer->getPlayer(); bool haveToMove = mWorldScene->isCellActive(*currCell) || isPlayer; - if (*currCell != newCell) { - if (isPlayer) { - if (!newCell.isExterior()) { + if (*currCell != newCell) + { + if (isPlayer) + if (!newCell.isExterior()) changeToInteriorCell(toLower(newCell.cell->mName), pos); - } else { + else + { int cellX = newCell.cell->mData.mX; int cellY = newCell.cell->mData.mY; mWorldScene->changeCell(cellX, cellY, pos, false); } - } else { - if (!mWorldScene->isCellActive(*currCell)) { + else { + if (!mWorldScene->isCellActive(*currCell)) copyObjectToCell(ptr, newCell, pos); - } else if (!mWorldScene->isCellActive(newCell)) { + else if (!mWorldScene->isCellActive(newCell)) + { MWWorld::Class::get(ptr).copyToCell(ptr, newCell); mWorldScene->removeObjectFromScene(ptr); mLocalScripts.remove(ptr); haveToMove = false; - } else { + } + else + { MWWorld::Ptr copy = MWWorld::Class::get(ptr).copyToCell(ptr, newCell); mRendering->moveObjectToCell(copy, vec, currCell); - if (MWWorld::Class::get(ptr).isActor()) { + if (MWWorld::Class::get(ptr).isActor()) + { MWBase::MechanicsManager *mechMgr = MWBase::Environment::get().getMechanicsManager(); mechMgr->removeActor(ptr); mechMgr->addActor(copy); - } else { + } + else + { std::string script = MWWorld::Class::get(ptr).getScript(ptr); - if (!script.empty()) { + if (!script.empty()) + { mLocalScripts.remove(ptr); mLocalScripts.add(script, copy); } @@ -621,9 +628,10 @@ namespace MWWorld ptr.getRefData().setCount(0); } } - if (haveToMove) { + if (haveToMove) + { mRendering->moveObject(ptr, vec); - mPhysics->moveObject (ptr.getRefData().getHandle(), ptr.getRefData().getBaseNode()); + mPhysics->moveObject (ptr); } } @@ -644,18 +652,17 @@ namespace MWWorld void World::moveObject (const Ptr& ptr, float x, float y, float z) { moveObjectImp(ptr, x, y, z); - - } void World::scaleObject (const Ptr& ptr, float scale) { MWWorld::Class::get(ptr).adjustScale(ptr,scale); - ptr.getCellRef().mScale = scale; - //scale = scale/ptr.getRefData().getBaseNode()->getScale().x; - ptr.getRefData().getBaseNode()->setScale(scale,scale,scale); - mPhysics->scaleObject( ptr.getRefData().getHandle(), ptr.getRefData().getBaseNode()); + + if(ptr.getRefData().getBaseNode() == 0) + return; + mRendering->scaleObject(ptr, Vector3(scale,scale,scale)); + mPhysics->scaleObject(ptr); } void World::rotateObject (const Ptr& ptr,float x,float y,float z, bool adjust) @@ -665,19 +672,16 @@ namespace MWWorld rot.y = Ogre::Degree(y).valueRadians(); rot.z = Ogre::Degree(z).valueRadians(); - if (mRendering->rotateObject(ptr, rot, adjust)) { - float *objRot = ptr.getRefData().getPosition().rot; - objRot[0] = rot.x, objRot[1] = rot.y, objRot[2] = rot.z; - - - if (ptr.getRefData().getBaseNode() != 0) { - mPhysics->rotateObject( - ptr.getRefData().getHandle(), - ptr.getRefData().getBaseNode() - ); - } - } + float *objRot = ptr.getRefData().getPosition().rot; + if(ptr.getRefData().getBaseNode() == 0 || !mRendering->rotateObject(ptr, rot, adjust)) + { + objRot[0] = (adjust ? objRot[0] + rot.x : rot.x), objRot[1] = (adjust ? objRot[1] + rot.y : rot.y), objRot[2] = (adjust ? objRot[2] + rot.z : rot.z); + return; + } + // do this after rendering rotated the object so it gets changed by Class->adjustRotation + objRot[0] = rot.x, objRot[1] = rot.y, objRot[2] = rot.z; + mPhysics->rotateObject(ptr); } void World::safePlaceObject(const MWWorld::Ptr& ptr,MWWorld::CellStore &Cell,ESM::Position pos)