From 1be922f986e0f55a5567861562a315cb28ce4a48 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 22 Aug 2014 11:20:53 -0700 Subject: [PATCH] add shapeVsList etc to dispatch table renamed some functions for more readability --- libraries/shared/src/ShapeCollider.cpp | 187 +++++------------------ libraries/shared/src/ShapeCollider.h | 73 +++------ tests/physics/src/ShapeColliderTests.cpp | 18 +-- 3 files changed, 70 insertions(+), 208 deletions(-) diff --git a/libraries/shared/src/ShapeCollider.cpp b/libraries/shared/src/ShapeCollider.cpp index 8d09c0408a..536d9bdcde 100644 --- a/libraries/shared/src/ShapeCollider.cpp +++ b/libraries/shared/src/ShapeCollider.cpp @@ -50,27 +50,27 @@ void initDispatchTable() { // NOTE: no need to update any that are notImplemented, but we leave them // commented out in the code so that we remember that they exist. - dispatchTable[getDispatchKey(SPHERE_SHAPE, SPHERE_SHAPE)] = &sphereSphere; - dispatchTable[getDispatchKey(SPHERE_SHAPE, CAPSULE_SHAPE)] = &sphereCapsule; - dispatchTable[getDispatchKey(SPHERE_SHAPE, PLANE_SHAPE)] = &spherePlane; - //dispatchTable[getDispatchKey(SPHERE_SHAPE, LIST_SHAPE)] = ¬Implemented; + dispatchTable[getDispatchKey(SPHERE_SHAPE, SPHERE_SHAPE)] = &sphereVsSphere; + dispatchTable[getDispatchKey(SPHERE_SHAPE, CAPSULE_SHAPE)] = &sphereVsCapsule; + dispatchTable[getDispatchKey(SPHERE_SHAPE, PLANE_SHAPE)] = &sphereVsPlane; + dispatchTable[getDispatchKey(SPHERE_SHAPE, LIST_SHAPE)] = &shapeVsList; - dispatchTable[getDispatchKey(CAPSULE_SHAPE, SPHERE_SHAPE)] = &capsuleSphere; - dispatchTable[getDispatchKey(CAPSULE_SHAPE, CAPSULE_SHAPE)] = &capsuleCapsule; - dispatchTable[getDispatchKey(CAPSULE_SHAPE, PLANE_SHAPE)] = &capsulePlane; - //dispatchTable[getDispatchKey(CAPSULE_SHAPE, LIST_SHAPE)] = ¬Implemented; + dispatchTable[getDispatchKey(CAPSULE_SHAPE, SPHERE_SHAPE)] = &capsuleVsSphere; + dispatchTable[getDispatchKey(CAPSULE_SHAPE, CAPSULE_SHAPE)] = &capsuleVsCapsule; + dispatchTable[getDispatchKey(CAPSULE_SHAPE, PLANE_SHAPE)] = &capsuleVsPlane; + dispatchTable[getDispatchKey(CAPSULE_SHAPE, LIST_SHAPE)] = &shapeVsList; - dispatchTable[getDispatchKey(PLANE_SHAPE, SPHERE_SHAPE)] = &planeSphere; - dispatchTable[getDispatchKey(PLANE_SHAPE, CAPSULE_SHAPE)] = &planeCapsule; - dispatchTable[getDispatchKey(PLANE_SHAPE, PLANE_SHAPE)] = &planePlane; - //dispatchTable[getDispatchKey(PLANE_SHAPE, LIST_SHAPE)] = ¬Implemented; + dispatchTable[getDispatchKey(PLANE_SHAPE, SPHERE_SHAPE)] = &planeVsSphere; + dispatchTable[getDispatchKey(PLANE_SHAPE, CAPSULE_SHAPE)] = &planeVsCapsule; + dispatchTable[getDispatchKey(PLANE_SHAPE, PLANE_SHAPE)] = &planeVsPlane; + dispatchTable[getDispatchKey(PLANE_SHAPE, LIST_SHAPE)] = &shapeVsList; - //dispatchTable[getDispatchKey(LIST_SHAPE, SPHERE_SHAPE)] = ¬Implemented; - //dispatchTable[getDispatchKey(LIST_SHAPE, CAPSULE_SHAPE)] = ¬Implemented; - //dispatchTable[getDispatchKey(LIST_SHAPE, PLANE_SHAPE)] = ¬Implemented; - //dispatchTable[getDispatchKey(LIST_SHAPE, LIST_SHAPE)] = ¬Implemented; + dispatchTable[getDispatchKey(LIST_SHAPE, SPHERE_SHAPE)] = &listVsShape; + dispatchTable[getDispatchKey(LIST_SHAPE, CAPSULE_SHAPE)] = &listVsShape; + dispatchTable[getDispatchKey(LIST_SHAPE, PLANE_SHAPE)] = &listVsShape; + dispatchTable[getDispatchKey(LIST_SHAPE, LIST_SHAPE)] = &listVsList; - // all of the UNKNOWN_SHAPE pairings point at notImplemented + // all of the UNKNOWN_SHAPE pairings are notImplemented } bool collideShapes(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions) { @@ -79,31 +79,6 @@ bool collideShapes(const Shape* shapeA, const Shape* shapeB, CollisionList& coll static CollisionList tempCollisions(32); -bool collideShapesCoarse(const QVector& shapesA, const QVector& shapesB, CollisionInfo& collision) { - tempCollisions.clear(); - foreach (const Shape* shapeA, shapesA) { - foreach (const Shape* shapeB, shapesB) { - collideShapes(shapeA, shapeB, tempCollisions); - } - } - if (tempCollisions.size() > 0) { - glm::vec3 totalPenetration(0.0f); - glm::vec3 averageContactPoint(0.0f); - for (int j = 0; j < tempCollisions.size(); ++j) { - CollisionInfo* c = tempCollisions.getCollision(j); - totalPenetration = addPenetrations(totalPenetration, c->_penetration); - averageContactPoint += c->_contactPoint; - } - collision._penetration = totalPenetration; - collision._contactPoint = averageContactPoint / (float)(tempCollisions.size()); - // there are no valid shape pointers for this collision so we set them NULL - collision._shapeA = NULL; - collision._shapeB = NULL; - return true; - } - return false; -} - bool collideShapeWithShapes(const Shape* shapeA, const QVector& shapes, int startIndex, CollisionList& collisions) { bool collided = false; if (shapeA) { @@ -145,9 +120,9 @@ bool collideShapesWithShapes(const QVector& shapesA, const QVectorgetType(); if (typeA == SPHERE_SHAPE) { - return sphereAACube(static_cast(shapeA), cubeCenter, cubeSide, collisions); + return sphereVsAACube(static_cast(shapeA), cubeCenter, cubeSide, collisions); } else if (typeA == CAPSULE_SHAPE) { - return capsuleAACube(static_cast(shapeA), cubeCenter, cubeSide, collisions); + return capsuleVsAACube(static_cast(shapeA), cubeCenter, cubeSide, collisions); } else if (typeA == LIST_SHAPE) { const ListShape* listA = static_cast(shapeA); bool touching = false; @@ -155,9 +130,9 @@ bool collideShapeWithAACube(const Shape* shapeA, const glm::vec3& cubeCenter, fl const Shape* subShape = listA->getSubShape(i); int subType = subShape->getType(); if (subType == SPHERE_SHAPE) { - touching = sphereAACube(static_cast(subShape), cubeCenter, cubeSide, collisions) || touching; + touching = sphereVsAACube(static_cast(subShape), cubeCenter, cubeSide, collisions) || touching; } else if (subType == CAPSULE_SHAPE) { - touching = capsuleAACube(static_cast(subShape), cubeCenter, cubeSide, collisions) || touching; + touching = capsuleVsAACube(static_cast(subShape), cubeCenter, cubeSide, collisions) || touching; } } return touching; @@ -165,7 +140,7 @@ bool collideShapeWithAACube(const Shape* shapeA, const glm::vec3& cubeCenter, fl return false; } -bool sphereSphere(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions) { +bool sphereVsSphere(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions) { const SphereShape* sphereA = static_cast(shapeA); const SphereShape* sphereB = static_cast(shapeB); glm::vec3 BA = sphereB->getTranslation() - sphereA->getTranslation(); @@ -195,7 +170,7 @@ bool sphereSphere(const Shape* shapeA, const Shape* shapeB, CollisionList& colli return false; } -bool sphereCapsule(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions) { +bool sphereVsCapsule(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions) { const SphereShape* sphereA = static_cast(shapeA); const CapsuleShape* capsuleB = static_cast(shapeB); // find sphereA's closest approach to axis of capsuleB @@ -266,7 +241,7 @@ bool sphereCapsule(const Shape* shapeA, const Shape* shapeB, CollisionList& coll return false; } -bool spherePlane(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions) { +bool sphereVsPlane(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions) { const SphereShape* sphereA = static_cast(shapeA); const PlaneShape* planeB = static_cast(shapeB); glm::vec3 penetration; @@ -284,7 +259,7 @@ bool spherePlane(const Shape* shapeA, const Shape* shapeB, CollisionList& collis return false; } -bool capsuleSphere(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions) { +bool capsuleVsSphere(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions) { const CapsuleShape* capsuleA = static_cast(shapeA); const SphereShape* sphereB = static_cast(shapeB); // find sphereB's closest approach to axis of capsuleA @@ -427,7 +402,7 @@ bool lineCylinder(const glm::vec3& lineP, const glm::vec3& lineDir, return true; } -bool capsuleCapsule(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions) { +bool capsuleVsCapsule(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions) { const CapsuleShape* capsuleA = static_cast(shapeA); const CapsuleShape* capsuleB = static_cast(shapeB); glm::vec3 axisA; @@ -588,7 +563,7 @@ bool capsuleCapsule(const Shape* shapeA, const Shape* shapeB, CollisionList& col return false; } -bool capsulePlane(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions) { +bool capsuleVsPlane(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions) { const CapsuleShape* capsuleA = static_cast(shapeA); const PlaneShape* planeB = static_cast(shapeB); glm::vec3 start, end, penetration; @@ -610,7 +585,7 @@ bool capsulePlane(const Shape* shapeA, const Shape* shapeB, CollisionList& colli return false; } -bool planeSphere(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions) { +bool planeVsSphere(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions) { const PlaneShape* planeA = static_cast(shapeA); const SphereShape* sphereB = static_cast(shapeB); glm::vec3 penetration; @@ -629,7 +604,7 @@ bool planeSphere(const Shape* shapeA, const Shape* shapeB, CollisionList& collis return false; } -bool planeCapsule(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions) { +bool planeVsCapsule(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions) { const PlaneShape* planeA = static_cast(shapeA); const CapsuleShape* capsuleB = static_cast(shapeB); glm::vec3 start, end, penetration; @@ -651,115 +626,33 @@ bool planeCapsule(const Shape* shapeA, const Shape* shapeB, CollisionList& colli return false; } -bool planePlane(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions) { +bool planeVsPlane(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions) { // technically, planes always collide unless they're parallel and not coincident; however, that's // not going to give us any useful information return false; } -bool sphereList(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions) { +bool shapeVsList(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions) { bool touching = false; const ListShape* listB = static_cast(shapeB); for (int i = 0; i < listB->size() && !collisions.isFull(); ++i) { const Shape* subShape = listB->getSubShape(i); - int subType = subShape->getType(); - if (subType == SPHERE_SHAPE) { - touching = sphereSphere(shapeA, subShape, collisions) || touching; - } else if (subType == CAPSULE_SHAPE) { - touching = sphereCapsule(shapeA, subShape, collisions) || touching; - } else if (subType == PLANE_SHAPE) { - touching = spherePlane(shapeA, subShape, collisions) || touching; - } + touching = collideShapes(shapeA, subShape, collisions) || touching; } return touching; } -bool capsuleList(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions) { - bool touching = false; - const ListShape* listB = static_cast(shapeB); - for (int i = 0; i < listB->size() && !collisions.isFull(); ++i) { - const Shape* subShape = listB->getSubShape(i); - int subType = subShape->getType(); - if (subType == SPHERE_SHAPE) { - touching = capsuleSphere(shapeA, subShape, collisions) || touching; - } else if (subType == CAPSULE_SHAPE) { - touching = capsuleCapsule(shapeA, subShape, collisions) || touching; - } else if (subType == PLANE_SHAPE) { - touching = capsulePlane(shapeA, subShape, collisions) || touching; - } - } - return touching; -} - -bool planeList(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions) { - bool touching = false; - const ListShape* listB = static_cast(shapeB); - for (int i = 0; i < listB->size() && !collisions.isFull(); ++i) { - const Shape* subShape = listB->getSubShape(i); - int subType = subShape->getType(); - if (subType == SPHERE_SHAPE) { - touching = planeSphere(shapeA, subShape, collisions) || touching; - } else if (subType == CAPSULE_SHAPE) { - touching = planeCapsule(shapeA, subShape, collisions) || touching; - } else if (subType == PLANE_SHAPE) { - touching = planePlane(shapeA, subShape, collisions) || touching; - } - } - return touching; -} - -bool listSphere(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions) { +bool listVsShape(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions) { bool touching = false; const ListShape* listA = static_cast(shapeA); for (int i = 0; i < listA->size() && !collisions.isFull(); ++i) { const Shape* subShape = listA->getSubShape(i); - int subType = subShape->getType(); - if (subType == SPHERE_SHAPE) { - touching = sphereSphere(subShape, shapeB, collisions) || touching; - } else if (subType == CAPSULE_SHAPE) { - touching = capsuleSphere(subShape, shapeB, collisions) || touching; - } else if (subType == PLANE_SHAPE) { - touching = planeSphere(subShape, shapeB, collisions) || touching; - } + touching = collideShapes(subShape, shapeB, collisions) || touching; } return touching; } -bool listCapsule(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions) { - bool touching = false; - const ListShape* listA = static_cast(shapeA); - for (int i = 0; i < listA->size() && !collisions.isFull(); ++i) { - const Shape* subShape = listA->getSubShape(i); - int subType = subShape->getType(); - if (subType == SPHERE_SHAPE) { - touching = sphereCapsule(subShape, shapeB, collisions) || touching; - } else if (subType == CAPSULE_SHAPE) { - touching = capsuleCapsule(subShape, shapeB, collisions) || touching; - } else if (subType == PLANE_SHAPE) { - touching = planeCapsule(subShape, shapeB, collisions) || touching; - } - } - return touching; -} - -bool listPlane(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions) { - bool touching = false; - const ListShape* listA = static_cast(shapeA); - for (int i = 0; i < listA->size() && !collisions.isFull(); ++i) { - const Shape* subShape = listA->getSubShape(i); - int subType = subShape->getType(); - if (subType == SPHERE_SHAPE) { - touching = spherePlane(subShape, shapeB, collisions) || touching; - } else if (subType == CAPSULE_SHAPE) { - touching = capsulePlane(subShape, shapeB, collisions) || touching; - } else if (subType == PLANE_SHAPE) { - touching = planePlane(subShape, shapeB, collisions) || touching; - } - } - return touching; -} - -bool listList(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions) { +bool listVsList(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions) { bool touching = false; const ListShape* listA = static_cast(shapeA); const ListShape* listB = static_cast(shapeB); @@ -773,7 +666,7 @@ bool listList(const Shape* shapeA, const Shape* shapeB, CollisionList& collision } // helper function -bool sphereAACube(const glm::vec3& sphereCenter, float sphereRadius, const glm::vec3& cubeCenter, +bool sphereVsAACube(const glm::vec3& sphereCenter, float sphereRadius, const glm::vec3& cubeCenter, float cubeSide, CollisionList& collisions) { // sphere is A // cube is B @@ -921,11 +814,11 @@ bool sphereAACube_StarkAngles(const glm::vec3& sphereCenter, float sphereRadius, } */ -bool sphereAACube(const SphereShape* sphereA, const glm::vec3& cubeCenter, float cubeSide, CollisionList& collisions) { - return sphereAACube(sphereA->getTranslation(), sphereA->getRadius(), cubeCenter, cubeSide, collisions); +bool sphereVsAACube(const SphereShape* sphereA, const glm::vec3& cubeCenter, float cubeSide, CollisionList& collisions) { + return sphereVsAACube(sphereA->getTranslation(), sphereA->getRadius(), cubeCenter, cubeSide, collisions); } -bool capsuleAACube(const CapsuleShape* capsuleA, const glm::vec3& cubeCenter, float cubeSide, CollisionList& collisions) { +bool capsuleVsAACube(const CapsuleShape* capsuleA, const glm::vec3& cubeCenter, float cubeSide, CollisionList& collisions) { // find nerest approach of capsule line segment to cube glm::vec3 capsuleAxis; capsuleA->computeNormalizedAxis(capsuleAxis); @@ -938,7 +831,7 @@ bool capsuleAACube(const CapsuleShape* capsuleA, const glm::vec3& cubeCenter, fl } glm::vec3 nearestApproach = capsuleA->getTranslation() + offset * capsuleAxis; // collide nearest approach like a sphere at that point - return sphereAACube(nearestApproach, capsuleA->getRadius(), cubeCenter, cubeSide, collisions); + return sphereVsAACube(nearestApproach, capsuleA->getRadius(), cubeCenter, cubeSide, collisions); } bool findRayIntersectionWithShapes(const QVector shapes, const glm::vec3& rayStart, const glm::vec3& rayDirection, float& minDistance) { diff --git a/libraries/shared/src/ShapeCollider.h b/libraries/shared/src/ShapeCollider.h index 11768f0a48..3aa795e6fa 100644 --- a/libraries/shared/src/ShapeCollider.h +++ b/libraries/shared/src/ShapeCollider.h @@ -35,13 +35,6 @@ namespace ShapeCollider { /// \param collisions[out] collision details /// \return true if shapes collide bool collideShapes(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions); - bool collideShapesOld(const Shape* shapeA, const Shape* shapeB, CollisionList& collisions); - - /// \param shapesA list of shapes - /// \param shapeB list of shapes - /// \param collisions[out] average collision details - /// \return true if any shapes collide - bool collideShapesCoarse(const QVector& shapesA, const QVector& shapesB, CollisionInfo& collision); bool collideShapeWithShapes(const Shape* shapeA, const QVector& shapes, int startIndex, CollisionList& collisions); bool collideShapesWithShapes(const QVector& shapesA, const QVector& shapesB, CollisionList& collisions); @@ -57,111 +50,87 @@ namespace ShapeCollider { /// \param sphereB pointer to second shape (cannot be NULL) /// \param[out] collisions where to append collision details /// \return true if shapes collide - bool sphereSphere(const Shape* sphereA, const Shape* sphereB, CollisionList& collisions); + bool sphereVsSphere(const Shape* sphereA, const Shape* sphereB, CollisionList& collisions); /// \param sphereA pointer to first shape (cannot be NULL) /// \param capsuleB pointer to second shape (cannot be NULL) /// \param[out] collisions where to append collision details /// \return true if shapes collide - bool sphereCapsule(const Shape* sphereA, const Shape* capsuleB, CollisionList& collisions); + bool sphereVsCapsule(const Shape* sphereA, const Shape* capsuleB, CollisionList& collisions); /// \param sphereA pointer to first shape (cannot be NULL) /// \param planeB pointer to second shape (cannot be NULL) /// \param[out] collisions where to append collision details /// \return true if shapes collide - bool spherePlane(const Shape* sphereA, const Shape* planeB, CollisionList& collisions); + bool sphereVsPlane(const Shape* sphereA, const Shape* planeB, CollisionList& collisions); /// \param capsuleA pointer to first shape (cannot be NULL) /// \param sphereB pointer to second shape (cannot be NULL) /// \param[out] collisions where to append collision details /// \return true if shapes collide - bool capsuleSphere(const Shape* capsuleA, const Shape* sphereB, CollisionList& collisions); + bool capsuleVsSphere(const Shape* capsuleA, const Shape* sphereB, CollisionList& collisions); /// \param capsuleA pointer to first shape (cannot be NULL) /// \param capsuleB pointer to second shape (cannot be NULL) /// \param[out] collisions where to append collision details /// \return true if shapes collide - bool capsuleCapsule(const Shape* capsuleA, const Shape* capsuleB, CollisionList& collisions); + bool capsuleVsCapsule(const Shape* capsuleA, const Shape* capsuleB, CollisionList& collisions); /// \param capsuleA pointer to first shape (cannot be NULL) /// \param planeB pointer to second shape (cannot be NULL) /// \param[out] collisions where to append collision details /// \return true if shapes collide - bool capsulePlane(const Shape* capsuleA, const Shape* planeB, CollisionList& collisions); + bool capsuleVsPlane(const Shape* capsuleA, const Shape* planeB, CollisionList& collisions); /// \param planeA pointer to first shape (cannot be NULL) /// \param sphereB pointer to second shape (cannot be NULL) /// \param[out] collisions where to append collision details /// \return true if shapes collide - bool planeSphere(const Shape* planeA, const Shape* sphereB, CollisionList& collisions); + bool planeVsSphere(const Shape* planeA, const Shape* sphereB, CollisionList& collisions); /// \param planeA pointer to first shape (cannot be NULL) /// \param capsuleB pointer to second shape (cannot be NULL) /// \param[out] collisions where to append collision details /// \return true if shapes collide - bool planeCapsule(const Shape* planeA, const Shape* capsuleB, CollisionList& collisions); + bool planeVsCapsule(const Shape* planeA, const Shape* capsuleB, CollisionList& collisions); /// \param planeA pointer to first shape (cannot be NULL) /// \param planeB pointer to second shape (cannot be NULL) /// \param[out] collisions where to append collision details /// \return true if shapes collide - bool planePlane(const Shape* planeA, const Shape* planeB, CollisionList& collisions); + bool planeVsPlane(const Shape* planeA, const Shape* planeB, CollisionList& collisions); - /// \param sphereA pointer to first shape (cannot be NULL) + /// \param shapeA pointer to first shape (cannot be NULL) /// \param listB pointer to second shape (cannot be NULL) /// \param[out] collisions where to append collision details /// \return true if shapes collide - bool sphereList(const Shape* sphereA, const Shape* listB, CollisionList& collisions); + bool shapeVsList(const Shape* shapeA, const Shape* listB, CollisionList& collisions); - /// \param capuleA pointer to first shape (cannot be NULL) + /// \param listA pointer to first shape (cannot be NULL) + /// \param shapeB pointer to second shape (cannot be NULL) + /// \param[out] collisions where to append collision details + /// \return true if shapes collide + bool listVsShape(const Shape* listA, const Shape* shapeB, CollisionList& collisions); + + /// \param listA pointer to first shape (cannot be NULL) /// \param listB pointer to second shape (cannot be NULL) /// \param[out] collisions where to append collision details /// \return true if shapes collide - bool capsuleList(const Shape* capsuleA, const Shape* listB, CollisionList& collisions); - - /// \param planeA pointer to first shape (cannot be NULL) - /// \param listB pointer to second shape (cannot be NULL) - /// \param[out] collisions where to append collision details - /// \return true if shapes collide - bool planeList(const Shape* planeA, const Shape* listB, CollisionList& collisions); - - /// \param listA pointer to first shape (cannot be NULL) - /// \param sphereB pointer to second shape (cannot be NULL) - /// \param[out] collisions where to append collision details - /// \return true if shapes collide - bool listSphere(const Shape* listA, const Shape* sphereB, CollisionList& collisions); - - /// \param listA pointer to first shape (cannot be NULL) - /// \param capsuleB pointer to second shape (cannot be NULL) - /// \param[out] collisions where to append collision details - /// \return true if shapes collide - bool listCapsule(const Shape* listA, const Shape* capsuleB, CollisionList& collisions); - - /// \param listA pointer to first shape (cannot be NULL) - /// \param planeB pointer to second shape (cannot be NULL) - /// \param[out] collisions where to append collision details - /// \return true if shapes collide - bool listPlane(const Shape* listA, const Shape* planeB, CollisionList& collisions); - - /// \param listA pointer to first shape (cannot be NULL) - /// \param capsuleB pointer to second shape (cannot be NULL) - /// \param[out] collisions where to append collision details - /// \return true if shapes collide - bool listList(const Shape* listA, const Shape* listB, CollisionList& collisions); + bool listVsList(const Shape* listA, const Shape* listB, CollisionList& collisions); /// \param sphereA pointer to sphere (cannot be NULL) /// \param cubeCenter center of cube /// \param cubeSide lenght of side of cube /// \param[out] collisions where to append collision details /// \return true if sphereA collides with axis aligned cube - bool sphereAACube(const SphereShape* sphereA, const glm::vec3& cubeCenter, float cubeSide, CollisionList& collisions); + bool sphereVsAACube(const SphereShape* sphereA, const glm::vec3& cubeCenter, float cubeSide, CollisionList& collisions); /// \param capsuleA pointer to capsule (cannot be NULL) /// \param cubeCenter center of cube /// \param cubeSide lenght of side of cube /// \param[out] collisions where to append collision details /// \return true if capsuleA collides with axis aligned cube - bool capsuleAACube(const CapsuleShape* capsuleA, const glm::vec3& cubeCenter, float cubeSide, CollisionList& collisions); + bool capsuleVsAACube(const CapsuleShape* capsuleA, const glm::vec3& cubeCenter, float cubeSide, CollisionList& collisions); /// \param shapes list of pointers to shapes (shape pointers may be NULL) /// \param startPoint beginning of ray diff --git a/tests/physics/src/ShapeColliderTests.cpp b/tests/physics/src/ShapeColliderTests.cpp index db4833b20a..9473cc3452 100644 --- a/tests/physics/src/ShapeColliderTests.cpp +++ b/tests/physics/src/ShapeColliderTests.cpp @@ -713,7 +713,7 @@ void ShapeColliderTests::sphereTouchesAACubeFaces() { sphereCenter = cubeCenter + sphereOffset * axis; sphere.setTranslation(sphereCenter); - if (!ShapeCollider::sphereAACube(&sphere, cubeCenter, cubeSide, collisions)){ + if (!ShapeCollider::sphereVsAACube(&sphere, cubeCenter, cubeSide, collisions)){ std::cout << __FILE__ << ":" << __LINE__ << " ERROR: sphere should collide with cube. axis = " << axis << std::endl; } CollisionInfo* collision = collisions[0]; @@ -746,7 +746,7 @@ void ShapeColliderTests::sphereTouchesAACubeFaces() { sphereCenter = cubeCenter + sphereOffset * axis; sphere.setTranslation(sphereCenter); - if (!ShapeCollider::sphereAACube(&sphere, cubeCenter, cubeSide, collisions)){ + if (!ShapeCollider::sphereVsAACube(&sphere, cubeCenter, cubeSide, collisions)){ std::cout << __FILE__ << ":" << __LINE__ << " ERROR: sphere should collide with cube." << " axis = " << axis << std::endl; @@ -820,7 +820,7 @@ void ShapeColliderTests::sphereTouchesAACubeEdges() { sphereCenter = cubeCenter + (lengthAxis * 0.5f * cubeSide + sphereRadius - overlap) * axis; sphere.setTranslation(sphereCenter); - if (!ShapeCollider::sphereAACube(&sphere, cubeCenter, cubeSide, collisions)){ + if (!ShapeCollider::sphereVsAACube(&sphere, cubeCenter, cubeSide, collisions)){ std::cout << __FILE__ << ":" << __LINE__ << " ERROR: sphere should collide with cube. axis = " << axis << std::endl; } CollisionInfo* collision = collisions[i]; @@ -861,42 +861,42 @@ void ShapeColliderTests::sphereMissesAACube() { // top sphereCenter = cubeCenter + sphereOffset * yAxis; sphere.setTranslation(sphereCenter); - if (ShapeCollider::sphereAACube(&sphere, cubeCenter, cubeSide, collisions)){ + if (ShapeCollider::sphereVsAACube(&sphere, cubeCenter, cubeSide, collisions)){ std::cout << __FILE__ << ":" << __LINE__ << " ERROR: sphere should NOT collide with cube" << std::endl; } // bottom sphereCenter = cubeCenter - sphereOffset * yAxis; sphere.setTranslation(sphereCenter); - if (ShapeCollider::sphereAACube(&sphere, cubeCenter, cubeSide, collisions)){ + if (ShapeCollider::sphereVsAACube(&sphere, cubeCenter, cubeSide, collisions)){ std::cout << __FILE__ << ":" << __LINE__ << " ERROR: sphere should NOT collide with cube" << std::endl; } // left sphereCenter = cubeCenter + sphereOffset * xAxis; sphere.setTranslation(sphereCenter); - if (ShapeCollider::sphereAACube(&sphere, cubeCenter, cubeSide, collisions)){ + if (ShapeCollider::sphereVsAACube(&sphere, cubeCenter, cubeSide, collisions)){ std::cout << __FILE__ << ":" << __LINE__ << " ERROR: sphere should NOT collide with cube" << std::endl; } // right sphereCenter = cubeCenter - sphereOffset * xAxis; sphere.setTranslation(sphereCenter); - if (ShapeCollider::sphereAACube(&sphere, cubeCenter, cubeSide, collisions)){ + if (ShapeCollider::sphereVsAACube(&sphere, cubeCenter, cubeSide, collisions)){ std::cout << __FILE__ << ":" << __LINE__ << " ERROR: sphere should NOT collide with cube" << std::endl; } // forward sphereCenter = cubeCenter + sphereOffset * zAxis; sphere.setTranslation(sphereCenter); - if (ShapeCollider::sphereAACube(&sphere, cubeCenter, cubeSide, collisions)){ + if (ShapeCollider::sphereVsAACube(&sphere, cubeCenter, cubeSide, collisions)){ std::cout << __FILE__ << ":" << __LINE__ << " ERROR: sphere should NOT collide with cube" << std::endl; } // back sphereCenter = cubeCenter - sphereOffset * zAxis; sphere.setTranslation(sphereCenter); - if (ShapeCollider::sphereAACube(&sphere, cubeCenter, cubeSide, collisions)){ + if (ShapeCollider::sphereVsAACube(&sphere, cubeCenter, cubeSide, collisions)){ std::cout << __FILE__ << ":" << __LINE__ << " ERROR: sphere should NOT collide with cube" << std::endl; } }