Make BroadPhaseAlgorithm a system
This commit is contained in:
parent
827b14f1b0
commit
4b919fb4fc
|
@ -81,7 +81,6 @@ SET (REACTPHYSICS3D_HEADERS
|
||||||
"src/body/CollisionBody.h"
|
"src/body/CollisionBody.h"
|
||||||
"src/body/RigidBody.h"
|
"src/body/RigidBody.h"
|
||||||
"src/collision/ContactPointInfo.h"
|
"src/collision/ContactPointInfo.h"
|
||||||
"src/collision/broadphase/BroadPhaseAlgorithm.h"
|
|
||||||
"src/collision/broadphase/DynamicAABBTree.h"
|
"src/collision/broadphase/DynamicAABBTree.h"
|
||||||
"src/collision/narrowphase/CollisionDispatch.h"
|
"src/collision/narrowphase/CollisionDispatch.h"
|
||||||
"src/collision/narrowphase/GJK/VoronoiSimplex.h"
|
"src/collision/narrowphase/GJK/VoronoiSimplex.h"
|
||||||
|
@ -139,7 +138,7 @@ SET (REACTPHYSICS3D_HEADERS
|
||||||
"src/engine/Material.h"
|
"src/engine/Material.h"
|
||||||
"src/engine/OverlappingPair.h"
|
"src/engine/OverlappingPair.h"
|
||||||
"src/engine/Timer.h"
|
"src/engine/Timer.h"
|
||||||
"src/engine/Timer.cpp"
|
"src/systems/BroadPhaseSystem.h"
|
||||||
"src/components/Components.h"
|
"src/components/Components.h"
|
||||||
"src/components/TransformComponents.h"
|
"src/components/TransformComponents.h"
|
||||||
"src/components/ProxyShapesComponents.h"
|
"src/components/ProxyShapesComponents.h"
|
||||||
|
@ -175,7 +174,6 @@ SET (REACTPHYSICS3D_SOURCES
|
||||||
"src/body/Body.cpp"
|
"src/body/Body.cpp"
|
||||||
"src/body/CollisionBody.cpp"
|
"src/body/CollisionBody.cpp"
|
||||||
"src/body/RigidBody.cpp"
|
"src/body/RigidBody.cpp"
|
||||||
"src/collision/broadphase/BroadPhaseAlgorithm.cpp"
|
|
||||||
"src/collision/broadphase/DynamicAABBTree.cpp"
|
"src/collision/broadphase/DynamicAABBTree.cpp"
|
||||||
"src/collision/narrowphase/CollisionDispatch.cpp"
|
"src/collision/narrowphase/CollisionDispatch.cpp"
|
||||||
"src/collision/narrowphase/GJK/VoronoiSimplex.cpp"
|
"src/collision/narrowphase/GJK/VoronoiSimplex.cpp"
|
||||||
|
@ -231,6 +229,7 @@ SET (REACTPHYSICS3D_SOURCES
|
||||||
"src/engine/Timer.cpp"
|
"src/engine/Timer.cpp"
|
||||||
"src/engine/Entity.cpp"
|
"src/engine/Entity.cpp"
|
||||||
"src/engine/EntityManager.cpp"
|
"src/engine/EntityManager.cpp"
|
||||||
|
"src/systems/BroadPhaseSystem.cpp"
|
||||||
"src/components/TransformComponents.cpp"
|
"src/components/TransformComponents.cpp"
|
||||||
"src/components/ProxyShapesComponents.cpp"
|
"src/components/ProxyShapesComponents.cpp"
|
||||||
"src/collision/CollisionCallback.cpp"
|
"src/collision/CollisionCallback.cpp"
|
||||||
|
|
|
@ -50,7 +50,7 @@ using namespace std;
|
||||||
// Constructor
|
// Constructor
|
||||||
CollisionDetection::CollisionDetection(CollisionWorld* world, ProxyShapesComponents& proxyShapesComponents, MemoryManager& memoryManager)
|
CollisionDetection::CollisionDetection(CollisionWorld* world, ProxyShapesComponents& proxyShapesComponents, MemoryManager& memoryManager)
|
||||||
: mMemoryManager(memoryManager), mProxyShapesComponents(proxyShapesComponents), mCollisionDispatch(mMemoryManager.getPoolAllocator()), mWorld(world),
|
: mMemoryManager(memoryManager), mProxyShapesComponents(proxyShapesComponents), mCollisionDispatch(mMemoryManager.getPoolAllocator()), mWorld(world),
|
||||||
mOverlappingPairs(mMemoryManager.getPoolAllocator()), mBroadPhaseAlgorithm(*this, mProxyShapesComponents),
|
mOverlappingPairs(mMemoryManager.getPoolAllocator()), mBroadPhaseSystem(*this, mProxyShapesComponents),
|
||||||
mNoCollisionPairs(mMemoryManager.getPoolAllocator()), mIsCollisionShapesAdded(false),
|
mNoCollisionPairs(mMemoryManager.getPoolAllocator()), mIsCollisionShapesAdded(false),
|
||||||
mNarrowPhaseInput(mMemoryManager.getSingleFrameAllocator()) {
|
mNarrowPhaseInput(mMemoryManager.getSingleFrameAllocator()) {
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ void CollisionDetection::computeBroadPhase() {
|
||||||
// Ask the broad-phase to recompute the overlapping pairs of collision
|
// Ask the broad-phase to recompute the overlapping pairs of collision
|
||||||
// shapes. This call can only add new overlapping pairs in the collision
|
// shapes. This call can only add new overlapping pairs in the collision
|
||||||
// detection.
|
// detection.
|
||||||
mBroadPhaseAlgorithm.computeOverlappingPairs(mMemoryManager);
|
mBroadPhaseSystem.computeOverlappingPairs(mMemoryManager);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ void CollisionDetection::computeMiddlePhase() {
|
||||||
|
|
||||||
// Check if the two shapes are still overlapping. Otherwise, we destroy the
|
// Check if the two shapes are still overlapping. Otherwise, we destroy the
|
||||||
// overlapping pair
|
// overlapping pair
|
||||||
if (!mBroadPhaseAlgorithm.testOverlappingShapes(shape1, shape2)) {
|
if (!mBroadPhaseSystem.testOverlappingShapes(shape1, shape2)) {
|
||||||
|
|
||||||
// Destroy the overlapping pair
|
// Destroy the overlapping pair
|
||||||
pair->~OverlappingPair();
|
pair->~OverlappingPair();
|
||||||
|
@ -393,7 +393,7 @@ void CollisionDetection::removeProxyCollisionShape(ProxyShape* proxyShape) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the body from the broad-phase
|
// Remove the body from the broad-phase
|
||||||
mBroadPhaseAlgorithm.removeProxyCollisionShape(proxyShape);
|
mBroadPhaseSystem.removeProxyCollisionShape(proxyShape);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CollisionDetection::addAllContactManifoldsToBodies() {
|
void CollisionDetection::addAllContactManifoldsToBodies() {
|
||||||
|
@ -420,7 +420,7 @@ void CollisionDetection::raycast(RaycastCallback* raycastCallback,
|
||||||
|
|
||||||
// Ask the broad-phase algorithm to call the testRaycastAgainstShape()
|
// Ask the broad-phase algorithm to call the testRaycastAgainstShape()
|
||||||
// callback method for each proxy shape hit by the ray in the broad-phase
|
// callback method for each proxy shape hit by the ray in the broad-phase
|
||||||
mBroadPhaseAlgorithm.raycast(ray, rayCastTest, raycastWithCategoryMaskBits);
|
mBroadPhaseSystem.raycast(ray, rayCastTest, raycastWithCategoryMaskBits);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a contact manifold to the linked list of contact manifolds of the two bodies involved
|
// Add a contact manifold to the linked list of contact manifolds of the two bodies involved
|
||||||
|
@ -571,7 +571,7 @@ void CollisionDetection::testAABBOverlap(const AABB& aabb, OverlapCallback* over
|
||||||
|
|
||||||
// Ask the broad-phase to get all the overlapping shapes
|
// Ask the broad-phase to get all the overlapping shapes
|
||||||
LinkedList<int> overlappingNodes(mMemoryManager.getPoolAllocator());
|
LinkedList<int> overlappingNodes(mMemoryManager.getPoolAllocator());
|
||||||
mBroadPhaseAlgorithm.reportAllShapesOverlappingWithAABB(aabb, overlappingNodes);
|
mBroadPhaseSystem.reportAllShapesOverlappingWithAABB(aabb, overlappingNodes);
|
||||||
|
|
||||||
// For each overlaping proxy shape
|
// For each overlaping proxy shape
|
||||||
LinkedList<int>::ListElement* element = overlappingNodes.getListHead();
|
LinkedList<int>::ListElement* element = overlappingNodes.getListHead();
|
||||||
|
@ -579,7 +579,7 @@ void CollisionDetection::testAABBOverlap(const AABB& aabb, OverlapCallback* over
|
||||||
|
|
||||||
// Get the overlapping proxy shape
|
// Get the overlapping proxy shape
|
||||||
int broadPhaseId = element->data;
|
int broadPhaseId = element->data;
|
||||||
ProxyShape* proxyShape = mBroadPhaseAlgorithm.getProxyShapeForBroadPhaseId(broadPhaseId);
|
ProxyShape* proxyShape = mBroadPhaseSystem.getProxyShapeForBroadPhaseId(broadPhaseId);
|
||||||
|
|
||||||
CollisionBody* overlapBody = proxyShape->getBody();
|
CollisionBody* overlapBody = proxyShape->getBody();
|
||||||
|
|
||||||
|
@ -662,11 +662,11 @@ void CollisionDetection::testOverlap(CollisionBody* body, OverlapCallback* overl
|
||||||
if (bodyProxyShape->getBroadPhaseId() != -1) {
|
if (bodyProxyShape->getBroadPhaseId() != -1) {
|
||||||
|
|
||||||
// Get the AABB of the shape
|
// Get the AABB of the shape
|
||||||
const AABB& shapeAABB = mBroadPhaseAlgorithm.getFatAABB(bodyProxyShape->getBroadPhaseId());
|
const AABB& shapeAABB = mBroadPhaseSystem.getFatAABB(bodyProxyShape->getBroadPhaseId());
|
||||||
|
|
||||||
// Ask the broad-phase to get all the overlapping shapes
|
// Ask the broad-phase to get all the overlapping shapes
|
||||||
LinkedList<int> overlappingNodes(mMemoryManager.getPoolAllocator());
|
LinkedList<int> overlappingNodes(mMemoryManager.getPoolAllocator());
|
||||||
mBroadPhaseAlgorithm.reportAllShapesOverlappingWithAABB(shapeAABB, overlappingNodes);
|
mBroadPhaseSystem.reportAllShapesOverlappingWithAABB(shapeAABB, overlappingNodes);
|
||||||
|
|
||||||
const bodyindex bodyId = body->getId();
|
const bodyindex bodyId = body->getId();
|
||||||
|
|
||||||
|
@ -676,7 +676,7 @@ void CollisionDetection::testOverlap(CollisionBody* body, OverlapCallback* overl
|
||||||
|
|
||||||
// Get the overlapping proxy shape
|
// Get the overlapping proxy shape
|
||||||
int broadPhaseId = element->data;
|
int broadPhaseId = element->data;
|
||||||
ProxyShape* proxyShape = mBroadPhaseAlgorithm.getProxyShapeForBroadPhaseId(broadPhaseId);
|
ProxyShape* proxyShape = mBroadPhaseSystem.getProxyShapeForBroadPhaseId(broadPhaseId);
|
||||||
|
|
||||||
// If the proxy shape is from a body that we have not already reported collision and the
|
// If the proxy shape is from a body that we have not already reported collision and the
|
||||||
// two proxy collision shapes are not from the same body
|
// two proxy collision shapes are not from the same body
|
||||||
|
@ -818,11 +818,11 @@ void CollisionDetection::testCollision(CollisionBody* body, CollisionCallback* c
|
||||||
if (bodyProxyShape->getBroadPhaseId() != -1) {
|
if (bodyProxyShape->getBroadPhaseId() != -1) {
|
||||||
|
|
||||||
// Get the AABB of the shape
|
// Get the AABB of the shape
|
||||||
const AABB& shapeAABB = mBroadPhaseAlgorithm.getFatAABB(bodyProxyShape->getBroadPhaseId());
|
const AABB& shapeAABB = mBroadPhaseSystem.getFatAABB(bodyProxyShape->getBroadPhaseId());
|
||||||
|
|
||||||
// Ask the broad-phase to get all the overlapping shapes
|
// Ask the broad-phase to get all the overlapping shapes
|
||||||
LinkedList<int> overlappingNodes(mMemoryManager.getPoolAllocator());
|
LinkedList<int> overlappingNodes(mMemoryManager.getPoolAllocator());
|
||||||
mBroadPhaseAlgorithm.reportAllShapesOverlappingWithAABB(shapeAABB, overlappingNodes);
|
mBroadPhaseSystem.reportAllShapesOverlappingWithAABB(shapeAABB, overlappingNodes);
|
||||||
|
|
||||||
const bodyindex bodyId = body->getId();
|
const bodyindex bodyId = body->getId();
|
||||||
|
|
||||||
|
@ -832,7 +832,7 @@ void CollisionDetection::testCollision(CollisionBody* body, CollisionCallback* c
|
||||||
|
|
||||||
// Get the overlapping proxy shape
|
// Get the overlapping proxy shape
|
||||||
int broadPhaseId = element->data;
|
int broadPhaseId = element->data;
|
||||||
ProxyShape* proxyShape = mBroadPhaseAlgorithm.getProxyShapeForBroadPhaseId(broadPhaseId);
|
ProxyShape* proxyShape = mBroadPhaseSystem.getProxyShapeForBroadPhaseId(broadPhaseId);
|
||||||
|
|
||||||
// If the two proxy collision shapes are not from the same body
|
// If the two proxy collision shapes are not from the same body
|
||||||
if (proxyShape->getBody()->getId() != bodyId) {
|
if (proxyShape->getBody()->getId() != bodyId) {
|
||||||
|
@ -948,7 +948,7 @@ void CollisionDetection::testCollision(CollisionCallback* callback) {
|
||||||
// that the two shapes are still overlapping.
|
// that the two shapes are still overlapping.
|
||||||
if (((shape1->getCollideWithMaskBits() & shape2->getCollisionCategoryBits()) != 0 &&
|
if (((shape1->getCollideWithMaskBits() & shape2->getCollisionCategoryBits()) != 0 &&
|
||||||
(shape1->getCollisionCategoryBits() & shape2->getCollideWithMaskBits()) != 0) &&
|
(shape1->getCollisionCategoryBits() & shape2->getCollideWithMaskBits()) != 0) &&
|
||||||
mBroadPhaseAlgorithm.testOverlappingShapes(shape1, shape2)) {
|
mBroadPhaseSystem.testOverlappingShapes(shape1, shape2)) {
|
||||||
|
|
||||||
// Compute the middle-phase collision detection between the two shapes
|
// Compute the middle-phase collision detection between the two shapes
|
||||||
computeMiddlePhaseForProxyShapes(pair, narrowPhaseInput);
|
computeMiddlePhaseForProxyShapes(pair, narrowPhaseInput);
|
||||||
|
@ -990,5 +990,5 @@ EventListener* CollisionDetection::getWorldEventListener() {
|
||||||
// Return the world-space AABB of a given proxy shape
|
// Return the world-space AABB of a given proxy shape
|
||||||
const AABB CollisionDetection::getWorldAABB(const ProxyShape* proxyShape) const {
|
const AABB CollisionDetection::getWorldAABB(const ProxyShape* proxyShape) const {
|
||||||
assert(proxyShape->getBroadPhaseId() > -1);
|
assert(proxyShape->getBroadPhaseId() > -1);
|
||||||
return mBroadPhaseAlgorithm.getFatAABB(proxyShape->getBroadPhaseId());
|
return mBroadPhaseSystem.getFatAABB(proxyShape->getBroadPhaseId());
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
// Libraries
|
// Libraries
|
||||||
#include "body/CollisionBody.h"
|
#include "body/CollisionBody.h"
|
||||||
#include "broadphase/BroadPhaseAlgorithm.h"
|
#include "systems/BroadPhaseSystem.h"
|
||||||
#include "collision/shapes/CollisionShape.h"
|
#include "collision/shapes/CollisionShape.h"
|
||||||
#include "engine/OverlappingPair.h"
|
#include "engine/OverlappingPair.h"
|
||||||
#include "collision/narrowphase/NarrowPhaseInput.h"
|
#include "collision/narrowphase/NarrowPhaseInput.h"
|
||||||
|
@ -80,8 +80,8 @@ class CollisionDetection {
|
||||||
/// Broad-phase overlapping pairs
|
/// Broad-phase overlapping pairs
|
||||||
OverlappingPairMap mOverlappingPairs;
|
OverlappingPairMap mOverlappingPairs;
|
||||||
|
|
||||||
/// Broad-phase algorithm
|
/// Broad-phase system
|
||||||
BroadPhaseAlgorithm mBroadPhaseAlgorithm;
|
BroadPhaseSystem mBroadPhaseSystem;
|
||||||
|
|
||||||
/// Set of pair of bodies that cannot collide between each other
|
/// Set of pair of bodies that cannot collide between each other
|
||||||
Set<bodyindexpair> mNoCollisionPairs;
|
Set<bodyindexpair> mNoCollisionPairs;
|
||||||
|
@ -245,7 +245,7 @@ inline void CollisionDetection::addProxyCollisionShape(ProxyShape* proxyShape,
|
||||||
const AABB& aabb) {
|
const AABB& aabb) {
|
||||||
|
|
||||||
// Add the body to the broad-phase
|
// Add the body to the broad-phase
|
||||||
mBroadPhaseAlgorithm.addProxyCollisionShape(proxyShape, aabb);
|
mBroadPhaseSystem.addProxyCollisionShape(proxyShape, aabb);
|
||||||
|
|
||||||
mIsCollisionShapesAdded = true;
|
mIsCollisionShapesAdded = true;
|
||||||
}
|
}
|
||||||
|
@ -268,14 +268,14 @@ inline void CollisionDetection::removeNoCollisionPair(CollisionBody* body1,
|
||||||
inline void CollisionDetection::askForBroadPhaseCollisionCheck(ProxyShape* shape) {
|
inline void CollisionDetection::askForBroadPhaseCollisionCheck(ProxyShape* shape) {
|
||||||
|
|
||||||
if (shape->getBroadPhaseId() != -1) {
|
if (shape->getBroadPhaseId() != -1) {
|
||||||
mBroadPhaseAlgorithm.addMovedCollisionShape(shape->getBroadPhaseId());
|
mBroadPhaseSystem.addMovedCollisionShape(shape->getBroadPhaseId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update a proxy collision shape (that has moved for instance)
|
// Update a proxy collision shape (that has moved for instance)
|
||||||
inline void CollisionDetection::updateProxyCollisionShape(ProxyShape* shape, const AABB& aabb,
|
inline void CollisionDetection::updateProxyCollisionShape(ProxyShape* shape, const AABB& aabb,
|
||||||
const Vector3& displacement, bool forceReinsert) {
|
const Vector3& displacement, bool forceReinsert) {
|
||||||
mBroadPhaseAlgorithm.updateProxyCollisionShape(shape, aabb, displacement);
|
mBroadPhaseSystem.updateProxyCollisionShape(shape, aabb, displacement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -294,7 +294,7 @@ inline MemoryManager& CollisionDetection::getMemoryManager() const {
|
||||||
// Set the profiler
|
// Set the profiler
|
||||||
inline void CollisionDetection::setProfiler(Profiler* profiler) {
|
inline void CollisionDetection::setProfiler(Profiler* profiler) {
|
||||||
mProfiler = profiler;
|
mProfiler = profiler;
|
||||||
mBroadPhaseAlgorithm.setProfiler(profiler);
|
mBroadPhaseSystem.setProfiler(profiler);
|
||||||
mCollisionDispatch.setProfiler(profiler);
|
mCollisionDispatch.setProfiler(profiler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
// Libraries
|
// Libraries
|
||||||
#include "DynamicAABBTree.h"
|
#include "DynamicAABBTree.h"
|
||||||
#include "BroadPhaseAlgorithm.h"
|
#include "systems/BroadPhaseSystem.h"
|
||||||
#include "containers/Stack.h"
|
#include "containers/Stack.h"
|
||||||
#include "utils/Profiler.h"
|
#include "utils/Profiler.h"
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
namespace reactphysics3d {
|
namespace reactphysics3d {
|
||||||
|
|
||||||
// Declarations
|
// Declarations
|
||||||
class BroadPhaseAlgorithm;
|
class BroadPhaseSystem;
|
||||||
class BroadPhaseRaycastTestCallback;
|
class BroadPhaseRaycastTestCallback;
|
||||||
class DynamicAABBTreeOverlapCallback;
|
class DynamicAABBTreeOverlapCallback;
|
||||||
class CollisionBody;
|
class CollisionBody;
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
|
|
||||||
// Libraries
|
// Libraries
|
||||||
#include "BroadPhaseAlgorithm.h"
|
#include "BroadPhaseSystem.h"
|
||||||
#include "collision/CollisionDetection.h"
|
#include "collision/CollisionDetection.h"
|
||||||
#include "utils/Profiler.h"
|
#include "utils/Profiler.h"
|
||||||
#include "collision/RaycastInfo.h"
|
#include "collision/RaycastInfo.h"
|
||||||
|
@ -35,7 +35,7 @@
|
||||||
using namespace reactphysics3d;
|
using namespace reactphysics3d;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
BroadPhaseAlgorithm::BroadPhaseAlgorithm(CollisionDetection& collisionDetection, ProxyShapesComponents& proxyShapesComponents)
|
BroadPhaseSystem::BroadPhaseSystem(CollisionDetection& collisionDetection, ProxyShapesComponents& proxyShapesComponents)
|
||||||
:mDynamicAABBTree(collisionDetection.getMemoryManager().getPoolAllocator(), DYNAMIC_TREE_AABB_GAP),
|
:mDynamicAABBTree(collisionDetection.getMemoryManager().getPoolAllocator(), DYNAMIC_TREE_AABB_GAP),
|
||||||
mProxyShapesComponents(proxyShapesComponents),
|
mProxyShapesComponents(proxyShapesComponents),
|
||||||
mMovedShapes(collisionDetection.getMemoryManager().getPoolAllocator()),
|
mMovedShapes(collisionDetection.getMemoryManager().getPoolAllocator()),
|
||||||
|
@ -51,7 +51,7 @@ BroadPhaseAlgorithm::BroadPhaseAlgorithm(CollisionDetection& collisionDetection,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return true if the two broad-phase collision shapes are overlapping
|
// Return true if the two broad-phase collision shapes are overlapping
|
||||||
bool BroadPhaseAlgorithm::testOverlappingShapes(const ProxyShape* shape1,
|
bool BroadPhaseSystem::testOverlappingShapes(const ProxyShape* shape1,
|
||||||
const ProxyShape* shape2) const {
|
const ProxyShape* shape2) const {
|
||||||
|
|
||||||
if (shape1->getBroadPhaseId() == -1 || shape2->getBroadPhaseId() == -1) return false;
|
if (shape1->getBroadPhaseId() == -1 || shape2->getBroadPhaseId() == -1) return false;
|
||||||
|
@ -65,7 +65,7 @@ bool BroadPhaseAlgorithm::testOverlappingShapes(const ProxyShape* shape1,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ray casting method
|
// Ray casting method
|
||||||
void BroadPhaseAlgorithm::raycast(const Ray& ray, RaycastTest& raycastTest,
|
void BroadPhaseSystem::raycast(const Ray& ray, RaycastTest& raycastTest,
|
||||||
unsigned short raycastWithCategoryMaskBits) const {
|
unsigned short raycastWithCategoryMaskBits) const {
|
||||||
|
|
||||||
RP3D_PROFILE("BroadPhaseAlgorithm::raycast()", mProfiler);
|
RP3D_PROFILE("BroadPhaseAlgorithm::raycast()", mProfiler);
|
||||||
|
@ -76,7 +76,7 @@ void BroadPhaseAlgorithm::raycast(const Ray& ray, RaycastTest& raycastTest,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a proxy collision shape into the broad-phase collision detection
|
// Add a proxy collision shape into the broad-phase collision detection
|
||||||
void BroadPhaseAlgorithm::addProxyCollisionShape(ProxyShape* proxyShape, const AABB& aabb) {
|
void BroadPhaseSystem::addProxyCollisionShape(ProxyShape* proxyShape, const AABB& aabb) {
|
||||||
|
|
||||||
assert(proxyShape->getBroadPhaseId() == -1);
|
assert(proxyShape->getBroadPhaseId() == -1);
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ void BroadPhaseAlgorithm::addProxyCollisionShape(ProxyShape* proxyShape, const A
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove a proxy collision shape from the broad-phase collision detection
|
// Remove a proxy collision shape from the broad-phase collision detection
|
||||||
void BroadPhaseAlgorithm::removeProxyCollisionShape(ProxyShape* proxyShape) {
|
void BroadPhaseSystem::removeProxyCollisionShape(ProxyShape* proxyShape) {
|
||||||
|
|
||||||
assert(proxyShape->getBroadPhaseId() != -1);
|
assert(proxyShape->getBroadPhaseId() != -1);
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ void BroadPhaseAlgorithm::removeProxyCollisionShape(ProxyShape* proxyShape) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify the broad-phase that a collision shape has moved and need to be updated
|
// Notify the broad-phase that a collision shape has moved and need to be updated
|
||||||
void BroadPhaseAlgorithm::updateProxyCollisionShape(ProxyShape* proxyShape, const AABB& aabb,
|
void BroadPhaseSystem::updateProxyCollisionShape(ProxyShape* proxyShape, const AABB& aabb,
|
||||||
const Vector3& displacement, bool forceReinsert) {
|
const Vector3& displacement, bool forceReinsert) {
|
||||||
|
|
||||||
int broadPhaseID = proxyShape->getBroadPhaseId();
|
int broadPhaseID = proxyShape->getBroadPhaseId();
|
||||||
|
@ -129,7 +129,7 @@ void BroadPhaseAlgorithm::updateProxyCollisionShape(ProxyShape* proxyShape, cons
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BroadPhaseAlgorithm::reportAllShapesOverlappingWithAABB(const AABB& aabb,
|
void BroadPhaseSystem::reportAllShapesOverlappingWithAABB(const AABB& aabb,
|
||||||
LinkedList<int>& overlappingNodes) const {
|
LinkedList<int>& overlappingNodes) const {
|
||||||
|
|
||||||
AABBOverlapCallback callback(overlappingNodes);
|
AABBOverlapCallback callback(overlappingNodes);
|
||||||
|
@ -139,7 +139,7 @@ void BroadPhaseAlgorithm::reportAllShapesOverlappingWithAABB(const AABB& aabb,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute all the overlapping pairs of collision shapes
|
// Compute all the overlapping pairs of collision shapes
|
||||||
void BroadPhaseAlgorithm::computeOverlappingPairs(MemoryManager& memoryManager) {
|
void BroadPhaseSystem::computeOverlappingPairs(MemoryManager& memoryManager) {
|
||||||
|
|
||||||
// TODO : Try to see if we can allocate potential pairs in single frame allocator
|
// TODO : Try to see if we can allocate potential pairs in single frame allocator
|
||||||
|
|
||||||
|
@ -217,7 +217,7 @@ void BroadPhaseAlgorithm::computeOverlappingPairs(MemoryManager& memoryManager)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify the broad-phase about a potential overlapping pair in the dynamic AABB tree
|
// Notify the broad-phase about a potential overlapping pair in the dynamic AABB tree
|
||||||
void BroadPhaseAlgorithm::addOverlappingNodes(int referenceNodeId, const LinkedList<int>& overlappingNodes) {
|
void BroadPhaseSystem::addOverlappingNodes(int referenceNodeId, const LinkedList<int>& overlappingNodes) {
|
||||||
|
|
||||||
// For each overlapping node in the linked list
|
// For each overlapping node in the linked list
|
||||||
LinkedList<int>::ListElement* elem = overlappingNodes.getListHead();
|
LinkedList<int>::ListElement* elem = overlappingNodes.getListHead();
|
|
@ -27,7 +27,7 @@
|
||||||
#define REACTPHYSICS3D_BROAD_PHASE_ALGORITHM_H
|
#define REACTPHYSICS3D_BROAD_PHASE_ALGORITHM_H
|
||||||
|
|
||||||
// Libraries
|
// Libraries
|
||||||
#include "DynamicAABBTree.h"
|
#include "collision/broadphase/DynamicAABBTree.h"
|
||||||
#include "containers/LinkedList.h"
|
#include "containers/LinkedList.h"
|
||||||
#include "containers/Set.h"
|
#include "containers/Set.h"
|
||||||
#include "components/ProxyShapesComponents.h"
|
#include "components/ProxyShapesComponents.h"
|
||||||
|
@ -37,7 +37,7 @@ namespace reactphysics3d {
|
||||||
|
|
||||||
// Declarations
|
// Declarations
|
||||||
class CollisionDetection;
|
class CollisionDetection;
|
||||||
class BroadPhaseAlgorithm;
|
class BroadPhaseSystem;
|
||||||
class CollisionBody;
|
class CollisionBody;
|
||||||
class ProxyShape;
|
class ProxyShape;
|
||||||
class MemoryManager;
|
class MemoryManager;
|
||||||
|
@ -132,7 +132,7 @@ class BroadPhaseRaycastCallback : public DynamicAABBTreeRaycastCallback {
|
||||||
* later for collision during the narrow-phase collision detection. A dynamic AABB
|
* later for collision during the narrow-phase collision detection. A dynamic AABB
|
||||||
* tree data structure is used for fast broad-phase collision detection.
|
* tree data structure is used for fast broad-phase collision detection.
|
||||||
*/
|
*/
|
||||||
class BroadPhaseAlgorithm {
|
class BroadPhaseSystem {
|
||||||
|
|
||||||
protected :
|
protected :
|
||||||
|
|
||||||
|
@ -167,16 +167,16 @@ class BroadPhaseAlgorithm {
|
||||||
// -------------------- Methods -------------------- //
|
// -------------------- Methods -------------------- //
|
||||||
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
BroadPhaseAlgorithm(CollisionDetection& collisionDetection, ProxyShapesComponents& proxyShapesComponents);
|
BroadPhaseSystem(CollisionDetection& collisionDetection, ProxyShapesComponents& proxyShapesComponents);
|
||||||
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
~BroadPhaseAlgorithm() = default;
|
~BroadPhaseSystem() = default;
|
||||||
|
|
||||||
/// Deleted copy-constructor
|
/// Deleted copy-constructor
|
||||||
BroadPhaseAlgorithm(const BroadPhaseAlgorithm& algorithm) = delete;
|
BroadPhaseSystem(const BroadPhaseSystem& algorithm) = delete;
|
||||||
|
|
||||||
/// Deleted assignment operator
|
/// Deleted assignment operator
|
||||||
BroadPhaseAlgorithm& operator=(const BroadPhaseAlgorithm& algorithm) = delete;
|
BroadPhaseSystem& operator=(const BroadPhaseSystem& algorithm) = delete;
|
||||||
|
|
||||||
/// Add a proxy collision shape into the broad-phase collision detection
|
/// Add a proxy collision shape into the broad-phase collision detection
|
||||||
void addProxyCollisionShape(ProxyShape* proxyShape, const AABB& aabb);
|
void addProxyCollisionShape(ProxyShape* proxyShape, const AABB& aabb);
|
||||||
|
@ -238,13 +238,13 @@ inline bool BroadPhasePair::smallerThan(const BroadPhasePair& pair1,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the fat AABB of a given broad-phase shape
|
// Return the fat AABB of a given broad-phase shape
|
||||||
inline const AABB& BroadPhaseAlgorithm::getFatAABB(int broadPhaseId) const {
|
inline const AABB& BroadPhaseSystem::getFatAABB(int broadPhaseId) const {
|
||||||
return mDynamicAABBTree.getFatAABB(broadPhaseId);
|
return mDynamicAABBTree.getFatAABB(broadPhaseId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a collision shape in the array of shapes that have moved in the last simulation step
|
// Add a collision shape in the array of shapes that have moved in the last simulation step
|
||||||
// and that need to be tested again for broad-phase overlapping.
|
// and that need to be tested again for broad-phase overlapping.
|
||||||
inline void BroadPhaseAlgorithm::addMovedCollisionShape(int broadPhaseID) {
|
inline void BroadPhaseSystem::addMovedCollisionShape(int broadPhaseID) {
|
||||||
|
|
||||||
// Store the broad-phase ID into the array of shapes that have moved
|
// Store the broad-phase ID into the array of shapes that have moved
|
||||||
mMovedShapes.add(broadPhaseID);
|
mMovedShapes.add(broadPhaseID);
|
||||||
|
@ -252,21 +252,21 @@ inline void BroadPhaseAlgorithm::addMovedCollisionShape(int broadPhaseID) {
|
||||||
|
|
||||||
// Remove a collision shape from the array of shapes that have moved in the last simulation step
|
// Remove a collision shape from the array of shapes that have moved in the last simulation step
|
||||||
// and that need to be tested again for broad-phase overlapping.
|
// and that need to be tested again for broad-phase overlapping.
|
||||||
inline void BroadPhaseAlgorithm::removeMovedCollisionShape(int broadPhaseID) {
|
inline void BroadPhaseSystem::removeMovedCollisionShape(int broadPhaseID) {
|
||||||
|
|
||||||
// Remove the broad-phase ID from the set
|
// Remove the broad-phase ID from the set
|
||||||
mMovedShapes.remove(broadPhaseID);
|
mMovedShapes.remove(broadPhaseID);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the proxy shape corresponding to the broad-phase node id in parameter
|
// Return the proxy shape corresponding to the broad-phase node id in parameter
|
||||||
inline ProxyShape* BroadPhaseAlgorithm::getProxyShapeForBroadPhaseId(int broadPhaseId) const {
|
inline ProxyShape* BroadPhaseSystem::getProxyShapeForBroadPhaseId(int broadPhaseId) const {
|
||||||
return static_cast<ProxyShape*>(mDynamicAABBTree.getNodeDataPointer(broadPhaseId));
|
return static_cast<ProxyShape*>(mDynamicAABBTree.getNodeDataPointer(broadPhaseId));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef IS_PROFILING_ACTIVE
|
#ifdef IS_PROFILING_ACTIVE
|
||||||
|
|
||||||
// Set the profiler
|
// Set the profiler
|
||||||
inline void BroadPhaseAlgorithm::setProfiler(Profiler* profiler) {
|
inline void BroadPhaseSystem::setProfiler(Profiler* profiler) {
|
||||||
mProfiler = profiler;
|
mProfiler = profiler;
|
||||||
mDynamicAABBTree.setProfiler(profiler);
|
mDynamicAABBTree.setProfiler(profiler);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user