Working on testOverlap() and testCollisionMethods

This commit is contained in:
Daniel Chappuis 2019-06-03 07:12:50 +02:00
parent 251333a6ef
commit 3f5916a280
22 changed files with 370 additions and 740 deletions

View File

@ -1,5 +1,12 @@
# Changelog
## Develop
### Changed
- The CollisionWorld::testCollision() methods do not have the 'categoryMaskBits' parameter anymore.
- The CollisionWorld::testOverlap() methods do not have the 'categoryMaskBits' parameter anymore.
## Release Candidate
### Fixed
@ -25,6 +32,7 @@
- The methods CollisionBody::getProxyShapesList() has been remove. You can now use the
CollisionBody::getNbProxyShapes() method to know the number of proxy-shapes of a body and the
CollisionBody::getProxyShape(uint proxyShapeIndex) method to get a given proxy-shape of the body.
- The CollisionWorld::testAABBOverlap() methods have been removed.
## Version 0.7.0 (May 1, 2018)

File diff suppressed because it is too large Load Diff

View File

@ -181,40 +181,46 @@ class CollisionDetection {
void computeBroadPhase();
/// Compute the middle-phase collision detection
void computeMiddlePhase();
void computeMiddlePhase(OverlappingPairMap& overlappingPairs, NarrowPhaseInput& narrowPhaseInput);
/// Compute the narrow-phase collision detection
void computeNarrowPhase();
/// Compute the narrow-phase collision detection for the testCollision() methods
bool computeNarrowPhaseSnapshot(NarrowPhaseInput& narrowPhaseInput, bool reportContacts);
/// Take a list of overlapping nodes in the broad-phase and create new overlapping pairs if necessary
void updateOverlappingPairs(List<Pair<int, int> >& overlappingNodes);
void updateOverlappingPairs(const List<Pair<int, int>>& overlappingNodes);
/// Remove pairs that are not overlapping anymore
void removeNonOverlappingPairs();
/// Execute the narrow-phase collision detection algorithm on batches
bool testNarrowPhaseCollision(NarrowPhaseInput& narrowPhaseInput, bool stopFirstContactFound,
bool reportContacts, MemoryAllocator& allocator);
bool testNarrowPhaseCollision(NarrowPhaseInput& narrowPhaseInput, bool reportContacts, MemoryAllocator& allocator);
/// Compute the concave vs convex middle-phase algorithm for a given pair of bodies
void computeConvexVsConcaveMiddlePhase(OverlappingPair* pair, MemoryAllocator& allocator,
NarrowPhaseInput& narrowPhaseInput);
/// Compute the middle-phase collision detection between two proxy shapes
void computeMiddlePhaseForProxyShapes(OverlappingPair* pair, NarrowPhaseInput& outNarrowPhaseInput);
/// Swap the previous and current contacts lists
void swapPreviousAndCurrentContacts();
/// Convert the potential contact into actual contacts
void processPotentialContacts(NarrowPhaseInfoBatch& narrowPhaseInfoBatch,
bool updateLastFrameInfo);
bool updateLastFrameInfo, List<ContactPointInfo>& potentialContactPoints,
Map<OverlappingPair::OverlappingPairId, uint>* mapPairIdToContactPairIndex,
List<ContactManifoldInfo>& potentialContactManifolds, List<ContactPair>* contactPairs,
Map<Entity, List<uint>>& mapBodyToContactPairs);
/// Process the potential contacts after narrow-phase collision detection
void processAllPotentialContacts(NarrowPhaseInput& narrowPhaseInput, bool updateLastFrameInfo);
void processAllPotentialContacts(NarrowPhaseInput& narrowPhaseInput, bool updateLastFrameInfo, List<ContactPointInfo>& potentialContactPoints,
Map<OverlappingPair::OverlappingPairId, uint>* mapPairIdToContactPairIndex,
List<ContactManifoldInfo> &potentialContactManifolds, List<ContactPair>* contactPairs,
Map<Entity, List<uint>>& mapBodyToContactPairs);
/// Reduce the potential contact manifolds and contact points of the overlapping pair contacts
void reducePotentialContactManifolds();
void reducePotentialContactManifolds(List<ContactPair>* contactPairs, List<ContactManifoldInfo>& potentialContactManifolds,
const List<ContactPointInfo>& potentialContactPoints) const;
/// Create the actual contact manifolds and contacts points (from potential contacts) for a given contact pair
void createContacts();
@ -223,17 +229,25 @@ class CollisionDetection {
void initContactsWithPreviousOnes();
/// Reduce the number of contact points of a potential contact manifold
void reduceContactPoints(ContactManifoldInfo& manifold, const Transform& shape1ToWorldTransform);
void reduceContactPoints(ContactManifoldInfo& manifold, const Transform& shape1ToWorldTransform,
const List<ContactPointInfo>& potentialContactPoints) const;
/// Report contacts for all the colliding overlapping pairs
void reportAllContacts();
/// Return the largest depth of all the contact points of a potential manifold
decimal computePotentialManifoldLargestContactDepth(const ContactManifoldInfo& manifold) const;
decimal computePotentialManifoldLargestContactDepth(const ContactManifoldInfo& manifold,
const List<ContactPointInfo>& potentialContactPoints) const;
/// Process the potential contacts where one collion is a concave shape
void processSmoothMeshContacts(OverlappingPair* pair);
/// Filter the overlapping pairs to keep only the pairs where a given body is involved
void filterOverlappingPairs(Entity bodyEntity, OverlappingPairMap& outFilteredPairs) const;
/// Filter the overlapping pairs to keep only the pairs where two given bodies are involved
void filterOverlappingPairs(Entity body1Entity, Entity body2Entity, OverlappingPairMap& outFilteredPairs) const;
public :
// -------------------- Methods -------------------- //
@ -283,22 +297,22 @@ class CollisionDetection {
void raycast(RaycastCallback* raycastCallback, const Ray& ray,
unsigned short raycastWithCategoryMaskBits) const;
/// Report all the bodies that overlap with the aabb in parameter
void testAABBOverlap(const AABB& aabb, OverlapCallback* overlapCallback, unsigned short categoryMaskBits = 0xFFFF);
/// Return true if two bodies overlap
/// Return true if two bodies (collide) overlap
bool testOverlap(CollisionBody* body1, CollisionBody* body2);
/// Report all the bodies that overlap with the body in parameter
void testOverlap(CollisionBody* body, OverlapCallback* overlapCallback, unsigned short categoryMaskBits = 0xFFFF);
/// Report all the bodies that overlap (collide) with the body in parameter
void testOverlap(CollisionBody* body, OverlapCallback* callback);
/// Test and report collisions between two bodies
/// Report all the bodies that overlap (collide) in the world
void testOverlap(OverlapCallback* overlapCallback);
/// Test collision and report contacts between two bodies.
void testCollision(CollisionBody* body1, CollisionBody* body2, CollisionCallback* callback);
/// Test and report collisions between a body and all the others bodies of the world
void testCollision(CollisionBody* body, CollisionCallback* callback, unsigned short categoryMaskBits = 0xFFFF);
/// Test collision and report all the contacts involving the body in parameter
void testCollision(CollisionBody* body, CollisionCallback* callback);
/// Test and report collisions between all shapes of the world
/// Test collision and report contacts between each colliding bodies in the world
void testCollision(CollisionCallback* callback);
/// Return a reference to the memory manager

View File

@ -35,7 +35,7 @@ using namespace reactphysics3d;
// This technique is based on the "Robust Contact Creation for Physics Simulations" presentation
// by Dirk Gregorius.
bool CapsuleVsCapsuleAlgorithm::testCollision(CapsuleVsCapsuleNarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex, uint batchNbItems,
bool reportContacts, bool stopFirstContactFound, MemoryAllocator& memoryAllocator) {
bool reportContacts, MemoryAllocator& memoryAllocator) {
bool isCollisionFound = false;
@ -154,9 +154,6 @@ bool CapsuleVsCapsuleAlgorithm::testCollision(CapsuleVsCapsuleNarrowPhaseInfoBat
narrowPhaseInfoBatch.isColliding[batchIndex] = true;
isCollisionFound = true;
if (stopFirstContactFound) {
return isCollisionFound;
}
continue;
}
}
@ -234,9 +231,6 @@ bool CapsuleVsCapsuleAlgorithm::testCollision(CapsuleVsCapsuleNarrowPhaseInfoBat
narrowPhaseInfoBatch.isColliding[batchIndex] = true;
isCollisionFound = true;
if (stopFirstContactFound) {
return isCollisionFound;
}
}
}

View File

@ -68,8 +68,7 @@ class CapsuleVsCapsuleAlgorithm : public NarrowPhaseAlgorithm {
/// Compute the narrow-phase collision detection between two capsules
bool testCollision(CapsuleVsCapsuleNarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex,
uint batchNbItems, bool reportContacts, bool stopFirstContactFound,
MemoryAllocator& memoryAllocator);
uint batchNbItems, bool reportContacts, MemoryAllocator& memoryAllocator);
};
}

