diff --git a/apps/openmw/mwphysics/physicssystem.cpp b/apps/openmw/mwphysics/physicssystem.cpp index dd5a7e826..7c8342707 100644 --- a/apps/openmw/mwphysics/physicssystem.cpp +++ b/apps/openmw/mwphysics/physicssystem.cpp @@ -237,9 +237,10 @@ namespace MWPhysics public: - static osg::Vec3f traceDown(const MWWorld::Ptr &ptr, Actor* actor, btCollisionWorld* collisionWorld, float maxHeight) + static osg::Vec3f traceDown(const MWWorld::Ptr &ptr, osg::Vec3f position, Actor* actor, btCollisionWorld* collisionWorld, float maxHeight) { - osg::Vec3f position(actor->getCollisionObjectPosition()); + osg::Vec3f offset = actor->getCollisionObjectPosition() - ptr.getRefData().getPosition().asVec3(); + position += offset; ActorTracer tracer; tracer.findGround(actor, position, position-osg::Vec3f(0,0,maxHeight), collisionWorld); @@ -1085,13 +1086,13 @@ namespace MWPhysics return resultCallback.mResult; } - osg::Vec3f PhysicsSystem::traceDown(const MWWorld::Ptr &ptr, float maxHeight) + osg::Vec3f PhysicsSystem::traceDown(const MWWorld::Ptr &ptr, const osg::Vec3f& position, float maxHeight) { ActorMap::iterator found = mActors.find(ptr); if (found == mActors.end()) return ptr.getRefData().getPosition().asVec3(); else - return MovementSolver::traceDown(ptr, found->second, mCollisionWorld, maxHeight); + return MovementSolver::traceDown(ptr, position, found->second, mCollisionWorld, maxHeight); } void PhysicsSystem::addHeightField (const float* heights, int x, int y, float triSize, float sqrtVerts) diff --git a/apps/openmw/mwphysics/physicssystem.hpp b/apps/openmw/mwphysics/physicssystem.hpp index d74631845..ec12f7681 100644 --- a/apps/openmw/mwphysics/physicssystem.hpp +++ b/apps/openmw/mwphysics/physicssystem.hpp @@ -90,7 +90,7 @@ namespace MWPhysics void debugDraw(); std::vector getCollisions(const MWWorld::ConstPtr &ptr, int collisionGroup, int collisionMask) const; ///< get handles this object collides with - osg::Vec3f traceDown(const MWWorld::Ptr &ptr, float maxHeight); + osg::Vec3f traceDown(const MWWorld::Ptr &ptr, const osg::Vec3f& position, float maxHeight); std::pair getHitContact(const MWWorld::ConstPtr& actor, const osg::Vec3f &origin, diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 0229f1f93..dcec8ea85 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1296,7 +1296,7 @@ namespace MWWorld void World::adjustPosition(const Ptr &ptr, bool force) { - ESM::Position pos (ptr.getRefData().getPosition()); + osg::Vec3f pos (ptr.getRefData().getPosition().asVec3()); if(!ptr.getRefData().getBaseNode()) { @@ -1306,34 +1306,31 @@ namespace MWWorld float terrainHeight = -std::numeric_limits::max(); if (ptr.getCell()->isExterior()) - terrainHeight = getTerrainHeightAt(pos.asVec3()); + terrainHeight = getTerrainHeightAt(pos); - if (pos.pos[2] < terrainHeight) - pos.pos[2] = terrainHeight; + if (pos.z() < terrainHeight) + pos.z() = terrainHeight; - pos.pos[2] += 20; // place slightly above. will snap down to ground with code below - - ptr.getRefData().setPosition(pos); + pos.z() += 20; // place slightly above. will snap down to ground with code below if (force || !isFlying(ptr)) { - osg::Vec3f traced = mPhysics->traceDown(ptr, 500); - if (traced.z() < pos.pos[2]) - pos.pos[2] = traced.z(); + osg::Vec3f traced = mPhysics->traceDown(ptr, pos, 500); + if (traced.z() < pos.z()) + pos.z() = traced.z(); } - moveObject(ptr, ptr.getCell(), pos.pos[0], pos.pos[1], pos.pos[2]); + moveObject(ptr, ptr.getCell(), pos.x(), pos.y(), pos.z()); } void World::fixPosition(const Ptr &actor) { const float dist = 8000; - ESM::Position pos (actor.getRefData().getPosition()); - pos.pos[2] += dist; - actor.getRefData().setPosition(pos); + osg::Vec3f pos (actor.getRefData().getPosition().asVec3()); + pos.z() += dist; - osg::Vec3f traced = mPhysics->traceDown(actor, dist*1.1f); - if (traced != pos.asVec3()) + osg::Vec3f traced = mPhysics->traceDown(actor, pos, dist*1.1f); + if (traced != pos) moveObject(actor, actor.getCell(), traced.x(), traced.y(), traced.z()); }