Replacing ProxyShape data by corresponding component data
This commit is contained in:
parent
9fb8580830
commit
449beaf7a6
|
@ -85,7 +85,7 @@ ProxyShape* CollisionBody::addCollisionShape(CollisionShape* collisionShape,
|
|||
// TODO : Maybe this method can directly returns an AABB
|
||||
collisionShape->getLocalBounds(localBoundsMin, localBoundsMax);
|
||||
|
||||
ProxyShapesComponents::ProxyShapeComponent proxyShapeComponent(proxyShape, proxyShape->getBroadPhaseId(),
|
||||
ProxyShapesComponents::ProxyShapeComponent proxyShapeComponent(proxyShape, -1,
|
||||
AABB(localBoundsMin, localBoundsMax),
|
||||
transform, collisionShape, decimal(1));
|
||||
mWorld.mProxyShapesComponents.addComponent(mEntity, mIsSleeping, proxyShapeComponent);
|
||||
|
|
|
@ -291,7 +291,7 @@ ProxyShape* RigidBody::addCollisionShape(CollisionShape* collisionShape,
|
|||
// TODO : Maybe this method can directly returns an AABB
|
||||
collisionShape->getLocalBounds(localBoundsMin, localBoundsMax);
|
||||
|
||||
ProxyShapesComponents::ProxyShapeComponent proxyShapeComponent(proxyShape, proxyShape->getBroadPhaseId(),
|
||||
ProxyShapesComponents::ProxyShapeComponent proxyShapeComponent(proxyShape, -1,
|
||||
AABB(localBoundsMin, localBoundsMax),
|
||||
transform, collisionShape, mass);
|
||||
mWorld.mProxyShapesComponents.addComponent(mEntity, mIsSleeping, proxyShapeComponent);
|
||||
|
|
|
@ -48,9 +48,9 @@ using namespace std;
|
|||
|
||||
|
||||
// Constructor
|
||||
CollisionDetection::CollisionDetection(CollisionWorld* world, MemoryManager& memoryManager)
|
||||
: mMemoryManager(memoryManager), mCollisionDispatch(mMemoryManager.getPoolAllocator()), mWorld(world),
|
||||
mOverlappingPairs(mMemoryManager.getPoolAllocator()), mBroadPhaseAlgorithm(*this),
|
||||
CollisionDetection::CollisionDetection(CollisionWorld* world, ProxyShapesComponents& proxyShapesComponents, MemoryManager& memoryManager)
|
||||
: mMemoryManager(memoryManager), mProxyShapesComponents(proxyShapesComponents), mCollisionDispatch(mMemoryManager.getPoolAllocator()), mWorld(world),
|
||||
mOverlappingPairs(mMemoryManager.getPoolAllocator()), mBroadPhaseAlgorithm(*this, mProxyShapesComponents),
|
||||
mNoCollisionPairs(mMemoryManager.getPoolAllocator()), mIsCollisionShapesAdded(false),
|
||||
mNarrowPhaseInput(mMemoryManager.getSingleFrameAllocator()) {
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "collision/narrowphase/CollisionDispatch.h"
|
||||
#include "containers/Map.h"
|
||||
#include "containers/Set.h"
|
||||
#include "components/ProxyShapesComponents.h"
|
||||
|
||||
/// ReactPhysics3D namespace
|
||||
namespace reactphysics3d {
|
||||
|
@ -67,6 +68,9 @@ class CollisionDetection {
|
|||
/// Memory manager
|
||||
MemoryManager& mMemoryManager;
|
||||
|
||||
/// Reference the the proxy-shapes components
|
||||
ProxyShapesComponents& mProxyShapesComponents;
|
||||
|
||||
/// Collision Detection Dispatch configuration
|
||||
CollisionDispatch mCollisionDispatch;
|
||||
|
||||
|
@ -145,7 +149,7 @@ class CollisionDetection {
|
|||
// -------------------- Methods -------------------- //
|
||||
|
||||
/// Constructor
|
||||
CollisionDetection(CollisionWorld* world, MemoryManager& memoryManager);
|
||||
CollisionDetection(CollisionWorld* world, ProxyShapesComponents& proxyShapesComponents, MemoryManager& memoryManager);
|
||||
|
||||
/// Destructor
|
||||
~CollisionDetection() = default;
|
||||
|
|
|
@ -41,7 +41,7 @@ using namespace reactphysics3d;
|
|||
*/
|
||||
ProxyShape::ProxyShape(CollisionBody* body, MemoryManager& memoryManager)
|
||||
:mMemoryManager(memoryManager), mBody(body),
|
||||
mNext(nullptr), mBroadPhaseID(-1), mUserData(nullptr), mCollisionCategoryBits(0x0001), mCollideWithMaskBits(0xFFFF) {
|
||||
mNext(nullptr), mUserData(nullptr), mCollisionCategoryBits(0x0001), mCollideWithMaskBits(0xFFFF) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -79,8 +79,10 @@ bool ProxyShape::testPointInside(const Vector3& worldPoint) {
|
|||
void ProxyShape::setCollisionCategoryBits(unsigned short collisionCategoryBits) {
|
||||
mCollisionCategoryBits = collisionCategoryBits;
|
||||
|
||||
int broadPhaseId = mBody->mWorld.mProxyShapesComponents.getBroadPhaseId(this);
|
||||
|
||||
RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::ProxyShape,
|
||||
"ProxyShape " + std::to_string(mBroadPhaseID) + ": Set collisionCategoryBits=" +
|
||||
"ProxyShape " + std::to_string(broadPhaseId) + ": Set collisionCategoryBits=" +
|
||||
std::to_string(mCollisionCategoryBits));
|
||||
}
|
||||
|
||||
|
@ -91,8 +93,10 @@ void ProxyShape::setCollisionCategoryBits(unsigned short collisionCategoryBits)
|
|||
void ProxyShape::setCollideWithMaskBits(unsigned short collideWithMaskBits) {
|
||||
mCollideWithMaskBits = collideWithMaskBits;
|
||||
|
||||
int broadPhaseId = mBody->mWorld.mProxyShapesComponents.getBroadPhaseId(this);
|
||||
|
||||
RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::ProxyShape,
|
||||
"ProxyShape " + std::to_string(mBroadPhaseID) + ": Set collideWithMaskBits=" +
|
||||
"ProxyShape " + std::to_string(broadPhaseId) + ": Set collideWithMaskBits=" +
|
||||
std::to_string(mCollideWithMaskBits));
|
||||
}
|
||||
|
||||
|
@ -107,8 +111,10 @@ void ProxyShape::setLocalToBodyTransform(const Transform& transform) {
|
|||
// Notify the body that the proxy shape has to be updated in the broad-phase
|
||||
mBody->updateProxyShapeInBroadPhase(this, true);
|
||||
|
||||
int broadPhaseId = mBody->mWorld.mProxyShapesComponents.getBroadPhaseId(this);
|
||||
|
||||
RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::ProxyShape,
|
||||
"ProxyShape " + std::to_string(mBroadPhaseID) + ": Set localToBodyTransform=" +
|
||||
"ProxyShape " + std::to_string(broadPhaseId) + ": Set localToBodyTransform=" +
|
||||
transform.to_string());
|
||||
}
|
||||
|
||||
|
@ -139,6 +145,11 @@ CollisionShape* ProxyShape::getCollisionShape() {
|
|||
return mBody->mWorld.mProxyShapesComponents.getCollisionShape(this);
|
||||
}
|
||||
|
||||
// Return the broad-phase id
|
||||
int ProxyShape::getBroadPhaseId() const {
|
||||
return mBody->mWorld.mProxyShapesComponents.getBroadPhaseId(this);
|
||||
}
|
||||
|
||||
// Return the local to parent body transform
|
||||
/**
|
||||
* @return The transformation that transforms the local-space of the collision shape
|
||||
|
|
|
@ -70,7 +70,7 @@ class ProxyShape {
|
|||
ProxyShape* mNext;
|
||||
|
||||
/// Broad-phase ID (node ID in the dynamic AABB tree)
|
||||
int mBroadPhaseID;
|
||||
//int mBroadPhaseID;
|
||||
|
||||
/// Pointer to user data
|
||||
void* mUserData;
|
||||
|
@ -265,11 +265,6 @@ inline unsigned short ProxyShape::getCollideWithMaskBits() const {
|
|||
return mCollideWithMaskBits;
|
||||
}
|
||||
|
||||
// Return the broad-phase id
|
||||
inline int ProxyShape::getBroadPhaseId() const {
|
||||
return mBroadPhaseID;
|
||||
}
|
||||
|
||||
/// Test if the proxy shape overlaps with a given AABB
|
||||
/**
|
||||
* @param worldAABB The AABB (in world-space coordinates) that will be used to test overlap
|
||||
|
|
|
@ -29,13 +29,15 @@
|
|||
#include "utils/Profiler.h"
|
||||
#include "collision/RaycastInfo.h"
|
||||
#include "memory/MemoryManager.h"
|
||||
#include "engine/CollisionWorld.h"
|
||||
|
||||
// We want to use the ReactPhysics3D namespace
|
||||
using namespace reactphysics3d;
|
||||
|
||||
// Constructor
|
||||
BroadPhaseAlgorithm::BroadPhaseAlgorithm(CollisionDetection& collisionDetection)
|
||||
BroadPhaseAlgorithm::BroadPhaseAlgorithm(CollisionDetection& collisionDetection, ProxyShapesComponents& proxyShapesComponents)
|
||||
:mDynamicAABBTree(collisionDetection.getMemoryManager().getPoolAllocator(), DYNAMIC_TREE_AABB_GAP),
|
||||
mProxyShapesComponents(proxyShapesComponents),
|
||||
mMovedShapes(collisionDetection.getMemoryManager().getPoolAllocator()),
|
||||
mPotentialPairs(collisionDetection.getMemoryManager().getPoolAllocator()),
|
||||
mCollisionDetection(collisionDetection) {
|
||||
|
@ -82,7 +84,7 @@ void BroadPhaseAlgorithm::addProxyCollisionShape(ProxyShape* proxyShape, const A
|
|||
int nodeId = mDynamicAABBTree.addObject(aabb, proxyShape);
|
||||
|
||||
// Set the broad-phase ID of the proxy shape
|
||||
proxyShape->mBroadPhaseID = nodeId;
|
||||
mProxyShapesComponents.setBroadPhaseId(proxyShape, nodeId);
|
||||
|
||||
// Add the collision shape into the array of bodies that have moved (or have been created)
|
||||
// during the last simulation step
|
||||
|
@ -96,7 +98,7 @@ void BroadPhaseAlgorithm::removeProxyCollisionShape(ProxyShape* proxyShape) {
|
|||
|
||||
int broadPhaseID = proxyShape->getBroadPhaseId();
|
||||
|
||||
proxyShape->mBroadPhaseID = -1;
|
||||
mProxyShapesComponents.setBroadPhaseId(proxyShape, -1);
|
||||
|
||||
// Remove the collision shape from the dynamic AABB tree
|
||||
mDynamicAABBTree.removeObject(broadPhaseID);
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "DynamicAABBTree.h"
|
||||
#include "containers/LinkedList.h"
|
||||
#include "containers/Set.h"
|
||||
#include "components/ProxyShapesComponents.h"
|
||||
|
||||
/// Namespace ReactPhysics3D
|
||||
namespace reactphysics3d {
|
||||
|
@ -140,6 +141,9 @@ class BroadPhaseAlgorithm {
|
|||
/// Dynamic AABB tree
|
||||
DynamicAABBTree mDynamicAABBTree;
|
||||
|
||||
/// Reference to the proxy-shapes components
|
||||
ProxyShapesComponents& mProxyShapesComponents;
|
||||
|
||||
/// Set with the broad-phase IDs of all collision shapes that have moved (or have been
|
||||
/// created) during the last simulation step. Those are the shapes that need to be tested
|
||||
/// for overlapping in the next simulation step.
|
||||
|
@ -163,7 +167,7 @@ class BroadPhaseAlgorithm {
|
|||
// -------------------- Methods -------------------- //
|
||||
|
||||
/// Constructor
|
||||
BroadPhaseAlgorithm(CollisionDetection& collisionDetection);
|
||||
BroadPhaseAlgorithm(CollisionDetection& collisionDetection, ProxyShapesComponents& proxyShapesComponents);
|
||||
|
||||
/// Destructor
|
||||
~BroadPhaseAlgorithm() = default;
|
||||
|
|
|
@ -194,6 +194,12 @@ class ProxyShapesComponents {
|
|||
|
||||
/// Return a pointer to the collision shape of a proxy-shape
|
||||
CollisionShape* getCollisionShape(const ProxyShape* proxyShape) const;
|
||||
|
||||
/// Return the broad-phase id of a given proxy shape
|
||||
int getBroadPhaseId(const ProxyShape* proxyShape) const;
|
||||
|
||||
/// Set the broad-phase id of a given proxy shape
|
||||
void setBroadPhaseId(const ProxyShape* proxyShape, int broadPhaseId);
|
||||
};
|
||||
|
||||
// Return the mass of a proxy-shape
|
||||
|
@ -227,6 +233,23 @@ inline CollisionShape* ProxyShapesComponents::getCollisionShape(const ProxyShape
|
|||
|
||||
return mCollisionShapes[mMapProxyShapeToComponentIndex[proxyShape]];
|
||||
}
|
||||
|
||||
// Return the broad-phase id of a given proxy shape
|
||||
inline int ProxyShapesComponents::getBroadPhaseId(const ProxyShape* proxyShape) const {
|
||||
|
||||
assert(mMapProxyShapeToComponentIndex.containsKey(proxyShape));
|
||||
|
||||
return mBroadPhaseIds[mMapProxyShapeToComponentIndex[proxyShape]];
|
||||
}
|
||||
|
||||
// Set the broad-phase id of a given proxy shape
|
||||
inline void ProxyShapesComponents::setBroadPhaseId(const ProxyShape* proxyShape, int broadPhaseId) {
|
||||
|
||||
assert(mMapProxyShapeToComponentIndex.containsKey(proxyShape));
|
||||
|
||||
mBroadPhaseIds[mMapProxyShapeToComponentIndex[proxyShape]] = broadPhaseId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -39,7 +39,7 @@ uint CollisionWorld::mNbWorlds = 0;
|
|||
CollisionWorld::CollisionWorld(const WorldSettings& worldSettings, Logger* logger, Profiler* profiler)
|
||||
: mConfig(worldSettings), mEntityManager(mMemoryManager.getPoolAllocator()),
|
||||
mTransformComponents(mMemoryManager.getBaseAllocator()), mProxyShapesComponents(mMemoryManager.getBaseAllocator()),
|
||||
mCollisionDetection(this, mMemoryManager), mBodies(mMemoryManager.getPoolAllocator()), mCurrentBodyId(0),
|
||||
mCollisionDetection(this, mProxyShapesComponents, mMemoryManager), mBodies(mMemoryManager.getPoolAllocator()), mCurrentBodyId(0),
|
||||
mFreeBodiesIds(mMemoryManager.getPoolAllocator()), mEventListener(nullptr), mName(worldSettings.worldName),
|
||||
mIsProfilerCreatedByUser(profiler != nullptr),
|
||||
mIsLoggerCreatedByUser(logger != nullptr) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user