View File

@ -41,8 +41,7 @@ using namespace reactphysics3d;
// by Dirk Gregorius.
bool CapsuleVsConvexPolyhedronAlgorithm::testCollision(NarrowPhaseInfoBatch& narrowPhaseInfoBatch,
uint batchStartIndex, uint batchNbItems,
bool reportContacts, bool stopFirstContactFound,
MemoryAllocator& memoryAllocator) {
bool reportContacts, MemoryAllocator& memoryAllocator) {
bool isCollisionFound = false;
@ -166,9 +165,6 @@ bool CapsuleVsConvexPolyhedronAlgorithm::testCollision(NarrowPhaseInfoBatch& nar
// Colision found
narrowPhaseInfoBatch.isColliding[batchIndex] = true;
isCollisionFound = true;
if (stopFirstContactFound) {
return isCollisionFound;
}
continue;
}
@ -183,9 +179,6 @@ bool CapsuleVsConvexPolyhedronAlgorithm::testCollision(NarrowPhaseInfoBatch& nar
if (narrowPhaseInfoBatch.isColliding[batchIndex]) {
isCollisionFound = true;
if (stopFirstContactFound) {
return isCollisionFound;
}
}
}
}

View File

@ -71,8 +71,7 @@ class CapsuleVsConvexPolyhedronAlgorithm : public NarrowPhaseAlgorithm {
/// Compute the narrow-phase collision detection between a capsule and a polyhedron
bool testCollision(NarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex,
uint batchNbItems, bool reportContacts, bool stopFirstContactFound,
MemoryAllocator& memoryAllocator);
uint batchNbItems, bool reportContacts, MemoryAllocator& memoryAllocator);
};
}

