Replace linked-list by rp3d::List for contactPoints of NarrowPhaseInfo
This commit is contained in:
parent
ea523e47d3
commit
cf3d76ce45
|
@ -242,7 +242,7 @@ void CollisionDetection::computeNarrowPhase() {
|
|||
|
||||
NarrowPhaseInfo* narrowPhaseInfo = mNarrowPhaseInfos[i];
|
||||
|
||||
assert(narrowPhaseInfo->contactPoints == nullptr);
|
||||
assert(narrowPhaseInfo->contactPoints.size() == 0);
|
||||
|
||||
// Select the narrow phase algorithm to use according to the two collision shapes
|
||||
const CollisionShapeType shape1Type = narrowPhaseInfo->collisionShape1->getType();
|
||||
|
@ -434,7 +434,7 @@ void CollisionDetection::processAllPotentialContacts(const List<NarrowPhaseInfo*
|
|||
NarrowPhaseInfo* narrowPhaseInfo = collidingNarrowPhaseInfos[i];
|
||||
|
||||
assert(narrowPhaseInfo != nullptr);
|
||||
assert(narrowPhaseInfo->contactPoints != nullptr);
|
||||
assert(narrowPhaseInfo->contactPoints.size() > 0);
|
||||
|
||||
// Transfer the contact points from the narrow phase info to the overlapping pair
|
||||
narrowPhaseInfo->overlappingPair->addPotentialContactPoints(narrowPhaseInfo);
|
||||
|
|
|
@ -51,11 +51,12 @@ ContactManifoldSet::~ContactManifoldSet() {
|
|||
|
||||
void ContactManifoldSet::addContactPoints(NarrowPhaseInfo* narrowPhaseInfo) {
|
||||
|
||||
assert(narrowPhaseInfo->contactPoints != nullptr);
|
||||
assert(narrowPhaseInfo->contactPoints.size() > 0);
|
||||
|
||||
// For each potential contact point to add
|
||||
ContactPointInfo* contactPoint = narrowPhaseInfo->contactPoints;
|
||||
while (contactPoint != nullptr) {
|
||||
for (uint i=0; i < narrowPhaseInfo->contactPoints.size(); i++) {
|
||||
|
||||
ContactPointInfo* contactPoint = narrowPhaseInfo->contactPoints[i];
|
||||
|
||||
// Look if the contact point correspond to an existing potential manifold
|
||||
// (if the contact point normal is similar to the normal of an existing manifold)
|
||||
|
@ -91,8 +92,6 @@ void ContactManifoldSet::addContactPoints(NarrowPhaseInfo* narrowPhaseInfo) {
|
|||
// Add the contact point to the manifold
|
||||
manifold->addContactPoint(contactPoint);
|
||||
}
|
||||
|
||||
contactPoint = contactPoint->next;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ NarrowPhaseInfo::NarrowPhaseInfo(OverlappingPair* pair, CollisionShape* shape1,
|
|||
const Transform& shape2Transform, MemoryAllocator& shapeAllocator)
|
||||
: overlappingPair(pair), collisionShape1(shape1), collisionShape2(shape2),
|
||||
shape1ToWorldTransform(shape1Transform), shape2ToWorldTransform(shape2Transform),
|
||||
contactPoints(nullptr), collisionShapeAllocator(shapeAllocator) {
|
||||
contactPoints(overlappingPair->getTemporaryAllocator()), collisionShapeAllocator(shapeAllocator) {
|
||||
|
||||
// Add a collision info for the two collision shapes into the overlapping pair (if not present yet)
|
||||
overlappingPair->addLastFrameInfoIfNecessary(shape1->getId(), shape2->getId());
|
||||
|
@ -46,7 +46,7 @@ NarrowPhaseInfo::NarrowPhaseInfo(OverlappingPair* pair, CollisionShape* shape1,
|
|||
// Destructor
|
||||
NarrowPhaseInfo::~NarrowPhaseInfo() {
|
||||
|
||||
assert(contactPoints == nullptr);
|
||||
assert(contactPoints.size() == 0);
|
||||
|
||||
// Release the memory of the TriangleShape (this memory was allocated in the
|
||||
// MiddlePhaseTriangleCallback::testTriangle() method)
|
||||
|
@ -73,9 +73,8 @@ void NarrowPhaseInfo::addContactPoint(const Vector3& contactNormal, decimal penD
|
|||
ContactPointInfo* contactPointInfo = new (allocator.allocate(sizeof(ContactPointInfo)))
|
||||
ContactPointInfo(contactNormal, penDepth, localPt1, localPt2);
|
||||
|
||||
// Add it into the linked list of contact points
|
||||
contactPointInfo->next = contactPoints;
|
||||
contactPoints = contactPointInfo;
|
||||
// Add it into the list of contact points
|
||||
contactPoints.add(contactPointInfo);
|
||||
}
|
||||
|
||||
// Reset the remaining contact points
|
||||
|
@ -85,19 +84,16 @@ void NarrowPhaseInfo::resetContactPoints() {
|
|||
MemoryAllocator& allocator = overlappingPair->getTemporaryAllocator();
|
||||
|
||||
// For each remaining contact point info
|
||||
ContactPointInfo* element = contactPoints;
|
||||
while(element != nullptr) {
|
||||
for (uint i=0; i < contactPoints.size(); i++) {
|
||||
|
||||
ContactPointInfo* elementToDelete = element;
|
||||
|
||||
element = element->next;
|
||||
ContactPointInfo* contactPoint = contactPoints[i];
|
||||
|
||||
// Call the destructor
|
||||
elementToDelete->~ContactPointInfo();
|
||||
contactPoint->~ContactPointInfo();
|
||||
|
||||
// Delete the current element
|
||||
allocator.release(elementToDelete, sizeof(ContactPointInfo));
|
||||
allocator.release(contactPoint, sizeof(ContactPointInfo));
|
||||
}
|
||||
|
||||
contactPoints = nullptr;
|
||||
contactPoints.clear();
|
||||
}
|
||||
|
|
|
@ -62,8 +62,8 @@ struct NarrowPhaseInfo {
|
|||
/// Transform that maps from collision shape 2 local-space to world-space
|
||||
Transform shape2ToWorldTransform;
|
||||
|
||||
/// Linked-list of contact points created during the narrow-phase
|
||||
ContactPointInfo* contactPoints;
|
||||
/// List of contact points created during the narrow-phase
|
||||
List<ContactPointInfo*> contactPoints;
|
||||
|
||||
/// Memory allocator for the collision shape (Used to release TriangleShape memory in destructor)
|
||||
MemoryAllocator& collisionShapeAllocator;
|
||||
|
|
|
@ -76,8 +76,8 @@ bool CapsuleVsConvexPolyhedronAlgorithm::testCollision(NarrowPhaseInfo* narrowPh
|
|||
// two contact points instead of a single one (as in the deep contact case with SAT algorithm)
|
||||
|
||||
// Get the contact point created by GJK
|
||||
ContactPointInfo* contactPoint = narrowPhaseInfo->contactPoints;
|
||||
assert(contactPoint != nullptr);
|
||||
assert(narrowPhaseInfo->contactPoints.size() > 0);
|
||||
ContactPointInfo*& contactPoint = narrowPhaseInfo->contactPoints[0];
|
||||
|
||||
bool isCapsuleShape1 = narrowPhaseInfo->collisionShape1->getType() == CollisionShapeType::CAPSULE;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user