Use a btCollisionWorld instead of btDiscreteDynamicsWorld

Slightly improves performance, since we no longer need to stepSimulation(). We don't use any Dynamics (yet).
c++11
scrawl 10 years ago
parent fe439e53ff
commit 1f00174c02

@ -152,7 +152,6 @@ if (ANDROID)
MyGUIEngineStatic MyGUIEngineStatic
cpufeatures cpufeatures
BulletCollision BulletCollision
BulletDynamics
LinearMath LinearMath
) )
endif (ANDROID) endif (ANDROID)

@ -4,7 +4,7 @@
#include <BulletCollision/CollisionShapes/btCylinderShape.h> #include <BulletCollision/CollisionShapes/btCylinderShape.h>
#include <BulletCollision/CollisionShapes/btBoxShape.h> #include <BulletCollision/CollisionShapes/btBoxShape.h>
#include <BulletDynamics/Dynamics/btDynamicsWorld.h> #include <BulletCollision/CollisionDispatch/btCollisionWorld.h>
#include <components/nifbullet/bulletnifloader.hpp> #include <components/nifbullet/bulletnifloader.hpp>
@ -17,12 +17,12 @@ namespace MWPhysics
{ {
Actor::Actor(const MWWorld::Ptr& ptr, osg::ref_ptr<NifBullet::BulletShapeInstance> shape, btDynamicsWorld* world) Actor::Actor(const MWWorld::Ptr& ptr, osg::ref_ptr<NifBullet::BulletShapeInstance> shape, btCollisionWorld* world)
: mCanWaterWalk(false), mWalkingOnWater(false) : mCanWaterWalk(false), mWalkingOnWater(false)
, mCollisionObject(0), mForce(0.f, 0.f, 0.f), mOnGround(false) , mCollisionObject(0), mForce(0.f, 0.f, 0.f), mOnGround(false)
, mInternalCollisionMode(true) , mInternalCollisionMode(true)
, mExternalCollisionMode(true) , mExternalCollisionMode(true)
, mDynamicsWorld(world) , mCollisionWorld(world)
{ {
mPtr = ptr; mPtr = ptr;
@ -55,7 +55,7 @@ Actor::Actor(const MWWorld::Ptr& ptr, osg::ref_ptr<NifBullet::BulletShapeInstanc
Actor::~Actor() Actor::~Actor()
{ {
if (mCollisionObject.get()) if (mCollisionObject.get())
mDynamicsWorld->removeCollisionObject(mCollisionObject.get()); mCollisionWorld->removeCollisionObject(mCollisionObject.get());
} }
void Actor::enableCollisionMode(bool collision) void Actor::enableCollisionMode(bool collision)
@ -74,13 +74,13 @@ void Actor::enableCollisionBody(bool collision)
void Actor::updateCollisionMask() void Actor::updateCollisionMask()
{ {
mDynamicsWorld->removeCollisionObject(mCollisionObject.get()); mCollisionWorld->removeCollisionObject(mCollisionObject.get());
int collisionMask = CollisionType_World | CollisionType_HeightMap; int collisionMask = CollisionType_World | CollisionType_HeightMap;
if (mExternalCollisionMode) if (mExternalCollisionMode)
collisionMask |= CollisionType_Actor | CollisionType_Projectile; collisionMask |= CollisionType_Actor | CollisionType_Projectile;
if (mCanWaterWalk) if (mCanWaterWalk)
collisionMask |= CollisionType_Water; collisionMask |= CollisionType_Water;
mDynamicsWorld->addCollisionObject(mCollisionObject.get(), CollisionType_Actor, collisionMask); mCollisionWorld->addCollisionObject(mCollisionObject.get(), CollisionType_Actor, collisionMask);
} }
void Actor::updatePosition() void Actor::updatePosition()

@ -9,7 +9,7 @@
#include <osg/Quat> #include <osg/Quat>
#include <osg/ref_ptr> #include <osg/ref_ptr>
class btDynamicsWorld; class btCollisionWorld;
class btCollisionShape; class btCollisionShape;
class btCollisionObject; class btCollisionObject;
@ -43,7 +43,7 @@ namespace MWPhysics
class Actor : public PtrHolder class Actor : public PtrHolder
{ {
public: public:
Actor(const MWWorld::Ptr& ptr, osg::ref_ptr<NifBullet::BulletShapeInstance> shape, btDynamicsWorld* world); Actor(const MWWorld::Ptr& ptr, osg::ref_ptr<NifBullet::BulletShapeInstance> shape, btCollisionWorld* world);
~Actor(); ~Actor();
/** /**
@ -125,7 +125,7 @@ namespace MWPhysics
bool mInternalCollisionMode; bool mInternalCollisionMode;
bool mExternalCollisionMode; bool mExternalCollisionMode;
btDynamicsWorld* mDynamicsWorld; btCollisionWorld* mCollisionWorld;
Actor(const Actor&); Actor(const Actor&);
Actor& operator=(const Actor&); Actor& operator=(const Actor&);

@ -12,9 +12,9 @@
#include <BulletCollision/CollisionDispatch/btCollisionObject.h> #include <BulletCollision/CollisionDispatch/btCollisionObject.h>
#include <BulletCollision/CollisionDispatch/btCollisionWorld.h> #include <BulletCollision/CollisionDispatch/btCollisionWorld.h>
#include <BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h> #include <BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h>
#include <BulletCollision/CollisionDispatch/btCollisionWorld.h>
#include <BulletCollision/BroadphaseCollision/btDbvtBroadphase.h> #include <BulletCollision/BroadphaseCollision/btDbvtBroadphase.h>
#include <BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h> #include <LinearMath/btQuickprof.h>
#include <BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h>
#include <components/nifbullet/bulletshapemanager.hpp> #include <components/nifbullet/bulletshapemanager.hpp>
#include <components/nifbullet/bulletnifloader.hpp> #include <components/nifbullet/bulletnifloader.hpp>
@ -65,7 +65,7 @@ namespace MWPhysics
} }
static bool stepMove(btCollisionObject *colobj, osg::Vec3f &position, static bool stepMove(btCollisionObject *colobj, osg::Vec3f &position,
const osg::Vec3f &toMove, float &remainingTime, btDynamicsWorld* dynamicsWorld) const osg::Vec3f &toMove, float &remainingTime, btCollisionWorld* collisionWorld)
{ {
/* /*
* Slide up an incline or set of stairs. Should be called only after a * Slide up an incline or set of stairs. Should be called only after a
@ -113,7 +113,7 @@ namespace MWPhysics
*/ */
ActorTracer tracer, stepper; ActorTracer tracer, stepper;
stepper.doTrace(colobj, position, position+osg::Vec3f(0.0f,0.0f,sStepSizeUp), dynamicsWorld); stepper.doTrace(colobj, position, position+osg::Vec3f(0.0f,0.0f,sStepSizeUp), collisionWorld);
if(stepper.mFraction < std::numeric_limits<float>::epsilon()) if(stepper.mFraction < std::numeric_limits<float>::epsilon())
return false; // didn't even move the smallest representable amount return false; // didn't even move the smallest representable amount
// (TODO: shouldn't this be larger? Why bother with such a small amount?) // (TODO: shouldn't this be larger? Why bother with such a small amount?)
@ -131,7 +131,7 @@ namespace MWPhysics
* +--+ * +--+
* ============================================== * ==============================================
*/ */
tracer.doTrace(colobj, stepper.mEndPos, stepper.mEndPos + toMove, dynamicsWorld); tracer.doTrace(colobj, stepper.mEndPos, stepper.mEndPos + toMove, collisionWorld);
if(tracer.mFraction < std::numeric_limits<float>::epsilon()) if(tracer.mFraction < std::numeric_limits<float>::epsilon())
return false; // didn't even move the smallest representable amount return false; // didn't even move the smallest representable amount
@ -150,7 +150,7 @@ namespace MWPhysics
* +--+ +--+ * +--+ +--+
* ============================================== * ==============================================
*/ */
stepper.doTrace(colobj, tracer.mEndPos, tracer.mEndPos-osg::Vec3f(0.0f,0.0f,sStepSizeDown), dynamicsWorld); stepper.doTrace(colobj, tracer.mEndPos, tracer.mEndPos-osg::Vec3f(0.0f,0.0f,sStepSizeDown), collisionWorld);
if(stepper.mFraction < 1.0f && getSlope(stepper.mPlaneNormal) <= sMaxSlope) if(stepper.mFraction < 1.0f && getSlope(stepper.mPlaneNormal) <= sMaxSlope)
{ {
// don't allow stepping up other actors // don't allow stepping up other actors
@ -191,12 +191,12 @@ namespace MWPhysics
public: public:
static osg::Vec3f traceDown(const MWWorld::Ptr &ptr, Actor* actor, btDynamicsWorld* dynamicsWorld, float maxHeight) static osg::Vec3f traceDown(const MWWorld::Ptr &ptr, Actor* actor, btCollisionWorld* collisionWorld, float maxHeight)
{ {
osg::Vec3f position(ptr.getRefData().getPosition().asVec3()); osg::Vec3f position(ptr.getRefData().getPosition().asVec3());
ActorTracer tracer; ActorTracer tracer;
tracer.findGround(actor, position, position-osg::Vec3f(0,0,maxHeight), dynamicsWorld); tracer.findGround(actor, position, position-osg::Vec3f(0,0,maxHeight), collisionWorld);
if(tracer.mFraction >= 1.0f) if(tracer.mFraction >= 1.0f)
{ {
actor->setOnGround(false); actor->setOnGround(false);
@ -214,7 +214,7 @@ namespace MWPhysics
resultCallback1.m_collisionFilterGroup = 0xff; resultCallback1.m_collisionFilterGroup = 0xff;
resultCallback1.m_collisionFilterMask = CollisionType_World|CollisionType_HeightMap; resultCallback1.m_collisionFilterMask = CollisionType_World|CollisionType_HeightMap;
dynamicsWorld->rayTest(from, to, resultCallback1); collisionWorld->rayTest(from, to, resultCallback1);
if (resultCallback1.hasHit() && if (resultCallback1.hasHit() &&
( (toOsg(resultCallback1.m_hitPointWorld) - tracer.mEndPos).length() > 30 ( (toOsg(resultCallback1.m_hitPointWorld) - tracer.mEndPos).length() > 30
|| getSlope(tracer.mPlaneNormal) > sMaxSlope)) || getSlope(tracer.mPlaneNormal) > sMaxSlope))
@ -230,7 +230,7 @@ namespace MWPhysics
} }
static osg::Vec3f move(const MWWorld::Ptr &ptr, Actor* physicActor, const osg::Vec3f &movement, float time, static osg::Vec3f move(const MWWorld::Ptr &ptr, Actor* physicActor, const osg::Vec3f &movement, float time,
bool isFlying, float waterlevel, float slowFall, btDynamicsWorld* dynamicsWorld bool isFlying, float waterlevel, float slowFall, btCollisionWorld* collisionWorld
, std::map<std::string, std::string>& collisionTracker , std::map<std::string, std::string>& collisionTracker
, std::map<std::string, std::string>& standingCollisionTracker) , std::map<std::string, std::string>& standingCollisionTracker)
{ {
@ -323,7 +323,7 @@ namespace MWPhysics
if((newPosition - nextpos).length2() > 0.0001) if((newPosition - nextpos).length2() > 0.0001)
{ {
// trace to where character would go if there were no obstructions // trace to where character would go if there were no obstructions
tracer.doTrace(colobj, newPosition, nextpos, dynamicsWorld); tracer.doTrace(colobj, newPosition, nextpos, collisionWorld);
// check for obstructions // check for obstructions
if(tracer.mFraction >= 1.0f) if(tracer.mFraction >= 1.0f)
@ -358,12 +358,12 @@ namespace MWPhysics
osg::Vec3f oldPosition = newPosition; osg::Vec3f oldPosition = newPosition;
// We hit something. Try to step up onto it. (NOTE: stepMove does not allow stepping over) // We hit something. Try to step up onto it. (NOTE: stepMove does not allow stepping over)
// NOTE: stepMove modifies newPosition if successful // NOTE: stepMove modifies newPosition if successful
bool result = stepMove(colobj, newPosition, velocity*remainingTime, remainingTime, dynamicsWorld); bool result = stepMove(colobj, newPosition, velocity*remainingTime, remainingTime, collisionWorld);
if (!result) // to make sure the maximum stepping distance isn't framerate-dependent or movement-speed dependent if (!result) // to make sure the maximum stepping distance isn't framerate-dependent or movement-speed dependent
{ {
osg::Vec3f normalizedVelocity = velocity; osg::Vec3f normalizedVelocity = velocity;
normalizedVelocity.normalize(); normalizedVelocity.normalize();
result = stepMove(colobj, newPosition, normalizedVelocity*10.f, remainingTime, dynamicsWorld); result = stepMove(colobj, newPosition, normalizedVelocity*10.f, remainingTime, collisionWorld);
} }
if(result) if(result)
{ {
@ -401,7 +401,7 @@ namespace MWPhysics
osg::Vec3f from = newPosition; osg::Vec3f from = newPosition;
osg::Vec3f to = newPosition - (physicActor->getOnGround() ? osg::Vec3f to = newPosition - (physicActor->getOnGround() ?
osg::Vec3f(0,0,sStepSizeDown+2.f) : osg::Vec3f(0,0,2.f)); osg::Vec3f(0,0,sStepSizeDown+2.f) : osg::Vec3f(0,0,2.f));
tracer.doTrace(colobj, from, to, dynamicsWorld); tracer.doTrace(colobj, from, to, collisionWorld);
if(tracer.mFraction < 1.0f && getSlope(tracer.mPlaneNormal) <= sMaxSlope if(tracer.mFraction < 1.0f && getSlope(tracer.mPlaneNormal) <= sMaxSlope
&& tracer.mHitObject->getBroadphaseHandle()->m_collisionFilterGroup != CollisionType_Actor) && tracer.mHitObject->getBroadphaseHandle()->m_collisionFilterGroup != CollisionType_Actor)
{ {
@ -549,7 +549,7 @@ namespace MWPhysics
return mCollisionObject.get(); return mCollisionObject.get();
} }
void animateCollisionShapes(btDynamicsWorld* dynamicsWorld) void animateCollisionShapes(btCollisionWorld* collisionWorld)
{ {
if (mShapeInstance->mAnimatedShapes.empty()) if (mShapeInstance->mAnimatedShapes.empty())
return; return;
@ -587,7 +587,7 @@ namespace MWPhysics
compound->updateChildTransform(shapeIndex, transform); compound->updateChildTransform(shapeIndex, transform);
} }
dynamicsWorld->updateSingleAabb(mCollisionObject.get()); collisionWorld->updateSingleAabb(mCollisionObject.get());
} }
private: private:
@ -607,33 +607,29 @@ namespace MWPhysics
{ {
mCollisionConfiguration = new btDefaultCollisionConfiguration(); mCollisionConfiguration = new btDefaultCollisionConfiguration();
mDispatcher = new btCollisionDispatcher(mCollisionConfiguration); mDispatcher = new btCollisionDispatcher(mCollisionConfiguration);
mSolver = new btSequentialImpulseConstraintSolver;
mBroadphase = new btDbvtBroadphase(); mBroadphase = new btDbvtBroadphase();
// Note we don't use any Dynamics at the moment - a btCollisionWorld might be sufficient? mCollisionWorld = new btCollisionWorld(mDispatcher, mBroadphase, mCollisionConfiguration);
mDynamicsWorld = new btDiscreteDynamicsWorld(mDispatcher,mBroadphase,mSolver,mCollisionConfiguration);
// Don't update AABBs of all objects every frame. Most objects in MW are static, so we don't need this. // Don't update AABBs of all objects every frame. Most objects in MW are static, so we don't need this.
// Should a "static" object ever be moved, we have to update its AABB manually using DynamicsWorld::updateSingleAabb. // Should a "static" object ever be moved, we have to update its AABB manually using DynamicsWorld::updateSingleAabb.
mDynamicsWorld->setForceUpdateAllAabbs(false); mCollisionWorld->setForceUpdateAllAabbs(false);
mDynamicsWorld->setGravity(btVector3(0,0,-10));
} }
PhysicsSystem::~PhysicsSystem() PhysicsSystem::~PhysicsSystem()
{ {
if (mWaterCollisionObject.get()) if (mWaterCollisionObject.get())
mDynamicsWorld->removeCollisionObject(mWaterCollisionObject.get()); mCollisionWorld->removeCollisionObject(mWaterCollisionObject.get());
for (HeightFieldMap::iterator it = mHeightFields.begin(); it != mHeightFields.end(); ++it) for (HeightFieldMap::iterator it = mHeightFields.begin(); it != mHeightFields.end(); ++it)
{ {
mDynamicsWorld->removeCollisionObject(it->second->getCollisionObject()); mCollisionWorld->removeCollisionObject(it->second->getCollisionObject());
delete it->second; delete it->second;
} }
for (ObjectMap::iterator it = mObjects.begin(); it != mObjects.end(); ++it) for (ObjectMap::iterator it = mObjects.begin(); it != mObjects.end(); ++it)
{ {
mDynamicsWorld->removeCollisionObject(it->second->getCollisionObject()); mCollisionWorld->removeCollisionObject(it->second->getCollisionObject());
delete it->second; delete it->second;
} }
@ -642,8 +638,7 @@ namespace MWPhysics
delete it->second; delete it->second;
} }
delete mDynamicsWorld; delete mCollisionWorld;
delete mSolver;
delete mCollisionConfiguration; delete mCollisionConfiguration;
delete mDispatcher; delete mDispatcher;
delete mBroadphase; delete mBroadphase;
@ -655,8 +650,8 @@ namespace MWPhysics
if (mDebugDrawEnabled && !mDebugDrawer.get()) if (mDebugDrawEnabled && !mDebugDrawer.get())
{ {
mDebugDrawer.reset(new MWRender::DebugDrawer(mParentNode, mDynamicsWorld)); mDebugDrawer.reset(new MWRender::DebugDrawer(mParentNode, mCollisionWorld));
mDynamicsWorld->setDebugDrawer(mDebugDrawer.get()); mCollisionWorld->setDebugDrawer(mDebugDrawer.get());
mDebugDrawer->setDebugMode(mDebugDrawEnabled); mDebugDrawer->setDebugMode(mDebugDrawEnabled);
} }
else if (mDebugDrawer.get()) else if (mDebugDrawer.get())
@ -727,7 +722,7 @@ namespace MWPhysics
DeepestNotMeContactTestResultCallback resultCallback(me, toBullet(origin)); DeepestNotMeContactTestResultCallback resultCallback(me, toBullet(origin));
resultCallback.m_collisionFilterGroup = CollisionType_Actor; resultCallback.m_collisionFilterGroup = CollisionType_Actor;
resultCallback.m_collisionFilterMask = CollisionType_World | CollisionType_HeightMap | CollisionType_Actor; resultCallback.m_collisionFilterMask = CollisionType_World | CollisionType_HeightMap | CollisionType_Actor;
mDynamicsWorld->contactTest(&object, resultCallback); mCollisionWorld->contactTest(&object, resultCallback);
if (resultCallback.mObject) if (resultCallback.mObject)
{ {
@ -761,7 +756,7 @@ namespace MWPhysics
resultCallback.m_collisionFilterGroup = 0xff; resultCallback.m_collisionFilterGroup = 0xff;
resultCallback.m_collisionFilterMask = CollisionType_World | CollisionType_HeightMap; resultCallback.m_collisionFilterMask = CollisionType_World | CollisionType_HeightMap;
mDynamicsWorld->rayTest(btFrom, btTo, resultCallback); mCollisionWorld->rayTest(btFrom, btTo, resultCallback);
if (resultCallback.hasHit()) if (resultCallback.hasHit())
{ {
return std::make_pair(true, toOsg(resultCallback.m_hitPointWorld)); return std::make_pair(true, toOsg(resultCallback.m_hitPointWorld));
@ -798,7 +793,7 @@ namespace MWPhysics
ContactTestResultCallback resultCallback; ContactTestResultCallback resultCallback;
resultCallback.m_collisionFilterGroup = collisionGroup; resultCallback.m_collisionFilterGroup = collisionGroup;
resultCallback.m_collisionFilterMask = collisionMask; resultCallback.m_collisionFilterMask = collisionMask;
mDynamicsWorld->contactTest(me, resultCallback); mCollisionWorld->contactTest(me, resultCallback);
return resultCallback.mResult; return resultCallback.mResult;
} }
@ -808,7 +803,7 @@ namespace MWPhysics
if (found == mActors.end()) if (found == mActors.end())
return ptr.getRefData().getPosition().asVec3(); return ptr.getRefData().getPosition().asVec3();
else else
return MovementSolver::traceDown(ptr, found->second, mDynamicsWorld, maxHeight); return MovementSolver::traceDown(ptr, found->second, mCollisionWorld, maxHeight);
} }
void PhysicsSystem::addHeightField (float* heights, int x, int y, float triSize, float sqrtVerts) void PhysicsSystem::addHeightField (float* heights, int x, int y, float triSize, float sqrtVerts)
@ -816,7 +811,7 @@ namespace MWPhysics
HeightField *heightfield = new HeightField(heights, x, y, triSize, sqrtVerts); HeightField *heightfield = new HeightField(heights, x, y, triSize, sqrtVerts);
mHeightFields[std::make_pair(x,y)] = heightfield; mHeightFields[std::make_pair(x,y)] = heightfield;
mDynamicsWorld->addCollisionObject(heightfield->getCollisionObject(), CollisionType_HeightMap, mCollisionWorld->addCollisionObject(heightfield->getCollisionObject(), CollisionType_HeightMap,
CollisionType_Actor|CollisionType_Projectile); CollisionType_Actor|CollisionType_Projectile);
} }
@ -825,7 +820,7 @@ namespace MWPhysics
HeightFieldMap::iterator heightfield = mHeightFields.find(std::make_pair(x,y)); HeightFieldMap::iterator heightfield = mHeightFields.find(std::make_pair(x,y));
if(heightfield != mHeightFields.end()) if(heightfield != mHeightFields.end())
{ {
mDynamicsWorld->removeCollisionObject(heightfield->second->getCollisionObject()); mCollisionWorld->removeCollisionObject(heightfield->second->getCollisionObject());
delete heightfield->second; delete heightfield->second;
mHeightFields.erase(heightfield); mHeightFields.erase(heightfield);
} }
@ -840,7 +835,7 @@ namespace MWPhysics
Object *obj = new Object(ptr, shapeInstance); Object *obj = new Object(ptr, shapeInstance);
mObjects.insert(std::make_pair(ptr, obj)); mObjects.insert(std::make_pair(ptr, obj));
mDynamicsWorld->addCollisionObject(obj->getCollisionObject(), CollisionType_World, mCollisionWorld->addCollisionObject(obj->getCollisionObject(), CollisionType_World,
CollisionType_Actor|CollisionType_HeightMap|CollisionType_Projectile); CollisionType_Actor|CollisionType_HeightMap|CollisionType_Projectile);
} }
@ -849,7 +844,7 @@ namespace MWPhysics
ObjectMap::iterator found = mObjects.find(ptr); ObjectMap::iterator found = mObjects.find(ptr);
if (found != mObjects.end()) if (found != mObjects.end())
{ {
mDynamicsWorld->removeCollisionObject(found->second->getCollisionObject()); mCollisionWorld->removeCollisionObject(found->second->getCollisionObject());
delete found->second; delete found->second;
mObjects.erase(found); mObjects.erase(found);
} }
@ -898,14 +893,14 @@ namespace MWPhysics
if (found != mObjects.end()) if (found != mObjects.end())
{ {
found->second->setScale(scale); found->second->setScale(scale);
mDynamicsWorld->updateSingleAabb(found->second->getCollisionObject()); mCollisionWorld->updateSingleAabb(found->second->getCollisionObject());
return; return;
} }
ActorMap::iterator foundActor = mActors.find(ptr); ActorMap::iterator foundActor = mActors.find(ptr);
if (foundActor != mActors.end()) if (foundActor != mActors.end())
{ {
foundActor->second->updateScale(); foundActor->second->updateScale();
// no aabb update needed (DISABLE_DEACTIVATION) mCollisionWorld->updateSingleAabb(foundActor->second->getCollisionObject());
return; return;
} }
} }
@ -916,14 +911,14 @@ namespace MWPhysics
if (found != mObjects.end()) if (found != mObjects.end())
{ {
found->second->setRotation(toBullet(ptr.getRefData().getBaseNode()->getAttitude())); found->second->setRotation(toBullet(ptr.getRefData().getBaseNode()->getAttitude()));
mDynamicsWorld->updateSingleAabb(found->second->getCollisionObject()); mCollisionWorld->updateSingleAabb(found->second->getCollisionObject());
return; return;
} }
ActorMap::iterator foundActor = mActors.find(ptr); ActorMap::iterator foundActor = mActors.find(ptr);
if (foundActor != mActors.end()) if (foundActor != mActors.end())
{ {
foundActor->second->updateRotation(); foundActor->second->updateRotation();
// no aabb update needed (DISABLE_DEACTIVATION) mCollisionWorld->updateSingleAabb(foundActor->second->getCollisionObject());
return; return;
} }
} }
@ -934,14 +929,14 @@ namespace MWPhysics
if (found != mObjects.end()) if (found != mObjects.end())
{ {
found->second->setOrigin(toBullet(ptr.getRefData().getPosition().asVec3())); found->second->setOrigin(toBullet(ptr.getRefData().getPosition().asVec3()));
mDynamicsWorld->updateSingleAabb(found->second->getCollisionObject()); mCollisionWorld->updateSingleAabb(found->second->getCollisionObject());
return; return;
} }
ActorMap::iterator foundActor = mActors.find(ptr); ActorMap::iterator foundActor = mActors.find(ptr);
if (foundActor != mActors.end()) if (foundActor != mActors.end())
{ {
foundActor->second->updatePosition(); foundActor->second->updatePosition();
// no aabb update needed (DISABLE_DEACTIVATION) mCollisionWorld->updateSingleAabb(foundActor->second->getCollisionObject());
return; return;
} }
} }
@ -950,7 +945,7 @@ namespace MWPhysics
{ {
osg::ref_ptr<NifBullet::BulletShapeInstance> shapeInstance = mShapeManager->createInstance(mesh); osg::ref_ptr<NifBullet::BulletShapeInstance> shapeInstance = mShapeManager->createInstance(mesh);
Actor* actor = new Actor(ptr, shapeInstance, mDynamicsWorld); Actor* actor = new Actor(ptr, shapeInstance, mCollisionWorld);
mActors.insert(std::make_pair(ptr, actor)); mActors.insert(std::make_pair(ptr, actor));
} }
@ -1032,7 +1027,7 @@ namespace MWPhysics
osg::Vec3f newpos = MovementSolver::move(iter->first, physicActor, iter->second, mTimeAccum, osg::Vec3f newpos = MovementSolver::move(iter->first, physicActor, iter->second, mTimeAccum,
world->isFlying(iter->first), world->isFlying(iter->first),
waterlevel, slowFall, mDynamicsWorld, mCollisions, mStandingCollisions); waterlevel, slowFall, mCollisionWorld, mCollisions, mStandingCollisions);
float heightDiff = newpos.z() - oldHeight; float heightDiff = newpos.z() - oldHeight;
@ -1052,10 +1047,10 @@ namespace MWPhysics
void PhysicsSystem::stepSimulation(float dt) void PhysicsSystem::stepSimulation(float dt)
{ {
for (ObjectMap::iterator it = mObjects.begin(); it != mObjects.end(); ++it) for (ObjectMap::iterator it = mObjects.begin(); it != mObjects.end(); ++it)
it->second->animateCollisionShapes(mDynamicsWorld); it->second->animateCollisionShapes(mCollisionWorld);
// We have nothing to simulate, but character controllers aren't working without this call. Might be related to updating AABBs. CProfileManager::Reset();
mDynamicsWorld->stepSimulation(static_cast<btScalar>(dt), 1, 1 / 60.0f); CProfileManager::Increment_Frame_Counter();
if (mDebugDrawer.get()) if (mDebugDrawer.get())
mDebugDrawer->step(); mDebugDrawer->step();
@ -1153,7 +1148,7 @@ namespace MWPhysics
{ {
if (mWaterCollisionObject.get()) if (mWaterCollisionObject.get())
{ {
mDynamicsWorld->removeCollisionObject(mWaterCollisionObject.get()); mCollisionWorld->removeCollisionObject(mWaterCollisionObject.get());
} }
if (!mWaterEnabled) if (!mWaterEnabled)
@ -1162,7 +1157,7 @@ namespace MWPhysics
mWaterCollisionObject.reset(new btCollisionObject()); mWaterCollisionObject.reset(new btCollisionObject());
mWaterCollisionShape.reset(new btStaticPlaneShape(btVector3(0,0,1), mWaterHeight)); mWaterCollisionShape.reset(new btStaticPlaneShape(btVector3(0,0,1), mWaterHeight));
mWaterCollisionObject->setCollisionShape(mWaterCollisionShape.get()); mWaterCollisionObject->setCollisionShape(mWaterCollisionShape.get());
mDynamicsWorld->addCollisionObject(mWaterCollisionObject.get(), CollisionType_Water, mCollisionWorld->addCollisionObject(mWaterCollisionObject.get(), CollisionType_Water,
CollisionType_Actor); CollisionType_Actor);
} }
} }

@ -31,8 +31,7 @@ namespace Resource
class ResourceSystem; class ResourceSystem;
} }
class btSequentialImpulseConstraintSolver; class btCollisionWorld;
class btDiscreteDynamicsWorld;
class btBroadphaseInterface; class btBroadphaseInterface;
class btDefaultCollisionConfiguration; class btDefaultCollisionConfiguration;
class btCollisionDispatcher; class btCollisionDispatcher;
@ -127,9 +126,8 @@ namespace MWPhysics
btBroadphaseInterface* mBroadphase; btBroadphaseInterface* mBroadphase;
btDefaultCollisionConfiguration* mCollisionConfiguration; btDefaultCollisionConfiguration* mCollisionConfiguration;
btSequentialImpulseConstraintSolver* mSolver;
btCollisionDispatcher* mDispatcher; btCollisionDispatcher* mDispatcher;
btDiscreteDynamicsWorld* mDynamicsWorld; btCollisionWorld* mCollisionWorld;
std::auto_ptr<NifBullet::BulletShapeManager> mShapeManager; std::auto_ptr<NifBullet::BulletShapeManager> mShapeManager;

@ -2,7 +2,7 @@
#include <map> #include <map>
#include <BulletDynamics/Dynamics/btDynamicsWorld.h> #include <BulletCollision/CollisionDispatch/btCollisionWorld.h>
#include <BulletCollision/CollisionShapes/btConvexShape.h> #include <BulletCollision/CollisionShapes/btConvexShape.h>
#include <BulletCollision/CollisionShapes/btCylinderShape.h> #include <BulletCollision/CollisionShapes/btCylinderShape.h>
@ -50,7 +50,7 @@ protected:
}; };
void ActorTracer::doTrace(btCollisionObject *actor, const osg::Vec3f& start, const osg::Vec3f& end, btDynamicsWorld* world) void ActorTracer::doTrace(btCollisionObject *actor, const osg::Vec3f& start, const osg::Vec3f& end, btCollisionWorld* world)
{ {
const btVector3 btstart = toBullet(start); const btVector3 btstart = toBullet(start);
const btVector3 btend = toBullet(end); const btVector3 btend = toBullet(end);
@ -89,7 +89,7 @@ void ActorTracer::doTrace(btCollisionObject *actor, const osg::Vec3f& start, con
} }
} }
void ActorTracer::findGround(const Actor* actor, const osg::Vec3f& start, const osg::Vec3f& end, btDynamicsWorld* world) void ActorTracer::findGround(const Actor* actor, const osg::Vec3f& start, const osg::Vec3f& end, btCollisionWorld* world)
{ {
const btVector3 btstart(start.x(), start.y(), start.z()+1.0f); const btVector3 btstart(start.x(), start.y(), start.z()+1.0f);
const btVector3 btend(end.x(), end.y(), end.z()+1.0f); const btVector3 btend(end.x(), end.y(), end.z()+1.0f);

@ -4,7 +4,7 @@
#include <osg/Vec3f> #include <osg/Vec3f>
class btCollisionObject; class btCollisionObject;
class btDynamicsWorld; class btCollisionWorld;
namespace MWPhysics namespace MWPhysics
@ -19,8 +19,8 @@ namespace MWPhysics
float mFraction; float mFraction;
void doTrace(btCollisionObject *actor, const osg::Vec3f& start, const osg::Vec3f& end, btDynamicsWorld* world); void doTrace(btCollisionObject *actor, const osg::Vec3f& start, const osg::Vec3f& end, btCollisionWorld* world);
void findGround(const Actor* actor, const osg::Vec3f& start, const osg::Vec3f& end, btDynamicsWorld* world); void findGround(const Actor* actor, const osg::Vec3f& start, const osg::Vec3f& end, btCollisionWorld* world);
}; };
} }

