From 4ce65e9aaa1a88673ce4c554e6e7621ad812dbde Mon Sep 17 00:00:00 2001 From: "chappuis.daniel" Date: Fri, 31 Jul 2009 16:13:57 +0000 Subject: [PATCH] git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@186 92aac97c-a6ce-11dd-a772-7fcde58d38e6 --- .../collision/CollisionDetection.cpp | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/sources/reactphysics3d/collision/CollisionDetection.cpp b/sources/reactphysics3d/collision/CollisionDetection.cpp index 82bfe28b..8b4855e0 100644 --- a/sources/reactphysics3d/collision/CollisionDetection.cpp +++ b/sources/reactphysics3d/collision/CollisionDetection.cpp @@ -57,7 +57,9 @@ void CollisionDetection::computeCollisionContacts() { // The method returns true if a collision occurs in the time interval [0, timeMax] bool CollisionDetection::computeCollisionDetection(CollisionWorld* collisionWorld, const Time& timeMax, Time& timeFirst, Time& timeLast) { - bool existsCollision = false; // True if a collision is found in the time interval [0, timeMax] + bool existsCollision = false; // True if a collision is found in the time interval [0, timeMax] + Time timeFirstTemp; // Temporary timeFirst value + Time timeLastTemp; // Temporary timeLast value // For each pair of bodies in the collisionWorld for(std::vector::const_iterator it1 = collisionWorld->getBodyListStartIterator(); it1 != collisionWorld->getBodyListEndIterator(); ++it1) { @@ -79,12 +81,30 @@ bool CollisionDetection::computeCollisionDetection(CollisionWorld* collisionWorl Vector3D velocity2 = rigidBody2->getInterpolatedState().getLinearVelocity(); // Use the narrow-phase algorithm to check if the two bodies really collide - if(narrowPhaseAlgorithm->testCollision(&obb1, &obb2, &contact, velocity1, velocity2, timeMax, timeFirst, timeLast)) { + if(narrowPhaseAlgorithm->testCollision(&obb1, &obb2, &contact, velocity1, velocity2, timeMax, timeFirstTemp, timeLastTemp)) { assert(contact != 0); existsCollision = true; - // Add the new collision contact into the collision world - collisionWorld->addConstraint(contact); + // Check if the collision time is the first collision between all bodies + if (timeFirstTemp < timeFirst) { + // Update the first collision time between all bodies + timeFirst.setValue(timeFirstTemp.getValue()); + timeLast.setValue(timeLastTemp.getValue()); + + // Add the new collision contact into the collision world + collisionWorld->addConstraint(contact); + + // TODO : Here we add some contacts to the collisionWorld when we + // found a new timeFirst value. But each time we found a new timeFirst + // value, the contacts that have been added before have to be deleted. + // Therefore, we have to find a way to do that. For instance, we can + // associate a contactTime value at each contact and delete all contacts + // that are no the first contact between all bodies. + } + else { + // Delete the contact + delete contact; + } } } }