move updateAabbs from dynamics world to collision world
This commit is contained in:
@@ -41,7 +41,8 @@ subject to the following restrictions:
|
|||||||
|
|
||||||
btCollisionWorld::btCollisionWorld(btDispatcher* dispatcher,btBroadphaseInterface* pairCache, btCollisionConfiguration* collisionConfiguration)
|
btCollisionWorld::btCollisionWorld(btDispatcher* dispatcher,btBroadphaseInterface* pairCache, btCollisionConfiguration* collisionConfiguration)
|
||||||
:m_dispatcher1(dispatcher),
|
:m_dispatcher1(dispatcher),
|
||||||
m_broadphasePairCache(pairCache)
|
m_broadphasePairCache(pairCache),
|
||||||
|
m_debugDrawer(0)
|
||||||
{
|
{
|
||||||
m_stackAlloc = collisionConfiguration->getStackAllocator();
|
m_stackAlloc = collisionConfiguration->getStackAllocator();
|
||||||
m_dispatchInfo.m_stackAllocator = m_stackAlloc;
|
m_dispatchInfo.m_stackAllocator = m_stackAlloc;
|
||||||
@@ -112,6 +113,47 @@ void btCollisionWorld::addCollisionObject(btCollisionObject* collisionObject,sho
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void btCollisionWorld::updateAabbs()
|
||||||
|
{
|
||||||
|
PROFILE("updateAabbs");
|
||||||
|
|
||||||
|
btTransform predictedTrans;
|
||||||
|
for ( int i=0;i<m_collisionObjects.size();i++)
|
||||||
|
{
|
||||||
|
btCollisionObject* colObj = m_collisionObjects[i];
|
||||||
|
|
||||||
|
//only update aabb of active objects
|
||||||
|
if (colObj->isActive())
|
||||||
|
{
|
||||||
|
btPoint3 minAabb,maxAabb;
|
||||||
|
colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(), minAabb,maxAabb);
|
||||||
|
btBroadphaseInterface* bp = (btBroadphaseInterface*)m_broadphasePairCache;
|
||||||
|
|
||||||
|
//moving objects should be moderately sized, probably something wrong if not
|
||||||
|
if ( colObj->isStaticObject() || ((maxAabb-minAabb).length2() < btScalar(1e12)))
|
||||||
|
{
|
||||||
|
bp->setAabb(colObj->getBroadphaseHandle(),minAabb,maxAabb, m_dispatcher1);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
//something went wrong, investigate
|
||||||
|
//this assert is unwanted in 3D modelers (danger of loosing work)
|
||||||
|
colObj->setActivationState(DISABLE_SIMULATION);
|
||||||
|
|
||||||
|
static bool reportMe = true;
|
||||||
|
if (reportMe && m_debugDrawer)
|
||||||
|
{
|
||||||
|
reportMe = false;
|
||||||
|
m_debugDrawer->reportErrorWarning("Overflow in AABB, object removed from simulation");
|
||||||
|
m_debugDrawer->reportErrorWarning("If you can reproduce this, please email bugs@continuousphysics.com\n");
|
||||||
|
m_debugDrawer->reportErrorWarning("Please include above information, your Platform, version of OS.\n");
|
||||||
|
m_debugDrawer->reportErrorWarning("Thanks.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
END_PROFILE("updateAabbs");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -124,16 +166,8 @@ void btCollisionWorld::performDiscreteCollisionDetection()
|
|||||||
BEGIN_PROFILE("perform Broadphase Collision Detection");
|
BEGIN_PROFILE("perform Broadphase Collision Detection");
|
||||||
|
|
||||||
|
|
||||||
//update aabb (of all moved objects)
|
updateAabbs();
|
||||||
{
|
|
||||||
PROFILE("setAabb");
|
|
||||||
btVector3 aabbMin,aabbMax;
|
|
||||||
for (int i=0;i<m_collisionObjects.size();i++)
|
|
||||||
{
|
|
||||||
m_collisionObjects[i]->getCollisionShape()->getAabb(m_collisionObjects[i]->getWorldTransform(),aabbMin,aabbMax);
|
|
||||||
m_broadphasePairCache->setAabb(m_collisionObjects[i]->getBroadphaseHandle(),aabbMin,aabbMax,m_dispatcher1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
{
|
||||||
PROFILE("calculateOverlappingPairs");
|
PROFILE("calculateOverlappingPairs");
|
||||||
m_broadphasePairCache->calculateOverlappingPairs(m_dispatcher1);
|
m_broadphasePairCache->calculateOverlappingPairs(m_dispatcher1);
|
||||||
|
|||||||
@@ -92,6 +92,9 @@ protected:
|
|||||||
|
|
||||||
btBroadphaseInterface* m_broadphasePairCache;
|
btBroadphaseInterface* m_broadphasePairCache;
|
||||||
|
|
||||||
|
btIDebugDraw* m_debugDrawer;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//this constructor doesn't own the dispatcher and paircache/broadphase
|
//this constructor doesn't own the dispatcher and paircache/broadphase
|
||||||
@@ -116,6 +119,19 @@ public:
|
|||||||
return m_dispatcher1;
|
return m_dispatcher1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void updateAabbs();
|
||||||
|
|
||||||
|
virtual void setDebugDrawer(btIDebugDraw* debugDrawer)
|
||||||
|
{
|
||||||
|
m_debugDrawer = debugDrawer;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual btIDebugDraw* getDebugDrawer()
|
||||||
|
{
|
||||||
|
return m_debugDrawer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///LocalShapeInfo gives extra information for complex shapes
|
///LocalShapeInfo gives extra information for complex shapes
|
||||||
///Currently, only btTriangleMeshShape is available, so it just contains triangleIndex and subpart
|
///Currently, only btTriangleMeshShape is available, so it just contains triangleIndex and subpart
|
||||||
struct LocalShapeInfo
|
struct LocalShapeInfo
|
||||||
|
|||||||
@@ -61,7 +61,6 @@ subject to the following restrictions:
|
|||||||
btDiscreteDynamicsWorld::btDiscreteDynamicsWorld(btDispatcher* dispatcher,btBroadphaseInterface* pairCache,btConstraintSolver* constraintSolver, btCollisionConfiguration* collisionConfiguration)
|
btDiscreteDynamicsWorld::btDiscreteDynamicsWorld(btDispatcher* dispatcher,btBroadphaseInterface* pairCache,btConstraintSolver* constraintSolver, btCollisionConfiguration* collisionConfiguration)
|
||||||
:btDynamicsWorld(dispatcher,pairCache,collisionConfiguration),
|
:btDynamicsWorld(dispatcher,pairCache,collisionConfiguration),
|
||||||
m_constraintSolver(constraintSolver),
|
m_constraintSolver(constraintSolver),
|
||||||
m_debugDrawer(0),
|
|
||||||
m_gravity(0,-10,0),
|
m_gravity(0,-10,0),
|
||||||
m_localTime(btScalar(1.)/btScalar(60.)),
|
m_localTime(btScalar(1.)/btScalar(60.)),
|
||||||
m_profileTimings(0)
|
m_profileTimings(0)
|
||||||
@@ -303,10 +302,6 @@ void btDiscreteDynamicsWorld::internalSingleStepSimulation(btScalar timeStep)
|
|||||||
|
|
||||||
PROFILE("internalSingleStepSimulation");
|
PROFILE("internalSingleStepSimulation");
|
||||||
|
|
||||||
|
|
||||||
///update aabbs information
|
|
||||||
updateAabbs();
|
|
||||||
|
|
||||||
///apply gravity, predict motion
|
///apply gravity, predict motion
|
||||||
predictUnconstraintMotion(timeStep);
|
predictUnconstraintMotion(timeStep);
|
||||||
|
|
||||||
@@ -640,53 +635,6 @@ void btDiscreteDynamicsWorld::calculateSimulationIslands()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void btDiscreteDynamicsWorld::updateAabbs()
|
|
||||||
{
|
|
||||||
PROFILE("updateAabbs");
|
|
||||||
|
|
||||||
btTransform predictedTrans;
|
|
||||||
for ( int i=0;i<m_collisionObjects.size();i++)
|
|
||||||
{
|
|
||||||
btCollisionObject* colObj = m_collisionObjects[i];
|
|
||||||
|
|
||||||
btRigidBody* body = btRigidBody::upcast(colObj);
|
|
||||||
if (body)
|
|
||||||
{
|
|
||||||
//only update aabb of active objects
|
|
||||||
if (body->isActive())
|
|
||||||
{
|
|
||||||
btPoint3 minAabb,maxAabb;
|
|
||||||
colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(), minAabb,maxAabb);
|
|
||||||
btBroadphaseInterface* bp = (btBroadphaseInterface*)m_broadphasePairCache;
|
|
||||||
|
|
||||||
//moving objects should be moderately sized, probably something wrong if not
|
|
||||||
if ( colObj->isStaticObject() || ((maxAabb-minAabb).length2() < btScalar(1e12)))
|
|
||||||
{
|
|
||||||
bp->setAabb(body->getBroadphaseHandle(),minAabb,maxAabb, m_dispatcher1);
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
//something went wrong, investigate
|
|
||||||
//this assert is unwanted in 3D modelers (danger of loosing work)
|
|
||||||
body->setActivationState(DISABLE_SIMULATION);
|
|
||||||
|
|
||||||
static bool reportMe = true;
|
|
||||||
if (reportMe && m_debugDrawer)
|
|
||||||
{
|
|
||||||
reportMe = false;
|
|
||||||
m_debugDrawer->reportErrorWarning("Overflow in AABB, object removed from simulation");
|
|
||||||
m_debugDrawer->reportErrorWarning("If you can reproduce this, please email bugs@continuousphysics.com\n");
|
|
||||||
m_debugDrawer->reportErrorWarning("Please include above information, your Platform, version of OS.\n");
|
|
||||||
m_debugDrawer->reportErrorWarning("Thanks.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
END_PROFILE("updateAabbs");
|
|
||||||
}
|
|
||||||
|
|
||||||
void btDiscreteDynamicsWorld::integrateTransforms(btScalar timeStep)
|
void btDiscreteDynamicsWorld::integrateTransforms(btScalar timeStep)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ protected:
|
|||||||
|
|
||||||
btAlignedObjectArray<btTypedConstraint*> m_constraints;
|
btAlignedObjectArray<btTypedConstraint*> m_constraints;
|
||||||
|
|
||||||
btIDebugDraw* m_debugDrawer;
|
|
||||||
|
|
||||||
btVector3 m_gravity;
|
btVector3 m_gravity;
|
||||||
|
|
||||||
@@ -93,7 +92,6 @@ public:
|
|||||||
///if maxSubSteps > 0, it will interpolate motion between fixedTimeStep's
|
///if maxSubSteps > 0, it will interpolate motion between fixedTimeStep's
|
||||||
virtual int stepSimulation( btScalar timeStep,int maxSubSteps=1, btScalar fixedTimeStep=btScalar(1.)/btScalar(60.));
|
virtual int stepSimulation( btScalar timeStep,int maxSubSteps=1, btScalar fixedTimeStep=btScalar(1.)/btScalar(60.));
|
||||||
|
|
||||||
virtual void updateAabbs();
|
|
||||||
|
|
||||||
void addConstraint(btTypedConstraint* constraint, bool disableCollisionsBetweenLinkedBodies=false);
|
void addConstraint(btTypedConstraint* constraint, bool disableCollisionsBetweenLinkedBodies=false);
|
||||||
|
|
||||||
@@ -118,15 +116,6 @@ public:
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void setDebugDrawer(btIDebugDraw* debugDrawer)
|
|
||||||
{
|
|
||||||
m_debugDrawer = debugDrawer;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual btIDebugDraw* getDebugDrawer()
|
|
||||||
{
|
|
||||||
return m_debugDrawer;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void setGravity(const btVector3& gravity);
|
virtual void setGravity(const btVector3& gravity);
|
||||||
|
|
||||||
|
|||||||
@@ -48,8 +48,6 @@ class btDynamicsWorld : public btCollisionWorld
|
|||||||
///if maxSubSteps > 0, it will interpolate time steps
|
///if maxSubSteps > 0, it will interpolate time steps
|
||||||
virtual int stepSimulation( btScalar timeStep,int maxSubSteps=1, btScalar fixedTimeStep=btScalar(1.)/btScalar(60.))=0;
|
virtual int stepSimulation( btScalar timeStep,int maxSubSteps=1, btScalar fixedTimeStep=btScalar(1.)/btScalar(60.))=0;
|
||||||
|
|
||||||
virtual void updateAabbs() = 0;
|
|
||||||
|
|
||||||
virtual void debugDrawWorld() = 0;
|
virtual void debugDrawWorld() = 0;
|
||||||
|
|
||||||
virtual void addConstraint(btTypedConstraint* constraint, bool disableCollisionsBetweenLinkedBodies=false) { (void)constraint;};
|
virtual void addConstraint(btTypedConstraint* constraint, bool disableCollisionsBetweenLinkedBodies=false) { (void)constraint;};
|
||||||
@@ -60,11 +58,6 @@ class btDynamicsWorld : public btCollisionWorld
|
|||||||
|
|
||||||
virtual void removeVehicle(btRaycastVehicle* vehicle) {(void)vehicle;};
|
virtual void removeVehicle(btRaycastVehicle* vehicle) {(void)vehicle;};
|
||||||
|
|
||||||
|
|
||||||
virtual void setDebugDrawer(btIDebugDraw* debugDrawer) = 0;
|
|
||||||
|
|
||||||
virtual btIDebugDraw* getDebugDrawer() = 0;
|
|
||||||
|
|
||||||
//once a rigidbody is added to the dynamics world, it will get this gravity assigned
|
//once a rigidbody is added to the dynamics world, it will get this gravity assigned
|
||||||
//existing rigidbodies in the world get gravity assigned too, during this method
|
//existing rigidbodies in the world get gravity assigned too, during this method
|
||||||
virtual void setGravity(const btVector3& gravity) = 0;
|
virtual void setGravity(const btVector3& gravity) = 0;
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ btSimpleDynamicsWorld::btSimpleDynamicsWorld(btDispatcher* dispatcher,btBroadpha
|
|||||||
:btDynamicsWorld(dispatcher,pairCache,collisionConfiguration),
|
:btDynamicsWorld(dispatcher,pairCache,collisionConfiguration),
|
||||||
m_constraintSolver(constraintSolver),
|
m_constraintSolver(constraintSolver),
|
||||||
m_ownsConstraintSolver(false),
|
m_ownsConstraintSolver(false),
|
||||||
m_debugDrawer(0),
|
|
||||||
m_gravity(0,0,-10)
|
m_gravity(0,0,-10)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -32,8 +32,6 @@ protected:
|
|||||||
|
|
||||||
bool m_ownsConstraintSolver;
|
bool m_ownsConstraintSolver;
|
||||||
|
|
||||||
btIDebugDraw* m_debugDrawer;
|
|
||||||
|
|
||||||
void predictUnconstraintMotion(btScalar timeStep);
|
void predictUnconstraintMotion(btScalar timeStep);
|
||||||
|
|
||||||
void integrateTransforms(btScalar timeStep);
|
void integrateTransforms(btScalar timeStep);
|
||||||
@@ -52,16 +50,6 @@ public:
|
|||||||
///maxSubSteps/fixedTimeStep for interpolation is currently ignored for btSimpleDynamicsWorld, use btDiscreteDynamicsWorld instead
|
///maxSubSteps/fixedTimeStep for interpolation is currently ignored for btSimpleDynamicsWorld, use btDiscreteDynamicsWorld instead
|
||||||
virtual int stepSimulation( btScalar timeStep,int maxSubSteps=1, btScalar fixedTimeStep=btScalar(1.)/btScalar(60.));
|
virtual int stepSimulation( btScalar timeStep,int maxSubSteps=1, btScalar fixedTimeStep=btScalar(1.)/btScalar(60.));
|
||||||
|
|
||||||
virtual void setDebugDrawer(btIDebugDraw* debugDrawer)
|
|
||||||
{
|
|
||||||
m_debugDrawer = debugDrawer;
|
|
||||||
};
|
|
||||||
|
|
||||||
virtual btIDebugDraw* getDebugDrawer()
|
|
||||||
{
|
|
||||||
return m_debugDrawer;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void setGravity(const btVector3& gravity);
|
virtual void setGravity(const btVector3& gravity);
|
||||||
|
|
||||||
virtual void addRigidBody(btRigidBody* body);
|
virtual void addRigidBody(btRigidBody* body);
|
||||||
|
|||||||
Reference in New Issue
Block a user