enable to suspend and restore dynamics. also, catched the case where failed dynamics (resulting in infinite AABB sizes) doesn't mess up the entire simulation, it just get's deactivated (with a message that a simulation error happened)

This commit is contained in:
ejcoumans
2006-06-22 03:00:43 +00:00
parent c5fdd98330
commit 2eed545a70
5 changed files with 43 additions and 11 deletions

View File

@@ -243,10 +243,14 @@ CollisionAlgorithm* CollisionDispatcher::InternalFindAlgorithm(BroadphaseProxy&
bool CollisionDispatcher::NeedsResponse(const CollisionObject& colObj0,const CollisionObject& colObj1) bool CollisionDispatcher::NeedsResponse(const CollisionObject& colObj0,const CollisionObject& colObj1)
{ {
//here you can do filtering //here you can do filtering
bool hasResponse = bool hasResponse =
(!(colObj0.m_collisionFlags & CollisionObject::noContactResponse)) && (!(colObj0.m_collisionFlags & CollisionObject::noContactResponse)) &&
(!(colObj1.m_collisionFlags & CollisionObject::noContactResponse)); (!(colObj1.m_collisionFlags & CollisionObject::noContactResponse));
hasResponse = hasResponse &&
(colObj0.IsActive() || colObj1.IsActive());
return hasResponse; return hasResponse;
} }
@@ -264,8 +268,8 @@ bool CollisionDispatcher::NeedsCollision(BroadphaseProxy& proxy0,BroadphaseProxy
if ((body0->m_collisionFlags & CollisionObject::isStatic) && if ((body0->m_collisionFlags & CollisionObject::isStatic) &&
(body1->m_collisionFlags & CollisionObject::isStatic)) (body1->m_collisionFlags & CollisionObject::isStatic))
needsCollision = false; needsCollision = false;
if ((body0->GetActivationState() == 2) &&(body1->GetActivationState() == 2)) if ((!body0->IsActive()) && (!body1->IsActive()))
needsCollision = false; needsCollision = false;
return needsCollision ; return needsCollision ;

View File

@@ -31,7 +31,7 @@ CollisionObject::CollisionObject()
void CollisionObject::SetActivationState(int newState) void CollisionObject::SetActivationState(int newState)
{ {
if (m_activationState1 != DISABLE_DEACTIVATION) if ( (m_activationState1 != DISABLE_DEACTIVATION) && (m_activationState1 != DISABLE_SIMULATION))
m_activationState1 = newState; m_activationState1 = newState;
} }

View File

@@ -23,6 +23,7 @@ subject to the following restrictions:
#define ISLAND_SLEEPING 2 #define ISLAND_SLEEPING 2
#define WANTS_DEACTIVATION 3 #define WANTS_DEACTIVATION 3
#define DISABLE_DEACTIVATION 4 #define DISABLE_DEACTIVATION 4
#define DISABLE_SIMULATION 5
struct BroadphaseProxy; struct BroadphaseProxy;
class CollisionShape; class CollisionShape;
@@ -94,6 +95,10 @@ struct CollisionObject
void activate(); void activate();
inline bool IsActive() const
{
return ((GetActivationState() != ISLAND_SLEEPING) && (GetActivationState() != DISABLE_SIMULATION));
}
}; };

View File

@@ -171,6 +171,7 @@ void CollisionWorld::RemoveCollisionObject(CollisionObject* collisionObject)
// //
GetBroadphase()->CleanProxyFromPairs(bp); GetBroadphase()->CleanProxyFromPairs(bp);
GetBroadphase()->DestroyProxy(bp); GetBroadphase()->DestroyProxy(bp);
collisionObject->m_broadphaseHandle = 0;
} }
} }

View File

@@ -638,7 +638,7 @@ bool CcdPhysicsEnvironment::proceedDeltaTimeOneStep(float timeStep)
CcdPhysicsController* ctrl = m_controllers[k]; CcdPhysicsController* ctrl = m_controllers[k];
// SimdTransform predictedTrans; // SimdTransform predictedTrans;
RigidBody* body = ctrl->GetRigidBody(); RigidBody* body = ctrl->GetRigidBody();
if (body->GetActivationState() != ISLAND_SLEEPING) if (body->IsActive())
{ {
if (!body->IsStatic()) if (!body->IsStatic())
{ {
@@ -695,14 +695,17 @@ bool CcdPhysicsEnvironment::proceedDeltaTimeOneStep(float timeStep)
{ {
TypedConstraint* constraint = m_constraints[i]; TypedConstraint* constraint = m_constraints[i];
const CollisionObject* colObj0 = &constraint->GetRigidBodyA(); const RigidBody* colObj0 = &constraint->GetRigidBodyA();
const CollisionObject* colObj1 = &constraint->GetRigidBodyB(); const RigidBody* colObj1 = &constraint->GetRigidBodyB();
if (((colObj0) && ((colObj0)->mergesSimulationIslands())) && if (((colObj0) && ((colObj0)->mergesSimulationIslands())) &&
((colObj1) && ((colObj1)->mergesSimulationIslands()))) ((colObj1) && ((colObj1)->mergesSimulationIslands())))
{ {
GetDispatcher()->GetUnionFind().unite((colObj0)->m_islandTag1, if (colObj0->IsActive() || colObj1->IsActive())
(colObj1)->m_islandTag1); {
GetDispatcher()->GetUnionFind().unite((colObj0)->m_islandTag1,
(colObj1)->m_islandTag1);
}
} }
} }
} }
@@ -863,7 +866,8 @@ bool CcdPhysicsEnvironment::proceedDeltaTimeOneStep(float timeStep)
SimdTransform predictedTrans; SimdTransform predictedTrans;
RigidBody* body = ctrl->GetRigidBody(); RigidBody* body = ctrl->GetRigidBody();
if (body->GetActivationState() != ISLAND_SLEEPING)
if (body->IsActive())
{ {
if (!body->IsStatic()) if (!body->IsStatic())
@@ -1698,9 +1702,27 @@ void CcdPhysicsEnvironment::UpdateAabbs(float timeStep)
} }
} }
scene->SetAabb(bp,minAabb,maxAabb);
if ( (maxAabb-minAabb).length2() < 1e12f)
{
scene->SetAabb(bp,minAabb,maxAabb);
} else
{
//something went wrong, investigate
//removeCcdPhysicsController(ctrl);
body->SetActivationState(DISABLE_SIMULATION);
static bool reportMe = true;
if (reportMe)
{
reportMe = false;
printf("Overflow in AABB, object removed from simulation \n");
printf("If you can reproduce this, please email bugs@continuousphysics.com\n");
printf("Please include above information, your Platform, version of OS.\n");
printf("Thanks.\n");
}
}
} }
} }