Fix issues in collision detection
This commit is contained in:
parent
730b687877
commit
6b0ba1cfbb
|
@ -407,10 +407,10 @@ void CollisionDetection::clearContactPoints() {
|
|||
}
|
||||
|
||||
// Compute the middle-phase collision detection between two proxy shapes
|
||||
NarrowPhaseInfo* CollisionDetection::computeMiddlePhaseForProxyShapes(ProxyShape* shape1, ProxyShape* shape2) {
|
||||
NarrowPhaseInfo* CollisionDetection::computeMiddlePhaseForProxyShapes(OverlappingPair* pair) {
|
||||
|
||||
// Create a temporary overlapping pair
|
||||
OverlappingPair pair(shape1, shape2, 0, mMemoryAllocator);
|
||||
ProxyShape* shape1 = pair->getShape1();
|
||||
ProxyShape* shape2 = pair->getShape2();
|
||||
|
||||
// -------------------------------------------------------
|
||||
|
||||
|
@ -424,7 +424,7 @@ NarrowPhaseInfo* CollisionDetection::computeMiddlePhaseForProxyShapes(ProxyShape
|
|||
|
||||
// No middle-phase is necessary, simply create a narrow phase info
|
||||
// for the narrow-phase collision detection
|
||||
narrowPhaseInfo = new (mMemoryAllocator.allocate(sizeof(NarrowPhaseInfo))) NarrowPhaseInfo(&pair, shape1->getCollisionShape(),
|
||||
narrowPhaseInfo = new (mMemoryAllocator.allocate(sizeof(NarrowPhaseInfo))) NarrowPhaseInfo(pair, shape1->getCollisionShape(),
|
||||
shape2->getCollisionShape(), shape1->getLocalToWorldTransform(),
|
||||
shape2->getLocalToWorldTransform(), shape1->getCachedCollisionData(),
|
||||
shape2->getCachedCollisionData());
|
||||
|
@ -436,7 +436,7 @@ NarrowPhaseInfo* CollisionDetection::computeMiddlePhaseForProxyShapes(ProxyShape
|
|||
|
||||
// Run the middle-phase collision detection algorithm to find the triangles of the concave
|
||||
// shape we need to use during the narrow-phase collision detection
|
||||
computeConvexVsConcaveMiddlePhase(&pair, mMemoryAllocator, &narrowPhaseInfo);
|
||||
computeConvexVsConcaveMiddlePhase(pair, mMemoryAllocator, &narrowPhaseInfo);
|
||||
}
|
||||
|
||||
return narrowPhaseInfo;
|
||||
|
@ -503,8 +503,11 @@ bool CollisionDetection::testOverlap(CollisionBody* body1, CollisionBody* body2)
|
|||
const CollisionShapeType shape1Type = body1ProxyShape->getCollisionShape()->getType();
|
||||
const CollisionShapeType shape2Type = body2ProxyShape->getCollisionShape()->getType();
|
||||
|
||||
// Create a temporary overlapping pair
|
||||
OverlappingPair pair(body1ProxyShape, body2ProxyShape, 0, mMemoryAllocator);
|
||||
|
||||
// Compute the middle-phase collision detection between the two shapes
|
||||
NarrowPhaseInfo* narrowPhaseInfo = computeMiddlePhaseForProxyShapes(body1ProxyShape, body2ProxyShape);
|
||||
NarrowPhaseInfo* narrowPhaseInfo = computeMiddlePhaseForProxyShapes(&pair);
|
||||
|
||||
bool isColliding = false;
|
||||
|
||||
|
@ -591,8 +594,11 @@ void CollisionDetection::testOverlap(CollisionBody* body, OverlapCallback* overl
|
|||
const CollisionShapeType shape1Type = bodyProxyShape->getCollisionShape()->getType();
|
||||
const CollisionShapeType shape2Type = proxyShape->getCollisionShape()->getType();
|
||||
|
||||
// Create a temporary overlapping pair
|
||||
OverlappingPair pair(bodyProxyShape, proxyShape, 0, mMemoryAllocator);
|
||||
|
||||
// Compute the middle-phase collision detection between the two shapes
|
||||
NarrowPhaseInfo* narrowPhaseInfo = computeMiddlePhaseForProxyShapes(bodyProxyShape, proxyShape);
|
||||
NarrowPhaseInfo* narrowPhaseInfo = computeMiddlePhaseForProxyShapes(&pair);
|
||||
|
||||
bool isColliding = false;
|
||||
|
||||
|
@ -666,8 +672,11 @@ void CollisionDetection::testCollision(CollisionBody* body1, CollisionBody* body
|
|||
// Test if the AABBs of the two proxy shapes overlap
|
||||
if (aabb1.testCollision(aabb2)) {
|
||||
|
||||
// Create a temporary overlapping pair
|
||||
OverlappingPair pair(body1ProxyShape, body2ProxyShape, 0, mMemoryAllocator);
|
||||
|
||||
// Compute the middle-phase collision detection between the two shapes
|
||||
NarrowPhaseInfo* narrowPhaseInfo = computeMiddlePhaseForProxyShapes(body1ProxyShape, body2ProxyShape);
|
||||
NarrowPhaseInfo* narrowPhaseInfo = computeMiddlePhaseForProxyShapes(&pair);
|
||||
|
||||
const CollisionShapeType shape1Type = body1ProxyShape->getCollisionShape()->getType();
|
||||
const CollisionShapeType shape2Type = body2ProxyShape->getCollisionShape()->getType();
|
||||
|
@ -747,8 +756,11 @@ void CollisionDetection::testCollision(CollisionBody* body, CollisionCallback* c
|
|||
const CollisionShapeType shape1Type = bodyProxyShape->getCollisionShape()->getType();
|
||||
const CollisionShapeType shape2Type = proxyShape->getCollisionShape()->getType();
|
||||
|
||||
// Create a temporary overlapping pair
|
||||
OverlappingPair pair(bodyProxyShape, proxyShape, 0, mMemoryAllocator);
|
||||
|
||||
// Compute the middle-phase collision detection between the two shapes
|
||||
NarrowPhaseInfo* narrowPhaseInfo = computeMiddlePhaseForProxyShapes(bodyProxyShape, proxyShape);
|
||||
NarrowPhaseInfo* narrowPhaseInfo = computeMiddlePhaseForProxyShapes(&pair);
|
||||
|
||||
// For each narrow-phase info object
|
||||
while (narrowPhaseInfo != nullptr) {
|
||||
|
@ -816,7 +828,7 @@ void CollisionDetection::testCollision(CollisionCallback* callback) {
|
|||
mBroadPhaseAlgorithm.testOverlappingShapes(shape1, shape2)) {
|
||||
|
||||
// Compute the middle-phase collision detection between the two shapes
|
||||
NarrowPhaseInfo* narrowPhaseInfo = computeMiddlePhaseForProxyShapes(shape1, shape2);
|
||||
NarrowPhaseInfo* narrowPhaseInfo = computeMiddlePhaseForProxyShapes(pair);
|
||||
|
||||
const CollisionShapeType shape1Type = shape1->getCollisionShape()->getType();
|
||||
const CollisionShapeType shape2Type = shape2->getCollisionShape()->getType();
|
||||
|
|
|
@ -136,7 +136,7 @@ class CollisionDetection {
|
|||
NarrowPhaseInfo** firstNarrowPhaseInfo);
|
||||
|
||||
/// Compute the middle-phase collision detection between two proxy shapes
|
||||
NarrowPhaseInfo* computeMiddlePhaseForProxyShapes(ProxyShape* shape1, ProxyShape* shape2);
|
||||
NarrowPhaseInfo* computeMiddlePhaseForProxyShapes(OverlappingPair* pair);
|
||||
|
||||
public :
|
||||
|
||||
|
|
|
@ -48,9 +48,10 @@ bool SATAlgorithm::testCollisionSphereVsConvexPolyhedron(const NarrowPhaseInfo*
|
|||
|
||||
bool isSphereShape1 = narrowPhaseInfo->collisionShape1->getType() == CollisionShapeType::SPHERE;
|
||||
|
||||
assert(isSphereShape1 || narrowPhaseInfo->collisionShape1->getType() == CollisionShapeType::CONVEX_POLYHEDRON);
|
||||
assert(!isSphereShape1 || narrowPhaseInfo->collisionShape1->getType() == CollisionShapeType::CONVEX_POLYHEDRON);
|
||||
assert(!isSphereShape1 || narrowPhaseInfo->collisionShape2->getType() == CollisionShapeType::SPHERE);
|
||||
assert(narrowPhaseInfo->collisionShape1->getType() == CollisionShapeType::CONVEX_POLYHEDRON ||
|
||||
narrowPhaseInfo->collisionShape2->getType() == CollisionShapeType::CONVEX_POLYHEDRON);
|
||||
assert(narrowPhaseInfo->collisionShape1->getType() == CollisionShapeType::SPHERE ||
|
||||
narrowPhaseInfo->collisionShape2->getType() == CollisionShapeType::SPHERE);
|
||||
|
||||
// Get the capsule collision shapes
|
||||
const SphereShape* sphere = static_cast<const SphereShape*>(isSphereShape1 ? narrowPhaseInfo->collisionShape1 : narrowPhaseInfo->collisionShape2);
|
||||
|
@ -116,9 +117,10 @@ bool SATAlgorithm::testCollisionCapsuleVsConvexPolyhedron(const NarrowPhaseInfo*
|
|||
|
||||
bool isCapsuleShape1 = narrowPhaseInfo->collisionShape1->getType() == CollisionShapeType::CAPSULE;
|
||||
|
||||
assert(isCapsuleShape1 || narrowPhaseInfo->collisionShape1->getType() == CollisionShapeType::CONVEX_POLYHEDRON);
|
||||
assert(!isCapsuleShape1 || narrowPhaseInfo->collisionShape1->getType() == CollisionShapeType::CONVEX_POLYHEDRON);
|
||||
assert(!isCapsuleShape1 || narrowPhaseInfo->collisionShape2->getType() == CollisionShapeType::CAPSULE);
|
||||
assert(narrowPhaseInfo->collisionShape1->getType() == CollisionShapeType::CONVEX_POLYHEDRON ||
|
||||
narrowPhaseInfo->collisionShape2->getType() == CollisionShapeType::CONVEX_POLYHEDRON);
|
||||
assert(narrowPhaseInfo->collisionShape1->getType() == CollisionShapeType::CAPSULE ||
|
||||
narrowPhaseInfo->collisionShape2->getType() == CollisionShapeType::CAPSULE);
|
||||
|
||||
// Get the collision shapes
|
||||
const CapsuleShape* capsuleShape = static_cast<const CapsuleShape*>(isCapsuleShape1 ? narrowPhaseInfo->collisionShape1 : narrowPhaseInfo->collisionShape2);
|
||||
|
|
2
src/collision/narrowphase/SphereVsCapsuleAlgorithm.cpp
Normal file → Executable file
2
src/collision/narrowphase/SphereVsCapsuleAlgorithm.cpp
Normal file → Executable file
|
@ -39,8 +39,6 @@ bool SphereVsCapsuleAlgorithm::testCollision(const NarrowPhaseInfo* narrowPhaseI
|
|||
bool isSphereShape1 = narrowPhaseInfo->collisionShape1->getType() == CollisionShapeType::SPHERE;
|
||||
|
||||
assert(isSphereShape1 || narrowPhaseInfo->collisionShape1->getType() == CollisionShapeType::CAPSULE);
|
||||
assert(!isSphereShape1 || narrowPhaseInfo->collisionShape1->getType() == CollisionShapeType::CAPSULE);
|
||||
assert(!isSphereShape1 || narrowPhaseInfo->collisionShape2->getType() == CollisionShapeType::SPHERE);
|
||||
|
||||
// Get the collision shapes
|
||||
const SphereShape* sphereShape = static_cast<const SphereShape*>(isSphereShape1 ? narrowPhaseInfo->collisionShape1 : narrowPhaseInfo->collisionShape2);
|
||||
|
|
Loading…
Reference in New Issue
Block a user