View File

@ -37,8 +37,7 @@ using namespace reactphysics3d;
// by Dirk Gregorius.
bool ConvexPolyhedronVsConvexPolyhedronAlgorithm::testCollision(NarrowPhaseInfoBatch& narrowPhaseInfoBatch,
uint batchStartIndex, uint batchNbItems,
bool reportContacts, bool stopFirstContactFound,
MemoryAllocator& memoryAllocator) {
bool reportContacts, MemoryAllocator& memoryAllocator) {
// Run the SAT algorithm to find the separating axis and compute contact point
SATAlgorithm satAlgorithm(memoryAllocator);
@ -50,7 +49,7 @@ bool ConvexPolyhedronVsConvexPolyhedronAlgorithm::testCollision(NarrowPhaseInfoB
#endif
bool isCollisionFound = satAlgorithm.testCollisionConvexPolyhedronVsConvexPolyhedron(narrowPhaseInfoBatch, batchStartIndex,
batchNbItems, reportContacts, stopFirstContactFound);
batchNbItems, reportContacts);
for (uint batchIndex = batchStartIndex; batchIndex < batchStartIndex + batchNbItems; batchIndex++) {
@ -59,10 +58,6 @@ bool ConvexPolyhedronVsConvexPolyhedronAlgorithm::testCollision(NarrowPhaseInfoB
lastFrameCollisionInfo->wasUsingSAT = true;
lastFrameCollisionInfo->wasUsingGJK = false;
if (isCollisionFound && stopFirstContactFound) {
return isCollisionFound;
}
}
return isCollisionFound;

View File

@ -65,9 +65,8 @@ class ConvexPolyhedronVsConvexPolyhedronAlgorithm : public NarrowPhaseAlgorithm
ConvexPolyhedronVsConvexPolyhedronAlgorithm& operator=(const ConvexPolyhedronVsConvexPolyhedronAlgorithm& algorithm) = delete;
/// Compute the narrow-phase collision detection between two convex polyhedra
bool testCollision(NarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex,
uint batchNbItems, bool reportContacts, bool stopFirstContactFound,
MemoryAllocator& memoryAllocator);
bool testCollision(NarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex, uint batchNbItems, bool reportContacts,
MemoryAllocator& memoryAllocator);
};
}

View File