@ -2,7 +2,7 @@
#include <iostream> #include <iostream>
#include <BulletDynamics/Dynamics/btDynamicsWorld.h> #include <BulletCollision/CollisionDispatch/btCollisionWorld.h>
#include <osg/Geode> #include <osg/Geode>
#include <osg/Geometry> #include <osg/Geometry>
@ -21,7 +21,7 @@ namespace
namespace MWRender namespace MWRender
{ {
DebugDrawer::DebugDrawer(osg::ref_ptr<osg::Group> parentNode, btDynamicsWorld *world) DebugDrawer::DebugDrawer(osg::ref_ptr<osg::Group> parentNode, btCollisionWorld *world)
: mParentNode(parentNode), : mParentNode(parentNode),
mWorld(world), mWorld(world),
mDebugOn(true) mDebugOn(true)

@ -7,7 +7,7 @@
#include <LinearMath/btIDebugDraw.h> #include <LinearMath/btIDebugDraw.h>
class btDynamicsWorld; class btCollisionWorld;
namespace osg namespace osg
{ {
@ -23,7 +23,7 @@ class DebugDrawer : public btIDebugDraw
{ {
protected: protected:
osg::ref_ptr<osg::Group> mParentNode; osg::ref_ptr<osg::Group> mParentNode;
btDynamicsWorld *mWorld; btCollisionWorld *mWorld;
osg::ref_ptr<osg::Geode> mGeode; osg::ref_ptr<osg::Geode> mGeode;
osg::ref_ptr<osg::Geometry> mGeometry; osg::ref_ptr<osg::Geometry> mGeometry;
osg::ref_ptr<osg::Vec3Array> mVertices; osg::ref_ptr<osg::Vec3Array> mVertices;
@ -36,7 +36,7 @@ protected:
public: public:
DebugDrawer(osg::ref_ptr<osg::Group> parentNode, btDynamicsWorld *world); DebugDrawer(osg::ref_ptr<osg::Group> parentNode, btCollisionWorld *world);
~DebugDrawer(); ~DebugDrawer();
void step(); void step();

@ -54,8 +54,8 @@ find_path(BULLET_INCLUDE_DIR NAMES btBulletCollisionCommon.h
# Find the libraries # Find the libraries
_FIND_BULLET_LIBRARY(BULLET_DYNAMICS_LIBRARY BulletDynamics) #_FIND_BULLET_LIBRARY(BULLET_DYNAMICS_LIBRARY BulletDynamics)
_FIND_BULLET_LIBRARY(BULLET_DYNAMICS_LIBRARY_DEBUG BulletDynamics_Debug BulletDynamics_d) #_FIND_BULLET_LIBRARY(BULLET_DYNAMICS_LIBRARY_DEBUG BulletDynamics_Debug BulletDynamics_d)
_FIND_BULLET_LIBRARY(BULLET_COLLISION_LIBRARY BulletCollision) _FIND_BULLET_LIBRARY(BULLET_COLLISION_LIBRARY BulletCollision)
_FIND_BULLET_LIBRARY(BULLET_COLLISION_LIBRARY_DEBUG BulletCollision_Debug BulletCollision_d) _FIND_BULLET_LIBRARY(BULLET_COLLISION_LIBRARY_DEBUG BulletCollision_Debug BulletCollision_d)
_FIND_BULLET_LIBRARY(BULLET_MATH_LIBRARY BulletMath LinearMath) _FIND_BULLET_LIBRARY(BULLET_MATH_LIBRARY BulletMath LinearMath)
@ -71,7 +71,7 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(Bullet DEFAULT_MSG
set(BULLET_INCLUDE_DIRS ${BULLET_INCLUDE_DIR}) set(BULLET_INCLUDE_DIRS ${BULLET_INCLUDE_DIR})
if(BULLET_FOUND) if(BULLET_FOUND)
_BULLET_APPEND_LIBRARIES(BULLET_LIBRARIES BULLET_DYNAMICS_LIBRARY) #_BULLET_APPEND_LIBRARIES(BULLET_LIBRARIES BULLET_DYNAMICS_LIBRARY)
_BULLET_APPEND_LIBRARIES(BULLET_LIBRARIES BULLET_COLLISION_LIBRARY) _BULLET_APPEND_LIBRARIES(BULLET_LIBRARIES BULLET_COLLISION_LIBRARY)
_BULLET_APPEND_LIBRARIES(BULLET_LIBRARIES BULLET_MATH_LIBRARY) _BULLET_APPEND_LIBRARIES(BULLET_LIBRARIES BULLET_MATH_LIBRARY)
endif() endif()

Loading…
Cancel
Save