more correct CONTINUE collision event filter

This commit is contained in:
Andrew Meadows 2017-01-10 21:29:08 -08:00
parent 2541bfb1a8
commit b5537304a3
3 changed files with 17 additions and 6 deletions

View file

@ -18,10 +18,20 @@ void ContactInfo::update(uint32_t currentStep, const btManifoldPoint& p) {
distance = p.m_distance1;
}
const uint32_t STEPS_BETWEEN_CONTINUE_EVENTS = 9;
ContactEventType ContactInfo::computeType(uint32_t thisStep) {
++_numChecks;
if (_numChecks == 1) {
if (_continueExpiry == 0) {
_continueExpiry = thisStep + STEPS_BETWEEN_CONTINUE_EVENTS;
return CONTACT_EVENT_TYPE_START;
}
return (_lastStep == thisStep) ? CONTACT_EVENT_TYPE_CONTINUE : CONTACT_EVENT_TYPE_END;
}
bool ContactInfo::readyForContinue(uint32_t thisStep) {
if (thisStep > _continueExpiry) {
_continueExpiry = thisStep + STEPS_BETWEEN_CONTINUE_EVENTS;
return true;
}
return false;
}

View file

@ -26,12 +26,14 @@ public:
const btVector3& getPositionWorldOnB() const { return positionWorldOnB; }
btVector3 getPositionWorldOnA() const { return positionWorldOnB + normalWorldOnB * distance; }
bool readyForContinue(uint32_t thisStep);
btVector3 positionWorldOnB;
btVector3 normalWorldOnB;
btScalar distance;
private:
uint32_t _lastStep { 0 };
uint32_t _numChecks { 0 };
uint32_t _continueExpiry { 0 };
};

View file

@ -270,7 +270,7 @@ void PhysicsEngine::stepSimulation() {
}
auto onSubStep = [this]() {
updateContactMap();
this->updateContactMap();
};
int numSubsteps = _dynamicsWorld->stepSimulationWithSubstepCallback(timeStep, PHYSICS_ENGINE_MAX_NUM_SUBSTEPS,
@ -393,7 +393,6 @@ void PhysicsEngine::updateContactMap() {
}
const CollisionEvents& PhysicsEngine::getCollisionEvents() {
const uint32_t CONTINUE_EVENT_FILTER_FREQUENCY = 10;
_collisionEvents.clear();
// scan known contacts and trigger events
@ -402,7 +401,7 @@ const CollisionEvents& PhysicsEngine::getCollisionEvents() {
while (contactItr != _contactMap.end()) {
ContactInfo& contact = contactItr->second;
ContactEventType type = contact.computeType(_numContactFrames);
if (type != CONTACT_EVENT_TYPE_CONTINUE || _numSubsteps % CONTINUE_EVENT_FILTER_FREQUENCY == 0) {
if (type != CONTACT_EVENT_TYPE_CONTINUE || contact.readyForContinue(_numContactFrames)) {
ObjectMotionState* motionStateA = static_cast<ObjectMotionState*>(contactItr->first._a);
ObjectMotionState* motionStateB = static_cast<ObjectMotionState*>(contactItr->first._b);