@ -54,7 +54,7 @@ SATAlgorithm::SATAlgorithm(MemoryAllocator& memoryAllocator) : mMemoryAllocator(
// Test collision between a sphere and a convex mesh
bool SATAlgorithm::testCollisionSphereVsConvexPolyhedron(NarrowPhaseInfoBatch& narrowPhaseInfoBatch,
uint batchStartIndex, uint batchNbItems,
bool reportContacts, bool stopFirstContactFound) const {
bool reportContacts) const {
bool isCollisionFound = false;
@ -136,9 +136,6 @@ bool SATAlgorithm::testCollisionSphereVsConvexPolyhedron(NarrowPhaseInfoBatch& n
narrowPhaseInfoBatch.isColliding[batchIndex] = true;
isCollisionFound = true;
if (stopFirstContactFound) {
return isCollisionFound;
}
}
return isCollisionFound;
@ -476,7 +473,7 @@ bool SATAlgorithm::isMinkowskiFaceCapsuleVsEdge(const Vector3& capsuleSegment, c
}
// Test collision between two convex polyhedrons
bool SATAlgorithm::testCollisionConvexPolyhedronVsConvexPolyhedron(NarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex, uint batchNbItems, bool reportContacts, bool stopFirstContactFound) const {
bool SATAlgorithm::testCollisionConvexPolyhedronVsConvexPolyhedron(NarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex, uint batchNbItems, bool reportContacts) const {
RP3D_PROFILE("SATAlgorithm::testCollisionConvexPolyhedronVsConvexPolyhedron()", mProfiler);
@ -548,9 +545,6 @@ bool SATAlgorithm::testCollisionConvexPolyhedronVsConvexPolyhedron(NarrowPhaseIn
// Therefore, we can return without running the whole SAT algorithm
narrowPhaseInfoBatch.isColliding[batchIndex] = true;
isCollisionFound = true;
if (stopFirstContactFound) {
return isCollisionFound;
}
continue;
}
@ -591,9 +585,6 @@ bool SATAlgorithm::testCollisionConvexPolyhedronVsConvexPolyhedron(NarrowPhaseIn
// Therefore, we can return without running the whole SAT algorithm
narrowPhaseInfoBatch.isColliding[batchIndex] = true;
isCollisionFound = true;
if (stopFirstContactFound) {
return isCollisionFound;
}
continue;
}
@ -683,9 +674,6 @@ bool SATAlgorithm::testCollisionConvexPolyhedronVsConvexPolyhedron(NarrowPhaseIn
// we return without running the whole SAT algorithm
narrowPhaseInfoBatch.isColliding[batchIndex] = true;
isCollisionFound = true;
if (stopFirstContactFound) {
return isCollisionFound;
}
continue;
}
@ -878,9 +866,6 @@ bool SATAlgorithm::testCollisionConvexPolyhedronVsConvexPolyhedron(NarrowPhaseIn
narrowPhaseInfoBatch.isColliding[batchIndex] = true;
isCollisionFound = true;
if (stopFirstContactFound) {
return isCollisionFound;
}
}
return isCollisionFound;

View File

@ -140,7 +140,7 @@ class SATAlgorithm {
/// Test collision between a sphere and a convex mesh
bool testCollisionSphereVsConvexPolyhedron(NarrowPhaseInfoBatch& narrowPhaseInfoBatch,
uint batchStartIndex, uint batchNbItems,
bool reportContacts, bool stopFirstContactFound) const;
bool reportContacts) const;
/// Test collision between a capsule and a convex mesh
bool testCollisionCapsuleVsConvexPolyhedron(NarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchIndex, bool reportContacts) const;
@ -158,7 +158,7 @@ class SATAlgorithm {
/// Test collision between two convex meshes
bool testCollisionConvexPolyhedronVsConvexPolyhedron(NarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex,
uint batchNbItems, bool reportContacts, bool stopFirstContactFound) const;
uint batchNbItems, bool reportContacts) const;
#ifdef IS_PROFILING_ACTIVE

View File

@ -36,7 +36,7 @@ using namespace reactphysics3d;
// This technique is based on the "Robust Contact Creation for Physics Simulations" presentation
// by Dirk Gregorius.
bool SphereVsCapsuleAlgorithm::testCollision(SphereVsCapsuleNarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex, uint batchNbItems,
bool reportContacts, bool stopFirstContactFound, MemoryAllocator& memoryAllocator) {
bool reportContacts, MemoryAllocator& memoryAllocator) {
bool isCollisionFound = false;
@ -137,9 +137,6 @@ bool SphereVsCapsuleAlgorithm::testCollision(SphereVsCapsuleNarrowPhaseInfoBatch
narrowPhaseInfoBatch.isColliding[batchIndex] = true;
isCollisionFound = true;
if (stopFirstContactFound) {
return isCollisionFound;
}
continue;
}
}

View File

@ -68,8 +68,7 @@ class SphereVsCapsuleAlgorithm : public NarrowPhaseAlgorithm {
/// Compute the narrow-phase collision detection between a sphere and a capsule
bool testCollision(SphereVsCapsuleNarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex,
uint batchNbItems, bool reportContacts, bool stopFirstContactFound,
MemoryAllocator& memoryAllocator);
uint batchNbItems, bool reportContacts, MemoryAllocator& memoryAllocator);
};
}

View File

@ -36,7 +36,7 @@ using namespace reactphysics3d;
// This technique is based on the "Robust Contact Creation for Physics Simulations" presentation
// by Dirk Gregorius.
bool SphereVsConvexPolyhedronAlgorithm::testCollision(NarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex, uint batchNbItems,
bool reportContacts, bool stopFirstContactFound, MemoryAllocator& memoryAllocator) {
bool reportContacts, MemoryAllocator& memoryAllocator) {
// First, we run the GJK algorithm
GJKAlgorithm gjkAlgorithm;
@ -73,9 +73,6 @@ bool SphereVsConvexPolyhedronAlgorithm::testCollision(NarrowPhaseInfoBatch& narr
// Return true
narrowPhaseInfoBatch.isColliding[batchIndex] = true;
isCollisionFound = true;
if (stopFirstContactFound) {
return isCollisionFound;
}
continue;
}
@ -91,15 +88,11 @@ bool SphereVsConvexPolyhedronAlgorithm::testCollision(NarrowPhaseInfoBatch& narr
#endif
isCollisionFound |= satAlgorithm.testCollisionSphereVsConvexPolyhedron(narrowPhaseInfoBatch, batchIndex, 1, reportContacts, stopFirstContactFound);
isCollisionFound |= satAlgorithm.testCollisionSphereVsConvexPolyhedron(narrowPhaseInfoBatch, batchIndex, 1, reportContacts);
lastFrameCollisionInfo->wasUsingGJK = false;
lastFrameCollisionInfo->wasUsingSAT = true;
if (isCollisionFound && stopFirstContactFound) {
return isCollisionFound;
}
continue;
}
}

View File

@ -71,9 +71,8 @@ class SphereVsConvexPolyhedronAlgorithm : public NarrowPhaseAlgorithm {
SphereVsConvexPolyhedronAlgorithm& operator=(const SphereVsConvexPolyhedronAlgorithm& algorithm) = delete;
/// Compute the narrow-phase collision detection between a sphere and a convex polyhedron
bool testCollision(NarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex,
uint batchNbItems, bool reportContacts, bool stopFirstContactFound,
MemoryAllocator& memoryAllocator);
bool testCollision(NarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex, uint batchNbItems, bool reportContacts,
MemoryAllocator& memoryAllocator);
};
}

View File

@ -32,7 +32,7 @@
using namespace reactphysics3d;
bool SphereVsSphereAlgorithm::testCollision(SphereVsSphereNarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex, uint batchNbItems,
bool reportContacts, bool stopFirstContactFound, MemoryAllocator& memoryAllocator) {
bool reportContacts, MemoryAllocator& memoryAllocator) {
bool isCollisionFound = false;
@ -94,9 +94,6 @@ bool SphereVsSphereAlgorithm::testCollision(SphereVsSphereNarrowPhaseInfoBatch&
narrowPhaseInfoBatch.isColliding[batchIndex] = true;
isCollisionFound = true;
if (stopFirstContactFound) {
return isCollisionFound;
}
}
}

View File

@ -67,8 +67,7 @@ class SphereVsSphereAlgorithm : public NarrowPhaseAlgorithm {
/// Compute a contact info if the two bounding volume collide
bool testCollision(SphereVsSphereNarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex,
uint batchNbItems, bool reportContacts, bool stopFirstContactFound,
MemoryAllocator& memoryAllocator);
uint batchNbItems, bool reportContacts, MemoryAllocator& memoryAllocator);
};
}

