Rename ProxyShape to Collider
This commit is contained in:
parent
5df91f2338
commit
b0fde22678
|
@ -18,6 +18,7 @@
|
|||
- An instance of the ConcaveMeshShape class cannot be instanciated directly anymore. You need to use the PhysicsCommon::createConcaveMeshShape() method.
|
||||
- An instance of the PolyhedronMesh class cannot be instanciated directly anymore. You need to use the PhysicsCommon::createPolyhedronMesh() method.
|
||||
- An instance of the TriangleMesh class cannot be instanciated directly anymore. You need to use the PhysicsCommon::createTriangleMesh() method.
|
||||
- The ProxyShape class has been renamed to Collider. The CollisionBody::addCollider(), RigidBody::addCollider() methods have to be used to create and add a collider to a body. Then methods CollisionBody::removeCollider(), RigidBody::removeCollider() need to be used to remove a collider.
|
||||
|
||||
### Removed
|
||||
|
||||
|
|
|
@ -112,7 +112,7 @@ SET (REACTPHYSICS3D_HEADERS
|
|||
"src/collision/shapes/ConcaveMeshShape.h"
|
||||
"src/collision/shapes/HeightFieldShape.h"
|
||||
"src/collision/RaycastInfo.h"
|
||||
"src/collision/ProxyShape.h"
|
||||
"src/collision/Collider.h"
|
||||
"src/collision/TriangleVertexArray.h"
|
||||
"src/collision/PolygonVertexArray.h"
|
||||
"src/collision/TriangleMesh.h"
|
||||
|
@ -149,7 +149,7 @@ SET (REACTPHYSICS3D_HEADERS
|
|||
"src/components/CollisionBodyComponents.h"
|
||||
"src/components/RigidBodyComponents.h"
|
||||
"src/components/TransformComponents.h"
|
||||
"src/components/ProxyShapeComponents.h"
|
||||
"src/components/ColliderComponents.h"
|
||||
"src/components/JointComponents.h"
|
||||
"src/components/BallAndSocketJointComponents.h"
|
||||
"src/components/FixedJointComponents.h"
|
||||
|
@ -216,7 +216,7 @@ SET (REACTPHYSICS3D_SOURCES
|
|||
"src/collision/shapes/ConcaveMeshShape.cpp"
|
||||
"src/collision/shapes/HeightFieldShape.cpp"
|
||||
"src/collision/RaycastInfo.cpp"
|
||||
"src/collision/ProxyShape.cpp"
|
||||
"src/collision/Collider.cpp"
|
||||
"src/collision/TriangleVertexArray.cpp"
|
||||
"src/collision/PolygonVertexArray.cpp"
|
||||
"src/collision/TriangleMesh.cpp"
|
||||
|
@ -251,7 +251,7 @@ SET (REACTPHYSICS3D_SOURCES
|
|||
"src/components/CollisionBodyComponents.cpp"
|
||||
"src/components/RigidBodyComponents.cpp"
|
||||
"src/components/TransformComponents.cpp"
|
||||
"src/components/ProxyShapeComponents.cpp"
|
||||
"src/components/ColliderComponents.cpp"
|
||||
"src/components/JointComponents.cpp"
|
||||
"src/components/BallAndSocketJointComponents.cpp"
|
||||
"src/components/FixedJointComponents.cpp"
|
||||
|
|
|
@ -57,55 +57,52 @@ CollisionBody::~CollisionBody() {
|
|||
|
||||
}
|
||||
|
||||
// Add a collision shape to the body. Note that you can share a collision
|
||||
// shape between several bodies using the same collision shape instance to
|
||||
// when you add the shape to the different bodies. Do not forget to delete
|
||||
// the collision shape you have created at the end of your program.
|
||||
/// This method will return a pointer to a new proxy shape. A proxy shape is
|
||||
/// an object that links a collision shape and a given body. You can use the
|
||||
/// returned proxy shape to get and set information about the corresponding
|
||||
// Create a new collider and add it to the body
|
||||
/// This method will return a pointer to a new collider. A collider is
|
||||
/// an object with a collision shape that is attached to a body. It is possible to
|
||||
/// attach multiple colliders to a given body. You can use the
|
||||
/// returned collider to get and set information about the corresponding
|
||||
/// collision shape for that body.
|
||||
/**
|
||||
* @param collisionShape A pointer to the collision shape you want to add to the body
|
||||
* @param transform The transformation of the collision shape that transforms the
|
||||
* local-space of the collision shape into the local-space of the body
|
||||
* @return A pointer to the proxy shape that has been created to link the body to
|
||||
* the new collision shape you have added.
|
||||
* @param collisionShape A pointer to the collision shape of the new collider
|
||||
* @param transform The transformation of the collider that transforms the
|
||||
* local-space of the collider into the local-space of the body
|
||||
* @return A pointer to the collider that has been created
|
||||
*/
|
||||
ProxyShape* CollisionBody::addCollisionShape(CollisionShape* collisionShape, const Transform& transform) {
|
||||
Collider* CollisionBody::addCollider(CollisionShape* collisionShape, const Transform& transform) {
|
||||
|
||||
// Create a new entity for the proxy-shape
|
||||
Entity proxyShapeEntity = mWorld.mEntityManager.createEntity();
|
||||
// Create a new entity for the collider
|
||||
Entity colliderEntity = mWorld.mEntityManager.createEntity();
|
||||
|
||||
// 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(proxyShapeEntity, this, mWorld.mMemoryManager);
|
||||
// Create a new collider to attach the collision shape to the body
|
||||
Collider* collider = new (mWorld.mMemoryManager.allocate(MemoryManager::AllocationType::Pool,
|
||||
sizeof(Collider))) Collider(colliderEntity, this, mWorld.mMemoryManager);
|
||||
|
||||
// Add the proxy-shape component to the entity of the body
|
||||
// Add the collider component to the entity of the body
|
||||
Vector3 localBoundsMin;
|
||||
Vector3 localBoundsMax;
|
||||
// TODO : Maybe this method can directly returns an AABB
|
||||
collisionShape->getLocalBounds(localBoundsMin, localBoundsMax);
|
||||
const Transform localToWorldTransform = mWorld.mTransformComponents.getTransform(mEntity) * transform;
|
||||
ProxyShapeComponents::ProxyShapeComponent proxyShapeComponent(mEntity, proxyShape,
|
||||
ColliderComponents::ColliderComponent colliderComponent(mEntity, collider,
|
||||
AABB(localBoundsMin, localBoundsMax),
|
||||
transform, collisionShape, decimal(1), 0x0001, 0xFFFF, localToWorldTransform);
|
||||
bool isActive = mWorld.mCollisionBodyComponents.getIsActive(mEntity);
|
||||
mWorld.mProxyShapesComponents.addComponent(proxyShapeEntity, !isActive, proxyShapeComponent);
|
||||
mWorld.mCollidersComponents.addComponent(colliderEntity, !isActive, colliderComponent);
|
||||
|
||||
mWorld.mCollisionBodyComponents.addProxyShapeToBody(mEntity, proxyShapeEntity);
|
||||
mWorld.mCollisionBodyComponents.addColliderToBody(mEntity, colliderEntity);
|
||||
|
||||
#ifdef IS_PROFILING_ACTIVE
|
||||
|
||||
// Set the profiler
|
||||
proxyShape->setProfiler(mProfiler);
|
||||
collider->setProfiler(mProfiler);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef IS_LOGGING_ACTIVE
|
||||
|
||||
// Set the logger
|
||||
proxyShape->setLogger(mLogger);
|
||||
collider->setLogger(mLogger);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -114,94 +111,92 @@ ProxyShape* CollisionBody::addCollisionShape(CollisionShape* collisionShape, con
|
|||
collisionShape->computeAABB(aabb, mWorld.mTransformComponents.getTransform(mEntity) * transform);
|
||||
|
||||
// Notify the collision detection about this new collision shape
|
||||
mWorld.mCollisionDetection.addProxyCollisionShape(proxyShape, aabb);
|
||||
mWorld.mCollisionDetection.addCollider(collider, aabb);
|
||||
|
||||
RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::Body,
|
||||
"Body " + std::to_string(mEntity.id) + ": Proxy shape " + std::to_string(proxyShape->getBroadPhaseId()) + " added to body");
|
||||
"Body " + std::to_string(mEntity.id) + ": Collider " + std::to_string(collider->getBroadPhaseId()) + " added to body");
|
||||
|
||||
RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::ProxyShape,
|
||||
"ProxyShape " + std::to_string(proxyShape->getBroadPhaseId()) + ": collisionShape=" +
|
||||
proxyShape->getCollisionShape()->to_string());
|
||||
RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::Collider,
|
||||
"Collider " + std::to_string(collider->getBroadPhaseId()) + ": collisionShape=" +
|
||||
collider->getCollisionShape()->to_string());
|
||||
|
||||
// Return a pointer to the collision shape
|
||||
return proxyShape;
|
||||
return collider;
|
||||
}
|
||||
|
||||
// Return the number of proxy-shapes associated with this body
|
||||
// Return the number of colliders associated with this body
|
||||
/**
|
||||
* @return The number of proxy-shapes associated with this body
|
||||
* @return The number of colliders associated with this body
|
||||
*/
|
||||
uint CollisionBody::getNbProxyShapes() const {
|
||||
return static_cast<uint>(mWorld.mCollisionBodyComponents.getProxyShapes(mEntity).size());
|
||||
uint CollisionBody::getNbColliders() const {
|
||||
return static_cast<uint>(mWorld.mCollisionBodyComponents.getColliders(mEntity).size());
|
||||
}
|
||||
|
||||
// Return a const pointer to a given proxy-shape of the body
|
||||
// Return a const pointer to a given collider of the body
|
||||
/**
|
||||
* @return The const pointer of a given proxy-shape of the body
|
||||
* @return The const pointer of a given collider of the body
|
||||
*/
|
||||
const ProxyShape* CollisionBody::getProxyShape(uint proxyShapeIndex) const {
|
||||
const Collider* CollisionBody::getCollider(uint colliderIndex) const {
|
||||
|
||||
assert(proxyShapeIndex < getNbProxyShapes());
|
||||
assert(colliderIndex < getNbColliders());
|
||||
|
||||
Entity proxyShapeEntity = mWorld.mCollisionBodyComponents.getProxyShapes(mEntity)[proxyShapeIndex];
|
||||
Entity colliderEntity = mWorld.mCollisionBodyComponents.getColliders(mEntity)[colliderIndex];
|
||||
|
||||
return mWorld.mProxyShapesComponents.getProxyShape(proxyShapeEntity);
|
||||
return mWorld.mCollidersComponents.getCollider(colliderEntity);
|
||||
}
|
||||
|
||||
// Return a pointer to a given proxy-shape of the body
|
||||
// Return a pointer to a given collider of the body
|
||||
/**
|
||||
* @return The pointer of a given proxy-shape of the body
|
||||
* @return The pointer of a given collider of the body
|
||||
*/
|
||||
ProxyShape* CollisionBody::getProxyShape(uint proxyShapeIndex) {
|
||||
Collider* CollisionBody::getCollider(uint colliderIndex) {
|
||||
|
||||
assert(proxyShapeIndex < getNbProxyShapes());
|
||||
assert(colliderIndex < getNbColliders());
|
||||
|
||||
Entity proxyShapeEntity = mWorld.mCollisionBodyComponents.getProxyShapes(mEntity)[proxyShapeIndex];
|
||||
Entity colliderEntity = mWorld.mCollisionBodyComponents.getColliders(mEntity)[colliderIndex];
|
||||
|
||||
return mWorld.mProxyShapesComponents.getProxyShape(proxyShapeEntity);
|
||||
return mWorld.mCollidersComponents.getCollider(colliderEntity);
|
||||
}
|
||||
|
||||
// Remove a collision shape from the body
|
||||
/// To remove a collision shape, you need to specify the pointer to the proxy
|
||||
/// shape that has been returned when you have added the collision shape to the
|
||||
/// body
|
||||
// Remove a collider from the body
|
||||
/// To remove a collider, you need to specify its pointer
|
||||
/**
|
||||
* @param proxyShape The pointer of the proxy shape you want to remove
|
||||
* @param collider The pointer of the collider you want to remove
|
||||
*/
|
||||
void CollisionBody::removeCollisionShape(ProxyShape* proxyShape) {
|
||||
void CollisionBody::removeCollider(Collider* collider) {
|
||||
|
||||
RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::Body,
|
||||
"Body " + std::to_string(mEntity.id) + ": Proxy shape " + std::to_string(proxyShape->getBroadPhaseId()) + " removed from body");
|
||||
"Body " + std::to_string(mEntity.id) + ": Collider " + std::to_string(collider->getBroadPhaseId()) + " removed from body");
|
||||
|
||||
// Remove the proxy-shape from the broad-phase
|
||||
if (proxyShape->getBroadPhaseId() != -1) {
|
||||
mWorld.mCollisionDetection.removeProxyCollisionShape(proxyShape);
|
||||
// Remove the collider from the broad-phase
|
||||
if (collider->getBroadPhaseId() != -1) {
|
||||
mWorld.mCollisionDetection.removeCollider(collider);
|
||||
}
|
||||
|
||||
mWorld.mCollisionBodyComponents.removeProxyShapeFromBody(mEntity, proxyShape->getEntity());
|
||||
mWorld.mCollisionBodyComponents.removeColliderFromBody(mEntity, collider->getEntity());
|
||||
|
||||
// Remove the proxy-shape component
|
||||
mWorld.mProxyShapesComponents.removeComponent(proxyShape->getEntity());
|
||||
// Remove the collider component
|
||||
mWorld.mCollidersComponents.removeComponent(collider->getEntity());
|
||||
|
||||
// Destroy the entity
|
||||
mWorld.mEntityManager.destroyEntity(proxyShape->getEntity());
|
||||
mWorld.mEntityManager.destroyEntity(collider->getEntity());
|
||||
|
||||
// Call the constructor of the proxy-shape
|
||||
proxyShape->~ProxyShape();
|
||||
// Call the constructor of the collider
|
||||
collider->~Collider();
|
||||
|
||||
// Release allocated memory for the proxy-shape
|
||||
mWorld.mMemoryManager.release(MemoryManager::AllocationType::Pool, proxyShape, sizeof(ProxyShape));
|
||||
// Release allocated memory for the collider
|
||||
mWorld.mMemoryManager.release(MemoryManager::AllocationType::Pool, collider, sizeof(Collider));
|
||||
}
|
||||
|
||||
// Remove all the collision shapes
|
||||
void CollisionBody::removeAllCollisionShapes() {
|
||||
|
||||
// Look for the proxy shape that contains the collision shape in parameter.
|
||||
// Note that we need to copy the list of proxy shapes entities because we are deleting them in a loop.
|
||||
const List<Entity> proxyShapesEntities = mWorld.mCollisionBodyComponents.getProxyShapes(mEntity);
|
||||
for (uint i=0; i < proxyShapesEntities.size(); i++) {
|
||||
// Look for the collider that contains the collision shape in parameter.
|
||||
// Note that we need to copy the list of collider entities because we are deleting them in a loop.
|
||||
const List<Entity> collidersEntities = mWorld.mCollisionBodyComponents.getColliders(mEntity);
|
||||
for (uint i=0; i < collidersEntities.size(); i++) {
|
||||
|
||||
removeCollisionShape(mWorld.mProxyShapesComponents.getProxyShape(proxyShapesEntities[i]));
|
||||
removeCollider(mWorld.mCollidersComponents.getCollider(collidersEntities[i]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -218,17 +213,17 @@ const Transform& CollisionBody::getTransform() const {
|
|||
// Update the broad-phase state for this body (because it has moved for instance)
|
||||
void CollisionBody::updateBroadPhaseState(decimal timeStep) const {
|
||||
|
||||
// For all the proxy collision shapes of the body
|
||||
const List<Entity>& proxyShapesEntities = mWorld.mCollisionBodyComponents.getProxyShapes(mEntity);
|
||||
for (uint i=0; i < proxyShapesEntities.size(); i++) {
|
||||
// For all the colliders of the body
|
||||
const List<Entity>& colliderEntities = mWorld.mCollisionBodyComponents.getColliders(mEntity);
|
||||
for (uint i=0; i < colliderEntities.size(); i++) {
|
||||
|
||||
// Update the local-to-world transform of the proxy-shape
|
||||
mWorld.mProxyShapesComponents.setLocalToWorldTransform(proxyShapesEntities[i],
|
||||
// Update the local-to-world transform of the collider
|
||||
mWorld.mCollidersComponents.setLocalToWorldTransform(colliderEntities[i],
|
||||
mWorld.mTransformComponents.getTransform(mEntity) *
|
||||
mWorld.mProxyShapesComponents.getLocalToBodyTransform(proxyShapesEntities[i]));
|
||||
mWorld.mCollidersComponents.getLocalToBodyTransform(colliderEntities[i]));
|
||||
|
||||
// Update the proxy
|
||||
mWorld.mCollisionDetection.updateProxyShape(proxyShapesEntities[i], timeStep);
|
||||
// Update the collider
|
||||
mWorld.mCollisionDetection.updateCollider(colliderEntities[i], timeStep);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -248,32 +243,32 @@ void CollisionBody::setIsActive(bool isActive) {
|
|||
|
||||
const Transform& transform = mWorld.mTransformComponents.getTransform(mEntity);
|
||||
|
||||
// For each proxy shape of the body
|
||||
const List<Entity>& proxyShapesEntities = mWorld.mCollisionBodyComponents.getProxyShapes(mEntity);
|
||||
for (uint i=0; i < proxyShapesEntities.size(); i++) {
|
||||
// For each collider of the body
|
||||
const List<Entity>& colliderEntities = mWorld.mCollisionBodyComponents.getColliders(mEntity);
|
||||
for (uint i=0; i < colliderEntities.size(); i++) {
|
||||
|
||||
ProxyShape* proxyShape = mWorld.mProxyShapesComponents.getProxyShape(proxyShapesEntities[i]);
|
||||
Collider* collider = mWorld.mCollidersComponents.getCollider(colliderEntities[i]);
|
||||
|
||||
// Compute the world-space AABB of the new collision shape
|
||||
AABB aabb;
|
||||
proxyShape->getCollisionShape()->computeAABB(aabb, transform * mWorld.mProxyShapesComponents.getLocalToBodyTransform(proxyShape->getEntity()));
|
||||
collider->getCollisionShape()->computeAABB(aabb, transform * mWorld.mCollidersComponents.getLocalToBodyTransform(collider->getEntity()));
|
||||
|
||||
// Add the proxy shape to the collision detection
|
||||
mWorld.mCollisionDetection.addProxyCollisionShape(proxyShape, aabb);
|
||||
// Add the collider to the collision detection
|
||||
mWorld.mCollisionDetection.addCollider(collider, aabb);
|
||||
}
|
||||
}
|
||||
else { // If we have to deactivate the body
|
||||
|
||||
// For each proxy shape of the body
|
||||
const List<Entity>& proxyShapesEntities = mWorld.mCollisionBodyComponents.getProxyShapes(mEntity);
|
||||
for (uint i=0; i < proxyShapesEntities.size(); i++) {
|
||||
// For each collider of the body
|
||||
const List<Entity>& colliderEntities = mWorld.mCollisionBodyComponents.getColliders(mEntity);
|
||||
for (uint i=0; i < colliderEntities.size(); i++) {
|
||||
|
||||
ProxyShape* proxyShape = mWorld.mProxyShapesComponents.getProxyShape(proxyShapesEntities[i]);
|
||||
Collider* collider = mWorld.mCollidersComponents.getCollider(colliderEntities[i]);
|
||||
|
||||
if (proxyShape->getBroadPhaseId() != -1) {
|
||||
if (collider->getBroadPhaseId() != -1) {
|
||||
|
||||
// Remove the proxy shape from the collision detection
|
||||
mWorld.mCollisionDetection.removeProxyCollisionShape(proxyShape);
|
||||
// Remove the collider from the collision detection
|
||||
mWorld.mCollisionDetection.removeCollider(collider);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -287,13 +282,13 @@ void CollisionBody::setIsActive(bool isActive) {
|
|||
// (as if the body has moved).
|
||||
void CollisionBody::askForBroadPhaseCollisionCheck() const {
|
||||
|
||||
// For all the proxy collision shapes of the body
|
||||
const List<Entity>& proxyShapesEntities = mWorld.mCollisionBodyComponents.getProxyShapes(mEntity);
|
||||
for (uint i=0; i < proxyShapesEntities.size(); i++) {
|
||||
// For all the colliders of the body
|
||||
const List<Entity>& colliderEntities = mWorld.mCollisionBodyComponents.getColliders(mEntity);
|
||||
for (uint i=0; i < colliderEntities.size(); i++) {
|
||||
|
||||
ProxyShape* proxyShape = mWorld.mProxyShapesComponents.getProxyShape(proxyShapesEntities[i]);
|
||||
Collider* collider = mWorld.mCollidersComponents.getCollider(colliderEntities[i]);
|
||||
|
||||
mWorld.mCollisionDetection.askForBroadPhaseCollisionCheck(proxyShape);
|
||||
mWorld.mCollisionDetection.askForBroadPhaseCollisionCheck(collider);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -305,14 +300,14 @@ void CollisionBody::askForBroadPhaseCollisionCheck() const {
|
|||
*/
|
||||
bool CollisionBody::testPointInside(const Vector3& worldPoint) const {
|
||||
|
||||
// For each collision shape of the body
|
||||
const List<Entity>& proxyShapesEntities = mWorld.mCollisionBodyComponents.getProxyShapes(mEntity);
|
||||
for (uint i=0; i < proxyShapesEntities.size(); i++) {
|
||||
// For each collider of the body
|
||||
const List<Entity>& colliderEntities = mWorld.mCollisionBodyComponents.getColliders(mEntity);
|
||||
for (uint i=0; i < colliderEntities.size(); i++) {
|
||||
|
||||
ProxyShape* proxyShape = mWorld.mProxyShapesComponents.getProxyShape(proxyShapesEntities[i]);
|
||||
Collider* collider = mWorld.mCollidersComponents.getCollider(colliderEntities[i]);
|
||||
|
||||
// Test if the point is inside the collision shape
|
||||
if (proxyShape->testPointInside(worldPoint)) return true;
|
||||
// Test if the point is inside the collider
|
||||
if (collider->testPointInside(worldPoint)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -334,14 +329,14 @@ bool CollisionBody::raycast(const Ray& ray, RaycastInfo& raycastInfo) {
|
|||
bool isHit = false;
|
||||
Ray rayTemp(ray);
|
||||
|
||||
// For each collision shape of the body
|
||||
const List<Entity>& proxyShapesEntities = mWorld.mCollisionBodyComponents.getProxyShapes(mEntity);
|
||||
for (uint i=0; i < proxyShapesEntities.size(); i++) {
|
||||
// For each collider of the body
|
||||
const List<Entity>& colliderEntities = mWorld.mCollisionBodyComponents.getColliders(mEntity);
|
||||
for (uint i=0; i < colliderEntities.size(); i++) {
|
||||
|
||||
ProxyShape* proxyShape = mWorld.mProxyShapesComponents.getProxyShape(proxyShapesEntities[i]);
|
||||
Collider* collider = mWorld.mCollidersComponents.getCollider(colliderEntities[i]);
|
||||
|
||||
// Test if the ray hits the collision shape
|
||||
if (proxyShape->raycast(rayTemp, raycastInfo)) {
|
||||
// Test if the ray hits the collider
|
||||
if (collider->raycast(rayTemp, raycastInfo)) {
|
||||
rayTemp.maxFraction = raycastInfo.hitFraction;
|
||||
isHit = true;
|
||||
}
|
||||
|
@ -350,7 +345,7 @@ bool CollisionBody::raycast(const Ray& ray, RaycastInfo& raycastInfo) {
|
|||
return isHit;
|
||||
}
|
||||
|
||||
// Compute and return the AABB of the body by merging all proxy shapes AABBs
|
||||
// Compute and return the AABB of the body by merging all colliders AABBs
|
||||
/**
|
||||
* @return The axis-aligned bounding box (AABB) of the body in world-space coordinates
|
||||
*/
|
||||
|
@ -358,24 +353,24 @@ AABB CollisionBody::getAABB() const {
|
|||
|
||||
AABB bodyAABB;
|
||||
|
||||
const List<Entity>& proxyShapesEntities = mWorld.mCollisionBodyComponents.getProxyShapes(mEntity);
|
||||
if (proxyShapesEntities.size() == 0) return bodyAABB;
|
||||
const List<Entity>& colliderEntities = mWorld.mCollisionBodyComponents.getColliders(mEntity);
|
||||
if (colliderEntities.size() == 0) return bodyAABB;
|
||||
|
||||
const Transform& transform = mWorld.mTransformComponents.getTransform(mEntity);
|
||||
|
||||
ProxyShape* proxyShape = mWorld.mProxyShapesComponents.getProxyShape(proxyShapesEntities[0]);
|
||||
proxyShape->getCollisionShape()->computeAABB(bodyAABB, transform * proxyShape->getLocalToBodyTransform());
|
||||
Collider* collider = mWorld.mCollidersComponents.getCollider(colliderEntities[0]);
|
||||
collider->getCollisionShape()->computeAABB(bodyAABB, transform * collider->getLocalToBodyTransform());
|
||||
|
||||
// For each proxy shape of the body
|
||||
for (uint i=1; i < proxyShapesEntities.size(); i++) {
|
||||
// For each collider of the body
|
||||
for (uint i=1; i < colliderEntities.size(); i++) {
|
||||
|
||||
ProxyShape* proxyShape = mWorld.mProxyShapesComponents.getProxyShape(proxyShapesEntities[i]);
|
||||
Collider* collider = mWorld.mCollidersComponents.getCollider(colliderEntities[i]);
|
||||
|
||||
// Compute the world-space AABB of the collision shape
|
||||
// Compute the world-space AABB of the collider
|
||||
AABB aabb;
|
||||
proxyShape->getCollisionShape()->computeAABB(aabb, transform * proxyShape->getLocalToBodyTransform());
|
||||
collider->getCollisionShape()->computeAABB(aabb, transform * collider->getLocalToBodyTransform());
|
||||
|
||||
// Merge the proxy shape AABB with the current body AABB
|
||||
// Merge the collider AABB with the current body AABB
|
||||
bodyAABB.mergeWithAABB(aabb);
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ namespace reactphysics3d {
|
|||
|
||||
// Declarations
|
||||
struct ContactManifoldListElement;
|
||||
class ProxyShape;
|
||||
class Collider;
|
||||
class CollisionWorld;
|
||||
class CollisionShape;
|
||||
struct RaycastInfo;
|
||||
|
@ -125,11 +125,11 @@ class CollisionBody {
|
|||
/// Set the current position and orientation
|
||||
virtual void setTransform(const Transform& transform);
|
||||
|
||||
/// Add a collision shape to the body.
|
||||
virtual ProxyShape* addCollisionShape(CollisionShape* collisionShape, const Transform& transform);
|
||||
/// Create a new collider and add it to the body.
|
||||
virtual Collider* addCollider(CollisionShape* collisionShape, const Transform& transform);
|
||||
|
||||
/// Remove a collision shape from the body
|
||||
virtual void removeCollisionShape(ProxyShape *proxyShape);
|
||||
/// Remove a collider from the body
|
||||
virtual void removeCollider(Collider* collider);
|
||||
|
||||
/// Return true if a point is inside the collision body
|
||||
bool testPointInside(const Vector3& worldPoint) const;
|
||||
|
@ -140,17 +140,17 @@ class CollisionBody {
|
|||
/// Test if the collision body overlaps with a given AABB
|
||||
bool testAABBOverlap(const AABB& worldAABB) const;
|
||||
|
||||
/// Compute and return the AABB of the body by merging all proxy shapes AABBs
|
||||
/// Compute and return the AABB of the body by merging all colliders AABBs
|
||||
AABB getAABB() const;
|
||||
|
||||
/// Return a const pointer to a given proxy-shape of the body
|
||||
const ProxyShape* getProxyShape(uint proxyShapeIndex) const;
|
||||
/// Return a const pointer to a given collider of the body
|
||||
const Collider* getCollider(uint colliderIndex) const;
|
||||
|
||||
/// Return a pointer to a given proxy-shape of the body
|
||||
ProxyShape* getProxyShape(uint proxyShapeIndex);
|
||||
/// Return a pointer to a given collider of the body
|
||||
Collider* getCollider(uint colliderIndex);
|
||||
|
||||
/// Return the number of proxy-shapes associated with this body
|
||||
uint getNbProxyShapes() const;
|
||||
/// Return the number of colliders associated with this body
|
||||
uint getNbColliders() const;
|
||||
|
||||
/// Return the world-space coordinates of a point given the local-space coordinates of the body
|
||||
Vector3 getWorldPoint(const Vector3& localPoint) const;
|
||||
|
@ -184,7 +184,7 @@ class CollisionBody {
|
|||
friend class CollisionDetectionSystem;
|
||||
friend class BroadPhaseAlgorithm;
|
||||
friend class ConvexMeshShape;
|
||||
friend class ProxyShape;
|
||||
friend class Collider;
|
||||
};
|
||||
|
||||
/// Test if the collision body overlaps with a given AABB
|
||||
|
|
|
@ -307,58 +307,53 @@ void RigidBody::setMass(decimal mass) {
|
|||
}
|
||||
|
||||
|
||||
// Add a collision shape to the body.
|
||||
/// When you add a collision shape to the body, an internal copy of this
|
||||
/// collision shape will be created internally. Therefore, you can delete it
|
||||
/// right after calling this method or use it later to add it to another body.
|
||||
/// This method will return a pointer to a new proxy shape. A proxy shape is
|
||||
/// an object that links a collision shape and a given body. You can use the
|
||||
/// returned proxy shape to get and set information about the corresponding
|
||||
// Create a new collider and add it to the body
|
||||
/// This method will return a pointer to a new collider. A collider is
|
||||
/// an object with a collision shape that is attached to a body. It is possible to
|
||||
/// attach multiple colliders to a given body. You can use the
|
||||
/// returned collider to get and set information about the corresponding
|
||||
/// collision shape for that body.
|
||||
/**
|
||||
* @param collisionShape The collision shape you want to add to the body
|
||||
* @param transform The transformation of the collision shape that transforms the
|
||||
* local-space of the collision shape into the local-space of the body
|
||||
* @param mass Mass (in kilograms) of the collision shape you want to add
|
||||
* @return A pointer to the proxy shape that has been created to link the body to
|
||||
* the new collision shape you have added.
|
||||
* @param collisionShape The collision shape of the new collider
|
||||
* @param transform The transformation of the collider that transforms the
|
||||
* local-space of the collider into the local-space of the body
|
||||
* @param mass Mass (in kilograms) of the collider you want to add
|
||||
* @return A pointer to the collider that has been created
|
||||
*/
|
||||
ProxyShape* RigidBody::addCollisionShape(CollisionShape* collisionShape,
|
||||
const Transform& transform,
|
||||
decimal mass) {
|
||||
Collider* RigidBody::addCollider(CollisionShape* collisionShape, const Transform& transform, decimal mass) {
|
||||
|
||||
// Create a new entity for the proxy-shape
|
||||
Entity proxyShapeEntity = mWorld.mEntityManager.createEntity();
|
||||
// Create a new entity for the collider
|
||||
Entity colliderEntity = mWorld.mEntityManager.createEntity();
|
||||
|
||||
// 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(proxyShapeEntity, this, mWorld.mMemoryManager);
|
||||
// Create a new collider for the body
|
||||
Collider* collider = new (mWorld.mMemoryManager.allocate(MemoryManager::AllocationType::Pool,
|
||||
sizeof(Collider))) Collider(colliderEntity, this, mWorld.mMemoryManager);
|
||||
|
||||
// Add the proxy-shape component to the entity of the body
|
||||
// Add the collider component to the entity of the body
|
||||
Vector3 localBoundsMin;
|
||||
Vector3 localBoundsMax;
|
||||
// TODO : Maybe this method can directly returns an AABB
|
||||
collisionShape->getLocalBounds(localBoundsMin, localBoundsMax);
|
||||
const Transform localToWorldTransform = mWorld.mTransformComponents.getTransform(mEntity) * transform;
|
||||
ProxyShapeComponents::ProxyShapeComponent proxyShapeComponent(mEntity, proxyShape,
|
||||
ColliderComponents::ColliderComponent colliderComponent(mEntity, collider,
|
||||
AABB(localBoundsMin, localBoundsMax),
|
||||
transform, collisionShape, mass, 0x0001, 0xFFFF, localToWorldTransform);
|
||||
bool isSleeping = mWorld.mRigidBodyComponents.getIsSleeping(mEntity);
|
||||
mWorld.mProxyShapesComponents.addComponent(proxyShapeEntity, isSleeping, proxyShapeComponent);
|
||||
mWorld.mCollidersComponents.addComponent(colliderEntity, isSleeping, colliderComponent);
|
||||
|
||||
mWorld.mCollisionBodyComponents.addProxyShapeToBody(mEntity, proxyShapeEntity);
|
||||
mWorld.mCollisionBodyComponents.addColliderToBody(mEntity, colliderEntity);
|
||||
|
||||
#ifdef IS_PROFILING_ACTIVE
|
||||
|
||||
// Set the profiler
|
||||
proxyShape->setProfiler(mProfiler);
|
||||
collider->setProfiler(mProfiler);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef IS_LOGGING_ACTIVE
|
||||
|
||||
// Set the logger
|
||||
proxyShape->setLogger(mLogger);
|
||||
collider->setLogger(mLogger);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -367,34 +362,32 @@ ProxyShape* RigidBody::addCollisionShape(CollisionShape* collisionShape,
|
|||
collisionShape->computeAABB(aabb, mWorld.mTransformComponents.getTransform(mEntity) * transform);
|
||||
|
||||
// Notify the collision detection about this new collision shape
|
||||
mWorld.mCollisionDetection.addProxyCollisionShape(proxyShape, aabb);
|
||||
mWorld.mCollisionDetection.addCollider(collider, aabb);
|
||||
|
||||
// Recompute the center of mass, total mass and inertia tensor of the body with the new
|
||||
// collision shape
|
||||
recomputeMassInformation();
|
||||
|
||||
RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::Body,
|
||||
"Body " + std::to_string(mEntity.id) + ": Proxy shape " + std::to_string(proxyShape->getBroadPhaseId()) + " added to body");
|
||||
"Body " + std::to_string(mEntity.id) + ": Collider " + std::to_string(collider->getBroadPhaseId()) + " added to body");
|
||||
|
||||
RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::ProxyShape,
|
||||
"ProxyShape " + std::to_string(proxyShape->getBroadPhaseId()) + ": collisionShape=" +
|
||||
proxyShape->getCollisionShape()->to_string());
|
||||
RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::Collider,
|
||||
"Collider " + std::to_string(collider->getBroadPhaseId()) + ": collisionShape=" +
|
||||
collider->getCollisionShape()->to_string());
|
||||
|
||||
// Return a pointer to the proxy collision shape
|
||||
return proxyShape;
|
||||
// Return a pointer to the collider
|
||||
return collider;
|
||||
}
|
||||
|
||||
// Remove a collision shape from the body
|
||||
/// To remove a collision shape, you need to specify the pointer to the proxy
|
||||
/// shape that has been returned when you have added the collision shape to the
|
||||
/// body
|
||||
// Remove a collider from the body
|
||||
/// To remove a collider, you need to specify its pointer.
|
||||
/**
|
||||
* @param proxyShape The pointer of the proxy shape you want to remove
|
||||
* @param collider The pointer of the collider you want to remove
|
||||
*/
|
||||
void RigidBody::removeCollisionShape(ProxyShape* proxyShape) {
|
||||
void RigidBody::removeCollider(Collider* collider) {
|
||||
|
||||
// Remove the collision shape
|
||||
CollisionBody::removeCollisionShape(proxyShape);
|
||||
CollisionBody::removeCollider(collider);
|
||||
|
||||
// Recompute the total mass, center of mass and inertia tensor
|
||||
recomputeMassInformation();
|
||||
|
@ -540,14 +533,14 @@ void RigidBody::recomputeMassInformation() {
|
|||
assert(mWorld.mRigidBodyComponents.getBodyType(mEntity) == BodyType::DYNAMIC);
|
||||
|
||||
// Compute the total mass of the body
|
||||
const List<Entity>& proxyShapesEntities = mWorld.mCollisionBodyComponents.getProxyShapes(mEntity);
|
||||
for (uint i=0; i < proxyShapesEntities.size(); i++) {
|
||||
ProxyShape* proxyShape = mWorld.mProxyShapesComponents.getProxyShape(proxyShapesEntities[i]);
|
||||
mWorld.mRigidBodyComponents.setInitMass(mEntity, mWorld.mRigidBodyComponents.getInitMass(mEntity) + proxyShape->getMass());
|
||||
const List<Entity>& colliderEntities = mWorld.mCollisionBodyComponents.getColliders(mEntity);
|
||||
for (uint i=0; i < colliderEntities.size(); i++) {
|
||||
Collider* collider = mWorld.mCollidersComponents.getCollider(colliderEntities[i]);
|
||||
mWorld.mRigidBodyComponents.setInitMass(mEntity, mWorld.mRigidBodyComponents.getInitMass(mEntity) + collider->getMass());
|
||||
|
||||
if (!mIsCenterOfMassSetByUser) {
|
||||
mWorld.mRigidBodyComponents.setCenterOfMassLocal(mEntity, mWorld.mRigidBodyComponents.getCenterOfMassLocal(mEntity) +
|
||||
proxyShape->getLocalToBodyTransform().getPosition() * proxyShape->getMass());
|
||||
collider->getLocalToBodyTransform().getPosition() * collider->getMass());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -570,22 +563,22 @@ void RigidBody::recomputeMassInformation() {
|
|||
|
||||
if (!mIsInertiaTensorSetByUser) {
|
||||
|
||||
// Compute the inertia tensor using all the collision shapes
|
||||
const List<Entity>& proxyShapesEntities = mWorld.mCollisionBodyComponents.getProxyShapes(mEntity);
|
||||
for (uint i=0; i < proxyShapesEntities.size(); i++) {
|
||||
// Compute the inertia tensor using all the colliders
|
||||
const List<Entity>& colliderEntities = mWorld.mCollisionBodyComponents.getColliders(mEntity);
|
||||
for (uint i=0; i < colliderEntities.size(); i++) {
|
||||
|
||||
ProxyShape* proxyShape = mWorld.mProxyShapesComponents.getProxyShape(proxyShapesEntities[i]);
|
||||
Collider* collider = mWorld.mCollidersComponents.getCollider(colliderEntities[i]);
|
||||
|
||||
// Get the inertia tensor of the collision shape in its local-space
|
||||
// Get the inertia tensor of the collider in its local-space
|
||||
Matrix3x3 inertiaTensor;
|
||||
proxyShape->getCollisionShape()->computeLocalInertiaTensor(inertiaTensor, proxyShape->getMass());
|
||||
collider->getCollisionShape()->computeLocalInertiaTensor(inertiaTensor, collider->getMass());
|
||||
|
||||
// Convert the collision shape inertia tensor into the local-space of the body
|
||||
const Transform& shapeTransform = proxyShape->getLocalToBodyTransform();
|
||||
// Convert the collider inertia tensor into the local-space of the body
|
||||
const Transform& shapeTransform = collider->getLocalToBodyTransform();
|
||||
Matrix3x3 rotationMatrix = shapeTransform.getOrientation().getMatrix();
|
||||
inertiaTensor = rotationMatrix * inertiaTensor * rotationMatrix.getTranspose();
|
||||
|
||||
// Use the parallel axis theorem to convert the inertia tensor w.r.t the collision shape
|
||||
// Use the parallel axis theorem to convert the inertia tensor w.r.t the collider
|
||||
// center into a inertia tensor w.r.t to the body origin.
|
||||
Vector3 offset = shapeTransform.getPosition() - mWorld.mRigidBodyComponents.getCenterOfMassLocal(mEntity);
|
||||
decimal offsetSquare = offset.lengthSquare();
|
||||
|
@ -596,7 +589,7 @@ void RigidBody::recomputeMassInformation() {
|
|||
offsetMatrix[0] += offset * (-offset.x);
|
||||
offsetMatrix[1] += offset * (-offset.y);
|
||||
offsetMatrix[2] += offset * (-offset.z);
|
||||
offsetMatrix *= proxyShape->getMass();
|
||||
offsetMatrix *= collider->getMass();
|
||||
|
||||
inertiaTensorLocal += inertiaTensor + offsetMatrix;
|
||||
}
|
||||
|
@ -705,12 +698,12 @@ void RigidBody::setIsSleeping(bool isSleeping) {
|
|||
// Update whether the current overlapping pairs where this body is involed are active or not
|
||||
void RigidBody::updateOverlappingPairs() {
|
||||
|
||||
// For each proxy-shape of the body
|
||||
const List<Entity>& proxyShapesEntities = mWorld.mCollisionBodyComponents.getProxyShapes(mEntity);
|
||||
for (uint i=0; i < proxyShapesEntities.size(); i++) {
|
||||
// For each collider of the body
|
||||
const List<Entity>& colliderEntities = mWorld.mCollisionBodyComponents.getColliders(mEntity);
|
||||
for (uint i=0; i < colliderEntities.size(); i++) {
|
||||
|
||||
// Get the currently overlapping pairs for this proxy-shape
|
||||
List<uint64> overlappingPairs = mWorld.mProxyShapesComponents.getOverlappingPairs(proxyShapesEntities[i]);
|
||||
// Get the currently overlapping pairs for this collider
|
||||
List<uint64> overlappingPairs = mWorld.mCollidersComponents.getOverlappingPairs(colliderEntities[i]);
|
||||
|
||||
for (uint j=0; j < overlappingPairs.size(); j++) {
|
||||
|
||||
|
@ -779,13 +772,13 @@ void RigidBody::setProfiler(Profiler* profiler) {
|
|||
|
||||
CollisionBody::setProfiler(profiler);
|
||||
|
||||
// Set the profiler for each proxy shape
|
||||
const List<Entity>& proxyShapesEntities = mWorld.mCollisionBodyComponents.getProxyShapes(mEntity);
|
||||
for (uint i=0; i < proxyShapesEntities.size(); i++) {
|
||||
// Set the profiler for each collider
|
||||
const List<Entity>& colliderEntities = mWorld.mCollisionBodyComponents.getColliders(mEntity);
|
||||
for (uint i=0; i < colliderEntities.size(); i++) {
|
||||
|
||||
ProxyShape* proxyShape = mWorld.mProxyShapesComponents.getProxyShape(proxyShapesEntities[i]);
|
||||
Collider* collider = mWorld.mCollidersComponents.getCollider(colliderEntities[i]);
|
||||
|
||||
proxyShape->setProfiler(profiler);
|
||||
collider->setProfiler(profiler);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -182,15 +182,13 @@ class RigidBody : public CollisionBody {
|
|||
/// Set whether or not the body is active
|
||||
virtual void setIsActive(bool isActive) override;
|
||||
|
||||
/// Add a collision shape to the body.
|
||||
/// Create a new collider and add it to the body
|
||||
// TODO : Remove the mass from this parameter so that we can correctly use inheritance here
|
||||
// The user will then need to call ProxyShape->setMass() to set the mass of the shape
|
||||
virtual ProxyShape* addCollisionShape(CollisionShape* collisionShape,
|
||||
const Transform& transform,
|
||||
decimal mass);
|
||||
// The user will then need to call Collider->setMass() to set the mass of the shape
|
||||
virtual Collider* addCollider(CollisionShape* collisionShape, const Transform& transform, decimal mass);
|
||||
|
||||
/// Remove a collision shape from the body
|
||||
virtual void removeCollisionShape(ProxyShape* proxyShape) override;
|
||||
/// Remove a collider from the body
|
||||
virtual void removeCollider(Collider* collider) override;
|
||||
|
||||
/// Recompute the center of mass, total mass and inertia tensor of the body using all
|
||||
/// the collision shapes attached to the body.
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
********************************************************************************/
|
||||
|
||||
// Libraries
|
||||
#include "ProxyShape.h"
|
||||
#include "Collider.h"
|
||||
#include "utils/Logger.h"
|
||||
#include "collision/RaycastInfo.h"
|
||||
#include "memory/MemoryManager.h"
|
||||
|
@ -39,14 +39,14 @@ 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(Entity entity, CollisionBody* body, MemoryManager& memoryManager)
|
||||
Collider::Collider(Entity entity, CollisionBody* body, MemoryManager& memoryManager)
|
||||
:mMemoryManager(memoryManager), mEntity(entity), mBody(body),
|
||||
mUserData(nullptr) {
|
||||
|
||||
}
|
||||
|
||||
// Destructor
|
||||
ProxyShape::~ProxyShape() {
|
||||
Collider::~Collider() {
|
||||
|
||||
}
|
||||
|
||||
|
@ -54,8 +54,8 @@ ProxyShape::~ProxyShape() {
|
|||
/**
|
||||
* @return Mass of the collision shape (in kilograms)
|
||||
*/
|
||||
decimal ProxyShape::getMass() const {
|
||||
return mBody->mWorld.mProxyShapesComponents.getMass(mEntity);
|
||||
decimal Collider::getMass() const {
|
||||
return mBody->mWorld.mCollidersComponents.getMass(mEntity);
|
||||
}
|
||||
|
||||
|
||||
|
@ -64,30 +64,30 @@ decimal ProxyShape::getMass() const {
|
|||
* @param worldPoint Point to test in world-space coordinates
|
||||
* @return True if the point is inside the collision shape
|
||||
*/
|
||||
bool ProxyShape::testPointInside(const Vector3& worldPoint) {
|
||||
bool Collider::testPointInside(const Vector3& worldPoint) {
|
||||
const Transform localToWorld = mBody->mWorld.mTransformComponents.getTransform(mBody->getEntity()) *
|
||||
mBody->mWorld.mProxyShapesComponents.getLocalToBodyTransform(mEntity);
|
||||
mBody->mWorld.mCollidersComponents.getLocalToBodyTransform(mEntity);
|
||||
const Vector3 localPoint = localToWorld.getInverse() * worldPoint;
|
||||
const CollisionShape* collisionShape = mBody->mWorld.mProxyShapesComponents.getCollisionShape(mEntity);
|
||||
const CollisionShape* collisionShape = mBody->mWorld.mCollidersComponents.getCollisionShape(mEntity);
|
||||
return collisionShape->testPointInside(localPoint, this);
|
||||
}
|
||||
|
||||
// Set the collision category bits
|
||||
/**
|
||||
* @param collisionCategoryBits The collision category bits mask of the proxy shape
|
||||
* @param collisionCategoryBits The collision category bits mask of the collider
|
||||
*/
|
||||
void ProxyShape::setCollisionCategoryBits(unsigned short collisionCategoryBits) {
|
||||
void Collider::setCollisionCategoryBits(unsigned short collisionCategoryBits) {
|
||||
|
||||
// TODO : Here we should probably remove all overlapping pairs with this shape in the
|
||||
// broad-phase and add the shape in the "has moved" shape list so it is reevaluated
|
||||
// with the new mask bits
|
||||
|
||||
mBody->mWorld.mProxyShapesComponents.setCollisionCategoryBits(mEntity, collisionCategoryBits);
|
||||
mBody->mWorld.mCollidersComponents.setCollisionCategoryBits(mEntity, collisionCategoryBits);
|
||||
|
||||
int broadPhaseId = mBody->mWorld.mProxyShapesComponents.getBroadPhaseId(mEntity);
|
||||
int broadPhaseId = mBody->mWorld.mCollidersComponents.getBroadPhaseId(mEntity);
|
||||
|
||||
RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::ProxyShape,
|
||||
"ProxyShape " + std::to_string(broadPhaseId) + ": Set collisionCategoryBits=" +
|
||||
RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::Collider,
|
||||
"Collider " + std::to_string(broadPhaseId) + ": Set collisionCategoryBits=" +
|
||||
std::to_string(collisionCategoryBits));
|
||||
}
|
||||
|
||||
|
@ -95,49 +95,49 @@ void ProxyShape::setCollisionCategoryBits(unsigned short collisionCategoryBits)
|
|||
/**
|
||||
* @param collideWithMaskBits The bits mask that specifies with which collision category this shape will collide
|
||||
*/
|
||||
void ProxyShape::setCollideWithMaskBits(unsigned short collideWithMaskBits) {
|
||||
void Collider::setCollideWithMaskBits(unsigned short collideWithMaskBits) {
|
||||
|
||||
// TODO : Here we should probably remove all overlapping pairs with this shape in the
|
||||
// broad-phase and add the shape in the "has moved" shape list so it is reevaluated
|
||||
// with the new mask bits
|
||||
|
||||
mBody->mWorld.mProxyShapesComponents.setCollideWithMaskBits(mEntity, collideWithMaskBits);
|
||||
mBody->mWorld.mCollidersComponents.setCollideWithMaskBits(mEntity, collideWithMaskBits);
|
||||
|
||||
int broadPhaseId = mBody->mWorld.mProxyShapesComponents.getBroadPhaseId(mEntity);
|
||||
int broadPhaseId = mBody->mWorld.mCollidersComponents.getBroadPhaseId(mEntity);
|
||||
|
||||
RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::ProxyShape,
|
||||
"ProxyShape " + std::to_string(broadPhaseId) + ": Set collideWithMaskBits=" +
|
||||
RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::Collider,
|
||||
"Collider" " + std::to_string(broadPhaseId) + ": Set collideWithMaskBits=" +
|
||||
std::to_string(collideWithMaskBits));
|
||||
}
|
||||
|
||||
// Set the local to parent body transform
|
||||
void ProxyShape::setLocalToBodyTransform(const Transform& transform) {
|
||||
void Collider::setLocalToBodyTransform(const Transform& transform) {
|
||||
|
||||
mBody->mWorld.mProxyShapesComponents.setLocalToBodyTransform(mEntity, transform);
|
||||
mBody->mWorld.mCollidersComponents.setLocalToBodyTransform(mEntity, transform);
|
||||
|
||||
// Update the local-to-world transform
|
||||
const Transform& bodyTransform = mBody->mWorld.mTransformComponents.getTransform(mBody->getEntity());
|
||||
mBody->mWorld.mProxyShapesComponents.setLocalToWorldTransform(mEntity, bodyTransform * transform);
|
||||
mBody->mWorld.mCollidersComponents.setLocalToWorldTransform(mEntity, bodyTransform * transform);
|
||||
|
||||
RigidBody* rigidBody = static_cast<RigidBody*>(mBody);
|
||||
if (rigidBody != nullptr) {
|
||||
mBody->mWorld.mRigidBodyComponents.setIsSleeping(mBody->getEntity(), false);
|
||||
}
|
||||
|
||||
mBody->mWorld.mCollisionDetection.updateProxyShape(mEntity, 0);
|
||||
mBody->mWorld.mCollisionDetection.updateCollider(mEntity, 0);
|
||||
|
||||
RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::ProxyShape,
|
||||
"ProxyShape " + std::to_string(broadPhaseId) + ": Set localToBodyTransform=" +
|
||||
RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::Collider,
|
||||
"Collider " + std::to_string(broadPhaseId) + ": Set localToBodyTransform=" +
|
||||
transform.to_string());
|
||||
}
|
||||
|
||||
// Return the AABB of the proxy shape in world-space
|
||||
// Return the AABB of the collider in world-space
|
||||
/**
|
||||
* @return The AABB of the proxy shape in world-space
|
||||
* @return The AABB of the collider in world-space
|
||||
*/
|
||||
const AABB ProxyShape::getWorldAABB() const {
|
||||
const AABB Collider::getWorldAABB() const {
|
||||
AABB aabb;
|
||||
CollisionShape* collisionShape = mBody->mWorld.mProxyShapesComponents.getCollisionShape(mEntity);
|
||||
CollisionShape* collisionShape = mBody->mWorld.mCollidersComponents.getCollisionShape(mEntity);
|
||||
collisionShape->computeAABB(aabb, getLocalToWorldTransform());
|
||||
return aabb;
|
||||
}
|
||||
|
@ -146,21 +146,21 @@ const AABB ProxyShape::getWorldAABB() const {
|
|||
/**
|
||||
* @return Pointer to the internal collision shape
|
||||
*/
|
||||
const CollisionShape* ProxyShape::getCollisionShape() const {
|
||||
return mBody->mWorld.mProxyShapesComponents.getCollisionShape(mEntity);
|
||||
const CollisionShape* Collider::getCollisionShape() const {
|
||||
return mBody->mWorld.mCollidersComponents.getCollisionShape(mEntity);
|
||||
}
|
||||
|
||||
// Return the collision shape
|
||||
/**
|
||||
* @return Pointer to the internal collision shape
|
||||
*/
|
||||
CollisionShape* ProxyShape::getCollisionShape() {
|
||||
return mBody->mWorld.mProxyShapesComponents.getCollisionShape(mEntity);
|
||||
CollisionShape* Collider::getCollisionShape() {
|
||||
return mBody->mWorld.mCollidersComponents.getCollisionShape(mEntity);
|
||||
}
|
||||
|
||||
// Return the broad-phase id
|
||||
int ProxyShape::getBroadPhaseId() const {
|
||||
return mBody->mWorld.mProxyShapesComponents.getBroadPhaseId(mEntity);
|
||||
int Collider::getBroadPhaseId() const {
|
||||
return mBody->mWorld.mCollidersComponents.getBroadPhaseId(mEntity);
|
||||
}
|
||||
|
||||
// Return the local to parent body transform
|
||||
|
@ -168,8 +168,8 @@ int ProxyShape::getBroadPhaseId() const {
|
|||
* @return The transformation that transforms the local-space of the collision shape
|
||||
* to the local-space of the parent body
|
||||
*/
|
||||
const Transform& ProxyShape::getLocalToBodyTransform() const {
|
||||
return mBody->mWorld.mProxyShapesComponents.getLocalToBodyTransform(mEntity);
|
||||
const Transform& Collider::getLocalToBodyTransform() const {
|
||||
return mBody->mWorld.mCollidersComponents.getLocalToBodyTransform(mEntity);
|
||||
}
|
||||
|
||||
// Raycast method with feedback information
|
||||
|
@ -179,19 +179,19 @@ const Transform& ProxyShape::getLocalToBodyTransform() const {
|
|||
* methods returned true
|
||||
* @return True if the ray hits the collision shape
|
||||
*/
|
||||
bool ProxyShape::raycast(const Ray& ray, RaycastInfo& raycastInfo) {
|
||||
bool Collider::raycast(const Ray& ray, RaycastInfo& raycastInfo) {
|
||||
|
||||
// If the corresponding body is not active, it cannot be hit by rays
|
||||
if (!mBody->isActive()) return false;
|
||||
|
||||
// Convert the ray into the local-space of the collision shape
|
||||
const Transform localToWorldTransform = mBody->mWorld.mProxyShapesComponents.getLocalToWorldTransform(mEntity);
|
||||
const Transform localToWorldTransform = mBody->mWorld.mCollidersComponents.getLocalToWorldTransform(mEntity);
|
||||
const Transform worldToLocalTransform = localToWorldTransform.getInverse();
|
||||
Ray rayLocal(worldToLocalTransform * ray.point1,
|
||||
worldToLocalTransform * ray.point2,
|
||||
ray.maxFraction);
|
||||
|
||||
const CollisionShape* collisionShape = mBody->mWorld.mProxyShapesComponents.getCollisionShape(mEntity);
|
||||
const CollisionShape* collisionShape = mBody->mWorld.mCollidersComponents.getCollisionShape(mEntity);
|
||||
bool isHit = collisionShape->raycast(rayLocal, raycastInfo, this, mMemoryManager.getPoolAllocator());
|
||||
|
||||
// Convert the raycast info into world-space
|
||||
|
@ -204,18 +204,18 @@ bool ProxyShape::raycast(const Ray& ray, RaycastInfo& raycastInfo) {
|
|||
|
||||
// Return the collision category bits
|
||||
/**
|
||||
* @return The collision category bits mask of the proxy shape
|
||||
* @return The collision category bits mask of the collider
|
||||
*/
|
||||
unsigned short ProxyShape::getCollisionCategoryBits() const {
|
||||
return mBody->mWorld.mProxyShapesComponents.getCollisionCategoryBits(mEntity);
|
||||
unsigned short Collider::getCollisionCategoryBits() const {
|
||||
return mBody->mWorld.mCollidersComponents.getCollisionCategoryBits(mEntity);
|
||||
}
|
||||
|
||||
// Return the collision bits mask
|
||||
/**
|
||||
* @return The bits mask that specifies with which collision category this shape will collide
|
||||
*/
|
||||
unsigned short ProxyShape::getCollideWithMaskBits() const {
|
||||
return mBody->mWorld.mProxyShapesComponents.getCollideWithMaskBits(mEntity);
|
||||
unsigned short Collider::getCollideWithMaskBits() const {
|
||||
return mBody->mWorld.mCollidersComponents.getCollideWithMaskBits(mEntity);
|
||||
}
|
||||
|
||||
// Return the local to world transform
|
||||
|
@ -223,18 +223,18 @@ unsigned short ProxyShape::getCollideWithMaskBits() const {
|
|||
* @return The transformation that transforms the local-space of the collision
|
||||
* shape to the world-space
|
||||
*/
|
||||
const Transform ProxyShape::getLocalToWorldTransform() const {
|
||||
return mBody->mWorld.mProxyShapesComponents.getLocalToWorldTransform(mEntity);
|
||||
const Transform Collider::getLocalToWorldTransform() const {
|
||||
return mBody->mWorld.mCollidersComponents.getLocalToWorldTransform(mEntity);
|
||||
}
|
||||
|
||||
#ifdef IS_PROFILING_ACTIVE
|
||||
|
||||
// Set the profiler
|
||||
void ProxyShape::setProfiler(Profiler* profiler) {
|
||||
void Collider::setProfiler(Profiler* profiler) {
|
||||
|
||||
mProfiler = profiler;
|
||||
|
||||
CollisionShape* collisionShape = mBody->mWorld.mProxyShapesComponents.getCollisionShape(mEntity);
|
||||
CollisionShape* collisionShape = mBody->mWorld.mCollidersComponents.getCollisionShape(mEntity);
|
||||
collisionShape->setProfiler(profiler);
|
||||
}
|
||||
|
|
@ -23,8 +23,8 @@
|
|||
* *
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef REACTPHYSICS3D_PROXY_SHAPE_H
|
||||
#define REACTPHYSICS3D_PROXY_SHAPE_H
|
||||
#ifndef REACTPHYSICS3D_COLLIDER_H
|
||||
#define REACTPHYSICS3D_COLLIDER_H
|
||||
|
||||
// Libraries
|
||||
#include "body/CollisionBody.h"
|
||||
|
@ -35,17 +35,17 @@ namespace reactphysics3d {
|
|||
// Declarations
|
||||
class MemoryManager;
|
||||
|
||||
// Class ProxyShape
|
||||
// Class Collider
|
||||
/**
|
||||
* The CollisionShape instances are supposed to be unique for memory optimization. For instance,
|
||||
* consider two rigid bodies with the same sphere collision shape. In this situation, we will have
|
||||
* a unique instance of SphereShape but we need to differentiate between the two instances during
|
||||
* the collision detection. They do not have the same position in the world and they do not
|
||||
* belong to the same rigid body. The ProxyShape class is used for that purpose by attaching a
|
||||
* rigid body with one of its collision shape. A body can have multiple proxy shapes (one for
|
||||
* belong to the same rigid body. The Collider class is used for that purpose by attaching a
|
||||
* rigid body with one of its collision shape. A body can have multiple colliders (one for
|
||||
* each collision shape attached to the body).
|
||||
*/
|
||||
class ProxyShape {
|
||||
class Collider {
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -60,37 +60,9 @@ class ProxyShape {
|
|||
/// Pointer to the parent body
|
||||
CollisionBody* mBody;
|
||||
|
||||
/// Internal collision shape
|
||||
//CollisionShape* mCollisionShape;
|
||||
|
||||
/// Local-space to parent body-space transform (does not change over time)
|
||||
//Transform mLocalToBodyTransform;
|
||||
|
||||
/// Mass (in kilogramms) of the corresponding collision shape
|
||||
//decimal mMass;
|
||||
|
||||
/// Pointer to the next proxy shape of the body (linked list)
|
||||
//ProxyShape* mNext;
|
||||
|
||||
/// Broad-phase ID (node ID in the dynamic AABB tree)
|
||||
//int mBroadPhaseID;
|
||||
|
||||
/// Pointer to user data
|
||||
void* mUserData;
|
||||
|
||||
/// Bits used to define the collision category of this shape.
|
||||
/// You can set a single bit to one to define a category value for this
|
||||
/// shape. This value is one (0x0001) by default. This variable can be used
|
||||
/// together with the mCollideWithMaskBits variable so that given
|
||||
/// categories of shapes collide with each other and do not collide with
|
||||
/// other categories.
|
||||
//unsigned short mCollisionCategoryBits;
|
||||
|
||||
/// Bits mask used to state which collision categories this shape can
|
||||
/// collide with. This value is 0xFFFF by default. It means that this
|
||||
/// proxy shape will collide with every collision categories by default.
|
||||
//unsigned short mCollideWithMaskBits;
|
||||
|
||||
#ifdef IS_PROFILING_ACTIVE
|
||||
|
||||
/// Pointer to the profiler
|
||||
|
@ -114,18 +86,18 @@ class ProxyShape {
|
|||
// -------------------- Methods -------------------- //
|
||||
|
||||
/// Constructor
|
||||
ProxyShape(Entity entity, CollisionBody* body, MemoryManager& memoryManager);
|
||||
Collider(Entity entity, CollisionBody* body, MemoryManager& memoryManager);
|
||||
|
||||
/// Destructor
|
||||
virtual ~ProxyShape();
|
||||
virtual ~Collider();
|
||||
|
||||
/// Deleted copy-constructor
|
||||
ProxyShape(const ProxyShape& proxyShape) = delete;
|
||||
Collider(const Collider& collider) = delete;
|
||||
|
||||
/// Deleted assignment operator
|
||||
ProxyShape& operator=(const ProxyShape& proxyShape) = delete;
|
||||
Collider& operator=(const Collider& collider) = delete;
|
||||
|
||||
/// Return the corresponding entity of the proxy-shape
|
||||
/// Return the corresponding entity of the collider
|
||||
Entity getEntity() const;
|
||||
|
||||
/// Return the collision shape
|
||||
|
@ -152,10 +124,10 @@ class ProxyShape {
|
|||
/// Return the local to world transform
|
||||
const Transform getLocalToWorldTransform() const;
|
||||
|
||||
/// Return the AABB of the proxy shape in world-space
|
||||
/// Return the AABB of the collider in world-space
|
||||
const AABB getWorldAABB() const;
|
||||
|
||||
/// Test if the proxy shape overlaps with a given AABB
|
||||
/// Test if the collider overlaps with a given AABB
|
||||
bool testAABBOverlap(const AABB& worldAABB) const;
|
||||
|
||||
/// Return true if a point is inside the collision shape
|
||||
|
@ -209,11 +181,11 @@ class ProxyShape {
|
|||
|
||||
};
|
||||
|
||||
// Return the corresponding entity of the proxy-shape
|
||||
// Return the corresponding entity of the collider
|
||||
/**
|
||||
* @return The entity of the proxy-shape
|
||||
* @return The entity of the collider
|
||||
*/
|
||||
inline Entity ProxyShape::getEntity() const {
|
||||
inline Entity Collider::getEntity() const {
|
||||
return mEntity;
|
||||
}
|
||||
|
||||
|
@ -221,39 +193,39 @@ inline Entity ProxyShape::getEntity() const {
|
|||
/**
|
||||
* @return Pointer to the parent body
|
||||
*/
|
||||
inline CollisionBody* ProxyShape::getBody() const {
|
||||
inline CollisionBody* Collider::getBody() const {
|
||||
return mBody;
|
||||
}
|
||||
|
||||
// Return a pointer to the user data attached to this body
|
||||
/**
|
||||
* @return A pointer to the user data stored into the proxy shape
|
||||
* @return A pointer to the user data stored into the collider
|
||||
*/
|
||||
inline void* ProxyShape::getUserData() const {
|
||||
inline void* Collider::getUserData() const {
|
||||
return mUserData;
|
||||
}
|
||||
|
||||
// Attach user data to this body
|
||||
/**
|
||||
* @param userData Pointer to the user data you want to store within the proxy shape
|
||||
* @param userData Pointer to the user data you want to store within the collider
|
||||
*/
|
||||
inline void ProxyShape::setUserData(void* userData) {
|
||||
inline void Collider::setUserData(void* userData) {
|
||||
mUserData = userData;
|
||||
}
|
||||
|
||||
/// Test if the proxy shape overlaps with a given AABB
|
||||
/// Test if the collider overlaps with a given AABB
|
||||
/**
|
||||
* @param worldAABB The AABB (in world-space coordinates) that will be used to test overlap
|
||||
* @return True if the given AABB overlaps with the AABB of the collision body
|
||||
*/
|
||||
inline bool ProxyShape::testAABBOverlap(const AABB& worldAABB) const {
|
||||
inline bool Collider::testAABBOverlap(const AABB& worldAABB) const {
|
||||
return worldAABB.testCollision(getWorldAABB());
|
||||
}
|
||||
|
||||
#ifdef IS_LOGGING_ACTIVE
|
||||
|
||||
// Set the logger
|
||||
inline void ProxyShape::setLogger(Logger* logger) {
|
||||
inline void Collider::setLogger(Logger* logger) {
|
||||
|
||||
mLogger = logger;
|
||||
}
|
|
@ -55,14 +55,14 @@ CollisionBody* CollisionCallback::ContactPair::getBody2() const {
|
|||
return static_cast<CollisionBody*>(mWorld.mCollisionBodyComponents.getBody(mContactPair.body2Entity));
|
||||
}
|
||||
|
||||
// Return a pointer to the first proxy-shape in contact (in body 1)
|
||||
ProxyShape* CollisionCallback::ContactPair::getProxyShape1() const {
|
||||
return mWorld.mProxyShapesComponents.getProxyShape(mContactPair.proxyShape1Entity);
|
||||
// Return a pointer to the first collider in contact (in body 1)
|
||||
Collider* CollisionCallback::ContactPair::getCollider1() const {
|
||||
return mWorld.mCollidersComponents.getCollider(mContactPair.collider1Entity);
|
||||
}
|
||||
|
||||
// Return a pointer to the second proxy-shape in contact (in body 1)
|
||||
ProxyShape* CollisionCallback::ContactPair::getProxyShape2() const {
|
||||
return mWorld.mProxyShapesComponents.getProxyShape(mContactPair.proxyShape2Entity);
|
||||
// Return a pointer to the second collider in contact (in body 1)
|
||||
Collider* CollisionCallback::ContactPair::getCollider2() const {
|
||||
return mWorld.mCollidersComponents.getCollider(mContactPair.collider2Entity);
|
||||
}
|
||||
|
||||
// CollisionCallbackInfo Constructor
|
||||
|
|
|
@ -39,7 +39,7 @@ class OverlappingPair;
|
|||
class ContactManifold;
|
||||
struct ContactManifoldListElement;
|
||||
class CollisionBody;
|
||||
class ProxyShape;
|
||||
class Collider;
|
||||
class MemoryManager;
|
||||
class CollisionCallbackInfo;
|
||||
|
||||
|
@ -90,10 +90,10 @@ class CollisionCallback {
|
|||
/// Return the world-space contact normal
|
||||
const Vector3& getWorldNormal() const;
|
||||
|
||||
/// Return the contact point on the first proxy shape in the local-space of the first proxy shape
|
||||
/// Return the contact point on the first collider in the local-space of the first collider
|
||||
const Vector3& getLocalPointOnShape1() const;
|
||||
|
||||
/// Return the contact point on the second proxy shape in the local-space of the second proxy shape
|
||||
/// Return the contact point on the second collider in the local-space of the second collider
|
||||
const Vector3& getLocalPointOnShape2() const;
|
||||
|
||||
// -------------------- Friendship -------------------- //
|
||||
|
@ -151,11 +151,11 @@ class CollisionCallback {
|
|||
/// Return a pointer to the second body in contact
|
||||
CollisionBody* getBody2() const;
|
||||
|
||||
/// Return a pointer to the first proxy-shape in contact (in body 1)
|
||||
ProxyShape* getProxyShape1() const;
|
||||
/// Return a pointer to the first collider in contact (in body 1)
|
||||
Collider* getCollider1() const;
|
||||
|
||||
/// Return a pointer to the second proxy-shape in contact (in body 2)
|
||||
ProxyShape* getProxyShape2() const;
|
||||
/// Return a pointer to the second collider in contact (in body 2)
|
||||
Collider* getCollider2() const;
|
||||
|
||||
// -------------------- Friendship -------------------- //
|
||||
|
||||
|
@ -253,17 +253,17 @@ inline const Vector3& CollisionCallback::ContactPoint::getWorldNormal() const {
|
|||
return mContactPoint.getNormal();
|
||||
}
|
||||
|
||||
// Return the contact point on the first proxy shape in the local-space of the first proxy shape
|
||||
// Return the contact point on the first collider in the local-space of the first collider
|
||||
/**
|
||||
* @return The contact point in the local-space of the first proxy-shape (from body1) in contact
|
||||
* @return The contact point in the local-space of the first collider (from body1) in contact
|
||||
*/
|
||||
inline const Vector3& CollisionCallback::ContactPoint::getLocalPointOnShape1() const {
|
||||
return mContactPoint.getLocalPointOnShape1();
|
||||
}
|
||||
|
||||
// Return the contact point on the second proxy shape in the local-space of the second proxy shape
|
||||
// Return the contact point on the second collider in the local-space of the second collider
|
||||
/**
|
||||
* @return The contact point in the local-space of the second proxy-shape (from body2) in contact
|
||||
* @return The contact point in the local-space of the second collider (from body2) in contact
|
||||
*/
|
||||
inline const Vector3& CollisionCallback::ContactPoint::getLocalPointOnShape2() const {
|
||||
return mContactPoint.getLocalPointOnShape2();
|
||||
|
|
|
@ -31,10 +31,10 @@
|
|||
using namespace reactphysics3d;
|
||||
|
||||
// Constructor
|
||||
ContactManifold::ContactManifold(Entity bodyEntity1, Entity bodyEntity2, Entity proxyShapeEntity1, Entity proxyShapeEntity2,
|
||||
ContactManifold::ContactManifold(Entity bodyEntity1, Entity bodyEntity2, Entity colliderEntity1, Entity colliderEntity2,
|
||||
uint contactPointsIndex, int8 nbContactPoints)
|
||||
:contactPointsIndex(contactPointsIndex), bodyEntity1(bodyEntity1), bodyEntity2(bodyEntity2),
|
||||
proxyShapeEntity1(proxyShapeEntity1), proxyShapeEntity2(proxyShapeEntity2), nbContactPoints(nbContactPoints), frictionImpulse1(0), frictionImpulse2(0),
|
||||
colliderEntity1(colliderEntity1), colliderEntity2(colliderEntity2), nbContactPoints(nbContactPoints), frictionImpulse1(0), frictionImpulse2(0),
|
||||
frictionTwistImpulse(0), isAlreadyInIsland(false) {
|
||||
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#define REACTPHYSICS3D_CONTACT_MANIFOLD_H
|
||||
|
||||
// Libraries
|
||||
#include "collision/ProxyShape.h"
|
||||
#include "collision/Collider.h"
|
||||
|
||||
/// ReactPhysics3D namespace
|
||||
namespace reactphysics3d {
|
||||
|
@ -71,11 +71,11 @@ class ContactManifold {
|
|||
/// Entity of the second body in contact
|
||||
Entity bodyEntity2;
|
||||
|
||||
/// Entity of the first proxy-shape in contact
|
||||
Entity proxyShapeEntity1;
|
||||
/// Entity of the first collider in contact
|
||||
Entity colliderEntity1;
|
||||
|
||||
/// Entity of the second proxy-shape in contact
|
||||
Entity proxyShapeEntity2;
|
||||
/// Entity of the second collider in contact
|
||||
Entity colliderEntity2;
|
||||
|
||||
/// Number of contacts in the cache
|
||||
int8 nbContactPoints;
|
||||
|
@ -106,7 +106,7 @@ class ContactManifold {
|
|||
// -------------------- Methods -------------------- //
|
||||
|
||||
/// Constructor
|
||||
ContactManifold(Entity bodyEntity1, Entity bodyEntity2, Entity proxyShapeEntity1, Entity proxyShapeEntity2,
|
||||
ContactManifold(Entity bodyEntity1, Entity bodyEntity2, Entity colliderEntity1, Entity colliderEntity2,
|
||||
uint contactPointsIndex, int8 nbContactPoints);
|
||||
|
||||
/// Destructor
|
||||
|
|
|
@ -56,11 +56,11 @@ struct ContactPair {
|
|||
/// Entity of the second body of the contact
|
||||
Entity body2Entity;
|
||||
|
||||
/// Entity of the first proxy-shape of the contact
|
||||
Entity proxyShape1Entity;
|
||||
/// Entity of the first collider of the contact
|
||||
Entity collider1Entity;
|
||||
|
||||
/// Entity of the second proxy-shape of the contact
|
||||
Entity proxyShape2Entity;
|
||||
/// Entity of the second collider of the contact
|
||||
Entity collider2Entity;
|
||||
|
||||
/// True if the manifold is already in an island
|
||||
bool isAlreadyInIsland;
|
||||
|
@ -83,10 +83,10 @@ struct ContactPair {
|
|||
// -------------------- Methods -------------------- //
|
||||
|
||||
/// Constructor
|
||||
ContactPair(uint64 pairId, Entity body1Entity, Entity body2Entity, Entity proxyShape1Entity,
|
||||
Entity proxyShape2Entity, uint contactPairIndex, MemoryAllocator& allocator)
|
||||
ContactPair(uint64 pairId, Entity body1Entity, Entity body2Entity, Entity collider1Entity,
|
||||
Entity collider2Entity, uint contactPairIndex, MemoryAllocator& allocator)
|
||||
: pairId(pairId), potentialContactManifoldsIndices(allocator), body1Entity(body1Entity), body2Entity(body2Entity),
|
||||
proxyShape1Entity(proxyShape1Entity), proxyShape2Entity(proxyShape2Entity),
|
||||
collider1Entity(collider1Entity), collider2Entity(collider2Entity),
|
||||
isAlreadyInIsland(false), contactPairIndex(contactPairIndex), contactManifoldsIndex(0), nbContactManifolds(0),
|
||||
contactPointsIndex(0), nbToTalContactPoints(0) {
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ CollisionBody* OverlapCallback::OverlapPair::getBody2() const {
|
|||
}
|
||||
|
||||
// CollisionCallbackData Constructor
|
||||
OverlapCallback::CallbackData::CallbackData(List<Pair<Entity, Entity>>& overlapBodies, CollisionWorld& world)
|
||||
:mOverlapBodies(overlapBodies), mWorld(world) {
|
||||
OverlapCallback::CallbackData::CallbackData(List<Pair<Entity, Entity>>& overlapColliders, CollisionWorld& world)
|
||||
:mOverlapBodies(overlapColliders), mWorld(world) {
|
||||
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace reactphysics3d {
|
|||
// Declarations
|
||||
class CollisionBody;
|
||||
class CollisionWorld;
|
||||
class ProxyShape;
|
||||
class Collider;
|
||||
struct Entity;
|
||||
|
||||
// Class OverlapCallback
|
||||
|
@ -49,7 +49,7 @@ class OverlapCallback {
|
|||
|
||||
// Class OverlapPair
|
||||
/**
|
||||
* This class represents the contact between two proxy-shapes of the physics world.
|
||||
* This class represents the contact between two colliders of the physics world.
|
||||
*/
|
||||
class OverlapPair {
|
||||
|
||||
|
@ -110,7 +110,7 @@ class OverlapCallback {
|
|||
// -------------------- Methods -------------------- //
|
||||
|
||||
/// Constructor
|
||||
CallbackData(List<Pair<Entity, Entity>>& overlapProxyShapes, CollisionWorld& world);
|
||||
CallbackData(List<Pair<Entity, Entity>>& overlapColliders, CollisionWorld& world);
|
||||
|
||||
/// Deleted copy constructor
|
||||
CallbackData(const CallbackData& callbackData) = delete;
|
||||
|
|
|
@ -26,12 +26,12 @@
|
|||
// Libraries
|
||||
#include "decimal.h"
|
||||
#include "RaycastInfo.h"
|
||||
#include "ProxyShape.h"
|
||||
#include "Collider.h"
|
||||
|
||||
using namespace reactphysics3d;
|
||||
|
||||
// Ray cast test against a proxy shape
|
||||
decimal RaycastTest::raycastAgainstShape(ProxyShape* shape, const Ray& ray) {
|
||||
// Ray cast test against a collider
|
||||
decimal RaycastTest::raycastAgainstShape(Collider* shape, const Ray& ray) {
|
||||
|
||||
// Ray casting test against the collision shape
|
||||
RaycastInfo raycastInfo;
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace reactphysics3d {
|
|||
|
||||
// Declarations
|
||||
class CollisionBody;
|
||||
class ProxyShape;
|
||||
class Collider;
|
||||
class CollisionShape;
|
||||
struct Ray;
|
||||
|
||||
|
@ -69,13 +69,13 @@ struct RaycastInfo {
|
|||
/// Pointer to the hit collision body
|
||||
CollisionBody* body;
|
||||
|
||||
/// Pointer to the hit proxy collision shape
|
||||
ProxyShape* proxyShape;
|
||||
/// Pointer to the hit collider
|
||||
Collider* collider;
|
||||
|
||||
// -------------------- Methods -------------------- //
|
||||
|
||||
/// Constructor
|
||||
RaycastInfo() : meshSubpart(-1), triangleIndex(-1), body(nullptr), proxyShape(nullptr) {
|
||||
RaycastInfo() : meshSubpart(-1), triangleIndex(-1), body(nullptr), collider(nullptr) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,7 @@ struct RaycastInfo {
|
|||
/**
|
||||
* This class can be used to register a callback for ray casting queries.
|
||||
* You should implement your own class inherited from this one and implement
|
||||
* the notifyRaycastHit() method. This method will be called for each ProxyShape
|
||||
* the notifyRaycastHit() method. This method will be called for each collider
|
||||
* that is hit by the ray.
|
||||
*/
|
||||
class RaycastCallback {
|
||||
|
@ -107,7 +107,7 @@ class RaycastCallback {
|
|||
|
||||
}
|
||||
|
||||
/// This method will be called for each ProxyShape that is hit by the
|
||||
/// This method will be called for each collider that is hit by the
|
||||
/// ray. You cannot make any assumptions about the order of the
|
||||
/// calls. You should use the return value to control the continuation
|
||||
/// of the ray. The returned value is the next maxFraction value to use.
|
||||
|
@ -117,7 +117,7 @@ class RaycastCallback {
|
|||
/// occurred. If you return the fraction in the parameter (hitFraction
|
||||
/// value in the RaycastInfo object), the current ray will be clipped
|
||||
/// to this fraction in the next queries. If you return -1.0, it will
|
||||
/// ignore this ProxyShape and continue the ray cast.
|
||||
/// ignore this collider and continue the ray cast.
|
||||
/**
|
||||
* @param raycastInfo Information about the raycast hit
|
||||
* @return Value that controls the continuation of the ray after a hit
|
||||
|
@ -139,8 +139,8 @@ struct RaycastTest {
|
|||
userCallback = callback;
|
||||
}
|
||||
|
||||
/// Ray cast test against a proxy shape
|
||||
decimal raycastAgainstShape(ProxyShape* shape, const Ray& ray);
|
||||
/// Ray cast test against a collider
|
||||
decimal raycastAgainstShape(Collider* shape, const Ray& ray);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -694,7 +694,7 @@ void DynamicAABBTree::raycast(const Ray& ray, DynamicAABBTreeRaycastCallback& ca
|
|||
Stack<int32> stack(mAllocator, 128);
|
||||
stack.push(mRootNodeID);
|
||||
|
||||
// Walk through the tree from the root looking for proxy shapes
|
||||
// Walk through the tree from the root looking for colliders
|
||||
// that overlap with the ray AABB
|
||||
while (stack.size() > 0) {
|
||||
|
||||
|
@ -735,7 +735,7 @@ void DynamicAABBTree::raycast(const Ray& ray, DynamicAABBTreeRaycastCallback& ca
|
|||
}
|
||||
|
||||
// If the user returned a negative fraction, we continue
|
||||
// the raycasting as if the proxy shape did not exist
|
||||
// the raycasting as if the collider did not exist
|
||||
}
|
||||
else { // If the node has children
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ CapsuleVsCapsuleNarrowPhaseInfoBatch::CapsuleVsCapsuleNarrowPhaseInfoBatch(Memor
|
|||
}
|
||||
|
||||
// Add shapes to be tested during narrow-phase collision detection into the batch
|
||||
void CapsuleVsCapsuleNarrowPhaseInfoBatch::addNarrowPhaseInfo(uint64 pairId, uint64 pairIndex, Entity proxyShape1, Entity proxyShape2, CollisionShape* shape1, CollisionShape* shape2,
|
||||
void CapsuleVsCapsuleNarrowPhaseInfoBatch::addNarrowPhaseInfo(uint64 pairId, uint64 pairIndex, Entity collider1, Entity collider2, CollisionShape* shape1, CollisionShape* shape2,
|
||||
const Transform& shape1Transform, const Transform& shape2Transform) {
|
||||
|
||||
assert(shape1->getType() == CollisionShapeType::CAPSULE);
|
||||
|
@ -47,8 +47,8 @@ void CapsuleVsCapsuleNarrowPhaseInfoBatch::addNarrowPhaseInfo(uint64 pairId, uin
|
|||
const CapsuleShape* capsule1 = static_cast<const CapsuleShape*>(shape1);
|
||||
const CapsuleShape* capsule2 = static_cast<const CapsuleShape*>(shape2);
|
||||
|
||||
proxyShapeEntities1.add(proxyShape1);
|
||||
proxyShapeEntities2.add(proxyShape2);
|
||||
colliderEntities1.add(collider1);
|
||||
colliderEntities2.add(collider2);
|
||||
capsule1Radiuses.add(capsule1->getRadius());
|
||||
capsule2Radiuses.add(capsule2->getRadius());
|
||||
capsule1Heights.add(capsule1->getHeight());
|
||||
|
@ -68,8 +68,8 @@ void CapsuleVsCapsuleNarrowPhaseInfoBatch::addNarrowPhaseInfo(uint64 pairId, uin
|
|||
void CapsuleVsCapsuleNarrowPhaseInfoBatch::reserveMemory() {
|
||||
|
||||
overlappingPairIds.reserve(mCachedCapacity);
|
||||
proxyShapeEntities1.reserve(mCachedCapacity);
|
||||
proxyShapeEntities2.reserve(mCachedCapacity);
|
||||
colliderEntities1.reserve(mCachedCapacity);
|
||||
colliderEntities2.reserve(mCachedCapacity);
|
||||
shape1ToWorldTransforms.reserve(mCachedCapacity);
|
||||
shape2ToWorldTransforms.reserve(mCachedCapacity);
|
||||
lastFrameCollisionInfos.reserve(mCachedCapacity);
|
||||
|
@ -93,8 +93,8 @@ void CapsuleVsCapsuleNarrowPhaseInfoBatch::clear() {
|
|||
mCachedCapacity = overlappingPairIds.size();
|
||||
|
||||
overlappingPairIds.clear(true);
|
||||
proxyShapeEntities1.clear(true);
|
||||
proxyShapeEntities2.clear(true);
|
||||
colliderEntities1.clear(true);
|
||||
colliderEntities2.clear(true);
|
||||
shape1ToWorldTransforms.clear(true);
|
||||
shape2ToWorldTransforms.clear(true);
|
||||
lastFrameCollisionInfos.clear(true);
|
||||
|
|
|
@ -61,7 +61,7 @@ struct CapsuleVsCapsuleNarrowPhaseInfoBatch : public NarrowPhaseInfoBatch {
|
|||
virtual ~CapsuleVsCapsuleNarrowPhaseInfoBatch() = default;
|
||||
|
||||
/// Add shapes to be tested during narrow-phase collision detection into the batch
|
||||
virtual void addNarrowPhaseInfo(uint64 pairId, uint64 pairIndex, Entity proxyShape1, Entity proxyShape2, CollisionShape* shape1,
|
||||
virtual void addNarrowPhaseInfo(uint64 pairId, uint64 pairIndex, Entity collider1, Entity collider2, CollisionShape* shape1,
|
||||
CollisionShape* shape2, const Transform& shape1Transform,
|
||||
const Transform& shape2Transform);
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ enum class NarrowPhaseAlgorithmType {
|
|||
/**
|
||||
* This is the collision dispatch configuration use in ReactPhysics3D.
|
||||
* Collision dispatching decides which collision
|
||||
* algorithm to use given two types of proxy collision shapes.
|
||||
* algorithm to use given two types of colliders.
|
||||
*/
|
||||
class CollisionDispatch {
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ class NarrowPhaseCallback {
|
|||
/**
|
||||
* This abstract class is the base class for a narrow-phase collision
|
||||
* detection algorithm. The goal of the narrow phase algorithm is to
|
||||
* compute information about the contact between two proxy shapes.
|
||||
* compute information about the contact between two colliders.
|
||||
*/
|
||||
class NarrowPhaseAlgorithm {
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ using namespace reactphysics3d;
|
|||
// Constructor
|
||||
NarrowPhaseInfoBatch::NarrowPhaseInfoBatch(MemoryAllocator& allocator, OverlappingPairs& overlappingPairs)
|
||||
: mMemoryAllocator(allocator), mOverlappingPairs(overlappingPairs), overlappingPairIds(allocator),
|
||||
proxyShapeEntities1(allocator), proxyShapeEntities2(allocator), collisionShapes1(allocator), collisionShapes2(allocator),
|
||||
colliderEntities1(allocator), colliderEntities2(allocator), collisionShapes1(allocator), collisionShapes2(allocator),
|
||||
shape1ToWorldTransforms(allocator), shape2ToWorldTransforms(allocator),
|
||||
isColliding(allocator), contactPoints(allocator), collisionShapeAllocators(allocator),
|
||||
lastFrameCollisionInfos(allocator) {
|
||||
|
@ -48,13 +48,13 @@ NarrowPhaseInfoBatch::~NarrowPhaseInfoBatch() {
|
|||
}
|
||||
|
||||
// Add shapes to be tested during narrow-phase collision detection into the batch
|
||||
void NarrowPhaseInfoBatch::addNarrowPhaseInfo(uint64 pairId, uint64 pairIndex, Entity proxyShape1, Entity proxyShape2, CollisionShape* shape1, CollisionShape* shape2,
|
||||
void NarrowPhaseInfoBatch::addNarrowPhaseInfo(uint64 pairId, uint64 pairIndex, Entity collider1, Entity collider2, CollisionShape* shape1, CollisionShape* shape2,
|
||||
const Transform& shape1Transform, const Transform& shape2Transform,
|
||||
MemoryAllocator& shapeAllocator) {
|
||||
|
||||
overlappingPairIds.add(pairId);
|
||||
proxyShapeEntities1.add(proxyShape1);
|
||||
proxyShapeEntities2.add(proxyShape2);
|
||||
colliderEntities1.add(collider1);
|
||||
colliderEntities2.add(collider2);
|
||||
collisionShapes1.add(shape1);
|
||||
collisionShapes2.add(shape2);
|
||||
shape1ToWorldTransforms.add(shape1Transform);
|
||||
|
@ -110,8 +110,8 @@ void NarrowPhaseInfoBatch::resetContactPoints(uint index) {
|
|||
void NarrowPhaseInfoBatch::reserveMemory() {
|
||||
|
||||
overlappingPairIds.reserve(mCachedCapacity);
|
||||
proxyShapeEntities1.reserve(mCachedCapacity);
|
||||
proxyShapeEntities2.reserve(mCachedCapacity);
|
||||
colliderEntities1.reserve(mCachedCapacity);
|
||||
colliderEntities2.reserve(mCachedCapacity);
|
||||
collisionShapes1.reserve(mCachedCapacity);
|
||||
collisionShapes2.reserve(mCachedCapacity);
|
||||
shape1ToWorldTransforms.reserve(mCachedCapacity);
|
||||
|
@ -149,8 +149,8 @@ void NarrowPhaseInfoBatch::clear() {
|
|||
mCachedCapacity = overlappingPairIds.size();
|
||||
|
||||
overlappingPairIds.clear(true);
|
||||
proxyShapeEntities1.clear(true);
|
||||
proxyShapeEntities2.clear(true);
|
||||
colliderEntities1.clear(true);
|
||||
colliderEntities2.clear(true);
|
||||
collisionShapes1.clear(true);
|
||||
collisionShapes2.clear(true);
|
||||
shape1ToWorldTransforms.clear(true);
|
||||
|
|
|
@ -63,11 +63,11 @@ struct NarrowPhaseInfoBatch {
|
|||
/// List of Broadphase overlapping pairs ids
|
||||
List<uint64> overlappingPairIds;
|
||||
|
||||
/// List of pointers to the first proxy-shapes to test collision with
|
||||
List<Entity> proxyShapeEntities1;
|
||||
/// List of pointers to the first colliders to test collision with
|
||||
List<Entity> colliderEntities1;
|
||||
|
||||
/// List of pointers to the second proxy-shapes to test collision with
|
||||
List<Entity> proxyShapeEntities2;
|
||||
/// List of pointers to the second colliders to test collision with
|
||||
List<Entity> colliderEntities2;
|
||||
|
||||
/// List of pointers to the first collision shapes to test collision with
|
||||
List<CollisionShape*> collisionShapes1;
|
||||
|
@ -103,7 +103,7 @@ struct NarrowPhaseInfoBatch {
|
|||
uint getNbObjects() const;
|
||||
|
||||
/// Add shapes to be tested during narrow-phase collision detection into the batch
|
||||
void addNarrowPhaseInfo(uint64 pairId, uint64 pairIndex, Entity proxyShape1, Entity proxyShape2, CollisionShape* shape1,
|
||||
void addNarrowPhaseInfo(uint64 pairId, uint64 pairIndex, Entity collider1, Entity collider2, CollisionShape* shape1,
|
||||
CollisionShape* shape2, const Transform& shape1Transform,
|
||||
const Transform& shape2Transform, MemoryAllocator& shapeAllocator);
|
||||
|
||||
|
|
|
@ -39,28 +39,28 @@ NarrowPhaseInput::NarrowPhaseInput(MemoryAllocator& allocator, OverlappingPairs&
|
|||
}
|
||||
|
||||
// Add shapes to be tested during narrow-phase collision detection into the batch
|
||||
void NarrowPhaseInput::addNarrowPhaseTest(uint64 pairId, uint64 pairIndex, Entity proxyShape1, Entity proxyShape2, CollisionShape* shape1, CollisionShape* shape2,
|
||||
void NarrowPhaseInput::addNarrowPhaseTest(uint64 pairId, uint64 pairIndex, Entity collider1, Entity collider2, CollisionShape* shape1, CollisionShape* shape2,
|
||||
const Transform& shape1Transform, const Transform& shape2Transform,
|
||||
NarrowPhaseAlgorithmType narrowPhaseAlgorithmType, MemoryAllocator& shapeAllocator) {
|
||||
|
||||
switch (narrowPhaseAlgorithmType) {
|
||||
case NarrowPhaseAlgorithmType::SphereVsSphere:
|
||||
mSphereVsSphereBatch.addNarrowPhaseInfo(pairId, pairIndex, proxyShape1, proxyShape2, shape1, shape2, shape1Transform, shape2Transform);
|
||||
mSphereVsSphereBatch.addNarrowPhaseInfo(pairId, pairIndex, collider1, collider2, shape1, shape2, shape1Transform, shape2Transform);
|
||||
break;
|
||||
case NarrowPhaseAlgorithmType::SphereVsCapsule:
|
||||
mSphereVsCapsuleBatch.addNarrowPhaseInfo(pairId, pairIndex, proxyShape1, proxyShape2, shape1, shape2, shape1Transform, shape2Transform);
|
||||
mSphereVsCapsuleBatch.addNarrowPhaseInfo(pairId, pairIndex, collider1, collider2, shape1, shape2, shape1Transform, shape2Transform);
|
||||
break;
|
||||
case NarrowPhaseAlgorithmType::CapsuleVsCapsule:
|
||||
mCapsuleVsCapsuleBatch.addNarrowPhaseInfo(pairId, pairIndex, proxyShape1, proxyShape2, shape1, shape2, shape1Transform, shape2Transform);
|
||||
mCapsuleVsCapsuleBatch.addNarrowPhaseInfo(pairId, pairIndex, collider1, collider2, shape1, shape2, shape1Transform, shape2Transform);
|
||||
break;
|
||||
case NarrowPhaseAlgorithmType::SphereVsConvexPolyhedron:
|
||||
mSphereVsConvexPolyhedronBatch.addNarrowPhaseInfo(pairId, pairIndex, proxyShape1, proxyShape2, shape1, shape2, shape1Transform, shape2Transform, shapeAllocator);
|
||||
mSphereVsConvexPolyhedronBatch.addNarrowPhaseInfo(pairId, pairIndex, collider1, collider2, shape1, shape2, shape1Transform, shape2Transform, shapeAllocator);
|
||||
break;
|
||||
case NarrowPhaseAlgorithmType::CapsuleVsConvexPolyhedron:
|
||||
mCapsuleVsConvexPolyhedronBatch.addNarrowPhaseInfo(pairId, pairIndex, proxyShape1, proxyShape2, shape1, shape2, shape1Transform, shape2Transform, shapeAllocator);
|
||||
mCapsuleVsConvexPolyhedronBatch.addNarrowPhaseInfo(pairId, pairIndex, collider1, collider2, shape1, shape2, shape1Transform, shape2Transform, shapeAllocator);
|
||||
break;
|
||||
case NarrowPhaseAlgorithmType::ConvexPolyhedronVsConvexPolyhedron:
|
||||
mConvexPolyhedronVsConvexPolyhedronBatch.addNarrowPhaseInfo(pairId, pairIndex, proxyShape1, proxyShape2, shape1, shape2, shape1Transform, shape2Transform, shapeAllocator);
|
||||
mConvexPolyhedronVsConvexPolyhedronBatch.addNarrowPhaseInfo(pairId, pairIndex, collider1, collider2, shape1, shape2, shape1Transform, shape2Transform, shapeAllocator);
|
||||
break;
|
||||
case NarrowPhaseAlgorithmType::None:
|
||||
// Must never happen
|
||||
|
|
|
@ -67,7 +67,7 @@ class NarrowPhaseInput {
|
|||
NarrowPhaseInput(MemoryAllocator& allocator, OverlappingPairs& overlappingPairs);
|
||||
|
||||
/// Add shapes to be tested during narrow-phase collision detection into the batch
|
||||
void addNarrowPhaseTest(uint64 pairId, uint64 pairIndex, Entity proxyShape1, Entity proxyShape2, CollisionShape* shape1,
|
||||
void addNarrowPhaseTest(uint64 pairId, uint64 pairIndex, Entity collider1, Entity collider2, CollisionShape* shape1,
|
||||
CollisionShape* shape2, const Transform& shape1Transform,
|
||||
const Transform& shape2Transform, NarrowPhaseAlgorithmType narrowPhaseAlgorithmType,
|
||||
MemoryAllocator& shapeAllocator);
|
||||
|
|
|
@ -39,7 +39,7 @@ SphereVsCapsuleNarrowPhaseInfoBatch::SphereVsCapsuleNarrowPhaseInfoBatch(MemoryA
|
|||
}
|
||||
|
||||
// Add shapes to be tested during narrow-phase collision detection into the batch
|
||||
void SphereVsCapsuleNarrowPhaseInfoBatch::addNarrowPhaseInfo(uint64 pairId, uint64 pairIndex, Entity proxyShape1, Entity proxyShape2, CollisionShape* shape1, CollisionShape* shape2,
|
||||
void SphereVsCapsuleNarrowPhaseInfoBatch::addNarrowPhaseInfo(uint64 pairId, uint64 pairIndex, Entity collider1, Entity collider2, CollisionShape* shape1, CollisionShape* shape2,
|
||||
const Transform& shape1Transform, const Transform& shape2Transform) {
|
||||
|
||||
bool isSphereShape1 = shape1->getType() == CollisionShapeType::SPHERE;
|
||||
|
@ -57,8 +57,8 @@ void SphereVsCapsuleNarrowPhaseInfoBatch::addNarrowPhaseInfo(uint64 pairId, uint
|
|||
shape1ToWorldTransforms.add(shape1Transform);
|
||||
shape2ToWorldTransforms.add(shape2Transform);
|
||||
overlappingPairIds.add(pairId);
|
||||
proxyShapeEntities1.add(proxyShape1);
|
||||
proxyShapeEntities2.add(proxyShape2);
|
||||
colliderEntities1.add(collider1);
|
||||
colliderEntities2.add(collider2);
|
||||
contactPoints.add(List<ContactPointInfo*>(mMemoryAllocator));
|
||||
isColliding.add(false);
|
||||
|
||||
|
@ -71,8 +71,8 @@ void SphereVsCapsuleNarrowPhaseInfoBatch::addNarrowPhaseInfo(uint64 pairId, uint
|
|||
void SphereVsCapsuleNarrowPhaseInfoBatch::reserveMemory() {
|
||||
|
||||
overlappingPairIds.reserve(mCachedCapacity);
|
||||
proxyShapeEntities1.reserve(mCachedCapacity);
|
||||
proxyShapeEntities2.reserve(mCachedCapacity);
|
||||
colliderEntities1.reserve(mCachedCapacity);
|
||||
colliderEntities2.reserve(mCachedCapacity);
|
||||
shape1ToWorldTransforms.reserve(mCachedCapacity);
|
||||
shape2ToWorldTransforms.reserve(mCachedCapacity);
|
||||
lastFrameCollisionInfos.reserve(mCachedCapacity);
|
||||
|
@ -96,8 +96,8 @@ void SphereVsCapsuleNarrowPhaseInfoBatch::clear() {
|
|||
mCachedCapacity = overlappingPairIds.size();
|
||||
|
||||
overlappingPairIds.clear(true);
|
||||
proxyShapeEntities1.clear(true);
|
||||
proxyShapeEntities2.clear(true);
|
||||
colliderEntities1.clear(true);
|
||||
colliderEntities2.clear(true);
|
||||
shape1ToWorldTransforms.clear(true);
|
||||
shape2ToWorldTransforms.clear(true);
|
||||
lastFrameCollisionInfos.clear(true);
|
||||
|
|
|
@ -61,7 +61,7 @@ struct SphereVsCapsuleNarrowPhaseInfoBatch : public NarrowPhaseInfoBatch {
|
|||
virtual ~SphereVsCapsuleNarrowPhaseInfoBatch() = default;
|
||||
|
||||
/// Add shapes to be tested during narrow-phase collision detection into the batch
|
||||
virtual void addNarrowPhaseInfo(uint64 pairId, uint64 pairIndex, Entity proxyShape1, Entity proxyShape2, CollisionShape* shape1,
|
||||
virtual void addNarrowPhaseInfo(uint64 pairId, uint64 pairIndex, Entity collider1, Entity collider2, CollisionShape* shape1,
|
||||
CollisionShape* shape2, const Transform& shape1Transform,
|
||||
const Transform& shape2Transform);
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ SphereVsSphereNarrowPhaseInfoBatch::SphereVsSphereNarrowPhaseInfoBatch(MemoryAll
|
|||
}
|
||||
|
||||
// Add shapes to be tested during narrow-phase collision detection into the batch
|
||||
void SphereVsSphereNarrowPhaseInfoBatch::addNarrowPhaseInfo(uint64 pairId, uint64 pairIndex, Entity proxyShape1, Entity proxyShape2, CollisionShape* shape1, CollisionShape* shape2,
|
||||
void SphereVsSphereNarrowPhaseInfoBatch::addNarrowPhaseInfo(uint64 pairId, uint64 pairIndex, Entity collider1, Entity collider2, CollisionShape* shape1, CollisionShape* shape2,
|
||||
const Transform& shape1Transform, const Transform& shape2Transform) {
|
||||
|
||||
assert(shape1->getType() == CollisionShapeType::SPHERE);
|
||||
|
@ -47,8 +47,8 @@ void SphereVsSphereNarrowPhaseInfoBatch::addNarrowPhaseInfo(uint64 pairId, uint6
|
|||
|
||||
sphere1Radiuses.add(sphere1->getRadius());
|
||||
sphere2Radiuses.add(sphere2->getRadius());
|
||||
proxyShapeEntities1.add(proxyShape1);
|
||||
proxyShapeEntities2.add(proxyShape2);
|
||||
colliderEntities1.add(collider1);
|
||||
colliderEntities2.add(collider2);
|
||||
shape1ToWorldTransforms.add(shape1Transform);
|
||||
shape2ToWorldTransforms.add(shape2Transform);
|
||||
overlappingPairIds.add(pairId);
|
||||
|
@ -64,8 +64,8 @@ void SphereVsSphereNarrowPhaseInfoBatch::addNarrowPhaseInfo(uint64 pairId, uint6
|
|||
void SphereVsSphereNarrowPhaseInfoBatch::reserveMemory() {
|
||||
|
||||
overlappingPairIds.reserve(mCachedCapacity);
|
||||
proxyShapeEntities1.reserve(mCachedCapacity);
|
||||
proxyShapeEntities2.reserve(mCachedCapacity);
|
||||
colliderEntities1.reserve(mCachedCapacity);
|
||||
colliderEntities2.reserve(mCachedCapacity);
|
||||
shape1ToWorldTransforms.reserve(mCachedCapacity);
|
||||
shape2ToWorldTransforms.reserve(mCachedCapacity);
|
||||
lastFrameCollisionInfos.reserve(mCachedCapacity);
|
||||
|
@ -87,8 +87,8 @@ void SphereVsSphereNarrowPhaseInfoBatch::clear() {
|
|||
mCachedCapacity = overlappingPairIds.size();
|
||||
|
||||
overlappingPairIds.clear(true);
|
||||
proxyShapeEntities1.clear(true);
|
||||
proxyShapeEntities2.clear(true);
|
||||
colliderEntities1.clear(true);
|
||||
colliderEntities2.clear(true);
|
||||
shape1ToWorldTransforms.clear(true);
|
||||
shape2ToWorldTransforms.clear(true);
|
||||
lastFrameCollisionInfos.clear(true);
|
||||
|
|
|
@ -55,7 +55,7 @@ struct SphereVsSphereNarrowPhaseInfoBatch : public NarrowPhaseInfoBatch {
|
|||
virtual ~SphereVsSphereNarrowPhaseInfoBatch() override = default;
|
||||
|
||||
/// Add shapes to be tested during narrow-phase collision detection into the batch
|
||||
virtual void addNarrowPhaseInfo(uint64 pairId, uint64 pairIndex, Entity proxyShape1, Entity proxyShape2, CollisionShape* shape1,
|
||||
virtual void addNarrowPhaseInfo(uint64 pairId, uint64 pairIndex, Entity collider1, Entity collider2, CollisionShape* shape1,
|
||||
CollisionShape* shape2, const Transform& shape1Transform,
|
||||
const Transform& shape2Transform);
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
// Libraries
|
||||
#include "BoxShape.h"
|
||||
#include "collision/ProxyShape.h"
|
||||
#include "collision/Collider.h"
|
||||
#include "configuration.h"
|
||||
#include "memory/MemoryManager.h"
|
||||
#include "collision/RaycastInfo.h"
|
||||
|
@ -96,7 +96,7 @@ void BoxShape::computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass) const
|
|||
}
|
||||
|
||||
// Raycast method with feedback information
|
||||
bool BoxShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape, MemoryAllocator& allocator) const {
|
||||
bool BoxShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, Collider* collider, MemoryAllocator& allocator) const {
|
||||
|
||||
Vector3 rayDirection = ray.point2 - ray.point1;
|
||||
decimal tMin = DECIMAL_SMALLEST;
|
||||
|
@ -151,8 +151,8 @@ bool BoxShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* pro
|
|||
// The ray intersects the three slabs, we compute the hit point
|
||||
Vector3 localHitPoint = ray.point1 + tMin * rayDirection;
|
||||
|
||||
raycastInfo.body = proxyShape->getBody();
|
||||
raycastInfo.proxyShape = proxyShape;
|
||||
raycastInfo.body = collider->getBody();
|
||||
raycastInfo.collider = collider;
|
||||
raycastInfo.hitFraction = tMin;
|
||||
raycastInfo.worldPoint = localHitPoint;
|
||||
raycastInfo.worldNormal = normalDirection;
|
||||
|
|
|
@ -65,10 +65,10 @@ class BoxShape : public ConvexPolyhedronShape {
|
|||
virtual Vector3 getLocalSupportPointWithoutMargin(const Vector3& direction) const override;
|
||||
|
||||
/// Return true if a point is inside the collision shape
|
||||
virtual bool testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const override;
|
||||
virtual bool testPointInside(const Vector3& localPoint, Collider* collider) const override;
|
||||
|
||||
/// Raycast method with feedback information
|
||||
virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape, MemoryAllocator& allocator) const override;
|
||||
virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, Collider* collider, MemoryAllocator& allocator) const override;
|
||||
|
||||
/// Return the number of bytes used by the collision shape
|
||||
virtual size_t getSizeInBytes() const override;
|
||||
|
@ -167,7 +167,7 @@ inline Vector3 BoxShape::getLocalSupportPointWithoutMargin(const Vector3& direct
|
|||
}
|
||||
|
||||
// Return true if a point is inside the collision shape
|
||||
inline bool BoxShape::testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const {
|
||||
inline bool BoxShape::testPointInside(const Vector3& localPoint, Collider* collider) const {
|
||||
return (localPoint.x < mExtent[0] && localPoint.x > -mExtent[0] &&
|
||||
localPoint.y < mExtent[1] && localPoint.y > -mExtent[1] &&
|
||||
localPoint.z < mExtent[2] && localPoint.z > -mExtent[2]);
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
// Libraries
|
||||
#include "CapsuleShape.h"
|
||||
#include "collision/ProxyShape.h"
|
||||
#include "collision/Collider.h"
|
||||
#include "configuration.h"
|
||||
#include "collision/RaycastInfo.h"
|
||||
#include <cassert>
|
||||
|
@ -70,7 +70,7 @@ void CapsuleShape::computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass) co
|
|||
}
|
||||
|
||||
// Return true if a point is inside the collision shape
|
||||
bool CapsuleShape::testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const {
|
||||
bool CapsuleShape::testPointInside(const Vector3& localPoint, Collider* collider) const {
|
||||
|
||||
const decimal diffYCenterSphere1 = localPoint.y - mHalfHeight;
|
||||
const decimal diffYCenterSphere2 = localPoint.y + mHalfHeight;
|
||||
|
@ -86,7 +86,7 @@ bool CapsuleShape::testPointInside(const Vector3& localPoint, ProxyShape* proxyS
|
|||
}
|
||||
|
||||
// Raycast method with feedback information
|
||||
bool CapsuleShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape, MemoryAllocator& allocator) const {
|
||||
bool CapsuleShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, Collider* collider, MemoryAllocator& allocator) const {
|
||||
|
||||
const Vector3 n = ray.point2 - ray.point1;
|
||||
|
||||
|
@ -129,8 +129,8 @@ bool CapsuleShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape*
|
|||
Vector3 hitLocalPoint;
|
||||
decimal hitFraction;
|
||||
if (raycastWithSphereEndCap(ray.point1, ray.point2, p, ray.maxFraction, hitLocalPoint, hitFraction)) {
|
||||
raycastInfo.body = proxyShape->getBody();
|
||||
raycastInfo.proxyShape = proxyShape;
|
||||
raycastInfo.body = collider->getBody();
|
||||
raycastInfo.collider = collider;
|
||||
raycastInfo.hitFraction = hitFraction;
|
||||
raycastInfo.worldPoint = hitLocalPoint;
|
||||
Vector3 normalDirection = hitLocalPoint - p;
|
||||
|
@ -147,8 +147,8 @@ bool CapsuleShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape*
|
|||
Vector3 hitLocalPoint;
|
||||
decimal hitFraction;
|
||||
if (raycastWithSphereEndCap(ray.point1, ray.point2, q, ray.maxFraction, hitLocalPoint, hitFraction)) {
|
||||
raycastInfo.body = proxyShape->getBody();
|
||||
raycastInfo.proxyShape = proxyShape;
|
||||
raycastInfo.body = collider->getBody();
|
||||
raycastInfo.collider = collider;
|
||||
raycastInfo.hitFraction = hitFraction;
|
||||
raycastInfo.worldPoint = hitLocalPoint;
|
||||
Vector3 normalDirection = hitLocalPoint - q;
|
||||
|
@ -180,8 +180,8 @@ bool CapsuleShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape*
|
|||
Vector3 hitLocalPoint;
|
||||
decimal hitFraction;
|
||||
if (raycastWithSphereEndCap(ray.point1, ray.point2, p, ray.maxFraction, hitLocalPoint, hitFraction)) {
|
||||
raycastInfo.body = proxyShape->getBody();
|
||||
raycastInfo.proxyShape = proxyShape;
|
||||
raycastInfo.body = collider->getBody();
|
||||
raycastInfo.collider = collider;
|
||||
raycastInfo.hitFraction = hitFraction;
|
||||
raycastInfo.worldPoint = hitLocalPoint;
|
||||
Vector3 normalDirection = hitLocalPoint - p;
|
||||
|
@ -198,8 +198,8 @@ bool CapsuleShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape*
|
|||
Vector3 hitLocalPoint;
|
||||
decimal hitFraction;
|
||||
if (raycastWithSphereEndCap(ray.point1, ray.point2, q, ray.maxFraction, hitLocalPoint, hitFraction)) {
|
||||
raycastInfo.body = proxyShape->getBody();
|
||||
raycastInfo.proxyShape = proxyShape;
|
||||
raycastInfo.body = collider->getBody();
|
||||
raycastInfo.collider = collider;
|
||||
raycastInfo.hitFraction = hitFraction;
|
||||
raycastInfo.worldPoint = hitLocalPoint;
|
||||
Vector3 normalDirection = hitLocalPoint - q;
|
||||
|
@ -219,8 +219,8 @@ bool CapsuleShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape*
|
|||
|
||||
// Compute the hit information
|
||||
Vector3 localHitPoint = ray.point1 + t * n;
|
||||
raycastInfo.body = proxyShape->getBody();
|
||||
raycastInfo.proxyShape = proxyShape;
|
||||
raycastInfo.body = collider->getBody();
|
||||
raycastInfo.collider = collider;
|
||||
raycastInfo.hitFraction = t;
|
||||
raycastInfo.worldPoint = localHitPoint;
|
||||
Vector3 v = localHitPoint - p;
|
||||
|
|
|
@ -64,10 +64,10 @@ class CapsuleShape : public ConvexShape {
|
|||
virtual Vector3 getLocalSupportPointWithoutMargin(const Vector3& direction) const override;
|
||||
|
||||
/// Return true if a point is inside the collision shape
|
||||
virtual bool testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const override;
|
||||
virtual bool testPointInside(const Vector3& localPoint, Collider* collider) const override;
|
||||
|
||||
/// Raycast method with feedback information
|
||||
virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape, MemoryAllocator& allocator) const override;
|
||||
virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, Collider* collider, MemoryAllocator& allocator) const override;
|
||||
|
||||
/// Raycasting method between a ray one of the two spheres end cap of the capsule
|
||||
bool raycastWithSphereEndCap(const Vector3& point1, const Vector3& point2,
|
||||
|
|
|
@ -52,7 +52,7 @@ const int NB_COLLISION_SHAPE_TYPES = 4;
|
|||
enum class CollisionShapeName { TRIANGLE, SPHERE, CAPSULE, BOX, CONVEX_MESH, TRIANGLE_MESH, HEIGHTFIELD };
|
||||
|
||||
// Declarations
|
||||
class ProxyShape;
|
||||
class Collider;
|
||||
class CollisionBody;
|
||||
|
||||
// Class CollisionShape
|
||||
|
@ -85,10 +85,10 @@ class CollisionShape {
|
|||
// -------------------- Methods -------------------- //
|
||||
|
||||
/// Return true if a point is inside the collision shape
|
||||
virtual bool testPointInside(const Vector3& worldPoint, ProxyShape* proxyShape) const=0;
|
||||
virtual bool testPointInside(const Vector3& worldPoint, Collider* collider) const=0;
|
||||
|
||||
/// Raycast method with feedback information
|
||||
virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape, MemoryAllocator& allocator) const=0;
|
||||
virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, Collider* collider, MemoryAllocator& allocator) const=0;
|
||||
|
||||
/// Return the number of bytes used by the collision shape
|
||||
virtual size_t getSizeInBytes() const = 0;
|
||||
|
@ -145,7 +145,7 @@ class CollisionShape {
|
|||
|
||||
// -------------------- Friendship -------------------- //
|
||||
|
||||
friend class ProxyShape;
|
||||
friend class Collider;
|
||||
friend class CollisionWorld;
|
||||
};
|
||||
|
||||
|
|
|
@ -176,12 +176,12 @@ void ConcaveMeshShape::computeOverlappingTriangles(const AABB& localAABB, List<V
|
|||
// Raycast method with feedback information
|
||||
/// Note that only the first triangle hit by the ray in the mesh will be returned, even if
|
||||
/// the ray hits many triangles.
|
||||
bool ConcaveMeshShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape, MemoryAllocator& allocator) const {
|
||||
bool ConcaveMeshShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, Collider* collider, MemoryAllocator& allocator) const {
|
||||
|
||||
RP3D_PROFILE("ConcaveMeshShape::raycast()", mProfiler);
|
||||
|
||||
// Create the callback object that will compute ray casting against triangles
|
||||
ConcaveMeshRaycastCallback raycastCallback(mDynamicAABBTree, *this, proxyShape, raycastInfo, ray, allocator);
|
||||
ConcaveMeshRaycastCallback raycastCallback(mDynamicAABBTree, *this, collider, raycastInfo, ray, allocator);
|
||||
|
||||
#ifdef IS_PROFILING_ACTIVE
|
||||
|
||||
|
@ -259,7 +259,7 @@ void ConcaveMeshRaycastCallback::raycastTriangles() {
|
|||
|
||||
// Ray casting test against the collision shape
|
||||
RaycastInfo raycastInfo;
|
||||
bool isTriangleHit = triangleShape.raycast(mRay, raycastInfo, mProxyShape, mAllocator);
|
||||
bool isTriangleHit = triangleShape.raycast(mRay, raycastInfo, mCollider, mAllocator);
|
||||
|
||||
// If the ray hit the collision shape
|
||||
if (isTriangleHit && raycastInfo.hitFraction <= smallestHitFraction) {
|
||||
|
@ -267,7 +267,7 @@ void ConcaveMeshRaycastCallback::raycastTriangles() {
|
|||
assert(raycastInfo.hitFraction >= decimal(0.0));
|
||||
|
||||
mRaycastInfo.body = raycastInfo.body;
|
||||
mRaycastInfo.proxyShape = raycastInfo.proxyShape;
|
||||
mRaycastInfo.collider = raycastInfo.collider;
|
||||
mRaycastInfo.hitFraction = raycastInfo.hitFraction;
|
||||
mRaycastInfo.worldPoint = raycastInfo.worldPoint;
|
||||
mRaycastInfo.worldNormal = raycastInfo.worldNormal;
|
||||
|
|
|
@ -75,7 +75,7 @@ class ConcaveMeshRaycastCallback : public DynamicAABBTreeRaycastCallback {
|
|||
List<int32> mHitAABBNodes;
|
||||
const DynamicAABBTree& mDynamicAABBTree;
|
||||
const ConcaveMeshShape& mConcaveMeshShape;
|
||||
ProxyShape* mProxyShape;
|
||||
Collider* mCollider;
|
||||
RaycastInfo& mRaycastInfo;
|
||||
const Ray& mRay;
|
||||
bool mIsHit;
|
||||
|
@ -92,8 +92,8 @@ class ConcaveMeshRaycastCallback : public DynamicAABBTreeRaycastCallback {
|
|||
|
||||
// Constructor
|
||||
ConcaveMeshRaycastCallback(const DynamicAABBTree& dynamicAABBTree, const ConcaveMeshShape& concaveMeshShape,
|
||||
ProxyShape* proxyShape, RaycastInfo& raycastInfo, const Ray& ray, MemoryAllocator& allocator)
|
||||
: mHitAABBNodes(allocator), mDynamicAABBTree(dynamicAABBTree), mConcaveMeshShape(concaveMeshShape), mProxyShape(proxyShape),
|
||||
Collider* collider, RaycastInfo& raycastInfo, const Ray& ray, MemoryAllocator& allocator)
|
||||
: mHitAABBNodes(allocator), mDynamicAABBTree(dynamicAABBTree), mConcaveMeshShape(concaveMeshShape), mCollider(collider),
|
||||
mRaycastInfo(raycastInfo), mRay(ray), mIsHit(false), mAllocator(allocator) {
|
||||
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ class ConcaveMeshShape : public ConcaveShape {
|
|||
ConcaveMeshShape(TriangleMesh* triangleMesh, MemoryAllocator& allocator, const Vector3& scaling = Vector3(1, 1, 1));
|
||||
|
||||
/// Raycast method with feedback information
|
||||
virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape, MemoryAllocator& allocator) const override;
|
||||
virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, Collider* collider, MemoryAllocator& allocator) const override;
|
||||
|
||||
/// Return the number of bytes used by the collision shape
|
||||
virtual size_t getSizeInBytes() const override;
|
||||
|
|
|
@ -68,7 +68,7 @@ class ConcaveShape : public CollisionShape {
|
|||
// -------------------- Methods -------------------- //
|
||||
|
||||
/// Return true if a point is inside the collision shape
|
||||
virtual bool testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const override;
|
||||
virtual bool testPointInside(const Vector3& localPoint, Collider* collider) const override;
|
||||
|
||||
public :
|
||||
|
||||
|
@ -115,7 +115,7 @@ inline bool ConcaveShape::isPolyhedron() const {
|
|||
}
|
||||
|
||||
// Return true if a point is inside the collision shape
|
||||
inline bool ConcaveShape::testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const {
|
||||
inline bool ConcaveShape::testPointInside(const Vector3& localPoint, Collider* collider) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ void ConvexMeshShape::recalculateBounds() {
|
|||
// Raycast method with feedback information
|
||||
/// This method implements the technique in the book "Real-time Collision Detection" by
|
||||
/// Christer Ericson.
|
||||
bool ConvexMeshShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape, MemoryAllocator& allocator) const {
|
||||
bool ConvexMeshShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, Collider* collider, MemoryAllocator& allocator) const {
|
||||
|
||||
// Ray direction
|
||||
Vector3 direction = ray.point2 - ray.point1;
|
||||
|
@ -172,8 +172,8 @@ bool ConvexMeshShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxySha
|
|||
Vector3 localHitPoint = ray.point1 + tMin * direction;
|
||||
|
||||
raycastInfo.hitFraction = tMin;
|
||||
raycastInfo.body = proxyShape->getBody();
|
||||
raycastInfo.proxyShape = proxyShape;
|
||||
raycastInfo.body = collider->getBody();
|
||||
raycastInfo.collider = collider;
|
||||
raycastInfo.worldPoint = localHitPoint;
|
||||
raycastInfo.worldNormal = currentFaceNormal;
|
||||
|
||||
|
@ -184,7 +184,7 @@ bool ConvexMeshShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxySha
|
|||
}
|
||||
|
||||
// Return true if a point is inside the collision shape
|
||||
bool ConvexMeshShape::testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const {
|
||||
bool ConvexMeshShape::testPointInside(const Vector3& localPoint, Collider* collider) const {
|
||||
|
||||
const HalfEdgeStructure& halfEdgeStructure = mPolyhedronMesh->getHalfEdgeStructure();
|
||||
|
||||
|
|
|
@ -76,10 +76,10 @@ class ConvexMeshShape : public ConvexPolyhedronShape {
|
|||
virtual Vector3 getLocalSupportPointWithoutMargin(const Vector3& direction) const override;
|
||||
|
||||
/// Return true if a point is inside the collision shape
|
||||
virtual bool testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const override;
|
||||
virtual bool testPointInside(const Vector3& localPoint, Collider* collider) const override;
|
||||
|
||||
/// Raycast method with feedback information
|
||||
virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape, MemoryAllocator& allocator) const override;
|
||||
virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, Collider* collider, MemoryAllocator& allocator) const override;
|
||||
|
||||
/// Return the number of bytes used by the collision shape
|
||||
virtual size_t getSizeInBytes() const override;
|
||||
|
|
|
@ -224,7 +224,7 @@ void HeightFieldShape::computeMinMaxGridCoordinates(int* minCoords, int* maxCoor
|
|||
// Raycast method with feedback information
|
||||
/// Note that only the first triangle hit by the ray in the mesh will be returned, even if
|
||||
/// the ray hits many triangles.
|
||||
bool HeightFieldShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape, MemoryAllocator& allocator) const {
|
||||
bool HeightFieldShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, Collider* collider, MemoryAllocator& allocator) const {
|
||||
|
||||
// TODO : Implement raycasting without using an AABB for the ray
|
||||
// but using a dynamic AABB tree or octree instead
|
||||
|
@ -265,7 +265,7 @@ bool HeightFieldShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxySh
|
|||
|
||||
// Ray casting test against the collision shape
|
||||
RaycastInfo triangleRaycastInfo;
|
||||
bool isTriangleHit = triangleShape.raycast(ray, triangleRaycastInfo, proxyShape, allocator);
|
||||
bool isTriangleHit = triangleShape.raycast(ray, triangleRaycastInfo, collider, allocator);
|
||||
|
||||
// If the ray hit the collision shape
|
||||
if (isTriangleHit && triangleRaycastInfo.hitFraction <= smallestHitFraction) {
|
||||
|
@ -273,7 +273,7 @@ bool HeightFieldShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxySh
|
|||
assert(triangleRaycastInfo.hitFraction >= decimal(0.0));
|
||||
|
||||
raycastInfo.body = triangleRaycastInfo.body;
|
||||
raycastInfo.proxyShape = triangleRaycastInfo.proxyShape;
|
||||
raycastInfo.collider = triangleRaycastInfo.collider;
|
||||
raycastInfo.hitFraction = triangleRaycastInfo.hitFraction;
|
||||
raycastInfo.worldPoint = triangleRaycastInfo.worldPoint;
|
||||
raycastInfo.worldNormal = triangleRaycastInfo.worldNormal;
|
||||
|
|
|
@ -103,7 +103,7 @@ class HeightFieldShape : public ConcaveShape {
|
|||
const Vector3& scaling = Vector3(1,1,1));
|
||||
|
||||
/// Raycast method with feedback information
|
||||
virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape, MemoryAllocator& allocator) const override;
|
||||
virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, Collider* collider, MemoryAllocator& allocator) const override;
|
||||
|
||||
/// Return the number of bytes used by the collision shape
|
||||
virtual size_t getSizeInBytes() const override;
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
// Libraries
|
||||
#include "SphereShape.h"
|
||||
#include "collision/ProxyShape.h"
|
||||
#include "collision/Collider.h"
|
||||
#include "configuration.h"
|
||||
#include "collision/RaycastInfo.h"
|
||||
#include <cassert>
|
||||
|
@ -60,7 +60,7 @@ void SphereShape::computeAABB(AABB& aabb, const Transform& transform) const {
|
|||
}
|
||||
|
||||
// Raycast method with feedback information
|
||||
bool SphereShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape, MemoryAllocator& allocator) const {
|
||||
bool SphereShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, Collider* collider, MemoryAllocator& allocator) const {
|
||||
|
||||
const Vector3 m = ray.point1;
|
||||
decimal c = m.dot(m) - mMargin * mMargin;
|
||||
|
@ -93,8 +93,8 @@ bool SphereShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape*
|
|||
|
||||
// Compute the intersection information
|
||||
t /= raySquareLength;
|
||||
raycastInfo.body = proxyShape->getBody();
|
||||
raycastInfo.proxyShape = proxyShape;
|
||||
raycastInfo.body = collider->getBody();
|
||||
raycastInfo.collider = collider;
|
||||
raycastInfo.hitFraction = t;
|
||||
raycastInfo.worldPoint = ray.point1 + t * rayDirection;
|
||||
raycastInfo.worldNormal = raycastInfo.worldPoint;
|
||||
|
|
|
@ -57,10 +57,10 @@ class SphereShape : public ConvexShape {
|
|||
virtual Vector3 getLocalSupportPointWithoutMargin(const Vector3& direction) const override;
|
||||
|
||||
/// Return true if a point is inside the collision shape
|
||||
virtual bool testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const override;
|
||||
virtual bool testPointInside(const Vector3& localPoint, Collider* collider) const override;
|
||||
|
||||
/// Raycast method with feedback information
|
||||
virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape, MemoryAllocator& allocator) const override;
|
||||
virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, Collider* collider, MemoryAllocator& allocator) const override;
|
||||
|
||||
/// Return the number of bytes used by the collision shape
|
||||
virtual size_t getSizeInBytes() const override;
|
||||
|
@ -165,7 +165,7 @@ inline void SphereShape::computeLocalInertiaTensor(Matrix3x3& tensor, decimal ma
|
|||
}
|
||||
|
||||
// Return true if a point is inside the collision shape
|
||||
inline bool SphereShape::testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const {
|
||||
inline bool SphereShape::testPointInside(const Vector3& localPoint, Collider* collider) const {
|
||||
return (localPoint.lengthSquare() < mMargin * mMargin);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
// Libraries
|
||||
#include "TriangleShape.h"
|
||||
#include "collision/ProxyShape.h"
|
||||
#include "collision/Collider.h"
|
||||
#include "mathematics/mathematics_functions.h"
|
||||
#include "collision/RaycastInfo.h"
|
||||
#include "utils/Profiler.h"
|
||||
|
@ -237,7 +237,7 @@ void TriangleShape::computeAABB(AABB& aabb, const Transform& transform) const {
|
|||
// Raycast method with feedback information
|
||||
/// This method use the line vs triangle raycasting technique described in
|
||||
/// Real-time Collision Detection by Christer Ericson.
|
||||
bool TriangleShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape, MemoryAllocator& allocator) const {
|
||||
bool TriangleShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, Collider* collider, MemoryAllocator& allocator) const {
|
||||
|
||||
RP3D_PROFILE("TriangleShape::raycast()", mProfiler);
|
||||
|
||||
|
@ -298,8 +298,8 @@ bool TriangleShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape
|
|||
Vector3 localHitNormal = (mPoints[1] - mPoints[0]).cross(mPoints[2] - mPoints[0]);
|
||||
if (localHitNormal.dot(pq) > decimal(0.0)) localHitNormal = -localHitNormal;
|
||||
|
||||
raycastInfo.body = proxyShape->getBody();
|
||||
raycastInfo.proxyShape = proxyShape;
|
||||
raycastInfo.body = collider->getBody();
|
||||
raycastInfo.collider = collider;
|
||||
raycastInfo.worldPoint = localHitPoint;
|
||||
raycastInfo.hitFraction = hitFraction;
|
||||
raycastInfo.worldNormal = localHitNormal;
|
||||
|
|
|
@ -87,11 +87,11 @@ class TriangleShape : public ConvexPolyhedronShape {
|
|||
/// Get a smooth contact normal for collision for a triangle of the mesh
|
||||
Vector3 computeSmoothLocalContactNormalForTriangle(const Vector3& localContactPoint) const;
|
||||
|
||||
/// Return true if a point is inside the collision shape
|
||||
virtual bool testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const override;
|
||||
/// Return true if a point is inside the collider
|
||||
virtual bool testPointInside(const Vector3& localPoint, Collider* collider) const override;
|
||||
|
||||
/// Raycast method with feedback information
|
||||
virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape,
|
||||
virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, Collider* collider,
|
||||
MemoryAllocator& allocator) const override;
|
||||
|
||||
/// Return the number of bytes used by the collision shape
|
||||
|
@ -224,7 +224,7 @@ inline void TriangleShape::computeLocalInertiaTensor(Matrix3x3& tensor, decimal
|
|||
}
|
||||
|
||||
// Return true if a point is inside the collision shape
|
||||
inline bool TriangleShape::testPointInside(const Vector3& localPoint, ProxyShape* proxyShape) const {
|
||||
inline bool TriangleShape::testPointInside(const Vector3& localPoint, Collider* collider) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,9 +24,9 @@
|
|||
********************************************************************************/
|
||||
|
||||
// Libraries
|
||||
#include "ProxyShapeComponents.h"
|
||||
#include "ColliderComponents.h"
|
||||
#include "engine/EntityManager.h"
|
||||
#include "collision/ProxyShape.h"
|
||||
#include "collision/Collider.h"
|
||||
#include <cassert>
|
||||
#include <random>
|
||||
|
||||
|
@ -34,8 +34,8 @@
|
|||
using namespace reactphysics3d;
|
||||
|
||||
// Constructor
|
||||
ProxyShapeComponents::ProxyShapeComponents(MemoryAllocator& allocator)
|
||||
:Components(allocator, sizeof(Entity) + sizeof(Entity) + sizeof(ProxyShape*) + sizeof(int) +
|
||||
ColliderComponents::ColliderComponents(MemoryAllocator& allocator)
|
||||
:Components(allocator, sizeof(Entity) + sizeof(Entity) + sizeof(Collider*) + sizeof(int) +
|
||||
sizeof(Transform) + sizeof(CollisionShape*) + sizeof(decimal) + sizeof(unsigned short) +
|
||||
sizeof(unsigned short) + sizeof(Transform) + sizeof(List<uint64>)) {
|
||||
|
||||
|
@ -44,7 +44,7 @@ ProxyShapeComponents::ProxyShapeComponents(MemoryAllocator& allocator)
|
|||
}
|
||||
|
||||
// Allocate memory for a given number of components
|
||||
void ProxyShapeComponents::allocate(uint32 nbComponentsToAllocate) {
|
||||
void ColliderComponents::allocate(uint32 nbComponentsToAllocate) {
|
||||
|
||||
assert(nbComponentsToAllocate > mNbAllocatedComponents);
|
||||
|
||||
|
@ -56,10 +56,10 @@ void ProxyShapeComponents::allocate(uint32 nbComponentsToAllocate) {
|
|||
assert(newBuffer != nullptr);
|
||||
|
||||
// New pointers to components data
|
||||
Entity* newProxyShapesEntities = static_cast<Entity*>(newBuffer);
|
||||
Entity* newBodiesEntities = reinterpret_cast<Entity*>(newProxyShapesEntities + nbComponentsToAllocate);
|
||||
ProxyShape** newProxyShapes = reinterpret_cast<ProxyShape**>(newBodiesEntities + nbComponentsToAllocate);
|
||||
int32* newBroadPhaseIds = reinterpret_cast<int32*>(newProxyShapes + nbComponentsToAllocate);
|
||||
Entity* newCollidersEntities = static_cast<Entity*>(newBuffer);
|
||||
Entity* newBodiesEntities = reinterpret_cast<Entity*>(newCollidersEntities + nbComponentsToAllocate);
|
||||
Collider** newColliders = reinterpret_cast<Collider**>(newBodiesEntities + nbComponentsToAllocate);
|
||||
int32* newBroadPhaseIds = reinterpret_cast<int32*>(newColliders + nbComponentsToAllocate);
|
||||
Transform* newLocalToBodyTransforms = reinterpret_cast<Transform*>(newBroadPhaseIds + nbComponentsToAllocate);
|
||||
CollisionShape** newCollisionShapes = reinterpret_cast<CollisionShape**>(newLocalToBodyTransforms + nbComponentsToAllocate);
|
||||
decimal* newMasses = reinterpret_cast<decimal*>(newCollisionShapes + nbComponentsToAllocate);
|
||||
|
@ -72,9 +72,9 @@ void ProxyShapeComponents::allocate(uint32 nbComponentsToAllocate) {
|
|||
if (mNbComponents > 0) {
|
||||
|
||||
// Copy component data from the previous buffer to the new one
|
||||
memcpy(newProxyShapesEntities, mProxyShapesEntities, mNbComponents * sizeof(Entity));
|
||||
memcpy(newCollidersEntities, mCollidersEntities, mNbComponents * sizeof(Entity));
|
||||
memcpy(newBodiesEntities, mBodiesEntities, mNbComponents * sizeof(Entity));
|
||||
memcpy(newProxyShapes, mProxyShapes, mNbComponents * sizeof(ProxyShape*));
|
||||
memcpy(newColliders, mColliders, mNbComponents * sizeof(Collider*));
|
||||
memcpy(newBroadPhaseIds, mBroadPhaseIds, mNbComponents * sizeof(int32));
|
||||
memcpy(newLocalToBodyTransforms, mLocalToBodyTransforms, mNbComponents * sizeof(Transform));
|
||||
memcpy(newCollisionShapes, mCollisionShapes, mNbComponents * sizeof(CollisionShape*));
|
||||
|
@ -89,10 +89,10 @@ void ProxyShapeComponents::allocate(uint32 nbComponentsToAllocate) {
|
|||
}
|
||||
|
||||
mBuffer = newBuffer;
|
||||
mProxyShapesEntities = newProxyShapesEntities;
|
||||
mCollidersEntities = newCollidersEntities;
|
||||
mBodiesEntities = newBodiesEntities;
|
||||
mProxyShapesEntities = newProxyShapesEntities;
|
||||
mProxyShapes = newProxyShapes;
|
||||
mCollidersEntities = newCollidersEntities;
|
||||
mColliders = newColliders;
|
||||
mBroadPhaseIds = newBroadPhaseIds;
|
||||
mLocalToBodyTransforms = newLocalToBodyTransforms;
|
||||
mCollisionShapes = newCollisionShapes;
|
||||
|
@ -106,15 +106,15 @@ void ProxyShapeComponents::allocate(uint32 nbComponentsToAllocate) {
|
|||
}
|
||||
|
||||
// Add a component
|
||||
void ProxyShapeComponents::addComponent(Entity proxyShapeEntity, bool isSleeping, const ProxyShapeComponent& component) {
|
||||
void ColliderComponents::addComponent(Entity colliderEntity, bool isSleeping, const ColliderComponent& component) {
|
||||
|
||||
// Prepare to add new component (allocate memory if necessary and compute insertion index)
|
||||
uint32 index = prepareAddComponent(isSleeping);
|
||||
|
||||
// Insert the new component data
|
||||
new (mProxyShapesEntities + index) Entity(proxyShapeEntity);
|
||||
new (mCollidersEntities + index) Entity(colliderEntity);
|
||||
new (mBodiesEntities + index) Entity(component.bodyEntity);
|
||||
mProxyShapes[index] = component.proxyShape;
|
||||
mColliders[index] = component.collider;
|
||||
new (mBroadPhaseIds + index) int32(-1);
|
||||
new (mLocalToBodyTransforms + index) Transform(component.localToBodyTransform);
|
||||
mCollisionShapes[index] = component.collisionShape;
|
||||
|
@ -125,7 +125,7 @@ void ProxyShapeComponents::addComponent(Entity proxyShapeEntity, bool isSleeping
|
|||
new (mOverlappingPairs + index) List<uint64>(mMemoryAllocator);
|
||||
|
||||
// Map the entity with the new component lookup index
|
||||
mMapEntityToComponentIndex.add(Pair<Entity, uint32>(proxyShapeEntity, index));
|
||||
mMapEntityToComponentIndex.add(Pair<Entity, uint32>(colliderEntity, index));
|
||||
|
||||
mNbComponents++;
|
||||
|
||||
|
@ -134,14 +134,14 @@ void ProxyShapeComponents::addComponent(Entity proxyShapeEntity, bool isSleeping
|
|||
|
||||
// Move a component from a source to a destination index in the components array
|
||||
// The destination location must contain a constructed object
|
||||
void ProxyShapeComponents::moveComponentToIndex(uint32 srcIndex, uint32 destIndex) {
|
||||
void ColliderComponents::moveComponentToIndex(uint32 srcIndex, uint32 destIndex) {
|
||||
|
||||
const Entity proxyShapeEntity = mProxyShapesEntities[srcIndex];
|
||||
const Entity colliderEntity = mCollidersEntities[srcIndex];
|
||||
|
||||
// Copy the data of the source component to the destination location
|
||||
new (mProxyShapesEntities + destIndex) Entity(mProxyShapesEntities[srcIndex]);
|
||||
new (mCollidersEntities + destIndex) Entity(mCollidersEntities[srcIndex]);
|
||||
new (mBodiesEntities + destIndex) Entity(mBodiesEntities[srcIndex]);
|
||||
mProxyShapes[destIndex] = mProxyShapes[srcIndex];
|
||||
mColliders[destIndex] = mColliders[srcIndex];
|
||||
new (mBroadPhaseIds + destIndex) int32(mBroadPhaseIds[srcIndex]);
|
||||
new (mLocalToBodyTransforms + destIndex) Transform(mLocalToBodyTransforms[srcIndex]);
|
||||
mCollisionShapes[destIndex] = mCollisionShapes[srcIndex];
|
||||
|
@ -154,21 +154,21 @@ void ProxyShapeComponents::moveComponentToIndex(uint32 srcIndex, uint32 destInde
|
|||
// Destroy the source component
|
||||
destroyComponent(srcIndex);
|
||||
|
||||
assert(!mMapEntityToComponentIndex.containsKey(proxyShapeEntity));
|
||||
assert(!mMapEntityToComponentIndex.containsKey(colliderEntity));
|
||||
|
||||
// Update the entity to component index mapping
|
||||
mMapEntityToComponentIndex.add(Pair<Entity, uint32>(proxyShapeEntity, destIndex));
|
||||
mMapEntityToComponentIndex.add(Pair<Entity, uint32>(colliderEntity, destIndex));
|
||||
|
||||
assert(mMapEntityToComponentIndex[mProxyShapesEntities[destIndex]] == destIndex);
|
||||
assert(mMapEntityToComponentIndex[mCollidersEntities[destIndex]] == destIndex);
|
||||
}
|
||||
|
||||
// Swap two components in the array
|
||||
void ProxyShapeComponents::swapComponents(uint32 index1, uint32 index2) {
|
||||
void ColliderComponents::swapComponents(uint32 index1, uint32 index2) {
|
||||
|
||||
// Copy component 1 data
|
||||
Entity proxyShapeEntity1(mProxyShapesEntities[index1]);
|
||||
Entity colliderEntity1(mCollidersEntities[index1]);
|
||||
Entity bodyEntity1(mBodiesEntities[index1]);
|
||||
ProxyShape* proxyShape1 = mProxyShapes[index1];
|
||||
Collider* collider1 = mColliders[index1];
|
||||
int32 broadPhaseId1 = mBroadPhaseIds[index1];
|
||||
Transform localToBodyTransform1 = mLocalToBodyTransforms[index1];
|
||||
CollisionShape* collisionShape1 = mCollisionShapes[index1];
|
||||
|
@ -184,9 +184,9 @@ void ProxyShapeComponents::swapComponents(uint32 index1, uint32 index2) {
|
|||
moveComponentToIndex(index2, index1);
|
||||
|
||||
// Reconstruct component 1 at component 2 location
|
||||
new (mProxyShapesEntities + index2) Entity(proxyShapeEntity1);
|
||||
new (mCollidersEntities + index2) Entity(colliderEntity1);
|
||||
new (mBodiesEntities + index2) Entity(bodyEntity1);
|
||||
mProxyShapes[index2] = proxyShape1;
|
||||
mColliders[index2] = collider1;
|
||||
new (mBroadPhaseIds + index2) int32(broadPhaseId1);
|
||||
new (mLocalToBodyTransforms + index2) Transform(localToBodyTransform1);
|
||||
mCollisionShapes[index2] = collisionShape1;
|
||||
|
@ -197,25 +197,25 @@ void ProxyShapeComponents::swapComponents(uint32 index1, uint32 index2) {
|
|||
new (mOverlappingPairs + index2) List<uint64>(overlappingPairs);
|
||||
|
||||
// Update the entity to component index mapping
|
||||
mMapEntityToComponentIndex.add(Pair<Entity, uint32>(proxyShapeEntity1, index2));
|
||||
mMapEntityToComponentIndex.add(Pair<Entity, uint32>(colliderEntity1, index2));
|
||||
|
||||
assert(mMapEntityToComponentIndex[mProxyShapesEntities[index1]] == index1);
|
||||
assert(mMapEntityToComponentIndex[mProxyShapesEntities[index2]] == index2);
|
||||
assert(mMapEntityToComponentIndex[mCollidersEntities[index1]] == index1);
|
||||
assert(mMapEntityToComponentIndex[mCollidersEntities[index2]] == index2);
|
||||
assert(mNbComponents == static_cast<uint32>(mMapEntityToComponentIndex.size()));
|
||||
}
|
||||
|
||||
// Destroy a component at a given index
|
||||
void ProxyShapeComponents::destroyComponent(uint32 index) {
|
||||
void ColliderComponents::destroyComponent(uint32 index) {
|
||||
|
||||
Components::destroyComponent(index);
|
||||
|
||||
assert(mMapEntityToComponentIndex[mProxyShapesEntities[index]] == index);
|
||||
assert(mMapEntityToComponentIndex[mCollidersEntities[index]] == index);
|
||||
|
||||
mMapEntityToComponentIndex.remove(mProxyShapesEntities[index]);
|
||||
mMapEntityToComponentIndex.remove(mCollidersEntities[index]);
|
||||
|
||||
mProxyShapesEntities[index].~Entity();
|
||||
mCollidersEntities[index].~Entity();
|
||||
mBodiesEntities[index].~Entity();
|
||||
mProxyShapes[index] = nullptr;
|
||||
mColliders[index] = nullptr;
|
||||
mLocalToBodyTransforms[index].~Transform();
|
||||
mCollisionShapes[index] = nullptr;
|
||||
mLocalToWorldTransforms[index].~Transform();
|
324
src/components/ColliderComponents.h
Normal file
324
src/components/ColliderComponents.h
Normal file
|
@ -0,0 +1,324 @@
|
|||
/********************************************************************************
|
||||
* ReactPhysics3D physics library, http://www.reactphysics3d.com *
|
||||
* Copyright (c) 2010-2018 Daniel Chappuis *
|
||||
*********************************************************************************
|
||||
* *
|
||||
* This software is provided 'as-is', without any express or implied warranty. *
|
||||
* In no event will the authors be held liable for any damages arising from the *
|
||||
* use of this software. *
|
||||
* *
|
||||
* Permission is granted to anyone to use this software for any purpose, *
|
||||
* including commercial applications, and to alter it and redistribute it *
|
||||
* freely, subject to the following restrictions: *
|
||||
* *
|
||||
* 1. The origin of this software must not be misrepresented; you must not claim *
|
||||
* that you wrote the original software. If you use this software in a *
|
||||
* product, an acknowledgment in the product documentation would be *
|
||||
* appreciated but is not required. *
|
||||
* *
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be *
|
||||
* misrepresented as being the original software. *
|
||||
* *
|
||||
* 3. This notice may not be removed or altered from any source distribution. *
|
||||
* *
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef REACTPHYSICS3D_COLLIDERS_COMPONENTS_H
|
||||
#define REACTPHYSICS3D_COLLIDERS_COMPONENTS_H
|
||||
|
||||
// Libraries
|
||||
#include "mathematics/Transform.h"
|
||||
#include "engine/Entity.h"
|
||||
#include "containers/Map.h"
|
||||
#include "collision/shapes/AABB.h"
|
||||
#include "components/Components.h"
|
||||
|
||||
// ReactPhysics3D namespace
|
||||
namespace reactphysics3d {
|
||||
|
||||
// Class declarations
|
||||
class MemoryAllocator;
|
||||
class EntityManager;
|
||||
class AABB;
|
||||
class CollisionShape;
|
||||
class Collider;
|
||||
|
||||
// Class ColliderComponents
|
||||
/**
|
||||
* This class represent the component of the ECS that contains data about the the colliders of the
|
||||
* different bodies. We also make sure that colliders of sleeping entities (bodies) are
|
||||
* always stored at the end of the array.
|
||||
*/
|
||||
class ColliderComponents : public Components {
|
||||
|
||||
private:
|
||||
|
||||
// -------------------- Attributes -------------------- //
|
||||
|
||||
/// Array of body entity of each component
|
||||
Entity* mBodiesEntities;
|
||||
|
||||
/// Array of collider entity of each component
|
||||
Entity* mCollidersEntities;
|
||||
|
||||
/// Array of pointer to the colliders
|
||||
Collider** mColliders;
|
||||
|
||||
/// Ids of the colliders for the broad-phase algorithm
|
||||
int32* mBroadPhaseIds;
|
||||
|
||||
/// Transform from local-space of the collider to the body-space of its body
|
||||
Transform* mLocalToBodyTransforms;
|
||||
|
||||
/// Pointers to the collision shapes of the colliders
|
||||
CollisionShape** mCollisionShapes;
|
||||
|
||||
/// Masses (in kilogramms) of the colliders
|
||||
decimal* mMasses;
|
||||
|
||||
/// Array of bits used to define the collision category of this shape.
|
||||
/// You can set a single bit to one to define a category value for this
|
||||
/// shape. This value is one (0x0001) by default. This variable can be used
|
||||
/// together with the mCollideWithMaskBits variable so that given
|
||||
/// categories of shapes collide with each other and do not collide with
|
||||
/// other categories.
|
||||
unsigned short* mCollisionCategoryBits;
|
||||
|
||||
/// Array of bits mask used to state which collision categories this shape can
|
||||
/// collide with. This value is 0xFFFF by default. It means that this
|
||||
/// collider will collide with every collision categories by default.
|
||||
unsigned short* mCollideWithMaskBits;
|
||||
|
||||
/// Array with the local-to-world transforms of the colliders
|
||||
Transform* mLocalToWorldTransforms;
|
||||
|
||||
/// Array with the list of involved overlapping pairs for each collider
|
||||
List<uint64>* mOverlappingPairs;
|
||||
|
||||
// -------------------- Methods -------------------- //
|
||||
|
||||
/// Allocate memory for a given number of components
|
||||
virtual void allocate(uint32 nbComponentsToAllocate) override;
|
||||
|
||||
/// Destroy a component at a given index
|
||||
virtual void destroyComponent(uint32 index) override;
|
||||
|
||||
/// Move a component from a source to a destination index in the components array
|
||||
virtual void moveComponentToIndex(uint32 srcIndex, uint32 destIndex) override;
|
||||
|
||||
/// Swap two components in the array
|
||||
virtual void swapComponents(uint32 index1, uint32 index2) override;
|
||||
|
||||
public:
|
||||
|
||||
/// Structure for the data of a collider component
|
||||
struct ColliderComponent {
|
||||
|
||||
Entity bodyEntity;
|
||||
Collider* collider;
|
||||
AABB localBounds;
|
||||
const Transform& localToBodyTransform;
|
||||
CollisionShape* collisionShape;
|
||||
decimal mass;
|
||||
unsigned short collisionCategoryBits;
|
||||
unsigned short collideWithMaskBits;
|
||||
const Transform& localToWorldTransform;
|
||||
|
||||
/// Constructor
|
||||
ColliderComponent(Entity bodyEntity, Collider* collider, AABB localBounds, const Transform& localToBodyTransform,
|
||||
CollisionShape* collisionShape, decimal mass, unsigned short collisionCategoryBits,
|
||||
unsigned short collideWithMaskBits, const Transform& localToWorldTransform)
|
||||
:bodyEntity(bodyEntity), collider(collider), localBounds(localBounds), localToBodyTransform(localToBodyTransform),
|
||||
collisionShape(collisionShape), mass(mass), collisionCategoryBits(collisionCategoryBits), collideWithMaskBits(collideWithMaskBits),
|
||||
localToWorldTransform(localToWorldTransform) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
// -------------------- Methods -------------------- //
|
||||
|
||||
/// Constructor
|
||||
ColliderComponents(MemoryAllocator& allocator);
|
||||
|
||||
/// Destructor
|
||||
virtual ~ColliderComponents() override = default;
|
||||
|
||||
/// Add a component
|
||||
void addComponent(Entity colliderEntity, bool isSleeping, const ColliderComponent& component);
|
||||
|
||||
/// Return the body entity of a given collider
|
||||
Entity getBody(Entity colliderEntity) const;
|
||||
|
||||
/// Return the mass of a collider
|
||||
decimal getMass(Entity colliderEntity) const;
|
||||
|
||||
/// Return a pointer to a given collider
|
||||
Collider* getCollider(Entity colliderEntity) const;
|
||||
|
||||
/// Return the local-to-body transform of a collider
|
||||
const Transform& getLocalToBodyTransform(Entity colliderEntity) const;
|
||||
|
||||
/// Set the local-to-body transform of a collider
|
||||
void setLocalToBodyTransform(Entity colliderEntity, const Transform& transform);
|
||||
|
||||
/// Return a pointer to the collision shape of a collider
|
||||
CollisionShape* getCollisionShape(Entity colliderEntity) const;
|
||||
|
||||
/// Return the broad-phase id of a given collider
|
||||
int32 getBroadPhaseId(Entity colliderEntity) const;
|
||||
|
||||
/// Set the broad-phase id of a given collider
|
||||
void setBroadPhaseId(Entity colliderEntity, int32 broadPhaseId);
|
||||
|
||||
/// Return the collision category bits of a given collider
|
||||
unsigned short getCollisionCategoryBits(Entity colliderEntity) const;
|
||||
|
||||
/// Set the collision category bits of a given collider
|
||||
void setCollisionCategoryBits(Entity colliderEntity, unsigned short collisionCategoryBits);
|
||||
|
||||
/// Return the "collide with" mask bits of a given collider
|
||||
unsigned short getCollideWithMaskBits(Entity colliderEntity) const;
|
||||
|
||||
/// Set the "collide with" mask bits of a given collider
|
||||
void setCollideWithMaskBits(Entity colliderEntity, unsigned short collideWithMaskBits);
|
||||
|
||||
/// Return the local-to-world transform of a collider
|
||||
const Transform& getLocalToWorldTransform(Entity colliderEntity) const;
|
||||
|
||||
/// Set the local-to-world transform of a collider
|
||||
void setLocalToWorldTransform(Entity colliderEntity, const Transform& transform);
|
||||
|
||||
/// Return a reference to the list of overlapping pairs for a given collider
|
||||
List<uint64>& getOverlappingPairs(Entity colliderEntity);
|
||||
|
||||
// -------------------- Friendship -------------------- //
|
||||
|
||||
friend class BroadPhaseSystem;
|
||||
friend class CollisionDetectionSystem;
|
||||
friend class DynamicsSystem;
|
||||
friend class OverlappingPairs;
|
||||
};
|
||||
|
||||
// Return the body entity of a given collider
|
||||
inline Entity ColliderComponents::getBody(Entity colliderEntity) const {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(colliderEntity));
|
||||
|
||||
return mBodiesEntities[mMapEntityToComponentIndex[colliderEntity]];
|
||||
}
|
||||
|
||||
// Return the mass of a collider
|
||||
inline decimal ColliderComponents::getMass(Entity colliderEntity) const {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(colliderEntity));
|
||||
|
||||
return mMasses[mMapEntityToComponentIndex[colliderEntity]];
|
||||
}
|
||||
|
||||
// Return a pointer to a given collider
|
||||
inline Collider *ColliderComponents::getCollider(Entity colliderEntity) const {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(colliderEntity));
|
||||
|
||||
return mColliders[mMapEntityToComponentIndex[colliderEntity]];
|
||||
}
|
||||
|
||||
// Return the local-to-body transform of a collider
|
||||
inline const Transform& ColliderComponents::getLocalToBodyTransform(Entity colliderEntity) const {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(colliderEntity));
|
||||
|
||||
return mLocalToBodyTransforms[mMapEntityToComponentIndex[colliderEntity]];
|
||||
}
|
||||
|
||||
// Set the local-to-body transform of a collider
|
||||
inline void ColliderComponents::setLocalToBodyTransform(Entity colliderEntity, const Transform& transform) {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(colliderEntity));
|
||||
|
||||
mLocalToBodyTransforms[mMapEntityToComponentIndex[colliderEntity]] = transform;
|
||||
}
|
||||
|
||||
// Return a pointer to the collision shape of a collider
|
||||
inline CollisionShape* ColliderComponents::getCollisionShape(Entity colliderEntity) const {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(colliderEntity));
|
||||
|
||||
return mCollisionShapes[mMapEntityToComponentIndex[colliderEntity]];
|
||||
}
|
||||
|
||||
// Return the broad-phase id of a given collider
|
||||
inline int32 ColliderComponents::getBroadPhaseId(Entity colliderEntity) const {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(colliderEntity));
|
||||
|
||||
return mBroadPhaseIds[mMapEntityToComponentIndex[colliderEntity]];
|
||||
}
|
||||
|
||||
// Set the broad-phase id of a given collider
|
||||
inline void ColliderComponents::setBroadPhaseId(Entity colliderEntity, int32 broadPhaseId) {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(colliderEntity));
|
||||
|
||||
mBroadPhaseIds[mMapEntityToComponentIndex[colliderEntity]] = broadPhaseId;
|
||||
}
|
||||
|
||||
// Return the collision category bits of a given collider
|
||||
inline unsigned short ColliderComponents::getCollisionCategoryBits(Entity colliderEntity) const {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(colliderEntity));
|
||||
|
||||
return mCollisionCategoryBits[mMapEntityToComponentIndex[colliderEntity]];
|
||||
}
|
||||
|
||||
// Return the "collide with" mask bits of a given collider
|
||||
inline unsigned short ColliderComponents::getCollideWithMaskBits(Entity colliderEntity) const {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(colliderEntity));
|
||||
|
||||
return mCollideWithMaskBits[mMapEntityToComponentIndex[colliderEntity]];
|
||||
}
|
||||
|
||||
// Set the collision category bits of a given collider
|
||||
inline void ColliderComponents::setCollisionCategoryBits(Entity colliderEntity, unsigned short collisionCategoryBits) {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(colliderEntity));
|
||||
|
||||
mCollisionCategoryBits[mMapEntityToComponentIndex[colliderEntity]] = collisionCategoryBits;
|
||||
}
|
||||
|
||||
// Set the "collide with" mask bits of a given collider
|
||||
inline void ColliderComponents::setCollideWithMaskBits(Entity colliderEntity, unsigned short collideWithMaskBits) {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(colliderEntity));
|
||||
|
||||
mCollideWithMaskBits[mMapEntityToComponentIndex[colliderEntity]] = collideWithMaskBits;
|
||||
}
|
||||
|
||||
// Return the local-to-world transform of a collider
|
||||
inline const Transform& ColliderComponents::getLocalToWorldTransform(Entity colliderEntity) const {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(colliderEntity));
|
||||
|
||||
return mLocalToWorldTransforms[mMapEntityToComponentIndex[colliderEntity]];
|
||||
}
|
||||
|
||||
// Set the local-to-world transform of a collider
|
||||
inline void ColliderComponents::setLocalToWorldTransform(Entity colliderEntity, const Transform& transform) {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(colliderEntity));
|
||||
|
||||
mLocalToWorldTransforms[mMapEntityToComponentIndex[colliderEntity]] = transform;
|
||||
}
|
||||
|
||||
// Return a reference to the list of overlapping pairs for a given collider
|
||||
inline List<uint64>& ColliderComponents::getOverlappingPairs(Entity colliderEntity) {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(colliderEntity));
|
||||
|
||||
return mOverlappingPairs[mMapEntityToComponentIndex[colliderEntity]];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -56,8 +56,8 @@ void CollisionBodyComponents::allocate(uint32 nbComponentsToAllocate) {
|
|||
// New pointers to components data
|
||||
Entity* newBodiesEntities = static_cast<Entity*>(newBuffer);
|
||||
CollisionBody** newBodies = reinterpret_cast<CollisionBody**>(newBodiesEntities + nbComponentsToAllocate);
|
||||
List<Entity>* newProxyShapes = reinterpret_cast<List<Entity>*>(newBodies + nbComponentsToAllocate);
|
||||
bool* newIsActive = reinterpret_cast<bool*>(newProxyShapes + nbComponentsToAllocate);
|
||||
List<Entity>* newColliders = reinterpret_cast<List<Entity>*>(newBodies + nbComponentsToAllocate);
|
||||
bool* newIsActive = reinterpret_cast<bool*>(newColliders + nbComponentsToAllocate);
|
||||
void** newUserData = reinterpret_cast<void**>(newIsActive + nbComponentsToAllocate);
|
||||
|
||||
// If there was already components before
|
||||
|
@ -66,7 +66,7 @@ void CollisionBodyComponents::allocate(uint32 nbComponentsToAllocate) {
|
|||
// Copy component data from the previous buffer to the new one
|
||||
memcpy(newBodiesEntities, mBodiesEntities, mNbComponents * sizeof(Entity));
|
||||
memcpy(newBodies, mBodies, mNbComponents * sizeof(CollisionBody*));
|
||||
memcpy(newProxyShapes, mProxyShapes, mNbComponents * sizeof(List<Entity>));
|
||||
memcpy(newColliders, mColliders, mNbComponents * sizeof(List<Entity>));
|
||||
memcpy(newIsActive, mIsActive, mNbComponents * sizeof(bool));
|
||||
memcpy(newUserData, mUserData, mNbComponents * sizeof(void*));
|
||||
|
||||
|
@ -77,7 +77,7 @@ void CollisionBodyComponents::allocate(uint32 nbComponentsToAllocate) {
|
|||
mBuffer = newBuffer;
|
||||
mBodiesEntities = newBodiesEntities;
|
||||
mBodies = newBodies;
|
||||
mProxyShapes = newProxyShapes;
|
||||
mColliders = newColliders;
|
||||
mIsActive = newIsActive;
|
||||
mUserData = newUserData;
|
||||
mNbAllocatedComponents = nbComponentsToAllocate;
|
||||
|
@ -92,7 +92,7 @@ void CollisionBodyComponents::addComponent(Entity bodyEntity, bool isSleeping, c
|
|||
// Insert the new component data
|
||||
new (mBodiesEntities + index) Entity(bodyEntity);
|
||||
mBodies[index] = component.body;
|
||||
new (mProxyShapes + index) List<Entity>(mMemoryAllocator);
|
||||
new (mColliders + index) List<Entity>(mMemoryAllocator);
|
||||
mIsActive[index] = true;
|
||||
mUserData[index] = nullptr;
|
||||
|
||||
|
@ -114,7 +114,7 @@ void CollisionBodyComponents::moveComponentToIndex(uint32 srcIndex, uint32 destI
|
|||
// Copy the data of the source component to the destination location
|
||||
new (mBodiesEntities + destIndex) Entity(mBodiesEntities[srcIndex]);
|
||||
mBodies[destIndex] = mBodies[srcIndex];
|
||||
new (mProxyShapes + destIndex) List<Entity>(mProxyShapes[srcIndex]);
|
||||
new (mColliders + destIndex) List<Entity>(mColliders[srcIndex]);
|
||||
mIsActive[destIndex] = mIsActive[srcIndex];
|
||||
mUserData[destIndex] = mUserData[srcIndex];
|
||||
|
||||
|
@ -135,7 +135,7 @@ void CollisionBodyComponents::swapComponents(uint32 index1, uint32 index2) {
|
|||
// Copy component 1 data
|
||||
Entity entity1(mBodiesEntities[index1]);
|
||||
CollisionBody* body1 = mBodies[index1];
|
||||
List<Entity> proxyShapes1(mProxyShapes[index1]);
|
||||
List<Entity> colliders1(mColliders[index1]);
|
||||
bool isActive1 = mIsActive[index1];
|
||||
void* userData1 = mUserData[index1];
|
||||
|
||||
|
@ -146,7 +146,7 @@ void CollisionBodyComponents::swapComponents(uint32 index1, uint32 index2) {
|
|||
|
||||
// Reconstruct component 1 at component 2 location
|
||||
new (mBodiesEntities + index2) Entity(entity1);
|
||||
new (mProxyShapes + index2) List<Entity>(proxyShapes1);
|
||||
new (mColliders + index2) List<Entity>(colliders1);
|
||||
mBodies[index2] = body1;
|
||||
mIsActive[index2] = isActive1;
|
||||
mUserData[index2] = userData1;
|
||||
|
@ -170,6 +170,6 @@ void CollisionBodyComponents::destroyComponent(uint32 index) {
|
|||
|
||||
mBodiesEntities[index].~Entity();
|
||||
mBodies[index] = nullptr;
|
||||
mProxyShapes[index].~List<Entity>();
|
||||
mColliders[index].~List<Entity>();
|
||||
mUserData[index] = nullptr;
|
||||
}
|
||||
|
|
|
@ -57,8 +57,8 @@ class CollisionBodyComponents : public Components {
|
|||
/// Array of pointers to the corresponding bodies
|
||||
CollisionBody** mBodies;
|
||||
|
||||
/// Array with the list of proxy-shapes of each body
|
||||
List<Entity>* mProxyShapes;
|
||||
/// Array with the list of colliders of each body
|
||||
List<Entity>* mColliders;
|
||||
|
||||
/// Array of boolean values to know if the body is active.
|
||||
bool* mIsActive;
|
||||
|
@ -104,17 +104,17 @@ class CollisionBodyComponents : public Components {
|
|||
/// Add a component
|
||||
void addComponent(Entity bodyEntity, bool isSleeping, const CollisionBodyComponent& component);
|
||||
|
||||
/// Add a proxy-shape to a body component
|
||||
void addProxyShapeToBody(Entity bodyEntity, Entity proxyShapeEntity);
|
||||
/// Add a collider to a body component
|
||||
void addColliderToBody(Entity bodyEntity, Entity colliderEntity);
|
||||
|
||||
/// Remove a proxy-shape from a body component
|
||||
void removeProxyShapeFromBody(Entity bodyEntity, Entity proxyShapeEntity);
|
||||
/// Remove a collider from a body component
|
||||
void removeColliderFromBody(Entity bodyEntity, Entity colliderEntity);
|
||||
|
||||
/// Return a pointer to a body
|
||||
CollisionBody* getBody(Entity bodyEntity);
|
||||
|
||||
/// Return the list of proxy-shapes of a body
|
||||
const List<Entity>& getProxyShapes(Entity bodyEntity) const;
|
||||
/// Return the list of colliders of a body
|
||||
const List<Entity>& getColliders(Entity bodyEntity) const;
|
||||
|
||||
/// Return true if the body is active
|
||||
bool getIsActive(Entity bodyEntity) const;
|
||||
|
@ -129,20 +129,20 @@ class CollisionBodyComponents : public Components {
|
|||
void setUserData(Entity bodyEntity, void* userData) const;
|
||||
};
|
||||
|
||||
// Add a proxy-shape to a body component
|
||||
inline void CollisionBodyComponents::addProxyShapeToBody(Entity bodyEntity, Entity proxyShapeEntity) {
|
||||
// Add a collider to a body component
|
||||
inline void CollisionBodyComponents::addColliderToBody(Entity bodyEntity, Entity colliderEntity) {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(bodyEntity));
|
||||
|
||||
mProxyShapes[mMapEntityToComponentIndex[bodyEntity]].add(proxyShapeEntity);
|
||||
mColliders[mMapEntityToComponentIndex[bodyEntity]].add(colliderEntity);
|
||||
}
|
||||
|
||||
// Remove a proxy-shape from a body component
|
||||
inline void CollisionBodyComponents::removeProxyShapeFromBody(Entity bodyEntity, Entity proxyShapeEntity) {
|
||||
// Remove a collider from a body component
|
||||
inline void CollisionBodyComponents::removeColliderFromBody(Entity bodyEntity, Entity colliderEntity) {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(bodyEntity));
|
||||
|
||||
mProxyShapes[mMapEntityToComponentIndex[bodyEntity]].remove(proxyShapeEntity);
|
||||
mColliders[mMapEntityToComponentIndex[bodyEntity]].remove(colliderEntity);
|
||||
}
|
||||
|
||||
// Return a pointer to a body
|
||||
|
@ -153,12 +153,12 @@ inline CollisionBody *CollisionBodyComponents::getBody(Entity bodyEntity) {
|
|||
return mBodies[mMapEntityToComponentIndex[bodyEntity]];
|
||||
}
|
||||
|
||||
// Return the list of proxy-shapes of a body
|
||||
inline const List<Entity>& CollisionBodyComponents::getProxyShapes(Entity bodyEntity) const {
|
||||
// Return the list of colliders of a body
|
||||
inline const List<Entity>& CollisionBodyComponents::getColliders(Entity bodyEntity) const {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(bodyEntity));
|
||||
|
||||
return mProxyShapes[mMapEntityToComponentIndex[bodyEntity]];
|
||||
return mColliders[mMapEntityToComponentIndex[bodyEntity]];
|
||||
}
|
||||
|
||||
// Return true if the body is active
|
||||
|
|
|
@ -1,324 +0,0 @@
|
|||
/********************************************************************************
|
||||
* ReactPhysics3D physics library, http://www.reactphysics3d.com *
|
||||
* Copyright (c) 2010-2018 Daniel Chappuis *
|
||||
*********************************************************************************
|
||||
* *
|
||||
* This software is provided 'as-is', without any express or implied warranty. *
|
||||
* In no event will the authors be held liable for any damages arising from the *
|
||||
* use of this software. *
|
||||
* *
|
||||
* Permission is granted to anyone to use this software for any purpose, *
|
||||
* including commercial applications, and to alter it and redistribute it *
|
||||
* freely, subject to the following restrictions: *
|
||||
* *
|
||||
* 1. The origin of this software must not be misrepresented; you must not claim *
|
||||
* that you wrote the original software. If you use this software in a *
|
||||
* product, an acknowledgment in the product documentation would be *
|
||||
* appreciated but is not required. *
|
||||
* *
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be *
|
||||
* misrepresented as being the original software. *
|
||||
* *
|
||||
* 3. This notice may not be removed or altered from any source distribution. *
|
||||
* *
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef REACTPHYSICS3D_PROXY_SHAPES_COMPONENTS_H
|
||||
#define REACTPHYSICS3D_PROXY_SHAPES_COMPONENTS_H
|
||||
|
||||
// Libraries
|
||||
#include "mathematics/Transform.h"
|
||||
#include "engine/Entity.h"
|
||||
#include "containers/Map.h"
|
||||
#include "collision/shapes/AABB.h"
|
||||
#include "components/Components.h"
|
||||
|
||||
// ReactPhysics3D namespace
|
||||
namespace reactphysics3d {
|
||||
|
||||
// Class declarations
|
||||
class MemoryAllocator;
|
||||
class EntityManager;
|
||||
class AABB;
|
||||
class CollisionShape;
|
||||
class ProxyShape;
|
||||
|
||||
// Class ProxyShapesComponents
|
||||
/**
|
||||
* This class represent the component of the ECS that contains data about the the proxy-shapes of the
|
||||
* different bodies. We also make sure that proxy shapes of sleeping entities (bodies) are
|
||||
* always stored at the end of the array.
|
||||
*/
|
||||
class ProxyShapeComponents : public Components {
|
||||
|
||||
private:
|
||||
|
||||
// -------------------- Attributes -------------------- //
|
||||
|
||||
/// Array of body entity of each component
|
||||
Entity* mBodiesEntities;
|
||||
|
||||
/// Array of proxy-shape entity of each component
|
||||
Entity* mProxyShapesEntities;
|
||||
|
||||
/// Array of pointer to the proxy-shapes
|
||||
ProxyShape** mProxyShapes;
|
||||
|
||||
/// Ids of the proxy-shapes for the broad-phase algorithm
|
||||
int32* mBroadPhaseIds;
|
||||
|
||||
/// Transform from local-space of the proxy-shape to the body-space of its body
|
||||
Transform* mLocalToBodyTransforms;
|
||||
|
||||
/// Pointers to the collision shapes of the proxy-shapes
|
||||
CollisionShape** mCollisionShapes;
|
||||
|
||||
/// Masses (in kilogramms) of the proxy-shapes
|
||||
decimal* mMasses;
|
||||
|
||||
/// Array of bits used to define the collision category of this shape.
|
||||
/// You can set a single bit to one to define a category value for this
|
||||
/// shape. This value is one (0x0001) by default. This variable can be used
|
||||
/// together with the mCollideWithMaskBits variable so that given
|
||||
/// categories of shapes collide with each other and do not collide with
|
||||
/// other categories.
|
||||
unsigned short* mCollisionCategoryBits;
|
||||
|
||||
/// Array of bits mask used to state which collision categories this shape can
|
||||
/// collide with. This value is 0xFFFF by default. It means that this
|
||||
/// proxy shape will collide with every collision categories by default.
|
||||
unsigned short* mCollideWithMaskBits;
|
||||
|
||||
/// Array with the local-to-world transforms of the proxy-shapes
|
||||
Transform* mLocalToWorldTransforms;
|
||||
|
||||
/// Array with the list of involved overlapping pairs for each proxy-shape
|
||||
List<uint64>* mOverlappingPairs;
|
||||
|
||||
// -------------------- Methods -------------------- //
|
||||
|
||||
/// Allocate memory for a given number of components
|
||||
virtual void allocate(uint32 nbComponentsToAllocate) override;
|
||||
|
||||
/// Destroy a component at a given index
|
||||
virtual void destroyComponent(uint32 index) override;
|
||||
|
||||
/// Move a component from a source to a destination index in the components array
|
||||
virtual void moveComponentToIndex(uint32 srcIndex, uint32 destIndex) override;
|
||||
|
||||
/// Swap two components in the array
|
||||
virtual void swapComponents(uint32 index1, uint32 index2) override;
|
||||
|
||||
public:
|
||||
|
||||
/// Structure for the data of a proxy shape component
|
||||
struct ProxyShapeComponent {
|
||||
|
||||
Entity bodyEntity;
|
||||
ProxyShape* proxyShape;
|
||||
AABB localBounds;
|
||||
const Transform& localToBodyTransform;
|
||||
CollisionShape* collisionShape;
|
||||
decimal mass;
|
||||
unsigned short collisionCategoryBits;
|
||||
unsigned short collideWithMaskBits;
|
||||
const Transform& localToWorldTransform;
|
||||
|
||||
/// Constructor
|
||||
ProxyShapeComponent(Entity bodyEntity, ProxyShape* proxyShape, AABB localBounds, const Transform& localToBodyTransform,
|
||||
CollisionShape* collisionShape, decimal mass, unsigned short collisionCategoryBits,
|
||||
unsigned short collideWithMaskBits, const Transform& localToWorldTransform)
|
||||
:bodyEntity(bodyEntity), proxyShape(proxyShape), localBounds(localBounds), localToBodyTransform(localToBodyTransform),
|
||||
collisionShape(collisionShape), mass(mass), collisionCategoryBits(collisionCategoryBits), collideWithMaskBits(collideWithMaskBits),
|
||||
localToWorldTransform(localToWorldTransform) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
// -------------------- Methods -------------------- //
|
||||
|
||||
/// Constructor
|
||||
ProxyShapeComponents(MemoryAllocator& allocator);
|
||||
|
||||
/// Destructor
|
||||
virtual ~ProxyShapeComponents() override = default;
|
||||
|
||||
/// Add a component
|
||||
void addComponent(Entity proxyShapeEntity, bool isSleeping, const ProxyShapeComponent& component);
|
||||
|
||||
/// Return the body entity of a given proxy-shape
|
||||
Entity getBody(Entity proxyShapeEntity) const;
|
||||
|
||||
/// Return the mass of a proxy-shape
|
||||
decimal getMass(Entity proxyShapeEntity) const;
|
||||
|
||||
/// Return a pointer to a given proxy-shape
|
||||
ProxyShape* getProxyShape(Entity proxyShapeEntity) const;
|
||||
|
||||
/// Return the local-to-body transform of a proxy-shape
|
||||
const Transform& getLocalToBodyTransform(Entity proxyShapeEntity) const;
|
||||
|
||||
/// Set the local-to-body transform of a proxy-shape
|
||||
void setLocalToBodyTransform(Entity proxyShapeEntity, const Transform& transform);
|
||||
|
||||
/// Return a pointer to the collision shape of a proxy-shape
|
||||
CollisionShape* getCollisionShape(Entity proxyShapeEntity) const;
|
||||
|
||||
/// Return the broad-phase id of a given proxy shape
|
||||
int32 getBroadPhaseId(Entity proxyShapeEntity) const;
|
||||
|
||||
/// Set the broad-phase id of a given proxy shape
|
||||
void setBroadPhaseId(Entity proxyShapeEntity, int32 broadPhaseId);
|
||||
|
||||
/// Return the collision category bits of a given proxy-shape
|
||||
unsigned short getCollisionCategoryBits(Entity proxyShapeEntity) const;
|
||||
|
||||
/// Set the collision category bits of a given proxy-shape
|
||||
void setCollisionCategoryBits(Entity proxyShapeEntity, unsigned short collisionCategoryBits);
|
||||
|
||||
/// Return the "collide with" mask bits of a given proxy-shape
|
||||
unsigned short getCollideWithMaskBits(Entity proxyShapeEntity) const;
|
||||
|
||||
/// Set the "collide with" mask bits of a given proxy-shape
|
||||
void setCollideWithMaskBits(Entity proxyShapeEntity, unsigned short collideWithMaskBits);
|
||||
|
||||
/// Return the local-to-world transform of a proxy-shape
|
||||
const Transform& getLocalToWorldTransform(Entity proxyShapeEntity) const;
|
||||
|
||||
/// Set the local-to-world transform of a proxy-shape
|
||||
void setLocalToWorldTransform(Entity proxyShapeEntity, const Transform& transform);
|
||||
|
||||
/// Return a reference to the list of overlapping pairs for a given proxy-shape
|
||||
List<uint64>& getOverlappingPairs(Entity proxyShapeEntity);
|
||||
|
||||
// -------------------- Friendship -------------------- //
|
||||
|
||||
friend class BroadPhaseSystem;
|
||||
friend class CollisionDetectionSystem;
|
||||
friend class DynamicsSystem;
|
||||
friend class OverlappingPairs;
|
||||
};
|
||||
|
||||
// Return the body entity of a given proxy-shape
|
||||
inline Entity ProxyShapeComponents::getBody(Entity proxyShapeEntity) const {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(proxyShapeEntity));
|
||||
|
||||
return mBodiesEntities[mMapEntityToComponentIndex[proxyShapeEntity]];
|
||||
}
|
||||
|
||||
// Return the mass of a proxy-shape
|
||||
inline decimal ProxyShapeComponents::getMass(Entity proxyShapeEntity) const {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(proxyShapeEntity));
|
||||
|
||||
return mMasses[mMapEntityToComponentIndex[proxyShapeEntity]];
|
||||
}
|
||||
|
||||
// Return a pointer to a given proxy-shape
|
||||
inline ProxyShape* ProxyShapeComponents::getProxyShape(Entity proxyShapeEntity) const {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(proxyShapeEntity));
|
||||
|
||||
return mProxyShapes[mMapEntityToComponentIndex[proxyShapeEntity]];
|
||||
}
|
||||
|
||||
// Return the local-to-body transform of a proxy-shape
|
||||
inline const Transform& ProxyShapeComponents::getLocalToBodyTransform(Entity proxyShapeEntity) const {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(proxyShapeEntity));
|
||||
|
||||
return mLocalToBodyTransforms[mMapEntityToComponentIndex[proxyShapeEntity]];
|
||||
}
|
||||
|
||||
// Set the local-to-body transform of a proxy-shape
|
||||
inline void ProxyShapeComponents::setLocalToBodyTransform(Entity proxyShapeEntity, const Transform& transform) {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(proxyShapeEntity));
|
||||
|
||||
mLocalToBodyTransforms[mMapEntityToComponentIndex[proxyShapeEntity]] = transform;
|
||||
}
|
||||
|
||||
// Return a pointer to the collision shape of a proxy-shape
|
||||
inline CollisionShape* ProxyShapeComponents::getCollisionShape(Entity proxyShapeEntity) const {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(proxyShapeEntity));
|
||||
|
||||
return mCollisionShapes[mMapEntityToComponentIndex[proxyShapeEntity]];
|
||||
}
|
||||
|
||||
// Return the broad-phase id of a given proxy shape
|
||||
inline int32 ProxyShapeComponents::getBroadPhaseId(Entity proxyShapeEntity) const {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(proxyShapeEntity));
|
||||
|
||||
return mBroadPhaseIds[mMapEntityToComponentIndex[proxyShapeEntity]];
|
||||
}
|
||||
|
||||
// Set the broad-phase id of a given proxy shape
|
||||
inline void ProxyShapeComponents::setBroadPhaseId(Entity proxyShapeEntity, int32 broadPhaseId) {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(proxyShapeEntity));
|
||||
|
||||
mBroadPhaseIds[mMapEntityToComponentIndex[proxyShapeEntity]] = broadPhaseId;
|
||||
}
|
||||
|
||||
// Return the collision category bits of a given proxy-shape
|
||||
inline unsigned short ProxyShapeComponents::getCollisionCategoryBits(Entity proxyShapeEntity) const {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(proxyShapeEntity));
|
||||
|
||||
return mCollisionCategoryBits[mMapEntityToComponentIndex[proxyShapeEntity]];
|
||||
}
|
||||
|
||||
// Return the "collide with" mask bits of a given proxy-shape
|
||||
inline unsigned short ProxyShapeComponents::getCollideWithMaskBits(Entity proxyShapeEntity) const {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(proxyShapeEntity));
|
||||
|
||||
return mCollideWithMaskBits[mMapEntityToComponentIndex[proxyShapeEntity]];
|
||||
}
|
||||
|
||||
// Set the collision category bits of a given proxy-shape
|
||||
inline void ProxyShapeComponents::setCollisionCategoryBits(Entity proxyShapeEntity, unsigned short collisionCategoryBits) {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(proxyShapeEntity));
|
||||
|
||||
mCollisionCategoryBits[mMapEntityToComponentIndex[proxyShapeEntity]] = collisionCategoryBits;
|
||||
}
|
||||
|
||||
// Set the "collide with" mask bits of a given proxy-shape
|
||||
inline void ProxyShapeComponents::setCollideWithMaskBits(Entity proxyShapeEntity, unsigned short collideWithMaskBits) {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(proxyShapeEntity));
|
||||
|
||||
mCollideWithMaskBits[mMapEntityToComponentIndex[proxyShapeEntity]] = collideWithMaskBits;
|
||||
}
|
||||
|
||||
// Return the local-to-world transform of a proxy-shape
|
||||
inline const Transform& ProxyShapeComponents::getLocalToWorldTransform(Entity proxyShapeEntity) const {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(proxyShapeEntity));
|
||||
|
||||
return mLocalToWorldTransforms[mMapEntityToComponentIndex[proxyShapeEntity]];
|
||||
}
|
||||
|
||||
// Set the local-to-world transform of a proxy-shape
|
||||
inline void ProxyShapeComponents::setLocalToWorldTransform(Entity proxyShapeEntity, const Transform& transform) {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(proxyShapeEntity));
|
||||
|
||||
mLocalToWorldTransforms[mMapEntityToComponentIndex[proxyShapeEntity]] = transform;
|
||||
}
|
||||
|
||||
// Return a reference to the list of overlapping pairs for a given proxy-shape
|
||||
inline List<uint64>& ProxyShapeComponents::getOverlappingPairs(Entity proxyShapeEntity) {
|
||||
|
||||
assert(mMapEntityToComponentIndex.containsKey(proxyShapeEntity));
|
||||
|
||||
return mOverlappingPairs[mMapEntityToComponentIndex[proxyShapeEntity]];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
// Libraries
|
||||
#include "ContactPoint.h"
|
||||
#include "collision/ProxyShape.h"
|
||||
#include "collision/Collider.h"
|
||||
|
||||
using namespace reactphysics3d;
|
||||
using namespace std;
|
||||
|
|
|
@ -54,10 +54,10 @@ class ContactPoint {
|
|||
/// Penetration depth
|
||||
decimal mPenetrationDepth;
|
||||
|
||||
/// Contact point on proxy shape 1 in local-space of proxy shape 1
|
||||
/// Contact point on collider 1 in local-space of collider 1
|
||||
Vector3 mLocalPointOnShape1;
|
||||
|
||||
/// Contact point on proxy shape 2 in local-space of proxy shape 2
|
||||
/// Contact point on collider 2 in local-space of collider 2
|
||||
Vector3 mLocalPointOnShape2;
|
||||
|
||||
/// True if the contact is a resting contact (exists for more than one time step)
|
||||
|
@ -115,10 +115,10 @@ class ContactPoint {
|
|||
/// Return the normal vector of the contact
|
||||
const Vector3& getNormal() const;
|
||||
|
||||
/// Return the contact point on the first proxy shape in the local-space of the proxy shape
|
||||
/// Return the contact point on the first collider in the local-space of the collider
|
||||
const Vector3& getLocalPointOnShape1() const;
|
||||
|
||||
/// Return the contact point on the second proxy shape in the local-space of the proxy shape
|
||||
/// Return the contact point on the second collider in the local-space of the collider
|
||||
const Vector3& getLocalPointOnShape2() const;
|
||||
|
||||
/// Return the cached penetration impulse
|
||||
|
@ -148,17 +148,17 @@ inline const Vector3& ContactPoint::getNormal() const {
|
|||
return mNormal;
|
||||
}
|
||||
|
||||
// Return the contact point on the first proxy shape in the local-space of the proxy shape
|
||||
// Return the contact point on the first collider in the local-space of the collider
|
||||
/**
|
||||
* @return The contact point on the first proxy shape in the local-space of the proxy shape
|
||||
* @return The contact point on the first collider in the local-space of the collider
|
||||
*/
|
||||
inline const Vector3& ContactPoint::getLocalPointOnShape1() const {
|
||||
return mLocalPointOnShape1;
|
||||
}
|
||||
|
||||
// Return the contact point on the second proxy shape in the local-space of the proxy shape
|
||||
// Return the contact point on the second collider in the local-space of the collider
|
||||
/**
|
||||
* @return The contact point on the second proxy shape in the local-space of the proxy shape
|
||||
* @return The contact point on the second collider in the local-space of the collider
|
||||
*/
|
||||
inline const Vector3& ContactPoint::getLocalPointOnShape2() const {
|
||||
return mLocalPointOnShape2;
|
||||
|
|
|
@ -39,11 +39,11 @@ uint CollisionWorld::mNbWorlds = 0;
|
|||
CollisionWorld::CollisionWorld(MemoryManager& memoryManager, const WorldSettings& worldSettings, Logger* logger, Profiler* profiler)
|
||||
: mMemoryManager(memoryManager), mConfig(worldSettings), mEntityManager(mMemoryManager.getHeapAllocator()),
|
||||
mCollisionBodyComponents(mMemoryManager.getHeapAllocator()), mRigidBodyComponents(mMemoryManager.getHeapAllocator()),
|
||||
mTransformComponents(mMemoryManager.getHeapAllocator()), mProxyShapesComponents(mMemoryManager.getHeapAllocator()),
|
||||
mTransformComponents(mMemoryManager.getHeapAllocator()), mCollidersComponents(mMemoryManager.getHeapAllocator()),
|
||||
mJointsComponents(mMemoryManager.getHeapAllocator()), mBallAndSocketJointsComponents(mMemoryManager.getHeapAllocator()),
|
||||
mFixedJointsComponents(mMemoryManager.getHeapAllocator()), mHingeJointsComponents(mMemoryManager.getHeapAllocator()),
|
||||
mSliderJointsComponents(mMemoryManager.getHeapAllocator()),
|
||||
mCollisionDetection(this, mProxyShapesComponents, mTransformComponents, mCollisionBodyComponents, mRigidBodyComponents, mMemoryManager),
|
||||
mCollisionDetection(this, mCollidersComponents, mTransformComponents, mCollisionBodyComponents, mRigidBodyComponents, mMemoryManager),
|
||||
mBodies(mMemoryManager.getHeapAllocator()), mEventListener(nullptr),
|
||||
mName(worldSettings.worldName), mIsProfilerCreatedByUser(profiler != nullptr),
|
||||
mIsLoggerCreatedByUser(logger != nullptr) {
|
||||
|
@ -137,7 +137,7 @@ CollisionWorld::~CollisionWorld() {
|
|||
assert(mBodies.size() == 0);
|
||||
assert(mCollisionBodyComponents.getNbComponents() == 0);
|
||||
assert(mTransformComponents.getNbComponents() == 0);
|
||||
assert(mProxyShapesComponents.getNbComponents() == 0);
|
||||
assert(mCollidersComponents.getNbComponents() == 0);
|
||||
}
|
||||
|
||||
// Create a collision body and add it to the world
|
||||
|
@ -222,11 +222,11 @@ void CollisionWorld::setBodyDisabled(Entity bodyEntity, bool isDisabled) {
|
|||
mRigidBodyComponents.setIsEntityDisabled(bodyEntity, isDisabled);
|
||||
}
|
||||
|
||||
// For each proxy-shape of the body
|
||||
const List<Entity>& proxyShapesEntities = mCollisionBodyComponents.getProxyShapes(bodyEntity);
|
||||
for (uint i=0; i < proxyShapesEntities.size(); i++) {
|
||||
// For each collider of the body
|
||||
const List<Entity>& collidersEntities = mCollisionBodyComponents.getColliders(bodyEntity);
|
||||
for (uint i=0; i < collidersEntities.size(); i++) {
|
||||
|
||||
mProxyShapesComponents.setIsEntityDisabled(proxyShapesEntities[i], isDisabled);
|
||||
mCollidersComponents.setIsEntityDisabled(collidersEntities[i], isDisabled);
|
||||
}
|
||||
|
||||
// Disable the joints of the body if necessary
|
||||
|
@ -288,16 +288,16 @@ bool CollisionWorld::testOverlap(CollisionBody* body1, CollisionBody* body2) {
|
|||
return mCollisionDetection.testOverlap(body1, body2);
|
||||
}
|
||||
|
||||
// Return the current world-space AABB of given proxy shape
|
||||
// Return the current world-space AABB of given collider
|
||||
/**
|
||||
* @param proxyShape Pointer to a proxy shape
|
||||
* @return The AAABB of the proxy shape in world-space
|
||||
* @param collider Pointer to a collider
|
||||
* @return The AAABB of the collider in world-space
|
||||
*/
|
||||
AABB CollisionWorld::getWorldAABB(const ProxyShape* proxyShape) const {
|
||||
AABB CollisionWorld::getWorldAABB(const Collider* collider) const {
|
||||
|
||||
if (proxyShape->getBroadPhaseId() == -1) {
|
||||
if (collider->getBroadPhaseId() == -1) {
|
||||
return AABB();
|
||||
}
|
||||
|
||||
return mCollisionDetection.getWorldAABB(proxyShape);
|
||||
return mCollisionDetection.getWorldAABB(collider);
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
#include "components/CollisionBodyComponents.h"
|
||||
#include "components/RigidBodyComponents.h"
|
||||
#include "components/TransformComponents.h"
|
||||
#include "components/ProxyShapeComponents.h"
|
||||
#include "components/ColliderComponents.h"
|
||||
#include "components/JointComponents.h"
|
||||
#include "components/BallAndSocketJointComponents.h"
|
||||
#include "components/FixedJointComponents.h"
|
||||
|
@ -90,8 +90,8 @@ class CollisionWorld {
|
|||
/// Transform Components
|
||||
TransformComponents mTransformComponents;
|
||||
|
||||
/// Proxy-Shapes Components
|
||||
ProxyShapeComponents mProxyShapesComponents;
|
||||
/// Collider Components
|
||||
ColliderComponents mCollidersComponents;
|
||||
|
||||
/// Joint Components
|
||||
JointComponents mJointsComponents;
|
||||
|
@ -213,8 +213,8 @@ class CollisionWorld {
|
|||
|
||||
#endif
|
||||
|
||||
/// Return the current world-space AABB of given proxy shape
|
||||
AABB getWorldAABB(const ProxyShape* proxyShape) const;
|
||||
/// Return the current world-space AABB of given collider
|
||||
AABB getWorldAABB(const Collider* collider) const;
|
||||
|
||||
/// Return the name of the world
|
||||
const std::string& getName() const;
|
||||
|
@ -225,7 +225,7 @@ class CollisionWorld {
|
|||
friend class CollisionDetectionSystem;
|
||||
friend class CollisionBody;
|
||||
friend class RigidBody;
|
||||
friend class ProxyShape;
|
||||
friend class Collider;
|
||||
friend class ConvexMeshShape;
|
||||
friend class CollisionCallback::ContactPair;
|
||||
friend class OverlapCallback::OverlapPair;
|
||||
|
|
|
@ -51,11 +51,11 @@ DynamicsWorld::DynamicsWorld(const Vector3& gravity, MemoryManager& memoryManage
|
|||
: CollisionWorld(memoryManager, worldSettings, logger, profiler),
|
||||
mIslands(mMemoryManager.getSingleFrameAllocator()),
|
||||
mContactSolverSystem(mMemoryManager, *this, mIslands, mCollisionBodyComponents, mRigidBodyComponents,
|
||||
mProxyShapesComponents, mConfig),
|
||||
mCollidersComponents, mConfig),
|
||||
mConstraintSolverSystem(*this, mIslands, mRigidBodyComponents, mTransformComponents, mJointsComponents,
|
||||
mBallAndSocketJointsComponents, mFixedJointsComponents, mHingeJointsComponents,
|
||||
mSliderJointsComponents),
|
||||
mDynamicsSystem(*this, mCollisionBodyComponents, mRigidBodyComponents, mTransformComponents, mProxyShapesComponents, mIsGravityEnabled, mGravity),
|
||||
mDynamicsSystem(*this, mCollisionBodyComponents, mRigidBodyComponents, mTransformComponents, mCollidersComponents, mIsGravityEnabled, mGravity),
|
||||
mNbVelocitySolverIterations(mConfig.defaultVelocitySolverNbIterations),
|
||||
mNbPositionSolverIterations(mConfig.defaultPositionSolverNbIterations),
|
||||
mIsSleepingEnabled(mConfig.isSleepingEnabled), mRigidBodies(mMemoryManager.getPoolAllocator()),
|
||||
|
@ -142,8 +142,8 @@ void DynamicsWorld::update(decimal timeStep) {
|
|||
// Update the state (positions and velocities) of the bodies
|
||||
mDynamicsSystem.updateBodiesState();
|
||||
|
||||
// Update the proxy-shapes components
|
||||
mCollisionDetection.updateProxyShapes(timeStep);
|
||||
// Update the colliders components
|
||||
mCollisionDetection.updateColliders(timeStep);
|
||||
|
||||
if (mIsSleepingEnabled) updateSleepingBodies(timeStep);
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
using namespace reactphysics3d;
|
||||
|
||||
// Constructor
|
||||
OverlappingPairs::OverlappingPairs(MemoryAllocator& persistentMemoryAllocator, MemoryAllocator& temporaryMemoryAllocator, ProxyShapeComponents& proxyShapeComponents,
|
||||
OverlappingPairs::OverlappingPairs(MemoryAllocator& persistentMemoryAllocator, MemoryAllocator& temporaryMemoryAllocator, ColliderComponents &colliderComponents,
|
||||
CollisionBodyComponents& collisionBodyComponents, RigidBodyComponents& rigidBodyComponents, Set<bodypair> &noCollisionPairs, CollisionDispatch &collisionDispatch)
|
||||
: mPersistentAllocator(persistentMemoryAllocator), mTempMemoryAllocator(temporaryMemoryAllocator),
|
||||
mNbPairs(0), mConcavePairsStartIndex(0), mPairDataSize(sizeof(uint64) + sizeof(int32) + sizeof(int32) + sizeof(Entity) +
|
||||
|
@ -43,7 +43,7 @@ OverlappingPairs::OverlappingPairs(MemoryAllocator& persistentMemoryAllocator, M
|
|||
sizeof(bool)),
|
||||
mNbAllocatedPairs(0), mBuffer(nullptr),
|
||||
mMapPairIdToPairIndex(persistentMemoryAllocator),
|
||||
mProxyShapeComponents(proxyShapeComponents), mCollisionBodyComponents(collisionBodyComponents),
|
||||
mColliderComponents(colliderComponents), mCollisionBodyComponents(collisionBodyComponents),
|
||||
mRigidBodyComponents(rigidBodyComponents), mNoCollisionPairs(noCollisionPairs), mCollisionDispatch(collisionDispatch) {
|
||||
|
||||
// Allocate memory for the components data
|
||||
|
@ -69,11 +69,11 @@ OverlappingPairs::~OverlappingPairs() {
|
|||
mPersistentAllocator.release(it->second, sizeof(LastFrameCollisionInfo));
|
||||
}
|
||||
|
||||
// Remove the involved overlapping pair to the two proxy-shapes
|
||||
assert(mProxyShapeComponents.getOverlappingPairs(mProxyShapes1[i]).find(mPairIds[i]) != mProxyShapeComponents.getOverlappingPairs(mProxyShapes1[i]).end());
|
||||
assert(mProxyShapeComponents.getOverlappingPairs(mProxyShapes2[i]).find(mPairIds[i]) != mProxyShapeComponents.getOverlappingPairs(mProxyShapes2[i]).end());
|
||||
mProxyShapeComponents.getOverlappingPairs(mProxyShapes1[i]).remove(mPairIds[i]);
|
||||
mProxyShapeComponents.getOverlappingPairs(mProxyShapes2[i]).remove(mPairIds[i]);
|
||||
// Remove the involved overlapping pair to the two colliders
|
||||
assert(mColliderComponents.getOverlappingPairs(mColliders1[i]).find(mPairIds[i]) != mColliderComponents.getOverlappingPairs(mColliders1[i]).end());
|
||||
assert(mColliderComponents.getOverlappingPairs(mColliders2[i]).find(mPairIds[i]) != mColliderComponents.getOverlappingPairs(mColliders2[i]).end());
|
||||
mColliderComponents.getOverlappingPairs(mColliders1[i]).remove(mPairIds[i]);
|
||||
mColliderComponents.getOverlappingPairs(mColliders2[i]).remove(mPairIds[i]);
|
||||
|
||||
destroyPair(i);
|
||||
}
|
||||
|
@ -144,11 +144,11 @@ void OverlappingPairs::removePair(uint64 pairId) {
|
|||
mPersistentAllocator.release(it->second, sizeof(LastFrameCollisionInfo));
|
||||
}
|
||||
|
||||
// Remove the involved overlapping pair to the two proxy-shapes
|
||||
assert(mProxyShapeComponents.getOverlappingPairs(mProxyShapes1[index]).find(pairId) != mProxyShapeComponents.getOverlappingPairs(mProxyShapes1[index]).end());
|
||||
assert(mProxyShapeComponents.getOverlappingPairs(mProxyShapes2[index]).find(pairId) != mProxyShapeComponents.getOverlappingPairs(mProxyShapes2[index]).end());
|
||||
mProxyShapeComponents.getOverlappingPairs(mProxyShapes1[index]).remove(pairId);
|
||||
mProxyShapeComponents.getOverlappingPairs(mProxyShapes2[index]).remove(pairId);
|
||||
// Remove the involved overlapping pair to the two colliders
|
||||
assert(mColliderComponents.getOverlappingPairs(mColliders1[index]).find(pairId) != mColliderComponents.getOverlappingPairs(mColliders1[index]).end());
|
||||
assert(mColliderComponents.getOverlappingPairs(mColliders2[index]).find(pairId) != mColliderComponents.getOverlappingPairs(mColliders2[index]).end());
|
||||
mColliderComponents.getOverlappingPairs(mColliders1[index]).remove(pairId);
|
||||
mColliderComponents.getOverlappingPairs(mColliders2[index]).remove(pairId);
|
||||
|
||||
// Destroy the pair
|
||||
destroyPair(index);
|
||||
|
@ -204,9 +204,9 @@ void OverlappingPairs::allocate(uint64 nbPairsToAllocate) {
|
|||
uint64* newPairIds = static_cast<uint64*>(newBuffer);
|
||||
int32* newPairBroadPhaseId1 = reinterpret_cast<int32*>(newPairIds + nbPairsToAllocate);
|
||||
int32* newPairBroadPhaseId2 = reinterpret_cast<int32*>(newPairBroadPhaseId1 + nbPairsToAllocate);
|
||||
Entity* newProxyShapes1 = reinterpret_cast<Entity*>(newPairBroadPhaseId2 + nbPairsToAllocate);
|
||||
Entity* newProxyShapes2 = reinterpret_cast<Entity*>(newProxyShapes1 + nbPairsToAllocate);
|
||||
Map<uint64, LastFrameCollisionInfo*>* newLastFrameCollisionInfos = reinterpret_cast<Map<uint64, LastFrameCollisionInfo*>*>(newProxyShapes2 + nbPairsToAllocate);
|
||||
Entity* newColliders1 = reinterpret_cast<Entity*>(newPairBroadPhaseId2 + nbPairsToAllocate);
|
||||
Entity* newColliders2 = reinterpret_cast<Entity*>(newColliders1 + nbPairsToAllocate);
|
||||
Map<uint64, LastFrameCollisionInfo*>* newLastFrameCollisionInfos = reinterpret_cast<Map<uint64, LastFrameCollisionInfo*>*>(newColliders2 + nbPairsToAllocate);
|
||||
bool* newNeedToTestOverlap = reinterpret_cast<bool*>(newLastFrameCollisionInfos + nbPairsToAllocate);
|
||||
bool* newIsActive = reinterpret_cast<bool*>(newNeedToTestOverlap + nbPairsToAllocate);
|
||||
NarrowPhaseAlgorithmType* newNarrowPhaseAlgorithmType = reinterpret_cast<NarrowPhaseAlgorithmType*>(newIsActive + nbPairsToAllocate);
|
||||
|
@ -219,8 +219,8 @@ void OverlappingPairs::allocate(uint64 nbPairsToAllocate) {
|
|||
memcpy(newPairIds, mPairIds, mNbPairs * sizeof(uint64));
|
||||
memcpy(newPairBroadPhaseId1, mPairBroadPhaseId1, mNbPairs * sizeof(int32));
|
||||
memcpy(newPairBroadPhaseId2, mPairBroadPhaseId2, mNbPairs * sizeof(int32));
|
||||
memcpy(newProxyShapes1, mProxyShapes1, mNbPairs * sizeof(Entity));
|
||||
memcpy(newProxyShapes2, mProxyShapes2, mNbPairs * sizeof(Entity));
|
||||
memcpy(newColliders1, mColliders1, mNbPairs * sizeof(Entity));
|
||||
memcpy(newColliders2, mColliders2, mNbPairs * sizeof(Entity));
|
||||
memcpy(newLastFrameCollisionInfos, mLastFrameCollisionInfos, mNbPairs * sizeof(Map<uint64, LastFrameCollisionInfo*>));
|
||||
memcpy(newNeedToTestOverlap, mNeedToTestOverlap, mNbPairs * sizeof(bool));
|
||||
memcpy(newIsActive, mIsActive, mNbPairs * sizeof(bool));
|
||||
|
@ -235,8 +235,8 @@ void OverlappingPairs::allocate(uint64 nbPairsToAllocate) {
|
|||
mPairIds = newPairIds;
|
||||
mPairBroadPhaseId1 = newPairBroadPhaseId1;
|
||||
mPairBroadPhaseId2 = newPairBroadPhaseId2;
|
||||
mProxyShapes1 = newProxyShapes1;
|
||||
mProxyShapes2 = newProxyShapes2;
|
||||
mColliders1 = newColliders1;
|
||||
mColliders2 = newColliders2;
|
||||
mLastFrameCollisionInfos = newLastFrameCollisionInfos;
|
||||
mNeedToTestOverlap = newNeedToTestOverlap;
|
||||
mIsActive = newIsActive;
|
||||
|
@ -247,18 +247,18 @@ void OverlappingPairs::allocate(uint64 nbPairsToAllocate) {
|
|||
}
|
||||
|
||||
// Add an overlapping pair
|
||||
uint64 OverlappingPairs::addPair(ProxyShape* shape1, ProxyShape* shape2) {
|
||||
uint64 OverlappingPairs::addPair(Collider* shape1, Collider* shape2) {
|
||||
|
||||
RP3D_PROFILE("OverlappingPairs::addPair()", mProfiler);
|
||||
|
||||
const Entity proxyShape1 = shape1->getEntity();
|
||||
const Entity proxyShape2 = shape2->getEntity();
|
||||
const Entity collider1 = shape1->getEntity();
|
||||
const Entity collider2 = shape2->getEntity();
|
||||
|
||||
const uint proxyShape1Index = mProxyShapeComponents.getEntityIndex(proxyShape1);
|
||||
const uint proxyShape2Index = mProxyShapeComponents.getEntityIndex(proxyShape2);
|
||||
const uint collider1Index = mColliderComponents.getEntityIndex(collider1);
|
||||
const uint collider2Index = mColliderComponents.getEntityIndex(collider2);
|
||||
|
||||
const CollisionShape* collisionShape1 = mProxyShapeComponents.mCollisionShapes[proxyShape1Index];
|
||||
const CollisionShape* collisionShape2 = mProxyShapeComponents.mCollisionShapes[proxyShape2Index];
|
||||
const CollisionShape* collisionShape1 = mColliderComponents.mCollisionShapes[collider1Index];
|
||||
const CollisionShape* collisionShape2 = mColliderComponents.mCollisionShapes[collider2Index];
|
||||
|
||||
const bool isShape1Convex = collisionShape1->isConvex();
|
||||
const bool isShape2Convex = collisionShape2->isConvex();
|
||||
|
@ -291,8 +291,8 @@ uint64 OverlappingPairs::addPair(ProxyShape* shape1, ProxyShape* shape2) {
|
|||
new (mPairIds + index) uint64(pairId);
|
||||
new (mPairBroadPhaseId1 + index) int32(shape1->getBroadPhaseId());
|
||||
new (mPairBroadPhaseId2 + index) int32(shape2->getBroadPhaseId());
|
||||
new (mProxyShapes1 + index) Entity(shape1->getEntity());
|
||||
new (mProxyShapes2 + index) Entity(shape2->getEntity());
|
||||
new (mColliders1 + index) Entity(shape1->getEntity());
|
||||
new (mColliders2 + index) Entity(shape2->getEntity());
|
||||
new (mLastFrameCollisionInfos + index) Map<uint64, LastFrameCollisionInfo*>(mPersistentAllocator);
|
||||
new (mNeedToTestOverlap + index) bool(false);
|
||||
new (mIsActive + index) bool(true);
|
||||
|
@ -302,11 +302,11 @@ uint64 OverlappingPairs::addPair(ProxyShape* shape1, ProxyShape* shape2) {
|
|||
// Map the entity with the new component lookup index
|
||||
mMapPairIdToPairIndex.add(Pair<uint64, uint64>(pairId, index));
|
||||
|
||||
// Add the involved overlapping pair to the two proxy-shapes
|
||||
assert(mProxyShapeComponents.mOverlappingPairs[proxyShape1Index].find(pairId) == mProxyShapeComponents.mOverlappingPairs[proxyShape1Index].end());
|
||||
assert(mProxyShapeComponents.mOverlappingPairs[proxyShape2Index].find(pairId) == mProxyShapeComponents.mOverlappingPairs[proxyShape2Index].end());
|
||||
mProxyShapeComponents.mOverlappingPairs[proxyShape1Index].add(pairId);
|
||||
mProxyShapeComponents.mOverlappingPairs[proxyShape2Index].add(pairId);
|
||||
// Add the involved overlapping pair to the two colliders
|
||||
assert(mColliderComponents.mOverlappingPairs[collider1Index].find(pairId) == mColliderComponents.mOverlappingPairs[collider1Index].end());
|
||||
assert(mColliderComponents.mOverlappingPairs[collider2Index].find(pairId) == mColliderComponents.mOverlappingPairs[collider2Index].end());
|
||||
mColliderComponents.mOverlappingPairs[collider1Index].add(pairId);
|
||||
mColliderComponents.mOverlappingPairs[collider2Index].add(pairId);
|
||||
|
||||
mNbPairs++;
|
||||
|
||||
|
@ -328,8 +328,8 @@ void OverlappingPairs::movePairToIndex(uint64 srcIndex, uint64 destIndex) {
|
|||
mPairIds[destIndex] = mPairIds[srcIndex];
|
||||
mPairBroadPhaseId1[destIndex] = mPairBroadPhaseId1[srcIndex];
|
||||
mPairBroadPhaseId2[destIndex] = mPairBroadPhaseId2[srcIndex];
|
||||
new (mProxyShapes1 + destIndex) Entity(mProxyShapes1[srcIndex]);
|
||||
new (mProxyShapes2 + destIndex) Entity(mProxyShapes2[srcIndex]);
|
||||
new (mColliders1 + destIndex) Entity(mColliders1[srcIndex]);
|
||||
new (mColliders2 + destIndex) Entity(mColliders2[srcIndex]);
|
||||
new (mLastFrameCollisionInfos + destIndex) Map<uint64, LastFrameCollisionInfo*>(mLastFrameCollisionInfos[srcIndex]);
|
||||
mNeedToTestOverlap[destIndex] = mNeedToTestOverlap[srcIndex];
|
||||
mIsActive[destIndex] = mIsActive[srcIndex];
|
||||
|
@ -354,8 +354,8 @@ void OverlappingPairs::swapPairs(uint64 index1, uint64 index2) {
|
|||
uint64 pairId = mPairIds[index1];
|
||||
int32 pairBroadPhaseId1 = mPairBroadPhaseId1[index1];
|
||||
int32 pairBroadPhaseId2 = mPairBroadPhaseId2[index1];
|
||||
Entity proxyShape1 = mProxyShapes1[index1];
|
||||
Entity proxyShape2 = mProxyShapes2[index1];
|
||||
Entity collider1 = mColliders1[index1];
|
||||
Entity collider2 = mColliders2[index1];
|
||||
Map<uint64, LastFrameCollisionInfo*> lastFrameCollisionInfo(mLastFrameCollisionInfos[index1]);
|
||||
bool needTestOverlap = mNeedToTestOverlap[index1];
|
||||
bool isActive = mIsActive[index1];
|
||||
|
@ -371,8 +371,8 @@ void OverlappingPairs::swapPairs(uint64 index1, uint64 index2) {
|
|||
mPairIds[index2] = pairId;
|
||||
mPairBroadPhaseId1[index2] = pairBroadPhaseId1;
|
||||
mPairBroadPhaseId2[index2] = pairBroadPhaseId2;
|
||||
new (mProxyShapes1 + index2) Entity(proxyShape1);
|
||||
new (mProxyShapes2 + index2) Entity(proxyShape2);
|
||||
new (mColliders1 + index2) Entity(collider1);
|
||||
new (mColliders2 + index2) Entity(collider2);
|
||||
new (mLastFrameCollisionInfos + index2) Map<uint64, LastFrameCollisionInfo*>(lastFrameCollisionInfo);
|
||||
mNeedToTestOverlap[index2] = needTestOverlap;
|
||||
mIsActive[index2] = isActive;
|
||||
|
@ -396,8 +396,8 @@ void OverlappingPairs::destroyPair(uint64 index) {
|
|||
|
||||
mMapPairIdToPairIndex.remove(mPairIds[index]);
|
||||
|
||||
mProxyShapes1[index].~Entity();
|
||||
mProxyShapes2[index].~Entity();
|
||||
mColliders1[index].~Entity();
|
||||
mColliders2[index].~Entity();
|
||||
mLastFrameCollisionInfos[index].~Map<uint64, LastFrameCollisionInfo*>();
|
||||
mNarrowPhaseAlgorithmType[index].~NarrowPhaseAlgorithmType();
|
||||
}
|
||||
|
@ -409,11 +409,11 @@ void OverlappingPairs::updateOverlappingPairIsActive(uint64 pairId) {
|
|||
|
||||
const uint64 pairIndex = mMapPairIdToPairIndex[pairId];
|
||||
|
||||
const Entity proxyShape1 = mProxyShapes1[pairIndex];
|
||||
const Entity proxyShape2 = mProxyShapes2[pairIndex];
|
||||
const Entity collider1 = mColliders1[pairIndex];
|
||||
const Entity collider2 = mColliders2[pairIndex];
|
||||
|
||||
const Entity body1 = mProxyShapeComponents.getBody(proxyShape1);
|
||||
const Entity body2 = mProxyShapeComponents.getBody(proxyShape2);
|
||||
const Entity body1 = mColliderComponents.getBody(collider1);
|
||||
const Entity body2 = mColliderComponents.getBody(collider2);
|
||||
|
||||
const bool isBody1Enabled = !mCollisionBodyComponents.getIsEntityDisabled(body1);
|
||||
const bool isBody2Enabled = !mCollisionBodyComponents.getIsEntityDisabled(body2);
|
||||
|
|
|
@ -27,13 +27,13 @@
|
|||
#define REACTPHYSICS3D_OVERLAPPING_PAIR_H
|
||||
|
||||
// Libraries
|
||||
#include "collision/ProxyShape.h"
|
||||
#include "collision/Collider.h"
|
||||
#include "containers/Map.h"
|
||||
#include "containers/Pair.h"
|
||||
#include "containers/Set.h"
|
||||
#include "containers/containers_common.h"
|
||||
#include "utils/Profiler.h"
|
||||
#include "components/ProxyShapeComponents.h"
|
||||
#include "components/ColliderComponents.h"
|
||||
#include "components/CollisionBodyComponents.h"
|
||||
#include "components/RigidBodyComponents.h"
|
||||
#include <cstddef>
|
||||
|
@ -96,9 +96,9 @@ struct LastFrameCollisionInfo {
|
|||
|
||||
// Class OverlappingPairs
|
||||
/**
|
||||
* This class contains pairs of two proxy collision shapes that are overlapping
|
||||
* This class contains pairs of two colliders that are overlapping
|
||||
* during the broad-phase collision detection. A pair is created when
|
||||
* the two proxy collision shapes start to overlap and is destroyed when they do not
|
||||
* the two colliders start to overlap and is destroyed when they do not
|
||||
* overlap anymore. Each contains a contact manifold that
|
||||
* store all the contact points between the two bodies.
|
||||
*/
|
||||
|
@ -148,11 +148,11 @@ class OverlappingPairs {
|
|||
/// Array with the broad-phase Ids of the second shape
|
||||
int32* mPairBroadPhaseId2;
|
||||
|
||||
/// Array of Entity of the first proxy-shape of the convex vs convex pairs
|
||||
Entity* mProxyShapes1;
|
||||
/// Array of Entity of the first collider of the convex vs convex pairs
|
||||
Entity* mColliders1;
|
||||
|
||||
/// Array of Entity of the second proxy-shape of the convex vs convex pairs
|
||||
Entity* mProxyShapes2;
|
||||
/// Array of Entity of the second collider of the convex vs convex pairs
|
||||
Entity* mColliders2;
|
||||
|
||||
/// Temporal coherence collision data for each overlapping collision shapes of this pair.
|
||||
/// Temporal coherence data store collision information about the last frame.
|
||||
|
@ -173,8 +173,8 @@ class OverlappingPairs {
|
|||
/// True if the first shape of the pair is convex
|
||||
bool* mIsShape1Convex;
|
||||
|
||||
/// Reference to the proxy-shapes components
|
||||
ProxyShapeComponents& mProxyShapeComponents;
|
||||
/// Reference to the colliders components
|
||||
ColliderComponents& mColliderComponents;
|
||||
|
||||
/// Reference to the collision body components
|
||||
CollisionBodyComponents& mCollisionBodyComponents;
|
||||
|
@ -218,7 +218,7 @@ class OverlappingPairs {
|
|||
|
||||
/// Constructor
|
||||
OverlappingPairs(MemoryAllocator& persistentMemoryAllocator, MemoryAllocator& temporaryMemoryAllocator,
|
||||
ProxyShapeComponents& proxyShapeComponents, CollisionBodyComponents& collisionBodyComponents,
|
||||
ColliderComponents& colliderComponents, CollisionBodyComponents& collisionBodyComponents,
|
||||
RigidBodyComponents& rigidBodyComponents, Set<bodypair>& noCollisionPairs,
|
||||
CollisionDispatch& collisionDispatch);
|
||||
|
||||
|
@ -232,7 +232,7 @@ class OverlappingPairs {
|
|||
OverlappingPairs& operator=(const OverlappingPairs& pair) = delete;
|
||||
|
||||
/// Add an overlapping pair
|
||||
uint64 addPair(ProxyShape* shape1, ProxyShape* shape2);
|
||||
uint64 addPair(Collider* shape1, Collider* shape2);
|
||||
|
||||
/// Remove a component at a given index
|
||||
void removePair(uint64 pairId);
|
||||
|
@ -249,11 +249,11 @@ class OverlappingPairs {
|
|||
/// Return the starting index of the convex vs concave pairs
|
||||
uint64 getConvexVsConcavePairsStartIndex() const;
|
||||
|
||||
/// Return the entity of the first proxy-shape
|
||||
Entity getProxyShape1(uint64 pairId) const;
|
||||
/// Return the entity of the first collider
|
||||
Entity getCollider1(uint64 pairId) const;
|
||||
|
||||
/// Return the entity of the second proxy-shape
|
||||
Entity getProxyShape2(uint64 pairId) const;
|
||||
/// Return the entity of the second collider
|
||||
Entity getCollider2(uint64 pairId) const;
|
||||
|
||||
/// Notify if a given pair is active or not
|
||||
void setIsPairActive(uint64 pairId, bool isActive);
|
||||
|
@ -295,18 +295,18 @@ class OverlappingPairs {
|
|||
friend class CollisionDetectionSystem;
|
||||
};
|
||||
|
||||
// Return the entity of the first proxy-shape
|
||||
inline Entity OverlappingPairs::getProxyShape1(uint64 pairId) const {
|
||||
// Return the entity of the first collider
|
||||
inline Entity OverlappingPairs::getCollider1(uint64 pairId) const {
|
||||
assert(mMapPairIdToPairIndex.containsKey(pairId));
|
||||
assert(mMapPairIdToPairIndex[pairId] < mNbPairs);
|
||||
return mProxyShapes1[mMapPairIdToPairIndex[pairId]];
|
||||
return mColliders1[mMapPairIdToPairIndex[pairId]];
|
||||
}
|
||||
|
||||
// Return the entity of the second proxy-shape
|
||||
inline Entity OverlappingPairs::getProxyShape2(uint64 pairId) const {
|
||||
// Return the entity of the second collider
|
||||
inline Entity OverlappingPairs::getCollider2(uint64 pairId) const {
|
||||
assert(mMapPairIdToPairIndex.containsKey(pairId));
|
||||
assert(mMapPairIdToPairIndex[pairId] < mNbPairs);
|
||||
return mProxyShapes2[mMapPairIdToPairIndex[pairId]];
|
||||
return mColliders2[mMapPairIdToPairIndex[pairId]];
|
||||
}
|
||||
|
||||
// Notify if a given pair is active or not
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
#include "collision/shapes/HeightFieldShape.h"
|
||||
#include "collision/PolyhedronMesh.h"
|
||||
#include "collision/shapes/AABB.h"
|
||||
#include "collision/ProxyShape.h"
|
||||
#include "collision/Collider.h"
|
||||
#include "collision/RaycastInfo.h"
|
||||
#include "collision/TriangleMesh.h"
|
||||
#include "collision/PolyhedronMesh.h"
|
||||
|
|
|
@ -35,10 +35,10 @@
|
|||
using namespace reactphysics3d;
|
||||
|
||||
// Constructor
|
||||
BroadPhaseSystem::BroadPhaseSystem(CollisionDetectionSystem& collisionDetection, ProxyShapeComponents& proxyShapesComponents,
|
||||
BroadPhaseSystem::BroadPhaseSystem(CollisionDetectionSystem& collisionDetection, ColliderComponents& collidersComponents,
|
||||
TransformComponents& transformComponents, RigidBodyComponents &rigidBodyComponents)
|
||||
:mDynamicAABBTree(collisionDetection.getMemoryManager().getPoolAllocator(), DYNAMIC_TREE_AABB_GAP),
|
||||
mProxyShapesComponents(proxyShapesComponents), mTransformsComponents(transformComponents),
|
||||
mCollidersComponents(collidersComponents), mTransformsComponents(transformComponents),
|
||||
mRigidBodyComponents(rigidBodyComponents), mMovedShapes(collisionDetection.getMemoryManager().getPoolAllocator()),
|
||||
mCollisionDetection(collisionDetection) {
|
||||
|
||||
|
@ -76,30 +76,30 @@ void BroadPhaseSystem::raycast(const Ray& ray, RaycastTest& raycastTest,
|
|||
mDynamicAABBTree.raycast(ray, broadPhaseRaycastCallback);
|
||||
}
|
||||
|
||||
// Add a proxy collision shape into the broad-phase collision detection
|
||||
void BroadPhaseSystem::addProxyCollisionShape(ProxyShape* proxyShape, const AABB& aabb) {
|
||||
// Add a collider into the broad-phase collision detection
|
||||
void BroadPhaseSystem::addCollider(Collider* collider, const AABB& aabb) {
|
||||
|
||||
assert(proxyShape->getBroadPhaseId() == -1);
|
||||
assert(collider->getBroadPhaseId() == -1);
|
||||
|
||||
// Add the collision shape into the dynamic AABB tree and get its broad-phase ID
|
||||
int nodeId = mDynamicAABBTree.addObject(aabb, proxyShape);
|
||||
int nodeId = mDynamicAABBTree.addObject(aabb, collider);
|
||||
|
||||
// Set the broad-phase ID of the proxy shape
|
||||
mProxyShapesComponents.setBroadPhaseId(proxyShape->getEntity(), nodeId);
|
||||
// Set the broad-phase ID of the collider
|
||||
mCollidersComponents.setBroadPhaseId(collider->getEntity(), nodeId);
|
||||
|
||||
// Add the collision shape into the array of bodies that have moved (or have been created)
|
||||
// during the last simulation step
|
||||
addMovedCollisionShape(proxyShape->getBroadPhaseId(), proxyShape);
|
||||
addMovedCollisionShape(collider->getBroadPhaseId(), collider);
|
||||
}
|
||||
|
||||
// Remove a proxy collision shape from the broad-phase collision detection
|
||||
void BroadPhaseSystem::removeProxyCollisionShape(ProxyShape* proxyShape) {
|
||||
// Remove a collider from the broad-phase collision detection
|
||||
void BroadPhaseSystem::removeCollider(Collider* collider) {
|
||||
|
||||
assert(proxyShape->getBroadPhaseId() != -1);
|
||||
assert(collider->getBroadPhaseId() != -1);
|
||||
|
||||
int broadPhaseID = proxyShape->getBroadPhaseId();
|
||||
int broadPhaseID = collider->getBroadPhaseId();
|
||||
|
||||
mProxyShapesComponents.setBroadPhaseId(proxyShape->getEntity(), -1);
|
||||
mCollidersComponents.setBroadPhaseId(collider->getEntity(), -1);
|
||||
|
||||
// Remove the collision shape from the dynamic AABB tree
|
||||
mDynamicAABBTree.removeObject(broadPhaseID);
|
||||
|
@ -109,31 +109,31 @@ void BroadPhaseSystem::removeProxyCollisionShape(ProxyShape* proxyShape) {
|
|||
removeMovedCollisionShape(broadPhaseID);
|
||||
}
|
||||
|
||||
// Update the broad-phase state of a single proxy-shape
|
||||
void BroadPhaseSystem::updateProxyShape(Entity proxyShapeEntity, decimal timeStep) {
|
||||
// Update the broad-phase state of a single collider
|
||||
void BroadPhaseSystem::updateCollider(Entity colliderEntity, decimal timeStep) {
|
||||
|
||||
assert(mProxyShapesComponents.mMapEntityToComponentIndex.containsKey(proxyShapeEntity));
|
||||
assert(mCollidersComponents.mMapEntityToComponentIndex.containsKey(colliderEntity));
|
||||
|
||||
// Get the index of the proxy-shape component in the array
|
||||
uint32 index = mProxyShapesComponents.mMapEntityToComponentIndex[proxyShapeEntity];
|
||||
// Get the index of the collider component in the array
|
||||
uint32 index = mCollidersComponents.mMapEntityToComponentIndex[colliderEntity];
|
||||
|
||||
// Update the proxy-shape component
|
||||
updateProxyShapesComponents(index, 1, timeStep);
|
||||
// Update the collider component
|
||||
updateCollidersComponents(index, 1, timeStep);
|
||||
}
|
||||
|
||||
// Update the broad-phase state of all the enabled proxy-shapes
|
||||
void BroadPhaseSystem::updateProxyShapes(decimal timeStep) {
|
||||
// Update the broad-phase state of all the enabled colliders
|
||||
void BroadPhaseSystem::updateColliders(decimal timeStep) {
|
||||
|
||||
RP3D_PROFILE("BroadPhaseSystem::updateProxyShapes()", mProfiler);
|
||||
RP3D_PROFILE("BroadPhaseSystem::updateColliders()", mProfiler);
|
||||
|
||||
// Update all the enabled proxy-shape components
|
||||
if (mProxyShapesComponents.getNbEnabledComponents() > 0) {
|
||||
updateProxyShapesComponents(0, mProxyShapesComponents.getNbEnabledComponents(), timeStep);
|
||||
// Update all the enabled collider components
|
||||
if (mCollidersComponents.getNbEnabledComponents() > 0) {
|
||||
updateCollidersComponents(0, mCollidersComponents.getNbEnabledComponents(), timeStep);
|
||||
}
|
||||
}
|
||||
|
||||
// Notify the broad-phase that a collision shape has moved and need to be updated
|
||||
void BroadPhaseSystem::updateProxyShapeInternal(int32 broadPhaseId, ProxyShape* proxyShape, const AABB& aabb, const Vector3& displacement) {
|
||||
void BroadPhaseSystem::updateColliderInternal(int32 broadPhaseId, Collider* collider, const AABB& aabb, const Vector3& displacement) {
|
||||
|
||||
assert(broadPhaseId >= 0);
|
||||
|
||||
|
@ -146,33 +146,33 @@ void BroadPhaseSystem::updateProxyShapeInternal(int32 broadPhaseId, ProxyShape*
|
|||
|
||||
// Add the collision shape into the array of shapes that have moved (or have been created)
|
||||
// during the last simulation step
|
||||
addMovedCollisionShape(broadPhaseId, proxyShape);
|
||||
addMovedCollisionShape(broadPhaseId, collider);
|
||||
}
|
||||
}
|
||||
|
||||
// Update the broad-phase state of some proxy-shapes components
|
||||
void BroadPhaseSystem::updateProxyShapesComponents(uint32 startIndex, uint32 nbItems, decimal timeStep) {
|
||||
// Update the broad-phase state of some colliders components
|
||||
void BroadPhaseSystem::updateCollidersComponents(uint32 startIndex, uint32 nbItems, decimal timeStep) {
|
||||
|
||||
RP3D_PROFILE("BroadPhaseSystem::updateProxyShapesComponents()", mProfiler);
|
||||
RP3D_PROFILE("BroadPhaseSystem::updateCollidersComponents()", mProfiler);
|
||||
|
||||
assert(nbItems > 0);
|
||||
assert(startIndex < mProxyShapesComponents.getNbComponents());
|
||||
assert(startIndex + nbItems <= mProxyShapesComponents.getNbComponents());
|
||||
assert(startIndex < mCollidersComponents.getNbComponents());
|
||||
assert(startIndex + nbItems <= mCollidersComponents.getNbComponents());
|
||||
|
||||
// Make sure we do not update disabled components
|
||||
startIndex = std::min(startIndex, mProxyShapesComponents.getNbEnabledComponents());
|
||||
uint32 endIndex = std::min(startIndex + nbItems, mProxyShapesComponents.getNbEnabledComponents());
|
||||
startIndex = std::min(startIndex, mCollidersComponents.getNbEnabledComponents());
|
||||
uint32 endIndex = std::min(startIndex + nbItems, mCollidersComponents.getNbEnabledComponents());
|
||||
nbItems = endIndex - startIndex;
|
||||
assert(nbItems >= 0);
|
||||
|
||||
// For each proxy-shape component to update
|
||||
// For each collider component to update
|
||||
for (uint32 i = startIndex; i < startIndex + nbItems; i++) {
|
||||
|
||||
// TODO : Can we remove this test
|
||||
const int32 broadPhaseId = mProxyShapesComponents.mBroadPhaseIds[i];
|
||||
const int32 broadPhaseId = mCollidersComponents.mBroadPhaseIds[i];
|
||||
if (broadPhaseId != -1) {
|
||||
|
||||
const Entity& bodyEntity = mProxyShapesComponents.mBodiesEntities[i];
|
||||
const Entity& bodyEntity = mCollidersComponents.mBodiesEntities[i];
|
||||
const Transform& transform = mTransformsComponents.getTransform(bodyEntity);
|
||||
|
||||
// If there is a dynamics component for the current entity
|
||||
|
@ -187,10 +187,10 @@ void BroadPhaseSystem::updateProxyShapesComponents(uint32 startIndex, uint32 nbI
|
|||
|
||||
// Recompute the world-space AABB of the collision shape
|
||||
AABB aabb;
|
||||
mProxyShapesComponents.mCollisionShapes[i]->computeAABB(aabb, transform * mProxyShapesComponents.mLocalToBodyTransforms[i]);
|
||||
mCollidersComponents.mCollisionShapes[i]->computeAABB(aabb, transform * mCollidersComponents.mLocalToBodyTransforms[i]);
|
||||
|
||||
// Update the broad-phase state for the proxy collision shape
|
||||
updateProxyShapeInternal(broadPhaseId, mProxyShapesComponents.mProxyShapes[i], aabb, displacement);
|
||||
// Update the broad-phase state for the collider
|
||||
updateColliderInternal(broadPhaseId, mCollidersComponents.mColliders[i], aabb, displacement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ void BroadPhaseSystem::updateProxyShapesComponents(uint32 startIndex, uint32 nbI
|
|||
|
||||
// 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.
|
||||
void BroadPhaseSystem::addMovedCollisionShape(int broadPhaseID, ProxyShape* proxyShape) {
|
||||
void BroadPhaseSystem::addMovedCollisionShape(int broadPhaseID, Collider* collider) {
|
||||
|
||||
assert(broadPhaseID != -1);
|
||||
|
||||
|
@ -206,7 +206,7 @@ void BroadPhaseSystem::addMovedCollisionShape(int broadPhaseID, ProxyShape* prox
|
|||
mMovedShapes.add(broadPhaseID);
|
||||
|
||||
// Notify that the overlapping pairs where this shape is involved need to be tested for overlap
|
||||
mCollisionDetection.notifyOverlappingPairsToTestOverlap(proxyShape);
|
||||
mCollisionDetection.notifyOverlappingPairsToTestOverlap(collider);
|
||||
}
|
||||
|
||||
// Compute all the overlapping pairs of collision shapes
|
||||
|
@ -214,7 +214,7 @@ void BroadPhaseSystem::computeOverlappingPairs(MemoryManager& memoryManager, Lis
|
|||
|
||||
RP3D_PROFILE("BroadPhaseSystem::computeOverlappingPairs()", mProfiler);
|
||||
|
||||
// Get the list of the proxy-shapes that have moved or have been created in the last frame
|
||||
// Get the list of the colliders that have moved or have been created in the last frame
|
||||
List<int> shapesToTest = mMovedShapes.toList(memoryManager.getPoolAllocator());
|
||||
|
||||
// Ask the dynamic AABB tree to report all collision shapes that overlap with the shapes to test
|
||||
|
@ -236,16 +236,16 @@ decimal BroadPhaseRaycastCallback::raycastBroadPhaseShape(int32 nodeId, const Ra
|
|||
|
||||
decimal hitFraction = decimal(-1.0);
|
||||
|
||||
// Get the proxy shape from the node
|
||||
ProxyShape* proxyShape = static_cast<ProxyShape*>(mDynamicAABBTree.getNodeDataPointer(nodeId));
|
||||
// Get the collider from the node
|
||||
Collider* collider = static_cast<Collider*>(mDynamicAABBTree.getNodeDataPointer(nodeId));
|
||||
|
||||
// Check if the raycast filtering mask allows raycast against this shape
|
||||
if ((mRaycastWithCategoryMaskBits & proxyShape->getCollisionCategoryBits()) != 0) {
|
||||
if ((mRaycastWithCategoryMaskBits & collider->getCollisionCategoryBits()) != 0) {
|
||||
|
||||
// Ask the collision detection to perform a ray cast test against
|
||||
// the proxy shape of this node because the ray is overlapping
|
||||
// the collider of this node because the ray is overlapping
|
||||
// with the shape in the broad-phase
|
||||
hitFraction = mRaycastTest.raycastAgainstShape(proxyShape, ray);
|
||||
hitFraction = mRaycastTest.raycastAgainstShape(collider, ray);
|
||||
}
|
||||
|
||||
return hitFraction;
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include "collision/broadphase/DynamicAABBTree.h"
|
||||
#include "containers/LinkedList.h"
|
||||
#include "containers/Set.h"
|
||||
#include "components/ProxyShapeComponents.h"
|
||||
#include "components/ColliderComponents.h"
|
||||
#include "components/TransformComponents.h"
|
||||
#include "components/RigidBodyComponents.h"
|
||||
#include <cstring>
|
||||
|
@ -42,7 +42,7 @@ namespace reactphysics3d {
|
|||
class CollisionDetectionSystem;
|
||||
class BroadPhaseSystem;
|
||||
class CollisionBody;
|
||||
class ProxyShape;
|
||||
class Collider;
|
||||
class MemoryManager;
|
||||
class Profiler;
|
||||
|
||||
|
@ -100,7 +100,7 @@ class BroadPhaseRaycastCallback : public DynamicAABBTreeRaycastCallback {
|
|||
// Class BroadPhaseSystem
|
||||
/**
|
||||
* This class represents the broad-phase collision detection. The
|
||||
* goal of the broad-phase collision detection is to compute the pairs of proxy shapes
|
||||
* goal of the broad-phase collision detection is to compute the pairs of colliders
|
||||
* that have their AABBs overlapping. Only those pairs of bodies will be tested
|
||||
* later for collision during the narrow-phase collision detection. A dynamic AABB
|
||||
* tree data structure is used for fast broad-phase collision detection.
|
||||
|
@ -114,8 +114,8 @@ class BroadPhaseSystem {
|
|||
/// Dynamic AABB tree
|
||||
DynamicAABBTree mDynamicAABBTree;
|
||||
|
||||
/// Reference to the proxy-shapes components
|
||||
ProxyShapeComponents& mProxyShapesComponents;
|
||||
/// Reference to the colliders components
|
||||
ColliderComponents& mCollidersComponents;
|
||||
|
||||
/// Reference to the transform components
|
||||
TransformComponents& mTransformsComponents;
|
||||
|
@ -139,18 +139,18 @@ class BroadPhaseSystem {
|
|||
#endif
|
||||
// -------------------- Methods -------------------- //
|
||||
|
||||
/// Notify the Dynamic AABB tree that a proxy-shape needs to be updated
|
||||
void updateProxyShapeInternal(int32 broadPhaseId, ProxyShape* proxyShape, const AABB& aabb, const Vector3& displacement);
|
||||
/// Notify the Dynamic AABB tree that a collider needs to be updated
|
||||
void updateColliderInternal(int32 broadPhaseId, Collider* collider, const AABB& aabb, const Vector3& displacement);
|
||||
|
||||
/// Update the broad-phase state of some proxy-shapes components
|
||||
void updateProxyShapesComponents(uint32 startIndex, uint32 nbItems, decimal timeStep);
|
||||
/// Update the broad-phase state of some colliders components
|
||||
void updateCollidersComponents(uint32 startIndex, uint32 nbItems, decimal timeStep);
|
||||
|
||||
public :
|
||||
|
||||
// -------------------- Methods -------------------- //
|
||||
|
||||
/// Constructor
|
||||
BroadPhaseSystem(CollisionDetectionSystem& collisionDetection, ProxyShapeComponents& proxyShapesComponents,
|
||||
BroadPhaseSystem(CollisionDetectionSystem& collisionDetection, ColliderComponents& collidersComponents,
|
||||
TransformComponents& transformComponents, RigidBodyComponents& rigidBodyComponents);
|
||||
|
||||
/// Destructor
|
||||
|
@ -162,21 +162,21 @@ class BroadPhaseSystem {
|
|||
/// Deleted assignment operator
|
||||
BroadPhaseSystem& operator=(const BroadPhaseSystem& algorithm) = delete;
|
||||
|
||||
/// Add a proxy collision shape into the broad-phase collision detection
|
||||
void addProxyCollisionShape(ProxyShape* proxyShape, const AABB& aabb);
|
||||
/// Add a collider into the broad-phase collision detection
|
||||
void addCollider(Collider* collider, const AABB& aabb);
|
||||
|
||||
/// Remove a proxy collision shape from the broad-phase collision detection
|
||||
void removeProxyCollisionShape(ProxyShape* proxyShape);
|
||||
/// Remove a collider from the broad-phase collision detection
|
||||
void removeCollider(Collider* collider);
|
||||
|
||||
/// Update the broad-phase state of a single proxy-shape
|
||||
void updateProxyShape(Entity proxyShapeEntity, decimal timeStep);
|
||||
/// Update the broad-phase state of a single collider
|
||||
void updateCollider(Entity colliderEntity, decimal timeStep);
|
||||
|
||||
/// Update the broad-phase state of all the enabled proxy-shapes
|
||||
void updateProxyShapes(decimal timeStep);
|
||||
/// Update the broad-phase state of all the enabled colliders
|
||||
void updateColliders(decimal timeStep);
|
||||
|
||||
/// 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.
|
||||
void addMovedCollisionShape(int broadPhaseID, ProxyShape* proxyShape);
|
||||
void addMovedCollisionShape(int broadPhaseID, Collider* collider);
|
||||
|
||||
/// 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.
|
||||
|
@ -185,8 +185,8 @@ class BroadPhaseSystem {
|
|||
/// Compute all the overlapping pairs of collision shapes
|
||||
void computeOverlappingPairs(MemoryManager& memoryManager, List<Pair<int32, int32>>& overlappingNodes);
|
||||
|
||||
/// Return the proxy shape corresponding to the broad-phase node id in parameter
|
||||
ProxyShape* getProxyShapeForBroadPhaseId(int broadPhaseId) const;
|
||||
/// Return the collider corresponding to the broad-phase node id in parameter
|
||||
Collider* getColliderForBroadPhaseId(int broadPhaseId) const;
|
||||
|
||||
/// Return true if the two broad-phase collision shapes are overlapping
|
||||
bool testOverlappingShapes(int32 shape1BroadPhaseId, int32 shape2BroadPhaseId) const;
|
||||
|
@ -219,9 +219,9 @@ inline void BroadPhaseSystem::removeMovedCollisionShape(int broadPhaseID) {
|
|||
mMovedShapes.remove(broadPhaseID);
|
||||
}
|
||||
|
||||
// Return the proxy shape corresponding to the broad-phase node id in parameter
|
||||
inline ProxyShape* BroadPhaseSystem::getProxyShapeForBroadPhaseId(int broadPhaseId) const {
|
||||
return static_cast<ProxyShape*>(mDynamicAABBTree.getNodeDataPointer(broadPhaseId));
|
||||
// Return the collider corresponding to the broad-phase node id in parameter
|
||||
inline Collider* BroadPhaseSystem::getColliderForBroadPhaseId(int broadPhaseId) const {
|
||||
return static_cast<Collider*>(mDynamicAABBTree.getNodeDataPointer(broadPhaseId));
|
||||
}
|
||||
|
||||
#ifdef IS_PROFILING_ACTIVE
|
||||
|
|
|
@ -51,15 +51,15 @@ using namespace std;
|
|||
|
||||
|
||||
// Constructor
|
||||
CollisionDetectionSystem::CollisionDetectionSystem(CollisionWorld* world, ProxyShapeComponents& proxyShapesComponents, TransformComponents& transformComponents,
|
||||
CollisionDetectionSystem::CollisionDetectionSystem(CollisionWorld* world, ColliderComponents& collidersComponents, TransformComponents& transformComponents,
|
||||
CollisionBodyComponents& collisionBodyComponents, RigidBodyComponents& rigidBodyComponents, MemoryManager& memoryManager)
|
||||
: mMemoryManager(memoryManager), mProxyShapesComponents(proxyShapesComponents),
|
||||
: mMemoryManager(memoryManager), mCollidersComponents(collidersComponents),
|
||||
mCollisionDispatch(mMemoryManager.getPoolAllocator()), mWorld(world),
|
||||
mNoCollisionPairs(mMemoryManager.getPoolAllocator()),
|
||||
mOverlappingPairs(mMemoryManager.getPoolAllocator(), mMemoryManager.getSingleFrameAllocator(), mProxyShapesComponents,
|
||||
mOverlappingPairs(mMemoryManager.getPoolAllocator(), mMemoryManager.getSingleFrameAllocator(), mCollidersComponents,
|
||||
collisionBodyComponents, rigidBodyComponents, mNoCollisionPairs, mCollisionDispatch),
|
||||
mBroadPhaseSystem(*this, mProxyShapesComponents, transformComponents, rigidBodyComponents),
|
||||
mMapBroadPhaseIdToProxyShapeEntity(memoryManager.getPoolAllocator()),
|
||||
mBroadPhaseSystem(*this, mCollidersComponents, transformComponents, rigidBodyComponents),
|
||||
mMapBroadPhaseIdToColliderEntity(memoryManager.getPoolAllocator()),
|
||||
mNarrowPhaseInput(mMemoryManager.getSingleFrameAllocator(), mOverlappingPairs), mPotentialContactPoints(mMemoryManager.getSingleFrameAllocator()),
|
||||
mPotentialContactManifolds(mMemoryManager.getSingleFrameAllocator()), mContactPairs1(mMemoryManager.getPoolAllocator()),
|
||||
mContactPairs2(mMemoryManager.getPoolAllocator()), mPreviousContactPairs(&mContactPairs1), mCurrentContactPairs(&mContactPairs2),
|
||||
|
@ -153,18 +153,18 @@ void CollisionDetectionSystem::updateOverlappingPairs(const List<Pair<int32, int
|
|||
// Skip pairs with same overlapping nodes
|
||||
if (nodePair.first != nodePair.second) {
|
||||
|
||||
// Get the two proxy-shapes
|
||||
const Entity proxyShape1Entity = mMapBroadPhaseIdToProxyShapeEntity[nodePair.first];
|
||||
const Entity proxyShape2Entity = mMapBroadPhaseIdToProxyShapeEntity[nodePair.second];
|
||||
// Get the two colliders
|
||||
const Entity collider1Entity = mMapBroadPhaseIdToColliderEntity[nodePair.first];
|
||||
const Entity collider2Entity = mMapBroadPhaseIdToColliderEntity[nodePair.second];
|
||||
|
||||
const uint proxyShape1Index = mProxyShapesComponents.getEntityIndex(proxyShape1Entity);
|
||||
const uint proxyShape2Index = mProxyShapesComponents.getEntityIndex(proxyShape2Entity);
|
||||
const uint collider1Index = mCollidersComponents.getEntityIndex(collider1Entity);
|
||||
const uint collider2Index = mCollidersComponents.getEntityIndex(collider2Entity);
|
||||
|
||||
// Get the two bodies
|
||||
const Entity body1Entity = mProxyShapesComponents.mBodiesEntities[proxyShape1Index];
|
||||
const Entity body2Entity = mProxyShapesComponents.mBodiesEntities[proxyShape2Index];
|
||||
const Entity body1Entity = mCollidersComponents.mBodiesEntities[collider1Index];
|
||||
const Entity body2Entity = mCollidersComponents.mBodiesEntities[collider2Index];
|
||||
|
||||
// If the two proxy collision shapes are from the same body, skip it
|
||||
// If the two colliders are from the same body, skip it
|
||||
if (body1Entity != body2Entity) {
|
||||
|
||||
// Compute the overlapping pair ID
|
||||
|
@ -174,18 +174,18 @@ void CollisionDetectionSystem::updateOverlappingPairs(const List<Pair<int32, int
|
|||
auto it = mOverlappingPairs.mMapPairIdToPairIndex.find(pairId);
|
||||
if (it == mOverlappingPairs.mMapPairIdToPairIndex.end()) {
|
||||
|
||||
const unsigned short shape1CollideWithMaskBits = mProxyShapesComponents.mCollideWithMaskBits[proxyShape1Index];
|
||||
const unsigned short shape2CollideWithMaskBits = mProxyShapesComponents.mCollideWithMaskBits[proxyShape2Index];
|
||||
const unsigned short shape1CollideWithMaskBits = mCollidersComponents.mCollideWithMaskBits[collider1Index];
|
||||
const unsigned short shape2CollideWithMaskBits = mCollidersComponents.mCollideWithMaskBits[collider2Index];
|
||||
|
||||
const unsigned short shape1CollisionCategoryBits = mProxyShapesComponents.mCollisionCategoryBits[proxyShape1Index];
|
||||
const unsigned short shape2CollisionCategoryBits = mProxyShapesComponents.mCollisionCategoryBits[proxyShape2Index];
|
||||
const unsigned short shape1CollisionCategoryBits = mCollidersComponents.mCollisionCategoryBits[collider1Index];
|
||||
const unsigned short shape2CollisionCategoryBits = mCollidersComponents.mCollisionCategoryBits[collider2Index];
|
||||
|
||||
// Check if the collision filtering allows collision between the two shapes
|
||||
if ((shape1CollideWithMaskBits & shape2CollisionCategoryBits) != 0 &&
|
||||
(shape1CollisionCategoryBits & shape2CollideWithMaskBits) != 0) {
|
||||
|
||||
ProxyShape* shape1 = mProxyShapesComponents.mProxyShapes[proxyShape1Index];
|
||||
ProxyShape* shape2 = mProxyShapesComponents.mProxyShapes[proxyShape2Index];
|
||||
Collider* shape1 = mCollidersComponents.mColliders[collider1Index];
|
||||
Collider* shape2 = mCollidersComponents.mColliders[collider2Index];
|
||||
|
||||
// Check that at least one collision shape is convex
|
||||
if (shape1->getCollisionShape()->isConvex() || shape2->getCollisionShape()->isConvex()) {
|
||||
|
@ -219,29 +219,29 @@ void CollisionDetectionSystem::computeMiddlePhase(NarrowPhaseInput& narrowPhaseI
|
|||
// For each possible convex vs convex pair of bodies
|
||||
for (uint64 i=0; i < mOverlappingPairs.getNbConvexVsConvexPairs(); i++) {
|
||||
|
||||
assert(mProxyShapesComponents.getBroadPhaseId(mOverlappingPairs.mProxyShapes1[i]) != -1);
|
||||
assert(mProxyShapesComponents.getBroadPhaseId(mOverlappingPairs.mProxyShapes2[i]) != -1);
|
||||
assert(mProxyShapesComponents.getBroadPhaseId(mOverlappingPairs.mProxyShapes1[i]) != mProxyShapesComponents.getBroadPhaseId(mOverlappingPairs.mProxyShapes2[i]));
|
||||
assert(mCollidersComponents.getBroadPhaseId(mOverlappingPairs.mColliders1[i]) != -1);
|
||||
assert(mCollidersComponents.getBroadPhaseId(mOverlappingPairs.mColliders2[i]) != -1);
|
||||
assert(mCollidersComponents.getBroadPhaseId(mOverlappingPairs.mColliders1[i]) != mCollidersComponents.getBroadPhaseId(mOverlappingPairs.mColliders2[i]));
|
||||
|
||||
// Check that at least one body is enabled (active and awake) and not static
|
||||
if (mOverlappingPairs.mIsActive[i]) {
|
||||
|
||||
const Entity proxyShape1Entity = mOverlappingPairs.mProxyShapes1[i];
|
||||
const Entity proxyShape2Entity = mOverlappingPairs.mProxyShapes2[i];
|
||||
const Entity collider1Entity = mOverlappingPairs.mColliders1[i];
|
||||
const Entity collider2Entity = mOverlappingPairs.mColliders2[i];
|
||||
|
||||
const uint proxyShape1Index = mProxyShapesComponents.getEntityIndex(proxyShape1Entity);
|
||||
const uint proxyShape2Index = mProxyShapesComponents.getEntityIndex(proxyShape2Entity);
|
||||
const uint collider1Index = mCollidersComponents.getEntityIndex(collider1Entity);
|
||||
const uint collider2Index = mCollidersComponents.getEntityIndex(collider2Entity);
|
||||
|
||||
CollisionShape* collisionShape1 = mProxyShapesComponents.mCollisionShapes[proxyShape1Index];
|
||||
CollisionShape* collisionShape2 = mProxyShapesComponents.mCollisionShapes[proxyShape2Index];
|
||||
CollisionShape* collisionShape1 = mCollidersComponents.mCollisionShapes[collider1Index];
|
||||
CollisionShape* collisionShape2 = mCollidersComponents.mCollisionShapes[collider2Index];
|
||||
|
||||
NarrowPhaseAlgorithmType algorithmType = mOverlappingPairs.mNarrowPhaseAlgorithmType[i];
|
||||
|
||||
// No middle-phase is necessary, simply create a narrow phase info
|
||||
// for the narrow-phase collision detection
|
||||
narrowPhaseInput.addNarrowPhaseTest(mOverlappingPairs.mPairIds[i], i, proxyShape1Entity, proxyShape2Entity, collisionShape1, collisionShape2,
|
||||
mProxyShapesComponents.mLocalToWorldTransforms[proxyShape1Index],
|
||||
mProxyShapesComponents.mLocalToWorldTransforms[proxyShape2Index],
|
||||
narrowPhaseInput.addNarrowPhaseTest(mOverlappingPairs.mPairIds[i], i, collider1Entity, collider2Entity, collisionShape1, collisionShape2,
|
||||
mCollidersComponents.mLocalToWorldTransforms[collider1Index],
|
||||
mCollidersComponents.mLocalToWorldTransforms[collider2Index],
|
||||
algorithmType, mMemoryManager.getSingleFrameAllocator());
|
||||
}
|
||||
}
|
||||
|
@ -250,9 +250,9 @@ void CollisionDetectionSystem::computeMiddlePhase(NarrowPhaseInput& narrowPhaseI
|
|||
const uint64 convexVsConcaveStartIndex = mOverlappingPairs.getConvexVsConcavePairsStartIndex();
|
||||
for (uint64 i=convexVsConcaveStartIndex; i < convexVsConcaveStartIndex + mOverlappingPairs.getNbConvexVsConcavePairs(); i++) {
|
||||
|
||||
assert(mProxyShapesComponents.getBroadPhaseId(mOverlappingPairs.mProxyShapes1[i]) != -1);
|
||||
assert(mProxyShapesComponents.getBroadPhaseId(mOverlappingPairs.mProxyShapes2[i]) != -1);
|
||||
assert(mProxyShapesComponents.getBroadPhaseId(mOverlappingPairs.mProxyShapes1[i]) != mProxyShapesComponents.getBroadPhaseId(mOverlappingPairs.mProxyShapes2[i]));
|
||||
assert(mCollidersComponents.getBroadPhaseId(mOverlappingPairs.mColliders1[i]) != -1);
|
||||
assert(mCollidersComponents.getBroadPhaseId(mOverlappingPairs.mColliders2[i]) != -1);
|
||||
assert(mCollidersComponents.getBroadPhaseId(mOverlappingPairs.mColliders1[i]) != mCollidersComponents.getBroadPhaseId(mOverlappingPairs.mColliders2[i]));
|
||||
|
||||
// Check that at least one body is enabled (active and awake) and not static
|
||||
if (mOverlappingPairs.mIsActive[i]) {
|
||||
|
@ -281,26 +281,26 @@ void CollisionDetectionSystem::computeMiddlePhaseCollisionSnapshot(List<uint64>&
|
|||
const uint64 pairIndex = mOverlappingPairs.mMapPairIdToPairIndex[pairId];
|
||||
assert(pairIndex < mOverlappingPairs.getNbPairs());
|
||||
|
||||
const Entity proxyShape1Entity = mOverlappingPairs.mProxyShapes1[pairIndex];
|
||||
const Entity proxyShape2Entity = mOverlappingPairs.mProxyShapes2[pairIndex];
|
||||
const Entity collider1Entity = mOverlappingPairs.mColliders1[pairIndex];
|
||||
const Entity collider2Entity = mOverlappingPairs.mColliders2[pairIndex];
|
||||
|
||||
const uint proxyShape1Index = mProxyShapesComponents.getEntityIndex(proxyShape1Entity);
|
||||
const uint proxyShape2Index = mProxyShapesComponents.getEntityIndex(proxyShape2Entity);
|
||||
const uint collider1Index = mCollidersComponents.getEntityIndex(collider1Entity);
|
||||
const uint collider2Index = mCollidersComponents.getEntityIndex(collider2Entity);
|
||||
|
||||
assert(mProxyShapesComponents.getBroadPhaseId(proxyShape1Entity) != -1);
|
||||
assert(mProxyShapesComponents.getBroadPhaseId(proxyShape2Entity) != -1);
|
||||
assert(mProxyShapesComponents.getBroadPhaseId(proxyShape1Entity) != mProxyShapesComponents.getBroadPhaseId(proxyShape2Entity));
|
||||
assert(mCollidersComponents.getBroadPhaseId(collider1Entity) != -1);
|
||||
assert(mCollidersComponents.getBroadPhaseId(collider2Entity) != -1);
|
||||
assert(mCollidersComponents.getBroadPhaseId(collider1Entity) != mCollidersComponents.getBroadPhaseId(collider2Entity));
|
||||
|
||||
CollisionShape* collisionShape1 = mProxyShapesComponents.mCollisionShapes[proxyShape1Index];
|
||||
CollisionShape* collisionShape2 = mProxyShapesComponents.mCollisionShapes[proxyShape2Index];
|
||||
CollisionShape* collisionShape1 = mCollidersComponents.mCollisionShapes[collider1Index];
|
||||
CollisionShape* collisionShape2 = mCollidersComponents.mCollisionShapes[collider2Index];
|
||||
|
||||
NarrowPhaseAlgorithmType algorithmType = mOverlappingPairs.mNarrowPhaseAlgorithmType[pairIndex];
|
||||
|
||||
// No middle-phase is necessary, simply create a narrow phase info
|
||||
// for the narrow-phase collision detection
|
||||
narrowPhaseInput.addNarrowPhaseTest(pairId, pairIndex, proxyShape1Entity, proxyShape2Entity, collisionShape1, collisionShape2,
|
||||
mProxyShapesComponents.mLocalToWorldTransforms[proxyShape1Index],
|
||||
mProxyShapesComponents.mLocalToWorldTransforms[proxyShape2Index],
|
||||
narrowPhaseInput.addNarrowPhaseTest(pairId, pairIndex, collider1Entity, collider2Entity, collisionShape1, collisionShape2,
|
||||
mCollidersComponents.mLocalToWorldTransforms[collider1Index],
|
||||
mCollidersComponents.mLocalToWorldTransforms[collider2Index],
|
||||
algorithmType, mMemoryManager.getSingleFrameAllocator());
|
||||
|
||||
}
|
||||
|
@ -311,9 +311,9 @@ void CollisionDetectionSystem::computeMiddlePhaseCollisionSnapshot(List<uint64>&
|
|||
const uint64 pairId = concavePairs[p];
|
||||
const uint64 pairIndex = mOverlappingPairs.mMapPairIdToPairIndex[pairId];
|
||||
|
||||
assert(mProxyShapesComponents.getBroadPhaseId(mOverlappingPairs.mProxyShapes1[pairIndex]) != -1);
|
||||
assert(mProxyShapesComponents.getBroadPhaseId(mOverlappingPairs.mProxyShapes2[pairIndex]) != -1);
|
||||
assert(mProxyShapesComponents.getBroadPhaseId(mOverlappingPairs.mProxyShapes1[pairIndex]) != mProxyShapesComponents.getBroadPhaseId(mOverlappingPairs.mProxyShapes2[pairIndex]));
|
||||
assert(mCollidersComponents.getBroadPhaseId(mOverlappingPairs.mColliders1[pairIndex]) != -1);
|
||||
assert(mCollidersComponents.getBroadPhaseId(mOverlappingPairs.mColliders2[pairIndex]) != -1);
|
||||
assert(mCollidersComponents.getBroadPhaseId(mOverlappingPairs.mColliders1[pairIndex]) != mCollidersComponents.getBroadPhaseId(mOverlappingPairs.mColliders2[pairIndex]));
|
||||
|
||||
computeConvexVsConcaveMiddlePhase(pairIndex, mMemoryManager.getSingleFrameAllocator(), narrowPhaseInput);
|
||||
}
|
||||
|
@ -324,14 +324,14 @@ void CollisionDetectionSystem::computeConvexVsConcaveMiddlePhase(uint64 pairInde
|
|||
|
||||
RP3D_PROFILE("CollisionDetectionSystem::computeConvexVsConcaveMiddlePhase()", mProfiler);
|
||||
|
||||
const Entity proxyShape1 = mOverlappingPairs.mProxyShapes1[pairIndex];
|
||||
const Entity proxyShape2 = mOverlappingPairs.mProxyShapes2[pairIndex];
|
||||
const Entity collider1 = mOverlappingPairs.mColliders1[pairIndex];
|
||||
const Entity collider2 = mOverlappingPairs.mColliders2[pairIndex];
|
||||
|
||||
const uint proxyShape1Index = mProxyShapesComponents.getEntityIndex(proxyShape1);
|
||||
const uint proxyShape2Index = mProxyShapesComponents.getEntityIndex(proxyShape2);
|
||||
const uint collider1Index = mCollidersComponents.getEntityIndex(collider1);
|
||||
const uint collider2Index = mCollidersComponents.getEntityIndex(collider2);
|
||||
|
||||
Transform& shape1LocalToWorldTransform = mProxyShapesComponents.mLocalToWorldTransforms[proxyShape1Index];
|
||||
Transform& shape2LocalToWorldTransform = mProxyShapesComponents.mLocalToWorldTransforms[proxyShape2Index];
|
||||
Transform& shape1LocalToWorldTransform = mCollidersComponents.mLocalToWorldTransforms[collider1Index];
|
||||
Transform& shape2LocalToWorldTransform = mCollidersComponents.mLocalToWorldTransforms[collider2Index];
|
||||
|
||||
Transform convexToConcaveTransform;
|
||||
|
||||
|
@ -340,13 +340,13 @@ void CollisionDetectionSystem::computeConvexVsConcaveMiddlePhase(uint64 pairInde
|
|||
ConcaveShape* concaveShape;
|
||||
const bool isShape1Convex = mOverlappingPairs.mIsShape1Convex[pairIndex];
|
||||
if (isShape1Convex) {
|
||||
convexShape = static_cast<ConvexShape*>(mProxyShapesComponents.mCollisionShapes[proxyShape1Index]);
|
||||
concaveShape = static_cast<ConcaveShape*>(mProxyShapesComponents.mCollisionShapes[proxyShape2Index]);
|
||||
convexShape = static_cast<ConvexShape*>(mCollidersComponents.mCollisionShapes[collider1Index]);
|
||||
concaveShape = static_cast<ConcaveShape*>(mCollidersComponents.mCollisionShapes[collider2Index]);
|
||||
convexToConcaveTransform = shape2LocalToWorldTransform.getInverse() * shape1LocalToWorldTransform;
|
||||
}
|
||||
else { // Collision shape 2 is convex, collision shape 1 is concave
|
||||
convexShape = static_cast<ConvexShape*>(mProxyShapesComponents.mCollisionShapes[proxyShape1Index]);
|
||||
concaveShape = static_cast<ConcaveShape*>(mProxyShapesComponents.mCollisionShapes[proxyShape2Index]);
|
||||
convexShape = static_cast<ConvexShape*>(mCollidersComponents.mCollisionShapes[collider1Index]);
|
||||
concaveShape = static_cast<ConcaveShape*>(mCollidersComponents.mCollisionShapes[collider2Index]);
|
||||
convexToConcaveTransform = shape1LocalToWorldTransform.getInverse() * shape2LocalToWorldTransform;
|
||||
}
|
||||
|
||||
|
@ -383,7 +383,7 @@ void CollisionDetectionSystem::computeConvexVsConcaveMiddlePhase(uint64 pairInde
|
|||
#endif
|
||||
|
||||
// Create a narrow phase info for the narrow-phase collision detection
|
||||
narrowPhaseInput.addNarrowPhaseTest(mOverlappingPairs.mPairIds[pairIndex], pairIndex, proxyShape1, proxyShape2, isShape1Convex ? convexShape : triangleShape,
|
||||
narrowPhaseInput.addNarrowPhaseTest(mOverlappingPairs.mPairIds[pairIndex], pairIndex, collider1, collider2, isShape1Convex ? convexShape : triangleShape,
|
||||
isShape1Convex ? triangleShape : convexShape,
|
||||
shape1LocalToWorldTransform, shape2LocalToWorldTransform,
|
||||
mOverlappingPairs.mNarrowPhaseAlgorithmType[pairIndex], allocator);
|
||||
|
@ -542,11 +542,11 @@ void CollisionDetectionSystem::computeSnapshotContactPairs(NarrowPhaseInput& nar
|
|||
computeSnapshotContactPairs(convexPolyhedronVsConvexPolyhedronBatch, overlapPairs);
|
||||
}
|
||||
|
||||
// Notify that the overlapping pairs where a given proxy-shape is involved need to be tested for overlap
|
||||
void CollisionDetectionSystem::notifyOverlappingPairsToTestOverlap(ProxyShape* proxyShape) {
|
||||
// Notify that the overlapping pairs where a given collider is involved need to be tested for overlap
|
||||
void CollisionDetectionSystem::notifyOverlappingPairsToTestOverlap(Collider* collider) {
|
||||
|
||||
// Get the overlapping pairs involved with this proxy-shape
|
||||
List<uint64>& overlappingPairs = mProxyShapesComponents.getOverlappingPairs(proxyShape->getEntity());
|
||||
// Get the overlapping pairs involved with this collider
|
||||
List<uint64>& overlappingPairs = mCollidersComponents.getOverlappingPairs(collider->getEntity());
|
||||
|
||||
for (uint i=0; i < overlappingPairs.size(); i++) {
|
||||
|
||||
|
@ -567,8 +567,8 @@ void CollisionDetectionSystem::computeSnapshotContactPairs(NarrowPhaseInfoBatch&
|
|||
if (narrowPhaseInfoBatch.isColliding[i]) {
|
||||
|
||||
// Add the pair of bodies in contact into the list
|
||||
overlapPairs.add(Pair<Entity, Entity>(mProxyShapesComponents.getBody(narrowPhaseInfoBatch.proxyShapeEntities1[i]),
|
||||
mProxyShapesComponents.getBody(narrowPhaseInfoBatch.proxyShapeEntities2[i])));
|
||||
overlapPairs.add(Pair<Entity, Entity>(mCollidersComponents.getBody(narrowPhaseInfoBatch.colliderEntities1[i]),
|
||||
mCollidersComponents.getBody(narrowPhaseInfoBatch.colliderEntities2[i])));
|
||||
}
|
||||
|
||||
narrowPhaseInfoBatch.resetContactPoints(i);
|
||||
|
@ -673,8 +673,8 @@ void CollisionDetectionSystem::createContacts() {
|
|||
contactPair.nbToTalContactPoints += nbContactPoints;
|
||||
|
||||
// We create a new contact manifold
|
||||
ContactManifold contactManifold(contactPair.body1Entity, contactPair.body2Entity, contactPair.proxyShape1Entity,
|
||||
contactPair.proxyShape2Entity, contactPointsIndex, nbContactPoints);
|
||||
ContactManifold contactManifold(contactPair.body1Entity, contactPair.body2Entity, contactPair.collider1Entity,
|
||||
contactPair.collider2Entity, contactPointsIndex, nbContactPoints);
|
||||
|
||||
// Add the contact manifold
|
||||
mCurrentContactManifolds->add(contactManifold);
|
||||
|
@ -741,8 +741,8 @@ void CollisionDetectionSystem::createSnapshotContacts(List<ContactPair>& contact
|
|||
contactPair.nbToTalContactPoints += nbContactPoints;
|
||||
|
||||
// We create a new contact manifold
|
||||
ContactManifold contactManifold(contactPair.body1Entity, contactPair.body2Entity, contactPair.proxyShape1Entity,
|
||||
contactPair.proxyShape2Entity, contactPointsIndex, nbContactPoints);
|
||||
ContactManifold contactManifold(contactPair.body1Entity, contactPair.body2Entity, contactPair.collider1Entity,
|
||||
contactPair.collider2Entity, contactPointsIndex, nbContactPoints);
|
||||
|
||||
// Add the contact manifold
|
||||
contactManifolds.add(contactManifold);
|
||||
|
@ -860,15 +860,15 @@ void CollisionDetectionSystem::initContactsWithPreviousOnes() {
|
|||
}
|
||||
|
||||
// Remove a body from the collision detection
|
||||
void CollisionDetectionSystem::removeProxyCollisionShape(ProxyShape* proxyShape) {
|
||||
void CollisionDetectionSystem::removeCollider(Collider* collider) {
|
||||
|
||||
const int proxyShapeBroadPhaseId = proxyShape->getBroadPhaseId();
|
||||
const int colliderBroadPhaseId = collider->getBroadPhaseId();
|
||||
|
||||
assert(proxyShapeBroadPhaseId != -1);
|
||||
assert(mMapBroadPhaseIdToProxyShapeEntity.containsKey(proxyShapeBroadPhaseId));
|
||||
assert(colliderBroadPhaseId != -1);
|
||||
assert(mMapBroadPhaseIdToColliderEntity.containsKey(colliderBroadPhaseId));
|
||||
|
||||
// Remove all the overlapping pairs involving this proxy shape
|
||||
List<uint64>& overlappingPairs = mProxyShapesComponents.getOverlappingPairs(proxyShape->getEntity());
|
||||
// Remove all the overlapping pairs involving this collider
|
||||
List<uint64>& overlappingPairs = mCollidersComponents.getOverlappingPairs(collider->getEntity());
|
||||
while(overlappingPairs.size() > 0) {
|
||||
|
||||
// TODO : Remove all the contact manifold of the overlapping pair from the contact manifolds list of the two bodies involved
|
||||
|
@ -877,10 +877,10 @@ void CollisionDetectionSystem::removeProxyCollisionShape(ProxyShape* proxyShape)
|
|||
mOverlappingPairs.removePair(overlappingPairs[0]);
|
||||
}
|
||||
|
||||
mMapBroadPhaseIdToProxyShapeEntity.remove(proxyShapeBroadPhaseId);
|
||||
mMapBroadPhaseIdToColliderEntity.remove(colliderBroadPhaseId);
|
||||
|
||||
// Remove the body from the broad-phase
|
||||
mBroadPhaseSystem.removeProxyCollisionShape(proxyShape);
|
||||
mBroadPhaseSystem.removeCollider(collider);
|
||||
}
|
||||
|
||||
// Ray casting method
|
||||
|
@ -893,7 +893,7 @@ void CollisionDetectionSystem::raycast(RaycastCallback* raycastCallback,
|
|||
RaycastTest rayCastTest(raycastCallback);
|
||||
|
||||
// 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 collider hit by the ray in the broad-phase
|
||||
mBroadPhaseSystem.raycast(ray, rayCastTest, raycastWithCategoryMaskBits);
|
||||
}
|
||||
|
||||
|
@ -980,17 +980,17 @@ void CollisionDetectionSystem::processPotentialContacts(NarrowPhaseInfoBatch& na
|
|||
// If the overlapping pair contact does not exists yet
|
||||
if (pairContact == nullptr) {
|
||||
|
||||
const Entity proxyShape1Entity = narrowPhaseInfoBatch.proxyShapeEntities1[i];
|
||||
const Entity proxyShape2Entity = narrowPhaseInfoBatch.proxyShapeEntities2[i];
|
||||
const Entity collider1Entity = narrowPhaseInfoBatch.colliderEntities1[i];
|
||||
const Entity collider2Entity = narrowPhaseInfoBatch.colliderEntities2[i];
|
||||
|
||||
const Entity body1Entity = mProxyShapesComponents.getBody(proxyShape1Entity);
|
||||
const Entity body2Entity = mProxyShapesComponents.getBody(proxyShape2Entity);
|
||||
const Entity body1Entity = mCollidersComponents.getBody(collider1Entity);
|
||||
const Entity body2Entity = mCollidersComponents.getBody(collider2Entity);
|
||||
|
||||
assert(!mWorld->mCollisionBodyComponents.getIsEntityDisabled(body1Entity) || !mWorld->mCollisionBodyComponents.getIsEntityDisabled(body2Entity));
|
||||
|
||||
const uint newContactPairIndex = contactPairs->size();
|
||||
ContactPair overlappingPairContact(pairId, body1Entity, body2Entity,
|
||||
proxyShape1Entity, proxyShape2Entity,
|
||||
collider1Entity, collider2Entity,
|
||||
newContactPairIndex, mMemoryManager.getHeapAllocator());
|
||||
contactPairs->add(overlappingPairContact);
|
||||
pairContact = &((*contactPairs)[newContactPairIndex]);
|
||||
|
@ -1086,9 +1086,9 @@ void CollisionDetectionSystem::reducePotentialContactManifolds(List<ContactPair>
|
|||
// If there are two many contact points in the manifold
|
||||
if (manifold.potentialContactPointsIndices.size() > MAX_CONTACT_POINTS_IN_MANIFOLD) {
|
||||
|
||||
Entity proxyShape1 = mOverlappingPairs.mProxyShapes1[mOverlappingPairs.mMapPairIdToPairIndex[manifold.pairId]];
|
||||
Entity collider1 = mOverlappingPairs.mColliders1[mOverlappingPairs.mMapPairIdToPairIndex[manifold.pairId]];
|
||||
|
||||
Transform shape1LocalToWorldTransoform = mProxyShapesComponents.getLocalToWorldTransform(proxyShape1);
|
||||
Transform shape1LocalToWorldTransoform = mCollidersComponents.getLocalToWorldTransform(collider1);
|
||||
|
||||
// Reduce the number of contact points in the manifold
|
||||
reduceContactPoints(manifold, shape1LocalToWorldTransoform, potentialContactPoints);
|
||||
|
@ -1453,8 +1453,8 @@ void CollisionDetectionSystem::filterOverlappingPairs(Entity bodyEntity, List<ui
|
|||
// For each possible collision pair of bodies
|
||||
for (uint i=0; i < mOverlappingPairs.getNbPairs(); i++) {
|
||||
|
||||
if (mProxyShapesComponents.getBody(mOverlappingPairs.mProxyShapes1[i]) == bodyEntity ||
|
||||
mProxyShapesComponents.getBody(mOverlappingPairs.mProxyShapes2[i]) == bodyEntity) {
|
||||
if (mCollidersComponents.getBody(mOverlappingPairs.mColliders1[i]) == bodyEntity ||
|
||||
mCollidersComponents.getBody(mOverlappingPairs.mColliders2[i]) == bodyEntity) {
|
||||
|
||||
if (i < mOverlappingPairs.getNbConvexVsConvexPairs()) {
|
||||
convexPairs.add(mOverlappingPairs.mPairIds[i]);
|
||||
|
@ -1474,11 +1474,11 @@ void CollisionDetectionSystem::filterOverlappingPairs(Entity body1Entity, Entity
|
|||
// For each possible collision pair of bodies
|
||||
for (uint i=0; i < mOverlappingPairs.getNbPairs(); i++) {
|
||||
|
||||
const Entity proxyShape1Body = mProxyShapesComponents.getBody(mOverlappingPairs.mProxyShapes1[i]);
|
||||
const Entity proxyShape2Body = mProxyShapesComponents.getBody(mOverlappingPairs.mProxyShapes2[i]);
|
||||
const Entity collider1Body = mCollidersComponents.getBody(mOverlappingPairs.mColliders1[i]);
|
||||
const Entity collider2Body = mCollidersComponents.getBody(mOverlappingPairs.mColliders2[i]);
|
||||
|
||||
if ((proxyShape1Body == body1Entity && proxyShape2Body == body2Entity) ||
|
||||
(proxyShape1Body == body2Entity && proxyShape2Body == body1Entity)) {
|
||||
if ((collider1Body == body1Entity && collider2Body == body2Entity) ||
|
||||
(collider1Body == body2Entity && collider2Body == body1Entity)) {
|
||||
|
||||
if (i < mOverlappingPairs.getNbConvexVsConvexPairs()) {
|
||||
convexPairs.add(mOverlappingPairs.mPairIds[i]);
|
||||
|
@ -1495,8 +1495,8 @@ EventListener* CollisionDetectionSystem::getWorldEventListener() {
|
|||
return mWorld->mEventListener;
|
||||
}
|
||||
|
||||
// Return the world-space AABB of a given proxy shape
|
||||
const AABB CollisionDetectionSystem::getWorldAABB(const ProxyShape* proxyShape) const {
|
||||
assert(proxyShape->getBroadPhaseId() > -1);
|
||||
return mBroadPhaseSystem.getFatAABB(proxyShape->getBroadPhaseId());
|
||||
// Return the world-space AABB of a given collider
|
||||
const AABB CollisionDetectionSystem::getWorldAABB(const Collider* collider) const {
|
||||
assert(collider->getBroadPhaseId() > -1);
|
||||
return mBroadPhaseSystem.getFatAABB(collider->getBroadPhaseId());
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
#include "collision/narrowphase/CollisionDispatch.h"
|
||||
#include "containers/Map.h"
|
||||
#include "containers/Set.h"
|
||||
#include "components/ProxyShapeComponents.h"
|
||||
#include "components/ColliderComponents.h"
|
||||
#include "components/TransformComponents.h"
|
||||
|
||||
/// ReactPhysics3D namespace
|
||||
|
@ -80,8 +80,8 @@ class CollisionDetectionSystem {
|
|||
/// Memory manager
|
||||
MemoryManager& mMemoryManager;
|
||||
|
||||
/// Reference the proxy-shape components
|
||||
ProxyShapeComponents& mProxyShapesComponents;
|
||||
/// Reference the collider components
|
||||
ColliderComponents& mCollidersComponents;
|
||||
|
||||
/// Collision Detection Dispatch configuration
|
||||
CollisionDispatch mCollisionDispatch;
|
||||
|
@ -98,8 +98,8 @@ class CollisionDetectionSystem {
|
|||
/// Broad-phase system
|
||||
BroadPhaseSystem mBroadPhaseSystem;
|
||||
|
||||
/// Map a broad-phase id with the corresponding entity of the proxy-shape
|
||||
Map<int, Entity> mMapBroadPhaseIdToProxyShapeEntity;
|
||||
/// Map a broad-phase id with the corresponding entity of the collider
|
||||
Map<int, Entity> mMapBroadPhaseIdToColliderEntity;
|
||||
|
||||
/// Narrow-phase collision detection input
|
||||
NarrowPhaseInput mNarrowPhaseInput;
|
||||
|
@ -267,7 +267,7 @@ class CollisionDetectionSystem {
|
|||
// -------------------- Methods -------------------- //
|
||||
|
||||
/// Constructor
|
||||
CollisionDetectionSystem(CollisionWorld* world, ProxyShapeComponents& proxyShapesComponents,
|
||||
CollisionDetectionSystem(CollisionWorld* world, ColliderComponents& collidersComponents,
|
||||
TransformComponents& transformComponents, CollisionBodyComponents& collisionBodyComponents, RigidBodyComponents& rigidBodyComponents,
|
||||
MemoryManager& memoryManager);
|
||||
|
||||
|
@ -283,17 +283,17 @@ class CollisionDetectionSystem {
|
|||
/// Set the collision dispatch configuration
|
||||
CollisionDispatch& getCollisionDispatch();
|
||||
|
||||
/// Add a proxy collision shape to the collision detection
|
||||
void addProxyCollisionShape(ProxyShape* proxyShape, const AABB& aabb);
|
||||
/// Add a collider to the collision detection
|
||||
void addCollider(Collider* collider, const AABB& aabb);
|
||||
|
||||
/// Remove a proxy collision shape from the collision detection
|
||||
void removeProxyCollisionShape(ProxyShape *proxyShape);
|
||||
/// Remove a collider from the collision detection
|
||||
void removeCollider(Collider* collider);
|
||||
|
||||
/// Update a proxy collision shape (that has moved for instance)
|
||||
void updateProxyShape(Entity proxyShapeEntity, decimal timeStep);
|
||||
/// Update a collider (that has moved for instance)
|
||||
void updateCollider(Entity colliderEntity, decimal timeStep);
|
||||
|
||||
/// Update all the enabled proxy-shapes
|
||||
void updateProxyShapes(decimal timeStep);
|
||||
/// Update all the enabled colliders
|
||||
void updateColliders(decimal timeStep);
|
||||
|
||||
/// Add a pair of bodies that cannot collide with each other
|
||||
void addNoCollisionPair(Entity body1Entity, Entity body2Entity);
|
||||
|
@ -302,10 +302,10 @@ class CollisionDetectionSystem {
|
|||
void removeNoCollisionPair(Entity body1Entity, Entity body2Entity);
|
||||
|
||||
/// Ask for a collision shape to be tested again during broad-phase.
|
||||
void askForBroadPhaseCollisionCheck(ProxyShape* shape);
|
||||
void askForBroadPhaseCollisionCheck(Collider* shape);
|
||||
|
||||
/// Notify that the overlapping pairs where a given proxy-shape is involved need to be tested for overlap
|
||||
void notifyOverlappingPairsToTestOverlap(ProxyShape* proxyShape);
|
||||
/// Notify that the overlapping pairs where a given collider is involved need to be tested for overlap
|
||||
void notifyOverlappingPairsToTestOverlap(Collider* collider);
|
||||
|
||||
/// Report contacts
|
||||
void reportContacts();
|
||||
|
@ -351,8 +351,8 @@ class CollisionDetectionSystem {
|
|||
|
||||
#endif
|
||||
|
||||
/// Return the world-space AABB of a given proxy shape
|
||||
const AABB getWorldAABB(const ProxyShape* proxyShape) const;
|
||||
/// Return the world-space AABB of a given collider
|
||||
const AABB getWorldAABB(const Collider* collider) const;
|
||||
|
||||
// -------------------- Friendship -------------------- //
|
||||
|
||||
|
@ -367,17 +367,17 @@ inline CollisionDispatch& CollisionDetectionSystem::getCollisionDispatch() {
|
|||
}
|
||||
|
||||
// Add a body to the collision detection
|
||||
inline void CollisionDetectionSystem::addProxyCollisionShape(ProxyShape* proxyShape, const AABB& aabb) {
|
||||
inline void CollisionDetectionSystem::addCollider(Collider* collider, const AABB& aabb) {
|
||||
|
||||
// Add the body to the broad-phase
|
||||
mBroadPhaseSystem.addProxyCollisionShape(proxyShape, aabb);
|
||||
mBroadPhaseSystem.addCollider(collider, aabb);
|
||||
|
||||
int broadPhaseId = mProxyShapesComponents.getBroadPhaseId(proxyShape->getEntity());
|
||||
int broadPhaseId = mCollidersComponents.getBroadPhaseId(collider->getEntity());
|
||||
|
||||
assert(!mMapBroadPhaseIdToProxyShapeEntity.containsKey(broadPhaseId));
|
||||
assert(!mMapBroadPhaseIdToColliderEntity.containsKey(broadPhaseId));
|
||||
|
||||
// Add the mapping between the proxy-shape broad-phase id and its entity
|
||||
mMapBroadPhaseIdToProxyShapeEntity.add(Pair<int, Entity>(broadPhaseId, proxyShape->getEntity()));
|
||||
// Add the mapping between the collider broad-phase id and its entity
|
||||
mMapBroadPhaseIdToColliderEntity.add(Pair<int, Entity>(broadPhaseId, collider->getEntity()));
|
||||
}
|
||||
|
||||
// Add a pair of bodies that cannot collide with each other
|
||||
|
@ -393,7 +393,7 @@ inline void CollisionDetectionSystem::removeNoCollisionPair(Entity body1Entity,
|
|||
// Ask for a collision shape to be tested again during broad-phase.
|
||||
/// We simply put the shape in the list of collision shape that have moved in the
|
||||
/// previous frame so that it is tested for collision again in the broad-phase.
|
||||
inline void CollisionDetectionSystem::askForBroadPhaseCollisionCheck(ProxyShape* shape) {
|
||||
inline void CollisionDetectionSystem::askForBroadPhaseCollisionCheck(Collider* shape) {
|
||||
|
||||
if (shape->getBroadPhaseId() != -1) {
|
||||
mBroadPhaseSystem.addMovedCollisionShape(shape->getBroadPhaseId(), shape);
|
||||
|
@ -410,16 +410,16 @@ inline MemoryManager& CollisionDetectionSystem::getMemoryManager() const {
|
|||
return mMemoryManager;
|
||||
}
|
||||
|
||||
// Update a proxy collision shape (that has moved for instance)
|
||||
inline void CollisionDetectionSystem::updateProxyShape(Entity proxyShapeEntity, decimal timeStep) {
|
||||
// Update a collider (that has moved for instance)
|
||||
inline void CollisionDetectionSystem::updateCollider(Entity colliderEntity, decimal timeStep) {
|
||||
|
||||
// Update the proxy-shape component
|
||||
mBroadPhaseSystem.updateProxyShape(proxyShapeEntity, timeStep);
|
||||
// Update the collider component
|
||||
mBroadPhaseSystem.updateCollider(colliderEntity, timeStep);
|
||||
}
|
||||
|
||||
// Update all the enabled proxy-shapes
|
||||
inline void CollisionDetectionSystem::updateProxyShapes(decimal timeStep) {
|
||||
mBroadPhaseSystem.updateProxyShapes(timeStep);
|
||||
// Update all the enabled colliders
|
||||
inline void CollisionDetectionSystem::updateColliders(decimal timeStep) {
|
||||
mBroadPhaseSystem.updateColliders(timeStep);
|
||||
}
|
||||
|
||||
#ifdef IS_PROFILING_ACTIVE
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#include "utils/Profiler.h"
|
||||
#include "engine/Island.h"
|
||||
#include "components/CollisionBodyComponents.h"
|
||||
#include "components/ProxyShapeComponents.h"
|
||||
#include "components/ColliderComponents.h"
|
||||
#include "collision/ContactManifold.h"
|
||||
|
||||
using namespace reactphysics3d;
|
||||
|
@ -44,12 +44,12 @@ const decimal ContactSolverSystem::SLOP = decimal(0.01);
|
|||
|
||||
// Constructor
|
||||
ContactSolverSystem::ContactSolverSystem(MemoryManager& memoryManager, DynamicsWorld& world, Islands& islands, CollisionBodyComponents& bodyComponents,
|
||||
RigidBodyComponents& rigidBodyComponents, ProxyShapeComponents& proxyShapeComponents,
|
||||
RigidBodyComponents& rigidBodyComponents, ColliderComponents& colliderComponents,
|
||||
const WorldSettings& worldSettings)
|
||||
:mMemoryManager(memoryManager), mWorld(world), mContactConstraints(nullptr), mContactPoints(nullptr),
|
||||
mIslands(islands), mAllContactManifolds(nullptr), mAllContactPoints(nullptr),
|
||||
mBodyComponents(bodyComponents), mRigidBodyComponents(rigidBodyComponents),
|
||||
mProxyShapeComponents(proxyShapeComponents), mIsSplitImpulseActive(true),
|
||||
mColliderComponents(colliderComponents), mIsSplitImpulseActive(true),
|
||||
mWorldSettings(worldSettings) {
|
||||
|
||||
#ifdef IS_PROFILING_ACTIVE
|
||||
|
@ -169,8 +169,8 @@ void ContactSolverSystem::initializeForIsland(uint islandIndex) {
|
|||
ContactPoint& externalContact = (*mAllContactPoints)[c];
|
||||
|
||||
// Get the contact point on the two bodies
|
||||
Vector3 p1 = mProxyShapeComponents.getLocalToWorldTransform(externalManifold.proxyShapeEntity1) * externalContact.getLocalPointOnShape1();
|
||||
Vector3 p2 = mProxyShapeComponents.getLocalToWorldTransform(externalManifold.proxyShapeEntity2) * externalContact.getLocalPointOnShape2();
|
||||
Vector3 p1 = mColliderComponents.getLocalToWorldTransform(externalManifold.colliderEntity1) * externalContact.getLocalPointOnShape1();
|
||||
Vector3 p2 = mColliderComponents.getLocalToWorldTransform(externalManifold.colliderEntity2) * externalContact.getLocalPointOnShape2();
|
||||
|
||||
new (mContactPoints + mNbContactPoints) ContactPointSolver();
|
||||
mContactPoints[mNbContactPoints].externalContact = &externalContact;
|
||||
|
|
|
@ -46,7 +46,7 @@ class RigidBody;
|
|||
class CollisionBodyComponents;
|
||||
class DynamicsComponents;
|
||||
class RigidBodyComponents;
|
||||
class ProxyShapeComponents;
|
||||
class ColliderComponents;
|
||||
|
||||
// Class ContactSolverSystem
|
||||
/**
|
||||
|
@ -319,8 +319,8 @@ class ContactSolverSystem {
|
|||
/// Reference to the dynamics components
|
||||
RigidBodyComponents& mRigidBodyComponents;
|
||||
|
||||
/// Reference to the proxy-shapes components
|
||||
ProxyShapeComponents& mProxyShapeComponents;
|
||||
/// Reference to the colliders components
|
||||
ColliderComponents& mColliderComponents;
|
||||
|
||||
/// True if the split impulse position correction is active
|
||||
bool mIsSplitImpulseActive;
|
||||
|
@ -363,7 +363,7 @@ class ContactSolverSystem {
|
|||
|
||||
/// Constructor
|
||||
ContactSolverSystem(MemoryManager& memoryManager, DynamicsWorld& world, Islands& islands, CollisionBodyComponents& bodyComponents,
|
||||
RigidBodyComponents& rigidBodyComponents, ProxyShapeComponents& proxyShapeComponents,
|
||||
RigidBodyComponents& rigidBodyComponents, ColliderComponents& colliderComponents,
|
||||
const WorldSettings& worldSettings);
|
||||
|
||||
/// Destructor
|
||||
|
|
|
@ -32,8 +32,8 @@ using namespace reactphysics3d;
|
|||
|
||||
// Constructor
|
||||
DynamicsSystem::DynamicsSystem(DynamicsWorld& world, CollisionBodyComponents& collisionBodyComponents, RigidBodyComponents& rigidBodyComponents,
|
||||
TransformComponents& transformComponents, ProxyShapeComponents& proxyShapeComponents, bool& isGravityEnabled, Vector3& gravity)
|
||||
:mWorld(world), mCollisionBodyComponents(collisionBodyComponents), mRigidBodyComponents(rigidBodyComponents), mTransformComponents(transformComponents), mProxyShapeComponents(proxyShapeComponents),
|
||||
TransformComponents& transformComponents, ColliderComponents& colliderComponents, bool& isGravityEnabled, Vector3& gravity)
|
||||
:mWorld(world), mCollisionBodyComponents(collisionBodyComponents), mRigidBodyComponents(rigidBodyComponents), mTransformComponents(transformComponents), mColliderComponents(colliderComponents),
|
||||
mIsGravityEnabled(isGravityEnabled), mGravity(gravity) {
|
||||
|
||||
}
|
||||
|
@ -97,12 +97,12 @@ void DynamicsSystem::updateBodiesState() {
|
|||
transform.setPosition(centerOfMassWorld - transform.getOrientation() * centerOfMassLocal);
|
||||
}
|
||||
|
||||
// Update the local-to-world transform of the proxy-shapes
|
||||
for (uint32 i=0; i < mProxyShapeComponents.getNbEnabledComponents(); i++) {
|
||||
// Update the local-to-world transform of the colliders
|
||||
for (uint32 i=0; i < mColliderComponents.getNbEnabledComponents(); i++) {
|
||||
|
||||
// Update the local-to-world transform of the proxy-shape
|
||||
mProxyShapeComponents.mLocalToWorldTransforms[i] = mTransformComponents.getTransform(mProxyShapeComponents.mBodiesEntities[i]) *
|
||||
mProxyShapeComponents.mLocalToBodyTransforms[i];
|
||||
// Update the local-to-world transform of the collider
|
||||
mColliderComponents.mLocalToWorldTransforms[i] = mTransformComponents.getTransform(mColliderComponents.mBodiesEntities[i]) *
|
||||
mColliderComponents.mLocalToBodyTransforms[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#include "components/CollisionBodyComponents.h"
|
||||
#include "components/RigidBodyComponents.h"
|
||||
#include "components/TransformComponents.h"
|
||||
#include "components/ProxyShapeComponents.h"
|
||||
#include "components/ColliderComponents.h"
|
||||
|
||||
namespace reactphysics3d {
|
||||
|
||||
|
@ -60,8 +60,8 @@ class DynamicsSystem {
|
|||
/// Reference to the transform components
|
||||
TransformComponents& mTransformComponents;
|
||||
|
||||
/// Reference to the proxy-shapes components
|
||||
ProxyShapeComponents& mProxyShapeComponents;
|
||||
/// Reference to the colliders components
|
||||
ColliderComponents& mColliderComponents;
|
||||
|
||||
/// Reference to the variable to know if gravity is enabled in the world
|
||||
bool& mIsGravityEnabled;
|
||||
|
@ -82,7 +82,7 @@ class DynamicsSystem {
|
|||
/// Constructor
|
||||
DynamicsSystem(DynamicsWorld& world, CollisionBodyComponents& collisionBodyComponents,
|
||||
RigidBodyComponents& rigidBodyComponents, TransformComponents& transformComponents,
|
||||
ProxyShapeComponents& proxyShapeComponents, bool& isGravityEnabled, Vector3& gravity);
|
||||
ColliderComponents& colliderComponents, bool& isGravityEnabled, Vector3& gravity);
|
||||
|
||||
/// Destructor
|
||||
~DynamicsSystem() = default;
|
||||
|
|
|
@ -55,7 +55,7 @@ class Logger {
|
|||
enum class Level {Error = 1, Warning = 2, Information = 4};
|
||||
|
||||
/// Log categories
|
||||
enum class Category {World, Body, Joint, ProxyShape};
|
||||
enum class Category {World, Body, Joint, Collider};
|
||||
|
||||
/// Log verbosity level
|
||||
enum class Format {Text, HTML};
|
||||
|
@ -67,7 +67,7 @@ class Logger {
|
|||
case Category::World: return "World";
|
||||
case Category::Body: return "Body";
|
||||
case Category::Joint: return "Joint";
|
||||
case Category::ProxyShape: return "ProxyShape";
|
||||
case Category::Collider: return "Collider";
|
||||
}
|
||||
|
||||
assert(false);
|
||||
|
@ -253,7 +253,7 @@ class Logger {
|
|||
".joint .category, .joint > .message { "
|
||||
"color: #bf8040; "
|
||||
"} "
|
||||
".proxyshape .category, .proxyshape > .message { "
|
||||
".collider .category, .collider > .message { "
|
||||
"color: #9933ff; "
|
||||
"} "
|
||||
".warning { "
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -83,11 +83,11 @@ class TestPointInside : public Test {
|
|||
Transform mLocalShapeToWorld;
|
||||
Transform mLocalShape2ToWorld;
|
||||
|
||||
// Proxy Shapes
|
||||
ProxyShape* mBoxProxyShape;
|
||||
ProxyShape* mSphereProxyShape;
|
||||
ProxyShape* mCapsuleProxyShape;
|
||||
ProxyShape* mConvexMeshProxyShape;
|
||||
// Colliders
|
||||
Collider* mBoxCollider;
|
||||
Collider* mSphereCollider;
|
||||
Collider* mCapsuleCollider;
|
||||
Collider* mConvexMeshCollider;
|
||||
|
||||
public :
|
||||
|
||||
|
@ -125,13 +125,13 @@ class TestPointInside : public Test {
|
|||
|
||||
// Create collision shapes
|
||||
mBoxShape = mPhysicsCommon.createBoxShape(Vector3(2, 3, 4));
|
||||
mBoxProxyShape = mBoxBody->addCollisionShape(mBoxShape, mShapeTransform);
|
||||
mBoxCollider = mBoxBody->addCollider(mBoxShape, mShapeTransform);
|
||||
|
||||
mSphereShape = mPhysicsCommon.createSphereShape(3);
|
||||
mSphereProxyShape = mSphereBody->addCollisionShape(mSphereShape, mShapeTransform);
|
||||
mSphereCollider = mSphereBody->addCollider(mSphereShape, mShapeTransform);
|
||||
|
||||
mCapsuleShape = mPhysicsCommon.createCapsuleShape(3, 10);
|
||||
mCapsuleProxyShape = mCapsuleBody->addCollisionShape(mCapsuleShape, mShapeTransform);
|
||||
mCapsuleCollider = mCapsuleBody->addCollider(mCapsuleShape, mShapeTransform);
|
||||
|
||||
mConvexMeshCubeVertices[0] = Vector3(-2, -3, 4);
|
||||
mConvexMeshCubeVertices[1] = Vector3(2, -3, 4);
|
||||
|
@ -163,15 +163,15 @@ class TestPointInside : public Test {
|
|||
mConvexMeshPolyhedronMesh = mPhysicsCommon.createPolyhedronMesh(mConvexMeshPolygonVertexArray);
|
||||
mConvexMeshShape = mPhysicsCommon.createConvexMeshShape(mConvexMeshPolyhedronMesh);
|
||||
Transform convexMeshTransform(Vector3(10, 0, 0), Quaternion::identity());
|
||||
mConvexMeshProxyShape = mConvexMeshBody->addCollisionShape(mConvexMeshShape, mShapeTransform);
|
||||
mConvexMeshCollider = mConvexMeshBody->addCollider(mConvexMeshShape, mShapeTransform);
|
||||
|
||||
// Compound shape is a capsule and a sphere
|
||||
Vector3 positionShape2(Vector3(4, 2, -3));
|
||||
Quaternion orientationShape2 = Quaternion::fromEulerAngles(-3 * PI / 8, 1.5 * PI/ 3, PI / 13);
|
||||
Transform shapeTransform2(positionShape2, orientationShape2);
|
||||
mLocalShape2ToWorld = mBodyTransform * shapeTransform2;
|
||||
mCompoundBody->addCollisionShape(mCapsuleShape, mShapeTransform);
|
||||
mCompoundBody->addCollisionShape(mSphereShape, shapeTransform2);
|
||||
mCompoundBody->addCollider(mCapsuleShape, mShapeTransform);
|
||||
mCompoundBody->addCollider(mSphereShape, shapeTransform2);
|
||||
}
|
||||
|
||||
/// Destructor
|
||||
|
@ -195,7 +195,7 @@ class TestPointInside : public Test {
|
|||
testCompound();
|
||||
}
|
||||
|
||||
/// Test the ProxyBoxShape::testPointInside() and
|
||||
/// Test the testPointInside() and
|
||||
/// CollisionBody::testPointInside() methods
|
||||
void testBox() {
|
||||
|
||||
|
@ -225,34 +225,34 @@ class TestPointInside : public Test {
|
|||
rp3d_test(!mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(-1, 4, -2.5)));
|
||||
rp3d_test(!mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 4.5)));
|
||||
|
||||
// Tests with ProxyBoxShape
|
||||
rp3d_test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0)));
|
||||
rp3d_test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 0, 0)));
|
||||
rp3d_test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, 0, 0)));
|
||||
rp3d_test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 0)));
|
||||
rp3d_test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 2.9, 0)));
|
||||
rp3d_test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.9)));
|
||||
rp3d_test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.9)));
|
||||
rp3d_test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, -2.9, -3.9)));
|
||||
rp3d_test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, 2.9, 3.9)));
|
||||
rp3d_test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, -2, -1.5)));
|
||||
rp3d_test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, -2.5)));
|
||||
rp3d_test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 3.5)));
|
||||
// Tests with Collider
|
||||
rp3d_test(mBoxCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0)));
|
||||
rp3d_test(mBoxCollider->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 0, 0)));
|
||||
rp3d_test(mBoxCollider->testPointInside(mLocalShapeToWorld * Vector3(1.9, 0, 0)));
|
||||
rp3d_test(mBoxCollider->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 0)));
|
||||
rp3d_test(mBoxCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 2.9, 0)));
|
||||
rp3d_test(mBoxCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.9)));
|
||||
rp3d_test(mBoxCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.9)));
|
||||
rp3d_test(mBoxCollider->testPointInside(mLocalShapeToWorld * Vector3(-1.9, -2.9, -3.9)));
|
||||
rp3d_test(mBoxCollider->testPointInside(mLocalShapeToWorld * Vector3(1.9, 2.9, 3.9)));
|
||||
rp3d_test(mBoxCollider->testPointInside(mLocalShapeToWorld * Vector3(-1, -2, -1.5)));
|
||||
rp3d_test(mBoxCollider->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, -2.5)));
|
||||
rp3d_test(mBoxCollider->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 3.5)));
|
||||
|
||||
rp3d_test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2.1, 0, 0)));
|
||||
rp3d_test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.1, 0, 0)));
|
||||
rp3d_test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -3.1, 0)));
|
||||
rp3d_test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 3.1, 0)));
|
||||
rp3d_test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -4.1)));
|
||||
rp3d_test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 4.1)));
|
||||
rp3d_test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2.1, -3.1, -4.1)));
|
||||
rp3d_test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.1, 3.1, 4.1)));
|
||||
rp3d_test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-10, -2, -1.5)));
|
||||
rp3d_test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, 4, -2.5)));
|
||||
rp3d_test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 4.5)));
|
||||
rp3d_test(!mBoxCollider->testPointInside(mLocalShapeToWorld * Vector3(-2.1, 0, 0)));
|
||||
rp3d_test(!mBoxCollider->testPointInside(mLocalShapeToWorld * Vector3(2.1, 0, 0)));
|
||||
rp3d_test(!mBoxCollider->testPointInside(mLocalShapeToWorld * Vector3(0, -3.1, 0)));
|
||||
rp3d_test(!mBoxCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 3.1, 0)));
|
||||
rp3d_test(!mBoxCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -4.1)));
|
||||
rp3d_test(!mBoxCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 4.1)));
|
||||
rp3d_test(!mBoxCollider->testPointInside(mLocalShapeToWorld * Vector3(-2.1, -3.1, -4.1)));
|
||||
rp3d_test(!mBoxCollider->testPointInside(mLocalShapeToWorld * Vector3(2.1, 3.1, 4.1)));
|
||||
rp3d_test(!mBoxCollider->testPointInside(mLocalShapeToWorld * Vector3(-10, -2, -1.5)));
|
||||
rp3d_test(!mBoxCollider->testPointInside(mLocalShapeToWorld * Vector3(-1, 4, -2.5)));
|
||||
rp3d_test(!mBoxCollider->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 4.5)));
|
||||
}
|
||||
|
||||
/// Test the ProxySphereShape::testPointInside() and
|
||||
/// Test the Collider::testPointInside() and
|
||||
/// CollisionBody::testPointInside() methods
|
||||
void testSphere() {
|
||||
|
||||
|
@ -278,30 +278,30 @@ class TestPointInside : public Test {
|
|||
rp3d_test(!mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(-2, 2, -1.5)));
|
||||
rp3d_test(!mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(1.5, -2, 2.5)));
|
||||
|
||||
// Tests with ProxySphereShape
|
||||
rp3d_test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0)));
|
||||
rp3d_test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.9, 0, 0)));
|
||||
rp3d_test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2.9, 0, 0)));
|
||||
rp3d_test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 2.9, 0)));
|
||||
rp3d_test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 0)));
|
||||
rp3d_test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 2.9)));
|
||||
rp3d_test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 2.9)));
|
||||
rp3d_test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, -2, -1.5)));
|
||||
rp3d_test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, -1.5)));
|
||||
rp3d_test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 1.5)));
|
||||
// Tests with Collider
|
||||
rp3d_test(mSphereCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0)));
|
||||
rp3d_test(mSphereCollider->testPointInside(mLocalShapeToWorld * Vector3(2.9, 0, 0)));
|
||||
rp3d_test(mSphereCollider->testPointInside(mLocalShapeToWorld * Vector3(-2.9, 0, 0)));
|
||||
rp3d_test(mSphereCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 2.9, 0)));
|
||||
rp3d_test(mSphereCollider->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 0)));
|
||||
rp3d_test(mSphereCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 2.9)));
|
||||
rp3d_test(mSphereCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 2.9)));
|
||||
rp3d_test(mSphereCollider->testPointInside(mLocalShapeToWorld * Vector3(-1, -2, -1.5)));
|
||||
rp3d_test(mSphereCollider->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, -1.5)));
|
||||
rp3d_test(mSphereCollider->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 1.5)));
|
||||
|
||||
rp3d_test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(3.1, 0, 0)));
|
||||
rp3d_test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-3.1, 0, 0)));
|
||||
rp3d_test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 3.1, 0)));
|
||||
rp3d_test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -3.1, 0)));
|
||||
rp3d_test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.1)));
|
||||
rp3d_test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.1)));
|
||||
rp3d_test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2, -2, -2)));
|
||||
rp3d_test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2, 2, -1.5)));
|
||||
rp3d_test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.5, -2, 2.5)));
|
||||
rp3d_test(!mSphereCollider->testPointInside(mLocalShapeToWorld * Vector3(3.1, 0, 0)));
|
||||
rp3d_test(!mSphereCollider->testPointInside(mLocalShapeToWorld * Vector3(-3.1, 0, 0)));
|
||||
rp3d_test(!mSphereCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 3.1, 0)));
|
||||
rp3d_test(!mSphereCollider->testPointInside(mLocalShapeToWorld * Vector3(0, -3.1, 0)));
|
||||
rp3d_test(!mSphereCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.1)));
|
||||
rp3d_test(!mSphereCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.1)));
|
||||
rp3d_test(!mSphereCollider->testPointInside(mLocalShapeToWorld * Vector3(-2, -2, -2)));
|
||||
rp3d_test(!mSphereCollider->testPointInside(mLocalShapeToWorld * Vector3(-2, 2, -1.5)));
|
||||
rp3d_test(!mSphereCollider->testPointInside(mLocalShapeToWorld * Vector3(1.5, -2, 2.5)));
|
||||
}
|
||||
|
||||
/// Test the ProxyCapsuleShape::testPointInside() and
|
||||
/// Test the Collider::testPointInside() and
|
||||
/// CollisionBody::testPointInside() methods
|
||||
void testCapsule() {
|
||||
|
||||
|
@ -352,55 +352,55 @@ class TestPointInside : public Test {
|
|||
rp3d_test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(2.5, -5, 2.6)));
|
||||
rp3d_test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(2.5, -5, -2.7)));
|
||||
|
||||
// Tests with ProxyCapsuleShape
|
||||
rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0)));
|
||||
rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 5, 0)));
|
||||
rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -5, 0)));
|
||||
rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -6.9, 0)));
|
||||
rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 6.9, 0)));
|
||||
rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 1.9)));
|
||||
rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -1.9)));
|
||||
rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, 0, 0)));
|
||||
rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 0, 0)));
|
||||
rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, 0, 0.9)));
|
||||
rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, 0, -0.9)));
|
||||
rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 5, 1.9)));
|
||||
rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 5, -1.9)));
|
||||
rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, 5, 0)));
|
||||
rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 5, 0)));
|
||||
rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, 5, 0.9)));
|
||||
rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, 5, -0.9)));
|
||||
rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -5, 1.9)));
|
||||
rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -5, -1.9)));
|
||||
rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, -5, 0)));
|
||||
rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, -5, 0)));
|
||||
rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, -5, 0.9)));
|
||||
rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, -5, -0.9)));
|
||||
rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.7, -4, -0.9)));
|
||||
rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, 0.4)));
|
||||
rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.3, 1, 1.5)));
|
||||
// Tests with Collider
|
||||
rp3d_test(mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0)));
|
||||
rp3d_test(mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 5, 0)));
|
||||
rp3d_test(mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(0, -5, 0)));
|
||||
rp3d_test(mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(0, -6.9, 0)));
|
||||
rp3d_test(mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 6.9, 0)));
|
||||
rp3d_test(mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 1.9)));
|
||||
rp3d_test(mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -1.9)));
|
||||
rp3d_test(mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(1.9, 0, 0)));
|
||||
rp3d_test(mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 0, 0)));
|
||||
rp3d_test(mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(0.9, 0, 0.9)));
|
||||
rp3d_test(mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(0.9, 0, -0.9)));
|
||||
rp3d_test(mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 5, 1.9)));
|
||||
rp3d_test(mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 5, -1.9)));
|
||||
rp3d_test(mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(1.9, 5, 0)));
|
||||
rp3d_test(mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 5, 0)));
|
||||
rp3d_test(mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(0.9, 5, 0.9)));
|
||||
rp3d_test(mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(0.9, 5, -0.9)));
|
||||
rp3d_test(mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(0, -5, 1.9)));
|
||||
rp3d_test(mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(0, -5, -1.9)));
|
||||
rp3d_test(mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(1.9, -5, 0)));
|
||||
rp3d_test(mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(-1.9, -5, 0)));
|
||||
rp3d_test(mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(0.9, -5, 0.9)));
|
||||
rp3d_test(mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(0.9, -5, -0.9)));
|
||||
rp3d_test(mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(-1.7, -4, -0.9)));
|
||||
rp3d_test(mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, 0.4)));
|
||||
rp3d_test(mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(1.3, 1, 1.5)));
|
||||
|
||||
rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -13.1, 0)));
|
||||
rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 13.1, 0)));
|
||||
rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.1)));
|
||||
rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.1)));
|
||||
rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(3.1, 0, 0)));
|
||||
rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-3.1, 0, 0)));
|
||||
rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 5, 3.1)));
|
||||
rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 5, -3.1)));
|
||||
rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(3.1, 5, 0)));
|
||||
rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-3.1, 5, 0)));
|
||||
rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.5, 5, 2.6)));
|
||||
rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.5, 5, -2.7)));
|
||||
rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -5, 3.1)));
|
||||
rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -5, -3.1)));
|
||||
rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(3.1, -5, 0)));
|
||||
rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-3.1, -5, 0)));
|
||||
rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.5, -5, 2.6)));
|
||||
rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.5, -5, -2.7)));
|
||||
rp3d_test(!mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(0, -13.1, 0)));
|
||||
rp3d_test(!mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 13.1, 0)));
|
||||
rp3d_test(!mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.1)));
|
||||
rp3d_test(!mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.1)));
|
||||
rp3d_test(!mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(3.1, 0, 0)));
|
||||
rp3d_test(!mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(-3.1, 0, 0)));
|
||||
rp3d_test(!mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 5, 3.1)));
|
||||
rp3d_test(!mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 5, -3.1)));
|
||||
rp3d_test(!mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(3.1, 5, 0)));
|
||||
rp3d_test(!mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(-3.1, 5, 0)));
|
||||
rp3d_test(!mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(2.5, 5, 2.6)));
|
||||
rp3d_test(!mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(2.5, 5, -2.7)));
|
||||
rp3d_test(!mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(0, -5, 3.1)));
|
||||
rp3d_test(!mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(0, -5, -3.1)));
|
||||
rp3d_test(!mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(3.1, -5, 0)));
|
||||
rp3d_test(!mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(-3.1, -5, 0)));
|
||||
rp3d_test(!mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(2.5, -5, 2.6)));
|
||||
rp3d_test(!mCapsuleCollider->testPointInside(mLocalShapeToWorld * Vector3(2.5, -5, -2.7)));
|
||||
}
|
||||
|
||||
/// Test the ProxyConvexMeshShape::testPointInside() and
|
||||
/// Test the Collider::testPointInside() and
|
||||
/// CollisionBody::testPointInside() methods
|
||||
void testConvexMesh() {
|
||||
|
||||
|
@ -430,31 +430,31 @@ class TestPointInside : public Test {
|
|||
rp3d_test(!mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(-1, 4, -2.5)));
|
||||
rp3d_test(!mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 4.5)));
|
||||
|
||||
// Tests with ProxyConvexMeshShape
|
||||
rp3d_test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0)));
|
||||
rp3d_test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 0, 0)));
|
||||
rp3d_test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, 0, 0)));
|
||||
rp3d_test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 0)));
|
||||
rp3d_test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 2.9, 0)));
|
||||
rp3d_test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.9)));
|
||||
rp3d_test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.9)));
|
||||
rp3d_test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, -2.9, -3.9)));
|
||||
rp3d_test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, 2.9, 3.9)));
|
||||
rp3d_test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, -2, -1.5)));
|
||||
rp3d_test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, -2.5)));
|
||||
rp3d_test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 3.5)));
|
||||
// Tests with Collider
|
||||
rp3d_test(mConvexMeshCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0)));
|
||||
rp3d_test(mConvexMeshCollider->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 0, 0)));
|
||||
rp3d_test(mConvexMeshCollider->testPointInside(mLocalShapeToWorld * Vector3(1.9, 0, 0)));
|
||||
rp3d_test(mConvexMeshCollider->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 0)));
|
||||
rp3d_test(mConvexMeshCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 2.9, 0)));
|
||||
rp3d_test(mConvexMeshCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.9)));
|
||||
rp3d_test(mConvexMeshCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.9)));
|
||||
rp3d_test(mConvexMeshCollider->testPointInside(mLocalShapeToWorld * Vector3(-1.9, -2.9, -3.9)));
|
||||
rp3d_test(mConvexMeshCollider->testPointInside(mLocalShapeToWorld * Vector3(1.9, 2.9, 3.9)));
|
||||
rp3d_test(mConvexMeshCollider->testPointInside(mLocalShapeToWorld * Vector3(-1, -2, -1.5)));
|
||||
rp3d_test(mConvexMeshCollider->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, -2.5)));
|
||||
rp3d_test(mConvexMeshCollider->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 3.5)));
|
||||
|
||||
rp3d_test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2.1, 0, 0)));
|
||||
rp3d_test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.1, 0, 0)));
|
||||
rp3d_test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -3.1, 0)));
|
||||
rp3d_test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 3.1, 0)));
|
||||
rp3d_test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -4.1)));
|
||||
rp3d_test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 4.1)));
|
||||
rp3d_test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2.1, -3.1, -4.1)));
|
||||
rp3d_test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.1, 3.1, 4.1)));
|
||||
rp3d_test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-10, -2, -1.5)));
|
||||
rp3d_test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, 4, -2.5)));
|
||||
rp3d_test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 4.5)));
|
||||
rp3d_test(!mConvexMeshCollider->testPointInside(mLocalShapeToWorld * Vector3(-2.1, 0, 0)));
|
||||
rp3d_test(!mConvexMeshCollider->testPointInside(mLocalShapeToWorld * Vector3(2.1, 0, 0)));
|
||||
rp3d_test(!mConvexMeshCollider->testPointInside(mLocalShapeToWorld * Vector3(0, -3.1, 0)));
|
||||
rp3d_test(!mConvexMeshCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 3.1, 0)));
|
||||
rp3d_test(!mConvexMeshCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -4.1)));
|
||||
rp3d_test(!mConvexMeshCollider->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 4.1)));
|
||||
rp3d_test(!mConvexMeshCollider->testPointInside(mLocalShapeToWorld * Vector3(-2.1, -3.1, -4.1)));
|
||||
rp3d_test(!mConvexMeshCollider->testPointInside(mLocalShapeToWorld * Vector3(2.1, 3.1, 4.1)));
|
||||
rp3d_test(!mConvexMeshCollider->testPointInside(mLocalShapeToWorld * Vector3(-10, -2, -1.5)));
|
||||
rp3d_test(!mConvexMeshCollider->testPointInside(mLocalShapeToWorld * Vector3(-1, 4, -2.5)));
|
||||
rp3d_test(!mConvexMeshCollider->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 4.5)));
|
||||
}
|
||||
|
||||
/// Test the CollisionBody::testPointInside() method
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -65,7 +65,7 @@ Box::Box(const openglframework::Vector3& size, reactphysics3d::PhysicsCommon& ph
|
|||
mBody = world->createCollisionBody(mPreviousTransform);
|
||||
|
||||
// Add the collision shape to the body
|
||||
mProxyShape = mBody->addCollisionShape(mBoxShape, rp3d::Transform::identity());
|
||||
mCollider = mBody->addCollider(mBoxShape, rp3d::Transform::identity());
|
||||
|
||||
// If the Vertex Buffer object has not been created yet
|
||||
if (totalNbBoxes == 0) {
|
||||
|
@ -106,7 +106,7 @@ Box::Box(const openglframework::Vector3& size, float mass, reactphysics3d::Physi
|
|||
rp3d::RigidBody* body = world->createRigidBody(mPreviousTransform);
|
||||
|
||||
// Add the collision shape to the body
|
||||
mProxyShape = body->addCollisionShape(mBoxShape, rp3d::Transform::identity(), mass);
|
||||
mCollider = body->addCollider(mBoxShape, rp3d::Transform::identity(), mass);
|
||||
|
||||
mBody = body;
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ class Box : public PhysicsObject {
|
|||
float mSize[3];
|
||||
|
||||
rp3d::BoxShape* mBoxShape;
|
||||
rp3d::ProxyShape* mProxyShape;
|
||||
rp3d::Collider* mCollider;
|
||||
|
||||
/// Scaling matrix (applied to a cube to obtain the correct box dimensions)
|
||||
openglframework::Matrix4 mScalingMatrix;
|
||||
|
|
|
@ -55,7 +55,7 @@ Capsule::Capsule(float radius, float height, rp3d::PhysicsCommon& physicsCommon,
|
|||
mBody = world->createCollisionBody(mPreviousTransform);
|
||||
|
||||
// Add a collision shape to the body and specify the mass of the shape
|
||||
mProxyShape = mBody->addCollisionShape(mCapsuleShape, rp3d::Transform::identity());
|
||||
mCollider = mBody->addCollider(mCapsuleShape, rp3d::Transform::identity());
|
||||
|
||||
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
||||
|
||||
|
@ -89,7 +89,7 @@ Capsule::Capsule(float radius, float height, float mass, reactphysics3d::Physics
|
|||
rp3d::RigidBody* body = dynamicsWorld->createRigidBody(mPreviousTransform);
|
||||
|
||||
// Add a collision shape to the body and specify the mass of the shape
|
||||
mProxyShape = body->addCollisionShape(mCapsuleShape, rp3d::Transform::identity(), mass);
|
||||
mCollider = body->addCollider(mCapsuleShape, rp3d::Transform::identity(), mass);
|
||||
|
||||
mBody = body;
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ class Capsule : public PhysicsObject {
|
|||
|
||||
/// Collision shape
|
||||
rp3d::CapsuleShape* mCapsuleShape;
|
||||
rp3d::ProxyShape* mProxyShape;
|
||||
rp3d::Collider* mCollider;
|
||||
|
||||
/// Previous transform (for interpolation)
|
||||
rp3d::Transform mPreviousTransform;
|
||||
|
|
|
@ -63,7 +63,7 @@ ConcaveMesh::ConcaveMesh(rp3d::PhysicsCommon& physicsCommon, rp3d::CollisionWorl
|
|||
mBody = world->createCollisionBody(mPreviousTransform);
|
||||
|
||||
// Add a collision shape to the body and specify the mass of the collision shape
|
||||
mProxyShape = mBody->addCollisionShape(mConcaveShape, rp3d::Transform::identity());
|
||||
mCollider = mBody->addCollider(mConcaveShape, rp3d::Transform::identity());
|
||||
|
||||
// Create the VBOs and VAO
|
||||
createVBOAndVAO();
|
||||
|
@ -106,7 +106,7 @@ ConcaveMesh::ConcaveMesh(float mass, reactphysics3d::PhysicsCommon& physicsCommo
|
|||
rp3d::RigidBody* body = dynamicsWorld->createRigidBody(mPreviousTransform);
|
||||
|
||||
// Add a collision shape to the body and specify the mass of the collision shape
|
||||
mProxyShape = body->addCollisionShape(mConcaveShape, rp3d::Transform::identity(), mass);
|
||||
mCollider = body->addCollider(mConcaveShape, rp3d::Transform::identity(), mass);
|
||||
|
||||
mBody = body;
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ class ConcaveMesh : public PhysicsObject {
|
|||
|
||||
/// Collision shape
|
||||
rp3d::ConcaveMeshShape* mConcaveShape;
|
||||
rp3d::ProxyShape* mProxyShape;
|
||||
rp3d::Collider* mCollider;
|
||||
|
||||
/// Scaling matrix
|
||||
openglframework::Matrix4 mScalingMatrix;
|
||||
|
|
|
@ -79,7 +79,7 @@ ConvexMesh::ConvexMesh(rp3d::PhysicsCommon& physicsCommon, rp3d::CollisionWorld*
|
|||
mBody = world->createCollisionBody(mPreviousTransform);
|
||||
|
||||
// Add a collision shape to the body and specify the mass of the collision shape
|
||||
mProxyShape = mBody->addCollisionShape(mConvexShape, rp3d::Transform::identity());
|
||||
mCollider = mBody->addCollider(mConvexShape, rp3d::Transform::identity());
|
||||
|
||||
// Create the VBOs and VAO
|
||||
createVBOAndVAO();
|
||||
|
@ -139,7 +139,7 @@ ConvexMesh::ConvexMesh(float mass, rp3d::PhysicsCommon& physicsCommon, rp3d::Dyn
|
|||
rp3d::RigidBody* body = dynamicsWorld->createRigidBody(mPreviousTransform);
|
||||
|
||||
// Add a collision shape to the body and specify the mass of the collision shape
|
||||
mProxyShape = body->addCollisionShape(mConvexShape, rp3d::Transform::identity(), mass);
|
||||
mCollider = body->addCollider(mConvexShape, rp3d::Transform::identity(), mass);
|
||||
|
||||
mBody = body;
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ class ConvexMesh : public PhysicsObject {
|
|||
|
||||
/// Collision shape
|
||||
rp3d::ConvexMeshShape* mConvexShape;
|
||||
rp3d::ProxyShape* mProxyShape;
|
||||
rp3d::Collider* mCollider;
|
||||
|
||||
/// Scaling matrix
|
||||
openglframework::Matrix4 mScalingMatrix;
|
||||
|
|
|
@ -72,9 +72,9 @@ Dumbbell::Dumbbell(rp3d::PhysicsCommon& physicsCommon, rp3d::DynamicsWorld* dyna
|
|||
rp3d::RigidBody* body = dynamicsWorld->createRigidBody(mPreviousTransform);
|
||||
|
||||
// Add the three collision shapes to the body and specify the mass and transform of the shapes
|
||||
mProxyShapeSphere1 = body->addCollisionShape(mSphereShape, transformSphereShape1, massSphere);
|
||||
mProxyShapeSphere2 = body->addCollisionShape(mSphereShape, transformSphereShape2, massSphere);
|
||||
mProxyShapeCapsule = body->addCollisionShape(mCapsuleShape, transformCylinderShape, massCylinder);
|
||||
mColliderSphere1 = body->addCollider(mSphereShape, transformSphereShape1, massSphere);
|
||||
mColliderSphere2 = body->addCollider(mSphereShape, transformSphereShape2, massSphere);
|
||||
mColliderCapsule = body->addCollider(mCapsuleShape, transformCylinderShape, massCylinder);
|
||||
|
||||
mBody = body;
|
||||
|
||||
|
@ -125,9 +125,9 @@ Dumbbell::Dumbbell(reactphysics3d::PhysicsCommon &physicsCommon, rp3d::Collision
|
|||
mBody = world->createCollisionBody(mPreviousTransform);
|
||||
|
||||
// Add the three collision shapes to the body and specify the mass and transform of the shapes
|
||||
mProxyShapeSphere1 = mBody->addCollisionShape(mSphereShape, transformSphereShape1);
|
||||
mProxyShapeSphere2 = mBody->addCollisionShape(mSphereShape, transformSphereShape2);
|
||||
mProxyShapeCapsule = mBody->addCollisionShape(mCapsuleShape, transformCylinderShape);
|
||||
mColliderSphere1 = mBody->addCollider(mSphereShape, transformSphereShape1);
|
||||
mColliderSphere2 = mBody->addCollider(mSphereShape, transformSphereShape2);
|
||||
mColliderCapsule = mBody->addCollider(mCapsuleShape, transformCylinderShape);
|
||||
|
||||
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
||||
|
||||
|
|
|
@ -44,9 +44,9 @@ class Dumbbell : public PhysicsObject {
|
|||
/// Collision shapes
|
||||
rp3d::CapsuleShape* mCapsuleShape;
|
||||
rp3d::SphereShape* mSphereShape;
|
||||
rp3d::ProxyShape* mProxyShapeCapsule;
|
||||
rp3d::ProxyShape* mProxyShapeSphere1;
|
||||
rp3d::ProxyShape* mProxyShapeSphere2;
|
||||
rp3d::Collider* mColliderCapsule;
|
||||
rp3d::Collider* mColliderSphere1;
|
||||
rp3d::Collider* mColliderSphere2;
|
||||
|
||||
/// Scaling matrix (applied to a sphere to obtain the correct sphere dimensions)
|
||||
openglframework::Matrix4 mScalingMatrix;
|
||||
|
|
|
@ -53,7 +53,7 @@ HeightField::HeightField(rp3d::PhysicsCommon& physicsCommon, rp3d::CollisionWorl
|
|||
mBody = world->createCollisionBody(mPreviousTransform);
|
||||
|
||||
// Add a collision shape to the body and specify the mass of the collision shape
|
||||
mProxyShape = mBody->addCollisionShape(mHeightFieldShape, rp3d::Transform::identity());
|
||||
mCollider = mBody->addCollider(mHeightFieldShape, rp3d::Transform::identity());
|
||||
|
||||
// Create the VBOs and VAO
|
||||
createVBOAndVAO();
|
||||
|
@ -87,7 +87,7 @@ HeightField::HeightField(float mass, reactphysics3d::PhysicsCommon& physicsCommo
|
|||
rp3d::RigidBody* body = dynamicsWorld->createRigidBody(mPreviousTransform);
|
||||
|
||||
// Add a collision shape to the body and specify the mass of the collision shape
|
||||
mProxyShape = body->addCollisionShape(mHeightFieldShape, rp3d::Transform::identity(), mass);
|
||||
mCollider = body->addCollider(mHeightFieldShape, rp3d::Transform::identity(), mass);
|
||||
|
||||
mBody = body;
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ class HeightField : public PhysicsObject {
|
|||
|
||||
/// Collision shape
|
||||
rp3d::HeightFieldShape* mHeightFieldShape;
|
||||
rp3d::ProxyShape* mProxyShape;
|
||||
rp3d::Collider* mCollider;
|
||||
|
||||
/// Scaling matrix
|
||||
openglframework::Matrix4 mScalingMatrix;
|
||||
|
|
|
@ -56,7 +56,7 @@ Sphere::Sphere(float radius, rp3d::PhysicsCommon& physicsCommon, rp3d::Collision
|
|||
mBody = world->createCollisionBody(mPreviousTransform);
|
||||
|
||||
// Add a collision shape to the body and specify the mass of the shape
|
||||
mProxyShape = mBody->addCollisionShape(mCollisionShape, rp3d::Transform::identity());
|
||||
mCollider = mBody->addCollider(mCollisionShape, rp3d::Transform::identity());
|
||||
|
||||
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
||||
|
||||
|
@ -90,7 +90,7 @@ Sphere::Sphere(float radius, float mass, rp3d::PhysicsCommon& physicsCommon,rea
|
|||
rp3d::RigidBody* body = world->createRigidBody(mPreviousTransform);
|
||||
|
||||
// Add a collision shape to the body and specify the mass of the shape
|
||||
mProxyShape = body->addCollisionShape(mCollisionShape, rp3d::Transform::identity(), mass);
|
||||
mCollider = body->addCollider(mCollisionShape, rp3d::Transform::identity(), mass);
|
||||
|
||||
mBody = body;
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ class Sphere : public PhysicsObject {
|
|||
|
||||
/// Collision shape
|
||||
rp3d::SphereShape* mCollisionShape;
|
||||
rp3d::ProxyShape* mProxyShape;
|
||||
rp3d::Collider* mCollider;
|
||||
|
||||
/// Scaling matrix (applied to a sphere to obtain the correct sphere dimensions)
|
||||
openglframework::Matrix4 mScalingMatrix;
|
||||
|
|
|
@ -331,13 +331,13 @@ void ContactManager::onContact(const CallbackData& callbackData) {
|
|||
openglframework::Vector3 contactNormal(normal.x, normal.y, normal.z);
|
||||
|
||||
rp3d::Vector3 point1 = contactPoint.getLocalPointOnShape1();
|
||||
point1 = contactPair.getProxyShape1()->getLocalToWorldTransform() * point1;
|
||||
point1 = contactPair.getCollider1()->getLocalToWorldTransform() * point1;
|
||||
|
||||
openglframework::Vector3 position1(point1.x, point1.y, point1.z);
|
||||
mContactPoints.push_back(SceneContactPoint(position1, contactNormal, openglframework::Color::red()));
|
||||
|
||||
rp3d::Vector3 point2 = contactPoint.getLocalPointOnShape2();
|
||||
point2 = contactPair.getProxyShape2()->getLocalToWorldTransform() * point2;
|
||||
point2 = contactPair.getCollider2()->getLocalToWorldTransform() * point2;
|
||||
openglframework::Vector3 position2(point2.x, point2.y, point2.z);
|
||||
mContactPoints.push_back(SceneContactPoint(position2, contactNormal, openglframework::Color::blue()));
|
||||
}
|
||||
|
|
|
@ -199,7 +199,7 @@ void Scene::onContact(const rp3d::CollisionCallback::CallbackData& callbackData)
|
|||
|
||||
rp3d::CollisionCallback::ContactPoint contactPoint = contactPair.getContactPoint(c);
|
||||
|
||||
rp3d::Vector3 point = contactPair.getProxyShape1()->getLocalToWorldTransform() * contactPoint.getLocalPointOnShape1();
|
||||
rp3d::Vector3 point = contactPair.getCollider1()->getLocalToWorldTransform() * contactPoint.getLocalPointOnShape1();
|
||||
rp3d::Vector3 normalWorld = contactPoint.getWorldNormal();
|
||||
openglframework::Vector3 normal = openglframework::Vector3(normalWorld.x, normalWorld.y, normalWorld.z);
|
||||
SceneContactPoint contact(openglframework::Vector3(point.x, point.y, point.z), normal, openglframework::Color::red());
|
||||
|
|
|
@ -443,13 +443,13 @@ void SceneDemo::renderAABBs(const openglframework::Matrix4& worldToCameraMatrix)
|
|||
// For each physics object of the scene
|
||||
for (std::vector<PhysicsObject*>::iterator it = mPhysicsObjects.begin(); it != mPhysicsObjects.end(); ++it) {
|
||||
|
||||
// For each proxy shape of the object
|
||||
for (uint i=0; i < (*it)->getCollisionBody()->getNbProxyShapes(); i++) {
|
||||
// For each collider of the object
|
||||
for (uint i=0; i < (*it)->getCollisionBody()->getNbColliders(); i++) {
|
||||
|
||||
rp3d::ProxyShape* proxyShape = (*it)->getCollisionBody()->getProxyShape(i);
|
||||
rp3d::Collider* collider = (*it)->getCollisionBody()->getCollider(i);
|
||||
|
||||
// Get the broad-phase AABB corresponding to the proxy shape
|
||||
rp3d::AABB aabb = mPhysicsWorld->getWorldAABB(proxyShape);
|
||||
// Get the broad-phase AABB corresponding to the collider
|
||||
rp3d::AABB aabb = mPhysicsWorld->getWorldAABB(collider);
|
||||
|
||||
openglframework::Vector3 aabbCenter(aabb.getCenter().x, aabb.getCenter().y, aabb.getCenter().z);
|
||||
openglframework::Vector3 aabbMin(aabb.getMin().x, aabb.getMin().y, aabb.getMin().z);
|
||||
|
|
Loading…
Reference in New Issue
Block a user