[STYLE] correct some coding style
This commit is contained in:
parent
33f24d6b17
commit
b85098fcaa
@ -40,20 +40,16 @@ void CollisionDetection::computeCollisionDetection() {
|
||||
computeNarrowPhase();
|
||||
}
|
||||
|
||||
void CollisionDetection::testCollisionBetweenShapes(CollisionCallback* callback,
|
||||
const etk::Set<uint32_t>& shapes1,
|
||||
const etk::Set<uint32_t>& shapes2) {
|
||||
void CollisionDetection::testCollisionBetweenShapes(CollisionCallback* _callback, const etk::Set<uint32_t>& _shapes1, const etk::Set<uint32_t>& _shapes2) {
|
||||
// Compute the broad-phase collision detection
|
||||
computeBroadPhase();
|
||||
// Delete all the contact points in the currently overlapping pairs
|
||||
clearContactPoints();
|
||||
// Compute the narrow-phase collision detection among given sets of shapes
|
||||
computeNarrowPhaseBetweenShapes(callback, shapes1, shapes2);
|
||||
computeNarrowPhaseBetweenShapes(_callback, _shapes1, _shapes2);
|
||||
}
|
||||
|
||||
void CollisionDetection::reportCollisionBetweenShapes(CollisionCallback* callback,
|
||||
const etk::Set<uint32_t>& shapes1,
|
||||
const etk::Set<uint32_t>& shapes2) {
|
||||
void CollisionDetection::reportCollisionBetweenShapes(CollisionCallback* _callback, const etk::Set<uint32_t>& _shapes1, const etk::Set<uint32_t>& _shapes2) {
|
||||
// For each possible collision pair of bodies
|
||||
etk::Map<overlappingpairid, OverlappingPair*>::Iterator it;
|
||||
for (it = m_overlappingPairs.begin(); it != m_overlappingPairs.end(); ++it) {
|
||||
@ -63,24 +59,24 @@ void CollisionDetection::reportCollisionBetweenShapes(CollisionCallback* callbac
|
||||
assert(shape1->m_broadPhaseID != shape2->m_broadPhaseID);
|
||||
// If both shapes1 and shapes2 sets are non-empty, we check that
|
||||
// shape1 is among on set and shape2 is among the other one
|
||||
if ( !shapes1.empty()
|
||||
&& !shapes2.empty()
|
||||
&& ( shapes1.count(shape1->m_broadPhaseID) == 0
|
||||
|| shapes2.count(shape2->m_broadPhaseID) == 0 )
|
||||
&& ( shapes1.count(shape2->m_broadPhaseID) == 0
|
||||
|| shapes2.count(shape1->m_broadPhaseID) == 0 ) ) {
|
||||
if ( !_shapes1.empty()
|
||||
&& !_shapes2.empty()
|
||||
&& ( _shapes1.count(shape1->m_broadPhaseID) == 0
|
||||
|| _shapes2.count(shape2->m_broadPhaseID) == 0 )
|
||||
&& ( _shapes1.count(shape2->m_broadPhaseID) == 0
|
||||
|| _shapes2.count(shape1->m_broadPhaseID) == 0 ) ) {
|
||||
continue;
|
||||
}
|
||||
if ( !shapes1.empty()
|
||||
&& shapes2.empty()
|
||||
&& shapes1.count(shape1->m_broadPhaseID) == 0
|
||||
&& shapes1.count(shape2->m_broadPhaseID) == 0) {
|
||||
if ( !_shapes1.empty()
|
||||
&& _shapes2.empty()
|
||||
&& _shapes1.count(shape1->m_broadPhaseID) == 0
|
||||
&& _shapes1.count(shape2->m_broadPhaseID) == 0) {
|
||||
continue;
|
||||
}
|
||||
if ( !shapes2.empty()
|
||||
&& shapes1.empty()
|
||||
&& shapes2.count(shape1->m_broadPhaseID) == 0
|
||||
&& shapes2.count(shape2->m_broadPhaseID) == 0) {
|
||||
if ( !_shapes2.empty()
|
||||
&& _shapes1.empty()
|
||||
&& _shapes2.count(shape1->m_broadPhaseID) == 0
|
||||
&& _shapes2.count(shape2->m_broadPhaseID) == 0) {
|
||||
continue;
|
||||
}
|
||||
// For each contact manifold set of the overlapping pair
|
||||
@ -92,15 +88,15 @@ void CollisionDetection::reportCollisionBetweenShapes(CollisionCallback* callbac
|
||||
ContactPoint* contactPoint = manifold->getContactPoint(i);
|
||||
// Create the contact info object for the contact
|
||||
ContactPointInfo contactInfo(manifold->getShape1(), manifold->getShape2(),
|
||||
manifold->getShape1()->getCollisionShape(),
|
||||
manifold->getShape2()->getCollisionShape(),
|
||||
contactPoint->getNormal(),
|
||||
contactPoint->getPenetrationDepth(),
|
||||
contactPoint->getLocalPointOnBody1(),
|
||||
contactPoint->getLocalPointOnBody2());
|
||||
manifold->getShape1()->getCollisionShape(),
|
||||
manifold->getShape2()->getCollisionShape(),
|
||||
contactPoint->getNormal(),
|
||||
contactPoint->getPenetrationDepth(),
|
||||
contactPoint->getLocalPointOnBody1(),
|
||||
contactPoint->getLocalPointOnBody2());
|
||||
// Notify the collision callback about this new contact
|
||||
if (callback != nullptr) {
|
||||
callback->notifyContact(contactInfo);
|
||||
if (_callback != nullptr) {
|
||||
_callback->notifyContact(contactInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -184,9 +180,7 @@ void CollisionDetection::computeNarrowPhase() {
|
||||
addAllContactManifoldsToBodies();
|
||||
}
|
||||
|
||||
void CollisionDetection::computeNarrowPhaseBetweenShapes(CollisionCallback* callback,
|
||||
const etk::Set<uint32_t>& shapes1,
|
||||
const etk::Set<uint32_t>& shapes2) {
|
||||
void CollisionDetection::computeNarrowPhaseBetweenShapes(CollisionCallback* _callback, const etk::Set<uint32_t>& _shapes1, const etk::Set<uint32_t>& _shapes2) {
|
||||
m_contactOverlappingPairs.clear();
|
||||
// For each possible collision pair of bodies
|
||||
etk::Map<overlappingpairid, OverlappingPair*>::Iterator it;
|
||||
@ -197,35 +191,35 @@ void CollisionDetection::computeNarrowPhaseBetweenShapes(CollisionCallback* call
|
||||
assert(shape1->m_broadPhaseID != shape2->m_broadPhaseID);
|
||||
// If both shapes1 and shapes2 sets are non-empty, we check that
|
||||
// shape1 is among on set and shape2 is among the other one
|
||||
if ( !shapes1.empty()
|
||||
&& !shapes2.empty()
|
||||
&& ( shapes1.count(shape1->m_broadPhaseID) == 0
|
||||
|| shapes2.count(shape2->m_broadPhaseID) == 0 )
|
||||
&& ( shapes1.count(shape2->m_broadPhaseID) == 0
|
||||
|| shapes2.count(shape1->m_broadPhaseID) == 0 ) ) {
|
||||
if ( !_shapes1.empty()
|
||||
&& !_shapes2.empty()
|
||||
&& ( _shapes1.count(shape1->m_broadPhaseID) == 0
|
||||
|| _shapes2.count(shape2->m_broadPhaseID) == 0 )
|
||||
&& ( _shapes1.count(shape2->m_broadPhaseID) == 0
|
||||
|| _shapes2.count(shape1->m_broadPhaseID) == 0 ) ) {
|
||||
++it;
|
||||
continue;
|
||||
}
|
||||
if ( !shapes1.empty()
|
||||
&& shapes2.empty()
|
||||
&& shapes1.count(shape1->m_broadPhaseID) == 0
|
||||
&& shapes1.count(shape2->m_broadPhaseID) == 0) {
|
||||
if ( !_shapes1.empty()
|
||||
&& _shapes2.empty()
|
||||
&& _shapes1.count(shape1->m_broadPhaseID) == 0
|
||||
&& _shapes1.count(shape2->m_broadPhaseID) == 0) {
|
||||
++it;
|
||||
continue;
|
||||
}
|
||||
if ( !shapes2.empty()
|
||||
&& shapes1.empty()
|
||||
&& shapes2.count(shape1->m_broadPhaseID) == 0
|
||||
&& shapes2.count(shape2->m_broadPhaseID) == 0) {
|
||||
if ( !_shapes2.empty()
|
||||
&& _shapes1.empty()
|
||||
&& _shapes2.count(shape1->m_broadPhaseID) == 0
|
||||
&& _shapes2.count(shape2->m_broadPhaseID) == 0) {
|
||||
++it;
|
||||
continue;
|
||||
}
|
||||
// Check if the collision filtering allows collision between the two shapes and
|
||||
// that the two shapes are still overlapping. Otherwise, we destroy the
|
||||
// overlapping pair
|
||||
if (((shape1->getCollideWithMaskBits() & shape2->getCollisionCategoryBits()) == 0 ||
|
||||
(shape1->getCollisionCategoryBits() & shape2->getCollideWithMaskBits()) == 0) ||
|
||||
!m_broadPhaseAlgorithm.testOverlappingShapes(shape1, shape2)) {
|
||||
if ( ( (shape1->getCollideWithMaskBits() & shape2->getCollisionCategoryBits()) == 0
|
||||
|| (shape1->getCollisionCategoryBits() & shape2->getCollideWithMaskBits()) == 0 )
|
||||
|| !m_broadPhaseAlgorithm.testOverlappingShapes(shape1, shape2) ) {
|
||||
// TODO : Remove all the contact manifold of the overlapping pair from the contact manifolds list of the two bodies involved
|
||||
// Destroy the overlapping pair
|
||||
ETK_DELETE(OverlappingPair, it->second);
|
||||
@ -262,11 +256,17 @@ void CollisionDetection::computeNarrowPhaseBetweenShapes(CollisionCallback* call
|
||||
// Notify the narrow-phase algorithm about the overlapping pair we are going to test
|
||||
narrowPhaseAlgorithm->setCurrentOverlappingPair(pair);
|
||||
// Create the CollisionShapeInfo objects
|
||||
CollisionShapeInfo shape1Info(shape1, shape1->getCollisionShape(), shape1->getLocalToWorldTransform(),
|
||||
pair, shape1->getCachedCollisionData());
|
||||
CollisionShapeInfo shape2Info(shape2, shape2->getCollisionShape(), shape2->getLocalToWorldTransform(),
|
||||
pair, shape2->getCachedCollisionData());
|
||||
TestCollisionBetweenShapesCallback narrowPhaseCallback(callback);
|
||||
CollisionShapeInfo shape1Info(shape1,
|
||||
shape1->getCollisionShape(),
|
||||
shape1->getLocalToWorldTransform(),
|
||||
pair,
|
||||
shape1->getCachedCollisionData());
|
||||
CollisionShapeInfo shape2Info(shape2,
|
||||
shape2->getCollisionShape(),
|
||||
shape2->getLocalToWorldTransform(),
|
||||
pair,
|
||||
shape2->getCachedCollisionData());
|
||||
TestCollisionBetweenShapesCallback narrowPhaseCallback(_callback);
|
||||
// Use the narrow-phase collision detection algorithm to check
|
||||
// if there really is a collision
|
||||
narrowPhaseAlgorithm->testCollision(shape1Info, shape2Info, &narrowPhaseCallback);
|
||||
@ -275,39 +275,39 @@ void CollisionDetection::computeNarrowPhaseBetweenShapes(CollisionCallback* call
|
||||
addAllContactManifoldsToBodies();
|
||||
}
|
||||
|
||||
void CollisionDetection::broadPhaseNotifyOverlappingPair(ProxyShape* shape1, ProxyShape* shape2) {
|
||||
assert(shape1->m_broadPhaseID != shape2->m_broadPhaseID);
|
||||
void CollisionDetection::broadPhaseNotifyOverlappingPair(ProxyShape* _shape1, ProxyShape* _shape2) {
|
||||
assert(_shape1->m_broadPhaseID != _shape2->m_broadPhaseID);
|
||||
// If the two proxy collision shapes are from the same body, skip it
|
||||
if (shape1->getBody()->getID() == shape2->getBody()->getID()) {
|
||||
if (_shape1->getBody()->getID() == _shape2->getBody()->getID()) {
|
||||
return;
|
||||
}
|
||||
// Check if the collision filtering allows collision between the two shapes
|
||||
if ( (shape1->getCollideWithMaskBits() & shape2->getCollisionCategoryBits()) == 0
|
||||
|| (shape1->getCollisionCategoryBits() & shape2->getCollideWithMaskBits()) == 0) {
|
||||
if ( (_shape1->getCollideWithMaskBits() & _shape2->getCollisionCategoryBits()) == 0
|
||||
|| (_shape1->getCollisionCategoryBits() & _shape2->getCollideWithMaskBits()) == 0) {
|
||||
return;
|
||||
}
|
||||
// Compute the overlapping pair ID
|
||||
overlappingpairid pairID = OverlappingPair::computeID(shape1, shape2);
|
||||
overlappingpairid pairID = OverlappingPair::computeID(_shape1, _shape2);
|
||||
// Check if the overlapping pair already exists
|
||||
if (m_overlappingPairs.find(pairID) != m_overlappingPairs.end()) return;
|
||||
// Compute the maximum number of contact manifolds for this pair
|
||||
int32_t nbMaxManifolds = CollisionShape::computeNbMaxContactManifolds(shape1->getCollisionShape()->getType(),
|
||||
shape2->getCollisionShape()->getType());
|
||||
int32_t nbMaxManifolds = CollisionShape::computeNbMaxContactManifolds(_shape1->getCollisionShape()->getType(),
|
||||
_shape2->getCollisionShape()->getType());
|
||||
// Create the overlapping pair and add it int32_to the set of overlapping pairs
|
||||
OverlappingPair* newPair = ETK_NEW(OverlappingPair, shape1, shape2, nbMaxManifolds);
|
||||
OverlappingPair* newPair = ETK_NEW(OverlappingPair, _shape1, _shape2, nbMaxManifolds);
|
||||
assert(newPair != nullptr);
|
||||
m_overlappingPairs.set(pairID, newPair);
|
||||
// Wake up the two bodies
|
||||
shape1->getBody()->setIsSleeping(false);
|
||||
shape2->getBody()->setIsSleeping(false);
|
||||
_shape1->getBody()->setIsSleeping(false);
|
||||
_shape2->getBody()->setIsSleeping(false);
|
||||
}
|
||||
|
||||
void CollisionDetection::removeProxyCollisionShape(ProxyShape* proxyShape) {
|
||||
void CollisionDetection::removeProxyCollisionShape(ProxyShape* _proxyShape) {
|
||||
// Remove all the overlapping pairs involving this proxy shape
|
||||
etk::Map<overlappingpairid, OverlappingPair*>::Iterator it;
|
||||
for (it = m_overlappingPairs.begin(); it != m_overlappingPairs.end(); ) {
|
||||
if (it->second->getShape1()->m_broadPhaseID == proxyShape->m_broadPhaseID||
|
||||
it->second->getShape2()->m_broadPhaseID == proxyShape->m_broadPhaseID) {
|
||||
if (it->second->getShape1()->m_broadPhaseID == _proxyShape->m_broadPhaseID||
|
||||
it->second->getShape2()->m_broadPhaseID == _proxyShape->m_broadPhaseID) {
|
||||
// TODO : Remove all the contact manifold of the overlapping pair from the contact manifolds list of the two bodies involved
|
||||
// Destroy the overlapping pair
|
||||
ETK_DELETE(OverlappingPair, it->second);
|
||||
@ -318,34 +318,34 @@ void CollisionDetection::removeProxyCollisionShape(ProxyShape* proxyShape) {
|
||||
}
|
||||
}
|
||||
// Remove the body from the broad-phase
|
||||
m_broadPhaseAlgorithm.removeProxyCollisionShape(proxyShape);
|
||||
m_broadPhaseAlgorithm.removeProxyCollisionShape(_proxyShape);
|
||||
}
|
||||
|
||||
void CollisionDetection::notifyContact(OverlappingPair* overlappingPair, const ContactPointInfo& contactInfo) {
|
||||
void CollisionDetection::notifyContact(OverlappingPair* _overlappingPair, const ContactPointInfo& _contactInfo) {
|
||||
// If it is the first contact since the pairs are overlapping
|
||||
if (overlappingPair->getNbContactPoints() == 0) {
|
||||
if (_overlappingPair->getNbContactPoints() == 0) {
|
||||
// Trigger a callback event
|
||||
if (m_world->m_eventListener != NULL) {
|
||||
m_world->m_eventListener->beginContact(contactInfo);
|
||||
m_world->m_eventListener->beginContact(_contactInfo);
|
||||
}
|
||||
}
|
||||
// Create a new contact
|
||||
createContact(overlappingPair, contactInfo);
|
||||
createContact(_overlappingPair, _contactInfo);
|
||||
// Trigger a callback event for the new contact
|
||||
if (m_world->m_eventListener != NULL) {
|
||||
m_world->m_eventListener->newContact(contactInfo);
|
||||
m_world->m_eventListener->newContact(_contactInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void CollisionDetection::createContact(OverlappingPair* overlappingPair, const ContactPointInfo& contactInfo) {
|
||||
void CollisionDetection::createContact(OverlappingPair* _overlappingPair, const ContactPointInfo& _contactInfo) {
|
||||
// Create a new contact
|
||||
ContactPoint* contact = ETK_NEW(ContactPoint, contactInfo);
|
||||
ContactPoint* contact = ETK_NEW(ContactPoint, _contactInfo);
|
||||
// Add the contact to the contact manifold set of the corresponding overlapping pair
|
||||
overlappingPair->addContact(contact);
|
||||
_overlappingPair->addContact(contact);
|
||||
// Add the overlapping pair int32_to the set of pairs in contact during narrow-phase
|
||||
overlappingpairid pairId = OverlappingPair::computeID(overlappingPair->getShape1(),
|
||||
overlappingPair->getShape2());
|
||||
m_contactOverlappingPairs.set(pairId, overlappingPair);
|
||||
overlappingpairid pairId = OverlappingPair::computeID(_overlappingPair->getShape1(),
|
||||
_overlappingPair->getShape2());
|
||||
m_contactOverlappingPairs.set(pairId, _overlappingPair);
|
||||
}
|
||||
|
||||
void CollisionDetection::addAllContactManifoldsToBodies() {
|
||||
@ -358,11 +358,11 @@ void CollisionDetection::addAllContactManifoldsToBodies() {
|
||||
}
|
||||
}
|
||||
|
||||
void CollisionDetection::addContactManifoldToBody(OverlappingPair* pair) {
|
||||
assert(pair != nullptr);
|
||||
CollisionBody* body1 = pair->getShape1()->getBody();
|
||||
CollisionBody* body2 = pair->getShape2()->getBody();
|
||||
const ContactManifoldSet& manifoldSet = pair->getContactManifoldSet();
|
||||
void CollisionDetection::addContactManifoldToBody(OverlappingPair* _pair) {
|
||||
assert(_pair != nullptr);
|
||||
CollisionBody* body1 = _pair->getShape1()->getBody();
|
||||
CollisionBody* body2 = _pair->getShape2()->getBody();
|
||||
const ContactManifoldSet& manifoldSet = _pair->getContactManifoldSet();
|
||||
// For each contact manifold in the set of manifolds in the pair
|
||||
for (int32_t i=0; i<manifoldSet.getNbContactManifolds(); i++) {
|
||||
ContactManifold* contactManifold = manifoldSet.getContactManifold(i);
|
||||
@ -377,7 +377,6 @@ void CollisionDetection::addContactManifoldToBody(OverlappingPair* pair) {
|
||||
}
|
||||
|
||||
void CollisionDetection::clearContactPoints() {
|
||||
|
||||
// For each overlapping pair
|
||||
etk::Map<overlappingpairid, OverlappingPair*>::Iterator it;
|
||||
for (it = m_overlappingPairs.begin(); it != m_overlappingPairs.end(); ++it) {
|
||||
@ -398,8 +397,7 @@ EventListener* CollisionDetection::getWorldEventListener() {
|
||||
return m_world->m_eventListener;
|
||||
}
|
||||
|
||||
void TestCollisionBetweenShapesCallback::notifyContact(OverlappingPair* _overlappingPair,
|
||||
const ContactPointInfo& _contactInfo) {
|
||||
void TestCollisionBetweenShapesCallback::notifyContact(OverlappingPair* _overlappingPair, const ContactPointInfo& _contactInfo) {
|
||||
m_collisionCallback->notifyContact(_contactInfo);
|
||||
}
|
||||
|
||||
@ -420,41 +418,37 @@ void CollisionDetection::addProxyCollisionShape(ProxyShape* _proxyShape, const A
|
||||
m_isCollisionShapesAdded = true;
|
||||
}
|
||||
|
||||
void CollisionDetection::addNoCollisionPair(CollisionBody* body1, CollisionBody* body2) {
|
||||
m_noCollisionPairs.set(OverlappingPair::computeBodiesIndexPair(body1, body2));
|
||||
void CollisionDetection::addNoCollisionPair(CollisionBody* _body1, CollisionBody* _body2) {
|
||||
m_noCollisionPairs.set(OverlappingPair::computeBodiesIndexPair(_body1, _body2));
|
||||
}
|
||||
|
||||
void CollisionDetection::removeNoCollisionPair(CollisionBody* body1,
|
||||
CollisionBody* body2) {
|
||||
m_noCollisionPairs.erase(m_noCollisionPairs.find(OverlappingPair::computeBodiesIndexPair(body1, body2)));
|
||||
void CollisionDetection::removeNoCollisionPair(CollisionBody* _body1, CollisionBody* _body2) {
|
||||
m_noCollisionPairs.erase(m_noCollisionPairs.find(OverlappingPair::computeBodiesIndexPair(_body1, _body2)));
|
||||
}
|
||||
|
||||
void CollisionDetection::askForBroadPhaseCollisionCheck(ProxyShape* shape) {
|
||||
m_broadPhaseAlgorithm.addMovedCollisionShape(shape->m_broadPhaseID);
|
||||
void CollisionDetection::askForBroadPhaseCollisionCheck(ProxyShape* _shape) {
|
||||
m_broadPhaseAlgorithm.addMovedCollisionShape(_shape->m_broadPhaseID);
|
||||
}
|
||||
|
||||
void CollisionDetection::updateProxyCollisionShape(ProxyShape* shape, const AABB& aabb,
|
||||
const vec3& displacement, bool forceReinsert) {
|
||||
m_broadPhaseAlgorithm.updateProxyCollisionShape(shape, aabb, displacement);
|
||||
void CollisionDetection::updateProxyCollisionShape(ProxyShape* _shape, const AABB& _aabb, const vec3& _displacement, bool _forceReinsert) {
|
||||
m_broadPhaseAlgorithm.updateProxyCollisionShape(_shape, _aabb, _displacement);
|
||||
}
|
||||
|
||||
void CollisionDetection::raycast(RaycastCallback* raycastCallback,
|
||||
const Ray& ray,
|
||||
unsigned short raycastWithCategoryMaskBits) const {
|
||||
void CollisionDetection::raycast(RaycastCallback* _raycastCallback, const Ray& _ray, unsigned short _raycastWithCategoryMaskBits) const {
|
||||
PROFILE("CollisionDetection::raycast()");
|
||||
RaycastTest rayCastTest(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
|
||||
m_broadPhaseAlgorithm.raycast(ray, rayCastTest, raycastWithCategoryMaskBits);
|
||||
m_broadPhaseAlgorithm.raycast(_ray, rayCastTest, _raycastWithCategoryMaskBits);
|
||||
}
|
||||
|
||||
bool CollisionDetection::testAABBOverlap(const ProxyShape* shape1,
|
||||
const ProxyShape* shape2) const {
|
||||
bool CollisionDetection::testAABBOverlap(const ProxyShape* _shape1, const ProxyShape* _shape2) const {
|
||||
// If one of the shape's body is not active, we return no overlap
|
||||
if (!shape1->getBody()->isActive() || !shape2->getBody()->isActive()) {
|
||||
if ( !_shape1->getBody()->isActive()
|
||||
|| !_shape2->getBody()->isActive()) {
|
||||
return false;
|
||||
}
|
||||
return m_broadPhaseAlgorithm.testOverlappingShapes(shape1, shape2);
|
||||
return m_broadPhaseAlgorithm.testOverlappingShapes(_shape1, _shape2);
|
||||
}
|
||||
|
||||
CollisionWorld* CollisionDetection::getWorld() {
|
||||
|
@ -25,18 +25,14 @@ CollisionWorld::~CollisionWorld() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Create a collision body and add it to the world
|
||||
* @param transform etk::Transform3Dation mapping the local-space of the body to world-space
|
||||
* @return A pointer to the body that has been created in the world
|
||||
*/
|
||||
CollisionBody* CollisionWorld::createCollisionBody(const etk::Transform3D& transform) {
|
||||
|
||||
CollisionBody* CollisionWorld::createCollisionBody(const etk::Transform3D& _transform) {
|
||||
// Get the next available body ID
|
||||
bodyindex bodyID = computeNextAvailableBodyID();
|
||||
// Largest index cannot be used (it is used for invalid index)
|
||||
EPHY_ASSERT(bodyID < UINT64_MAX, "index too big");
|
||||
// Create the collision body
|
||||
CollisionBody* collisionBody = ETK_NEW(CollisionBody, transform, *this, bodyID);
|
||||
CollisionBody* collisionBody = ETK_NEW(CollisionBody, _transform, *this, bodyID);
|
||||
EPHY_ASSERT(collisionBody != nullptr, "empty Body collision");
|
||||
// Add the collision body to the world
|
||||
m_bodies.add(collisionBody);
|
||||
@ -44,186 +40,115 @@ CollisionBody* CollisionWorld::createCollisionBody(const etk::Transform3D& trans
|
||||
return collisionBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Destroy a collision body
|
||||
* @param collisionBody Pointer to the body to destroy
|
||||
*/
|
||||
void CollisionWorld::destroyCollisionBody(CollisionBody* collisionBody) {
|
||||
|
||||
void CollisionWorld::destroyCollisionBody(CollisionBody* _collisionBody) {
|
||||
// Remove all the collision shapes of the body
|
||||
collisionBody->removeAllCollisionShapes();
|
||||
|
||||
_collisionBody->removeAllCollisionShapes();
|
||||
// Add the body ID to the list of free IDs
|
||||
m_freeBodiesIDs.pushBack(collisionBody->getID());
|
||||
|
||||
m_freeBodiesIDs.pushBack(_collisionBody->getID());
|
||||
// Remove the collision body from the list of bodies
|
||||
m_bodies.erase(m_bodies.find(collisionBody));
|
||||
|
||||
ETK_DELETE(CollisionBody, collisionBody);
|
||||
collisionBody = nullptr;
|
||||
m_bodies.erase(m_bodies.find(_collisionBody));
|
||||
ETK_DELETE(CollisionBody, _collisionBody);
|
||||
_collisionBody = nullptr;
|
||||
}
|
||||
|
||||
// Return the next available body ID
|
||||
bodyindex CollisionWorld::computeNextAvailableBodyID() {
|
||||
|
||||
// Compute the body ID
|
||||
bodyindex bodyID;
|
||||
if (!m_freeBodiesIDs.empty()) {
|
||||
bodyID = m_freeBodiesIDs.back();
|
||||
m_freeBodiesIDs.popBack();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
bodyID = m_currentBodyID;
|
||||
m_currentBodyID++;
|
||||
}
|
||||
|
||||
return bodyID;
|
||||
}
|
||||
|
||||
// Reset all the contact manifolds linked list of each body
|
||||
void CollisionWorld::resetContactManifoldListsOfBodies() {
|
||||
|
||||
// For each rigid body of the world
|
||||
for (etk::Set<CollisionBody*>::Iterator it = m_bodies.begin(); it != m_bodies.end(); ++it) {
|
||||
|
||||
// Reset the contact manifold list of the body
|
||||
(*it)->resetContactManifoldsList();
|
||||
}
|
||||
}
|
||||
|
||||
// Test if the AABBs of two bodies overlap
|
||||
/**
|
||||
* @param body1 Pointer to the first body to test
|
||||
* @param body2 Pointer to the second body to test
|
||||
* @return True if the AABBs of the two bodies overlap and false otherwise
|
||||
*/
|
||||
bool CollisionWorld::testAABBOverlap(const CollisionBody* body1,
|
||||
const CollisionBody* body2) const {
|
||||
|
||||
bool CollisionWorld::testAABBOverlap(const CollisionBody* _body1, const CollisionBody* _body2) const {
|
||||
// If one of the body is not active, we return no overlap
|
||||
if (!body1->isActive() || !body2->isActive()) return false;
|
||||
|
||||
if ( !_body1->isActive()
|
||||
|| !_body2->isActive()) {
|
||||
return false;
|
||||
}
|
||||
// Compute the AABBs of both bodies
|
||||
AABB body1AABB = body1->getAABB();
|
||||
AABB body2AABB = body2->getAABB();
|
||||
|
||||
AABB body1AABB = _body1->getAABB();
|
||||
AABB body2AABB = _body2->getAABB();
|
||||
// Return true if the two AABBs overlap
|
||||
return body1AABB.testCollision(body2AABB);
|
||||
}
|
||||
|
||||
// Test and report collisions between a given shape and all the others
|
||||
// shapes of the world.
|
||||
/**
|
||||
* @param shape Pointer to the proxy shape to test
|
||||
* @param callback Pointer to the object with the callback method
|
||||
*/
|
||||
void CollisionWorld::testCollision(const ProxyShape* shape,
|
||||
CollisionCallback* callback) {
|
||||
|
||||
void CollisionWorld::testCollision(const ProxyShape* _shape, CollisionCallback* _callback) {
|
||||
// Reset all the contact manifolds lists of each body
|
||||
resetContactManifoldListsOfBodies();
|
||||
|
||||
// Create the sets of shapes
|
||||
etk::Set<uint32_t> shapes;
|
||||
shapes.add(shape->m_broadPhaseID);
|
||||
shapes.add(_shape->m_broadPhaseID);
|
||||
etk::Set<uint32_t> emptySet;
|
||||
|
||||
// Perform the collision detection and report contacts
|
||||
m_collisionDetection.testCollisionBetweenShapes(callback, shapes, emptySet);
|
||||
m_collisionDetection.testCollisionBetweenShapes(_callback, shapes, emptySet);
|
||||
}
|
||||
|
||||
// Test and report collisions between two given shapes
|
||||
/**
|
||||
* @param shape1 Pointer to the first proxy shape to test
|
||||
* @param shape2 Pointer to the second proxy shape to test
|
||||
* @param callback Pointer to the object with the callback method
|
||||
*/
|
||||
void CollisionWorld::testCollision(const ProxyShape* shape1,
|
||||
const ProxyShape* shape2,
|
||||
CollisionCallback* callback) {
|
||||
|
||||
void CollisionWorld::testCollision(const ProxyShape* _shape1, const ProxyShape* _shape2, CollisionCallback* _callback) {
|
||||
// Reset all the contact manifolds lists of each body
|
||||
resetContactManifoldListsOfBodies();
|
||||
|
||||
// Create the sets of shapes
|
||||
etk::Set<uint32_t> shapes1;
|
||||
shapes1.add(shape1->m_broadPhaseID);
|
||||
shapes1.add(_shape1->m_broadPhaseID);
|
||||
etk::Set<uint32_t> shapes2;
|
||||
shapes2.add(shape2->m_broadPhaseID);
|
||||
|
||||
shapes2.add(_shape2->m_broadPhaseID);
|
||||
// Perform the collision detection and report contacts
|
||||
m_collisionDetection.testCollisionBetweenShapes(callback, shapes1, shapes2);
|
||||
m_collisionDetection.testCollisionBetweenShapes(_callback, shapes1, shapes2);
|
||||
}
|
||||
|
||||
// Test and report collisions between a body and all the others bodies of the
|
||||
// world
|
||||
/**
|
||||
* @param body Pointer to the first body to test
|
||||
* @param callback Pointer to the object with the callback method
|
||||
*/
|
||||
void CollisionWorld::testCollision(const CollisionBody* body,
|
||||
CollisionCallback* callback) {
|
||||
|
||||
void CollisionWorld::testCollision(const CollisionBody* _body, CollisionCallback* _callback) {
|
||||
// Reset all the contact manifolds lists of each body
|
||||
resetContactManifoldListsOfBodies();
|
||||
|
||||
// Create the sets of shapes
|
||||
etk::Set<uint32_t> shapes1;
|
||||
|
||||
// For each shape of the body
|
||||
for (const ProxyShape* shape=body->getProxyShapesList(); shape != nullptr;
|
||||
shape = shape->getNext()) {
|
||||
for (const ProxyShape* shape = _body->getProxyShapesList();
|
||||
shape != nullptr;
|
||||
shape = shape->getNext()) {
|
||||
shapes1.add(shape->m_broadPhaseID);
|
||||
}
|
||||
|
||||
etk::Set<uint32_t> emptySet;
|
||||
|
||||
// Perform the collision detection and report contacts
|
||||
m_collisionDetection.testCollisionBetweenShapes(callback, shapes1, emptySet);
|
||||
m_collisionDetection.testCollisionBetweenShapes(_callback, shapes1, emptySet);
|
||||
}
|
||||
|
||||
// Test and report collisions between two bodies
|
||||
/**
|
||||
* @param body1 Pointer to the first body to test
|
||||
* @param body2 Pointer to the second body to test
|
||||
* @param callback Pointer to the object with the callback method
|
||||
*/
|
||||
void CollisionWorld::testCollision(const CollisionBody* body1,
|
||||
const CollisionBody* body2,
|
||||
CollisionCallback* callback) {
|
||||
|
||||
void CollisionWorld::testCollision(const CollisionBody* _body1, const CollisionBody* _body2, CollisionCallback* _callback) {
|
||||
// Reset all the contact manifolds lists of each body
|
||||
resetContactManifoldListsOfBodies();
|
||||
|
||||
// Create the sets of shapes
|
||||
etk::Set<uint32_t> shapes1;
|
||||
for (const ProxyShape* shape=body1->getProxyShapesList(); shape != nullptr;
|
||||
shape = shape->getNext()) {
|
||||
for (const ProxyShape* shape = _body1->getProxyShapesList();
|
||||
shape != nullptr;
|
||||
shape = shape->getNext()) {
|
||||
shapes1.add(shape->m_broadPhaseID);
|
||||
}
|
||||
|
||||
etk::Set<uint32_t> shapes2;
|
||||
for (const ProxyShape* shape=body2->getProxyShapesList(); shape != nullptr;
|
||||
shape = shape->getNext()) {
|
||||
for (const ProxyShape* shape = _body2->getProxyShapesList();
|
||||
shape != nullptr;
|
||||
shape = shape->getNext()) {
|
||||
shapes2.add(shape->m_broadPhaseID);
|
||||
}
|
||||
|
||||
// Perform the collision detection and report contacts
|
||||
m_collisionDetection.testCollisionBetweenShapes(callback, shapes1, shapes2);
|
||||
m_collisionDetection.testCollisionBetweenShapes(_callback, shapes1, shapes2);
|
||||
}
|
||||
|
||||
// Test and report collisions between all shapes of the world
|
||||
/**
|
||||
* @param callback Pointer to the object with the callback method
|
||||
*/
|
||||
void CollisionWorld::testCollision(CollisionCallback* callback) {
|
||||
|
||||
void CollisionWorld::testCollision(CollisionCallback* _callback) {
|
||||
// Reset all the contact manifolds lists of each body
|
||||
resetContactManifoldListsOfBodies();
|
||||
|
||||
etk::Set<uint32_t> emptySet;
|
||||
|
||||
// Perform the collision detection and report contacts
|
||||
m_collisionDetection.testCollisionBetweenShapes(callback, emptySet, emptySet);
|
||||
m_collisionDetection.testCollisionBetweenShapes(_callback, emptySet, emptySet);
|
||||
}
|
||||
|
||||
|
@ -60,9 +60,16 @@ namespace ephysics {
|
||||
etk::Set<CollisionBody*>::Iterator getBodiesEndIterator() {
|
||||
return m_bodies.end();
|
||||
}
|
||||
/// Create a collision body
|
||||
/**
|
||||
* @brief Create a collision body and add it to the world
|
||||
* @param transform etk::Transform3Dation mapping the local-space of the body to world-space
|
||||
* @return A pointer to the body that has been created in the world
|
||||
*/
|
||||
CollisionBody* createCollisionBody(const etk::Transform3D& transform);
|
||||
/// Destroy a collision body
|
||||
/**
|
||||
* @brief Destroy a collision body
|
||||
* @param collisionBody Pointer to the body to destroy
|
||||
*/
|
||||
void destroyCollisionBody(CollisionBody* collisionBody);
|
||||
/**
|
||||
* @brief Set the collision dispatch configuration
|
||||
@ -85,7 +92,12 @@ namespace ephysics {
|
||||
unsigned short _raycastWithCategoryMaskBits = 0xFFFF) const {
|
||||
m_collisionDetection.raycast(_raycastCallback, _ray, _raycastWithCategoryMaskBits);
|
||||
}
|
||||
/// Test if the AABBs of two bodies overlap
|
||||
/**
|
||||
* @brief Test if the AABBs of two bodies overlap
|
||||
* @param _body1 Pointer to the first body to test
|
||||
* @param _body2 Pointer to the second body to test
|
||||
* @return True if the AABBs of the two bodies overlap and false otherwise
|
||||
*/
|
||||
bool testAABBOverlap(const CollisionBody* _body1,
|
||||
const CollisionBody* _body2) const;
|
||||
/**
|
||||
@ -97,23 +109,42 @@ namespace ephysics {
|
||||
const ProxyShape* _shape2) const {
|
||||
return m_collisionDetection.testAABBOverlap(_shape1, _shape2);
|
||||
}
|
||||
/// Test and report collisions between a given shape and all the others
|
||||
/// shapes of the world
|
||||
/**
|
||||
* @brief Test and report collisions between a given shape and all the others shapes of the world.
|
||||
* @param _shape Pointer to the proxy shape to test
|
||||
* @param _callback Pointer to the object with the callback method
|
||||
*/
|
||||
virtual void testCollision(const ProxyShape* _shape,
|
||||
CollisionCallback* _callback);
|
||||
/// Test and report collisions between two given shapes
|
||||
/**
|
||||
* @briefTest and report collisions between two given shapes
|
||||
* @param _shape1 Pointer to the first proxy shape to test
|
||||
* @param _shape2 Pointer to the second proxy shape to test
|
||||
* @param _callback Pointer to the object with the callback method
|
||||
*/
|
||||
virtual void testCollision(const ProxyShape* _shape1,
|
||||
const ProxyShape* _shape2,
|
||||
CollisionCallback* _callback);
|
||||
/// Test and report collisions between a body and all the others bodies of the
|
||||
/// world
|
||||
/**
|
||||
* @brief Test and report collisions between a body and all the others bodies of the world.
|
||||
* @param _body Pointer to the first body to test
|
||||
* @param _callback Pointer to the object with the callback method
|
||||
*/
|
||||
virtual void testCollision(const CollisionBody* _body,
|
||||
CollisionCallback* _callback);
|
||||
/// Test and report collisions between two bodies
|
||||
/**
|
||||
* @brief Test and report collisions between two bodies
|
||||
* @param _body1 Pointer to the first body to test
|
||||
* @param _body2 Pointer to the second body to test
|
||||
* @param _callback Pointer to the object with the callback method
|
||||
*/
|
||||
virtual void testCollision(const CollisionBody* _body1,
|
||||
const CollisionBody* _body2,
|
||||
CollisionCallback* _callback);
|
||||
/// Test and report collisions between all shapes of the world
|
||||
/**
|
||||
* @brief Test and report collisions between all shapes of the world
|
||||
* @param _callback Pointer to the object with the callback method
|
||||
*/
|
||||
virtual void testCollision(CollisionCallback* _callback);
|
||||
friend class CollisionDetection;
|
||||
friend class CollisionBody;
|
||||
|
Loading…
x
Reference in New Issue
Block a user