View File

@ -543,7 +543,7 @@ class Set {
}
/// Return a list with all the values of the set
List<V> toList(MemoryAllocator& listAllocator) {
List<V> toList(MemoryAllocator& listAllocator) const {
List<V> list(listAllocator);

View File

@ -256,37 +256,10 @@ void CollisionWorld::notifyBodyDisabled(Entity bodyEntity, bool isDisabled) {
}
}
// Test if the AABBs of two bodies overlap
/**
* @param body1 Pointer to the first body to test
* @param body2 Pointer to the second body to test
* @return True if the AABBs of the two bodies overlap and false otherwise
*/
bool CollisionWorld::testAABBOverlap(const CollisionBody* body1,
const CollisionBody* body2) const {
// If one of the body is not active, we return no overlap
if (!body1->isActive() || !body2->isActive()) return false;
// Compute the AABBs of both bodies
AABB body1AABB = body1->getAABB();
AABB body2AABB = body2->getAABB();
// Return true if the two AABBs overlap
return body1AABB.testCollision(body2AABB);
}
// Report all the bodies which have an AABB that overlaps with the AABB in parameter
/**
* @param aabb AABB used to test for overlap
* @param overlapCallback Pointer to the callback class to report overlap
* @param categoryMaskBits bits mask used to filter the bodies to test overlap with
*/
void CollisionWorld::testAABBOverlap(const AABB& aabb, OverlapCallback* overlapCallback, unsigned short categoryMaskBits) {
mCollisionDetection.testAABBOverlap(aabb, overlapCallback, categoryMaskBits);
}
// Return true if two bodies overlap
/// Use this method if you are not interested in contacts but if you simply want to know
/// if the two bodies overlap. If you want to get the contacts, you need to use the
/// testCollision() method instead.
/**
* @param body1 Pointer to the first body
* @param body2 Pointer to a second body

View File

@ -162,25 +162,22 @@ class CollisionWorld {
/// Ray cast method
void raycast(const Ray& ray, RaycastCallback* raycastCallback, unsigned short raycastWithCategoryMaskBits = 0xFFFF) const;
/// Test if the AABBs of two bodies overlap
bool testAABBOverlap(const CollisionBody* body1, const CollisionBody* body2) const;
/// Report all the bodies which have an AABB that overlaps with the AABB in parameter
void testAABBOverlap(const AABB& aabb, OverlapCallback* overlapCallback, unsigned short categoryMaskBits = 0xFFFF);
/// Return true if two bodies overlap
/// Return true if two bodies overlap (collide)
bool testOverlap(CollisionBody* body1, CollisionBody* body2);
/// Report all the bodies that overlap with the body in parameter
void testOverlap(CollisionBody* body, OverlapCallback* overlapCallback, unsigned short categoryMaskBits = 0xFFFF);
/// Report all the bodies that overlap (collide) with the body in parameter
void testOverlap(CollisionBody* body, OverlapCallback* overlapCallback);
/// Test and report collisions between two bodies
/// Report all the bodies that overlap (collide) in the world
void testOverlap(OverlapCallback* overlapCallback);
/// Test collision and report contacts between two bodies.
void testCollision(CollisionBody* body1, CollisionBody* body2, CollisionCallback* callback);
/// Test and report collisions between a body and all the others bodies of the world
void testCollision(CollisionBody* body, CollisionCallback* callback, unsigned short categoryMaskBits = 0xFFFF);
/// Test collision and report all the contacts involving the body in parameter
void testCollision(CollisionBody* body, CollisionCallback* callback);
/// Test and report collisions between all shapes of the world
/// Test collision and report contacts between each colliding bodies in the world
void testCollision(CollisionCallback* callback);
#ifdef IS_PROFILING_ACTIVE
@ -236,7 +233,11 @@ inline void CollisionWorld::raycast(const Ray& ray,
mCollisionDetection.raycast(raycastCallback, ray, raycastWithCategoryMaskBits);
}
// Test and report collisions between two bodies
// Test collision and report contacts between two bodies.
/// Use this method if you only want to get all the contacts between two bodies.
/// All the contacts will be reported using the callback object in paramater.
/// If you are not interested in the contacts but you only want to know if the bodies collide,
/// you can use the testOverlap() method instead.
/**
* @param body1 Pointer to the first body to test
* @param body2 Pointer to the second body to test
@ -246,17 +247,24 @@ inline void CollisionWorld::testCollision(CollisionBody* body1, CollisionBody* b
mCollisionDetection.testCollision(body1, body2, callback);
}
// Test and report collisions between a body and all the others bodies of the world
// Test collision and report all the contacts involving the body in parameter
/// Use this method if you only want to get all the contacts involving a given body.
/// All the contacts will be reported using the callback object in paramater.
/// If you are not interested in the contacts but you only want to know if the bodies collide,
/// you can use the testOverlap() method instead.
/**
* @param body Pointer to the body against which we need to test collision
* @param callback Pointer to the object with the callback method to report contacts
* @param categoryMaskBits Bits mask corresponding to the category of bodies we need to test collision with
*/
inline void CollisionWorld::testCollision(CollisionBody* body, CollisionCallback* callback, unsigned short categoryMaskBits) {
mCollisionDetection.testCollision(body, callback, categoryMaskBits);
inline void CollisionWorld::testCollision(CollisionBody* body, CollisionCallback* callback) {
mCollisionDetection.testCollision(body, callback);
}
// Test and report collisions between all bodies of the world
// Test collision and report contacts between each colliding bodies in the world
/// Use this method if you want to get all the contacts between colliding bodies in the world.
/// All the contacts will be reported using the callback object in paramater.
/// If you are not interested in the contacts but you only want to know if the bodies collide,
/// you can use the testOverlap() method instead.
/**
* @param callback Pointer to the object with the callback method to report contacts
*/
@ -264,14 +272,24 @@ inline void CollisionWorld::testCollision(CollisionCallback* callback) {
mCollisionDetection.testCollision(callback);
}
// Report all the bodies that overlap with the body in parameter
// Report all the bodies that overlap (collide) with the body in parameter
/// Use this method if you are not interested in contacts but if you simply want to know
/// which bodies overlap with the body in parameter. If you want to get the contacts, you need to use the
/// testCollision() method instead.
/**
* @param body Pointer to the collision body to test overlap with
* @param overlapCallback Pointer to the callback class to report overlap
* @param categoryMaskBits bits mask used to filter the bodies to test overlap with
*/
inline void CollisionWorld::testOverlap(CollisionBody* body, OverlapCallback* overlapCallback, unsigned short categoryMaskBits) {
mCollisionDetection.testOverlap(body, overlapCallback, categoryMaskBits);
inline void CollisionWorld::testOverlap(CollisionBody* body, OverlapCallback* overlapCallback) {
mCollisionDetection.testOverlap(body, overlapCallback);
}
// Report all the bodies that overlap (collide) in the world
/// Use this method if you are not interested in contacts but if you simply want to know
/// which bodies overlap. If you want to get the contacts, you need to use the
/// testCollision() method instead.
inline void CollisionWorld::testOverlap(OverlapCallback* overlapCallback) {
mCollisionDetection.testOverlap(overlapCallback);
}
// Return the name of the world

View File

@ -186,7 +186,7 @@ class BroadPhaseSystem {
void reportAllShapesOverlappingWithAABB(const AABB& aabb, List<int>& overlappingNodes) const;
/// Compute all the overlapping pairs of collision shapes
void computeOverlappingPairs(MemoryManager& memoryManager, List<Pair<int, int> >& overlappingNodes);
void computeOverlappingPairs(MemoryManager& memoryManager, List<Pair<int, int>>& overlappingNodes);
/// Return the proxy shape corresponding to the broad-phase node id in parameter
ProxyShape* getProxyShapeForBroadPhaseId(int broadPhaseId) const;

View File

@ -32,6 +32,7 @@
#include "constraint/ContactPoint.h"
#include "collision/ContactManifold.h"
#include <map>
#include <vector>
/// Reactphysics3D namespace
namespace reactphysics3d {
@ -481,7 +482,6 @@ class TestCollisionWorld : public Test {
testNoCollisions();
testNoOverlap();
testNoAABBOverlap();
testSphereVsSphereCollision();
testSphereVsBoxCollision();
@ -624,21 +624,6 @@ class TestCollisionWorld : public Test {
rp3d_test(!mWorld->testOverlap(mBoxBody2, mSphereBody2));
}
void testNoAABBOverlap() {
// All the shapes of the world are not touching when they are created.
// Here we test that at the beginning, there is no AABB overlap at all.
// Two bodies test
rp3d_test(!mWorld->testAABBOverlap(mBoxBody1, mBoxBody2));
rp3d_test(!mWorld->testAABBOverlap(mSphereBody1, mSphereBody2));
rp3d_test(!mWorld->testAABBOverlap(mBoxBody1, mSphereBody1));
rp3d_test(!mWorld->testAABBOverlap(mBoxBody1, mSphereBody2));
rp3d_test(!mWorld->testAABBOverlap(mBoxBody2, mSphereBody1));
rp3d_test(!mWorld->testAABBOverlap(mBoxBody2, mSphereBody2));
}
void testSphereVsSphereCollision() {
Transform initTransform1 = mSphereBody1->getTransform();
@ -651,10 +636,6 @@ class TestCollisionWorld : public Test {
mSphereBody1->setTransform(transform1);
mSphereBody2->setTransform(transform2);
// ----- Test AABB overlap ----- //
rp3d_test(mWorld->testAABBOverlap(mSphereBody1, mSphereBody2));
mOverlapCallback.reset();
mWorld->testOverlap(mSphereBody1, &mOverlapCallback);
rp3d_test(mOverlapCallback.hasOverlap());
@ -771,10 +752,6 @@ class TestCollisionWorld : public Test {
mSphereBody1->setTransform(transform1);
mBoxBody1->setTransform(transform2);
// ----- Test AABB overlap ----- //
rp3d_test(mWorld->testAABBOverlap(mSphereBody1, mBoxBody1));
mOverlapCallback.reset();
mWorld->testOverlap(mSphereBody1, &mOverlapCallback);
rp3d_test(mOverlapCallback.hasOverlap());
@ -881,10 +858,6 @@ class TestCollisionWorld : public Test {
mSphereBody1->setTransform(transform1);
mBoxBody1->setTransform(transform2);
// ----- Test AABB overlap ----- //
rp3d_test(mWorld->testAABBOverlap(mSphereBody1, mBoxBody1));
mOverlapCallback.reset();
mWorld->testOverlap(mSphereBody1, &mOverlapCallback);
rp3d_test(mOverlapCallback.hasOverlap());
@ -991,10 +964,6 @@ class TestCollisionWorld : public Test {
mSphereBody1->setTransform(transform1);
mBoxBody1->setTransform(transform2);
// ----- Test AABB overlap ----- //
rp3d_test(mWorld->testAABBOverlap(mSphereBody1, mBoxBody1));
mOverlapCallback.reset();
mWorld->testOverlap(mSphereBody1, &mOverlapCallback);
rp3d_test(mOverlapCallback.hasOverlap());
@ -1111,10 +1080,6 @@ class TestCollisionWorld : public Test {
mSphereBody1->setTransform(transform1);
mCapsuleBody1->setTransform(transform2);
// ----- Test AABB overlap ----- //
rp3d_test(mWorld->testAABBOverlap(mSphereBody1, mCapsuleBody1));
mOverlapCallback.reset();
mWorld->testOverlap(mSphereBody1, &mOverlapCallback);
rp3d_test(mOverlapCallback.hasOverlap());
@ -1221,10 +1186,6 @@ class TestCollisionWorld : public Test {
mSphereBody1->setTransform(transform1);
mCapsuleBody1->setTransform(transform2);
// ----- Test AABB overlap ----- //
rp3d_test(mWorld->testAABBOverlap(mSphereBody1, mCapsuleBody1));
mOverlapCallback.reset();
mWorld->testOverlap(mSphereBody1, &mOverlapCallback);
rp3d_test(mOverlapCallback.hasOverlap());
@ -1341,10 +1302,6 @@ class TestCollisionWorld : public Test {
mSphereBody1->setTransform(transform1);
mConvexMeshBody1->setTransform(transform2);
// ----- Test AABB overlap ----- //
rp3d_test(mWorld->testAABBOverlap(mSphereBody1, mConvexMeshBody1));
mOverlapCallback.reset();
mWorld->testOverlap(mSphereBody1, &mOverlapCallback);
rp3d_test(mOverlapCallback.hasOverlap());
@ -1451,10 +1408,6 @@ class TestCollisionWorld : public Test {
mSphereBody1->setTransform(transform1);
mConvexMeshBody1->setTransform(transform2);
// ----- Test AABB overlap ----- //
rp3d_test(mWorld->testAABBOverlap(mSphereBody1, mConvexMeshBody1));
mOverlapCallback.reset();
mWorld->testOverlap(mSphereBody1, &mOverlapCallback);
rp3d_test(mOverlapCallback.hasOverlap());
@ -1561,10 +1514,6 @@ class TestCollisionWorld : public Test {
mSphereBody1->setTransform(transform1);
mConvexMeshBody1->setTransform(transform2);
// ----- Test AABB overlap ----- //
rp3d_test(mWorld->testAABBOverlap(mSphereBody1, mConvexMeshBody1));
mOverlapCallback.reset();
mWorld->testOverlap(mSphereBody1, &mOverlapCallback);
rp3d_test(mOverlapCallback.hasOverlap());
@ -1681,10 +1630,6 @@ class TestCollisionWorld : public Test {
mSphereBody1->setTransform(transform1);
mConcaveMeshBody->setTransform(transform2);
// ----- Test AABB overlap ----- //
rp3d_test(mWorld->testAABBOverlap(mSphereBody1, mConcaveMeshBody));
mOverlapCallback.reset();
mWorld->testOverlap(mSphereBody1, &mOverlapCallback);
rp3d_test(mOverlapCallback.hasOverlap());
@ -1801,10 +1746,6 @@ class TestCollisionWorld : public Test {
mBoxBody1->setTransform(transform1);
mBoxBody2->setTransform(transform2);
// ----- Test AABB overlap ----- //
rp3d_test(mWorld->testAABBOverlap(mBoxBody1, mBoxBody2));
mOverlapCallback.reset();
mWorld->testOverlap(mBoxBody1, &mOverlapCallback);
rp3d_test(mOverlapCallback.hasOverlap());
@ -1965,10 +1906,6 @@ class TestCollisionWorld : public Test {
mBoxBody1->setTransform(transform1);
mConvexMeshBody2->setTransform(transform2);
// ----- Test AABB overlap ----- //
rp3d_test(mWorld->testAABBOverlap(mBoxBody1, mConvexMeshBody2));
mOverlapCallback.reset();
mWorld->testOverlap(mBoxBody1, &mOverlapCallback);
rp3d_test(mOverlapCallback.hasOverlap());
@ -2129,10 +2066,6 @@ class TestCollisionWorld : public Test {
mConvexMeshBody1->setTransform(transform1);
mConvexMeshBody2->setTransform(transform2);
// ----- Test AABB overlap ----- //
rp3d_test(mWorld->testAABBOverlap(mConvexMeshBody1, mConvexMeshBody2));
mOverlapCallback.reset();
mWorld->testOverlap(mConvexMeshBody1, &mOverlapCallback);
rp3d_test(mOverlapCallback.hasOverlap());
@ -2293,10 +2226,6 @@ class TestCollisionWorld : public Test {
mBoxBody1->setTransform(transform1);
mCapsuleBody1->setTransform(transform2);
// ----- Test AABB overlap ----- //
rp3d_test(mWorld->testAABBOverlap(mBoxBody1, mCapsuleBody1));
mOverlapCallback.reset();
mWorld->testOverlap(mBoxBody1, &mOverlapCallback);
rp3d_test(mOverlapCallback.hasOverlap());
@ -2412,10 +2341,6 @@ class TestCollisionWorld : public Test {
mConvexMeshBody1->setTransform(transform1);
mCapsuleBody1->setTransform(transform2);
// ----- Test AABB overlap ----- //
rp3d_test(mWorld->testAABBOverlap(mConvexMeshBody1, mCapsuleBody1));
mOverlapCallback.reset();
mWorld->testOverlap(mConvexMeshBody1, &mOverlapCallback);
rp3d_test(mOverlapCallback.hasOverlap());
@ -2531,10 +2456,6 @@ class TestCollisionWorld : public Test {
mBoxBody1->setTransform(transform1);
mConcaveMeshBody->setTransform(transform2);
// ----- Test AABB overlap ----- //
rp3d_test(mWorld->testAABBOverlap(mBoxBody1, mConcaveMeshBody));
mOverlapCallback.reset();
mWorld->testOverlap(mBoxBody1, &mOverlapCallback);
rp3d_test(mOverlapCallback.hasOverlap());
@ -2633,10 +2554,6 @@ class TestCollisionWorld : public Test {
mConvexMeshBody1->setTransform(transform1);
mConcaveMeshBody->setTransform(transform2);
// ----- Test AABB overlap ----- //
rp3d_test(mWorld->testAABBOverlap(mConvexMeshBody1, mConcaveMeshBody));
mOverlapCallback.reset();
mWorld->testOverlap(mConvexMeshBody1, &mOverlapCallback);
rp3d_test(mOverlapCallback.hasOverlap());
@ -2735,10 +2652,6 @@ class TestCollisionWorld : public Test {
mCapsuleBody1->setTransform(transform1);
mCapsuleBody2->setTransform(transform2);
// ----- Test AABB overlap ----- //
rp3d_test(mWorld->testAABBOverlap(mCapsuleBody1, mCapsuleBody2));
mOverlapCallback.reset();
mWorld->testOverlap(mCapsuleBody1, &mOverlapCallback);
rp3d_test(mOverlapCallback.hasOverlap());
@ -2845,10 +2758,6 @@ class TestCollisionWorld : public Test {
mCapsuleBody1->setTransform(transform1);
mCapsuleBody2->setTransform(transform2);
// ----- Test AABB overlap ----- //
rp3d_test(mWorld->testAABBOverlap(mCapsuleBody1, mCapsuleBody2));
mOverlapCallback.reset();
mWorld->testOverlap(mCapsuleBody1, &mOverlapCallback);
rp3d_test(mOverlapCallback.hasOverlap());
@ -2965,10 +2874,6 @@ class TestCollisionWorld : public Test {
mCapsuleBody1->setTransform(transform1);
mConcaveMeshBody->setTransform(transform2);
// ----- Test AABB overlap ----- //
rp3d_test(mWorld->testAABBOverlap(mCapsuleBody1, mConcaveMeshBody));
mOverlapCallback.reset();
mWorld->testOverlap(mCapsuleBody1, &mOverlapCallback);
rp3d_test(mOverlapCallback.hasOverlap());