Replacing ProxyShape data by corresponding component data

This commit is contained in:
Daniel Chappuis 2019-01-11 07:38:55 +01:00
parent 176186e126
commit 9fb8580830
5 changed files with 62 additions and 50 deletions

View File

@ -77,14 +77,13 @@ ProxyShape* CollisionBody::addCollisionShape(CollisionShape* collisionShape,
// Create a new proxy collision shape to attach the collision shape to the body
ProxyShape* proxyShape = new (mWorld.mMemoryManager.allocate(MemoryManager::AllocationType::Pool,
sizeof(ProxyShape))) ProxyShape(this, collisionShape,
mWorld.mMemoryManager);
sizeof(ProxyShape))) ProxyShape(this, mWorld.mMemoryManager);
// Add the proxy-shape component to the entity of the body
Vector3 localBoundsMin;
Vector3 localBoundsMax;
// TODO : Maybe this method can directly returns an AABB
proxyShape->getCollisionShape()->getLocalBounds(localBoundsMin, localBoundsMax);
collisionShape->getLocalBounds(localBoundsMin, localBoundsMax);
ProxyShapesComponents::ProxyShapeComponent proxyShapeComponent(proxyShape, proxyShape->getBroadPhaseId(),
AABB(localBoundsMin, localBoundsMax),

View File

@ -283,14 +283,13 @@ ProxyShape* RigidBody::addCollisionShape(CollisionShape* collisionShape,
// Create a new proxy collision shape to attach the collision shape to the body
ProxyShape* proxyShape = new (mWorld.mMemoryManager.allocate(MemoryManager::AllocationType::Pool,
sizeof(ProxyShape))) ProxyShape(this, collisionShape,
mWorld.mMemoryManager);
sizeof(ProxyShape))) ProxyShape(this, mWorld.mMemoryManager);
// Add the proxy-shape component to the entity of the body
Vector3 localBoundsMin;
Vector3 localBoundsMax;
// TODO : Maybe this method can directly returns an AABB
proxyShape->getCollisionShape()->getLocalBounds(localBoundsMin, localBoundsMax);
collisionShape->getLocalBounds(localBoundsMin, localBoundsMax);
ProxyShapesComponents::ProxyShapeComponent proxyShapeComponent(proxyShape, proxyShape->getBroadPhaseId(),
AABB(localBoundsMin, localBoundsMax),

View File

@ -39,8 +39,8 @@ using namespace reactphysics3d;
* @param transform Transformation from collision shape local-space to body local-space
* @param mass Mass of the collision shape (in kilograms)
*/
ProxyShape::ProxyShape(CollisionBody* body, CollisionShape* shape, MemoryManager& memoryManager)
:mMemoryManager(memoryManager), mBody(body), mCollisionShape(shape),
ProxyShape::ProxyShape(CollisionBody* body, MemoryManager& memoryManager)
:mMemoryManager(memoryManager), mBody(body),
mNext(nullptr), mBroadPhaseID(-1), mUserData(nullptr), mCollisionCategoryBits(0x0001), mCollideWithMaskBits(0xFFFF) {
}
@ -68,7 +68,8 @@ bool ProxyShape::testPointInside(const Vector3& worldPoint) {
const Transform localToWorld = mBody->mWorld.mTransformComponents.getTransform(mBody->getEntity()) *
mBody->mWorld.mProxyShapesComponents.getLocalToBodyTransform(this);
const Vector3 localPoint = localToWorld.getInverse() * worldPoint;
return mCollisionShape->testPointInside(localPoint, this);
const CollisionShape* collisionShape = mBody->mWorld.mProxyShapesComponents.getCollisionShape(this);
return collisionShape->testPointInside(localPoint, this);
}
// Set the collision category bits
@ -111,6 +112,33 @@ void ProxyShape::setLocalToBodyTransform(const Transform& transform) {
transform.to_string());
}
// Return the AABB of the proxy shape in world-space
/**
* @return The AABB of the proxy shape in world-space
*/
const AABB ProxyShape::getWorldAABB() const {
AABB aabb;
CollisionShape* collisionShape = mBody->mWorld.mProxyShapesComponents.getCollisionShape(this);
collisionShape->computeAABB(aabb, getLocalToWorldTransform());
return aabb;
}
// Return the collision shape
/**
* @return Pointer to the internal collision shape
*/
const CollisionShape* ProxyShape::getCollisionShape() const {
return mBody->mWorld.mProxyShapesComponents.getCollisionShape(this);
}
// Return the collision shape
/**
* @return Pointer to the internal collision shape
*/
CollisionShape* ProxyShape::getCollisionShape() {
return mBody->mWorld.mProxyShapesComponents.getCollisionShape(this);
}
// Return the local to parent body transform
/**
* @return The transformation that transforms the local-space of the collision shape
@ -139,7 +167,8 @@ bool ProxyShape::raycast(const Ray& ray, RaycastInfo& raycastInfo) {
worldToLocalTransform * ray.point2,
ray.maxFraction);
bool isHit = mCollisionShape->raycast(rayLocal, raycastInfo, this, mMemoryManager.getPoolAllocator());
const CollisionShape* collisionShape = mBody->mWorld.mProxyShapesComponents.getCollisionShape(this);
bool isHit = collisionShape->raycast(rayLocal, raycastInfo, this, mMemoryManager.getPoolAllocator());
// Convert the raycast info into world-space
raycastInfo.worldPoint = localToWorldTransform * raycastInfo.worldPoint;
@ -159,3 +188,16 @@ const Transform ProxyShape::getLocalToWorldTransform() const {
mBody->mWorld.mProxyShapesComponents.getLocalToBodyTransform(this);
}
#ifdef IS_PROFILING_ACTIVE
// Set the profiler
void ProxyShape::setProfiler(Profiler* profiler) {
mProfiler = profiler;
CollisionShape* collisionShape = mBody->mWorld.mProxyShapesComponents.getCollisionShape(this);
collisionShape->setProfiler(profiler);
}
#endif

View File

@ -58,7 +58,7 @@ class ProxyShape {
CollisionBody* mBody;
/// Internal collision shape
CollisionShape* mCollisionShape;
//CollisionShape* mCollisionShape;
/// Local-space to parent body-space transform (does not change over time)
//Transform mLocalToBodyTransform;
@ -111,7 +111,7 @@ class ProxyShape {
// -------------------- Methods -------------------- //
/// Constructor
ProxyShape(CollisionBody* body, CollisionShape* shape, MemoryManager& memoryManager);
ProxyShape(CollisionBody* body, MemoryManager& memoryManager);
/// Destructor
virtual ~ProxyShape();
@ -209,22 +209,6 @@ class ProxyShape {
};
// Return the collision shape
/**
* @return Pointer to the internal collision shape
*/
inline const CollisionShape* ProxyShape::getCollisionShape() const {
return mCollisionShape;
}
// Return the collision shape
/**
* @return Pointer to the internal collision shape
*/
inline CollisionShape* ProxyShape::getCollisionShape() {
return mCollisionShape;
}
// Return the parent body
/**
* @return Pointer to the parent body
@ -249,16 +233,6 @@ inline void ProxyShape::setUserData(void* userData) {
mUserData = userData;
}
// Return the AABB of the proxy shape in world-space
/**
* @return The AABB of the proxy shape in world-space
*/
inline const AABB ProxyShape::getWorldAABB() const {
AABB aabb;
mCollisionShape->computeAABB(aabb, getLocalToWorldTransform());
return aabb;
}
// Return the next proxy shape in the linked list of proxy shapes
/**
* @return Pointer to the next proxy shape in the linked list of proxy shapes
@ -305,18 +279,6 @@ inline bool ProxyShape::testAABBOverlap(const AABB& worldAABB) const {
return worldAABB.testCollision(getWorldAABB());
}
#ifdef IS_PROFILING_ACTIVE
// Set the profiler
inline void ProxyShape::setProfiler(Profiler* profiler) {
mProfiler = profiler;
mCollisionShape->setProfiler(profiler);
}
#endif
#ifdef IS_LOGGING_ACTIVE
// Set the logger

View File

@ -191,6 +191,9 @@ class ProxyShapesComponents {
/// Set the local-to-body transform of a proxy-shape
void setLocalToBodyTransform(const ProxyShape* proxyShape, const Transform& transform);
/// Return a pointer to the collision shape of a proxy-shape
CollisionShape* getCollisionShape(const ProxyShape* proxyShape) const;
};
// Return the mass of a proxy-shape
@ -217,6 +220,13 @@ inline void ProxyShapesComponents::setLocalToBodyTransform(const ProxyShape* pro
mLocalToBodyTransforms[mMapProxyShapeToComponentIndex[proxyShape]] = transform;
}
// Return a pointer to the collision shape of a proxy-shape
inline CollisionShape* ProxyShapesComponents::getCollisionShape(const ProxyShape* proxyShape) const {
assert(mMapProxyShapeToComponentIndex.containsKey(proxyShape));
return mCollisionShapes[mMapProxyShapeToComponentIndex[proxyShape]];
}
}
#endif