diff --git a/src/collision/ContactInfo.h b/src/collision/ContactInfo.h index e9f15824..6b599725 100644 --- a/src/collision/ContactInfo.h +++ b/src/collision/ContactInfo.h @@ -76,7 +76,7 @@ struct ContactInfo { const Vector3& localPoint1, const Vector3& localPoint2); }; -} // End of the ReactPhysics3D namespace +} #endif diff --git a/src/collision/broadphase/NoBroadPhaseAlgorithm.h b/src/collision/broadphase/NoBroadPhaseAlgorithm.h index 745ca459..b8b6b8df 100644 --- a/src/collision/broadphase/NoBroadPhaseAlgorithm.h +++ b/src/collision/broadphase/NoBroadPhaseAlgorithm.h @@ -82,9 +82,7 @@ class NoBroadPhaseAlgorithm : public BroadPhaseAlgorithm { // Notify the broad-phase about a new object in the world inline void NoBroadPhaseAlgorithm::addObject(CollisionBody* body, const AABB& aabb) { - - std::cout << "New body in broadphase with id=" << body->getID() << std::endl; - + // For each body that is already in the world for (std::set::iterator it = mBodies.begin(); it != mBodies.end(); ++it) { diff --git a/src/collision/broadphase/PairManager.cpp b/src/collision/broadphase/PairManager.cpp index 4ba35866..fcbae22e 100644 --- a/src/collision/broadphase/PairManager.cpp +++ b/src/collision/broadphase/PairManager.cpp @@ -36,9 +36,9 @@ bodyindex PairManager::INVALID_INDEX = std::numeric_limits 0) { diff --git a/src/collision/narrowphase/EPA/EPAAlgorithm.cpp b/src/collision/narrowphase/EPA/EPAAlgorithm.cpp index c940a0e3..e81b6796 100644 --- a/src/collision/narrowphase/EPA/EPAAlgorithm.cpp +++ b/src/collision/narrowphase/EPA/EPAAlgorithm.cpp @@ -225,9 +225,9 @@ bool EPAAlgorithm::computePenetrationDepthAndContactPoints(const Simplex& simple TriangleEPA* face3 = triangleStore.newTriangle(points, 1, 3, 2); // If the constructed tetrahedron is not correct - if (!(face0 && face1 && face2 && face3 && face0->getDistSquare() > 0.0 && - face1->getDistSquare() > 0.0 && face2->getDistSquare() > 0.0 && - face3->getDistSquare() > 0.0)) { + if (!((face0 != NULL) && (face1 != NULL) && (face2 != NULL) && (face3 != NULL) + && face0->getDistSquare() > 0.0 && face1->getDistSquare() > 0.0 + && face2->getDistSquare() > 0.0 && face3->getDistSquare() > 0.0)) { return false; } @@ -250,6 +250,7 @@ bool EPAAlgorithm::computePenetrationDepthAndContactPoints(const Simplex& simple // If the tetrahedron contains a wrong vertex (the origin is not inside the tetrahedron) if (badVertex < 4) { + // Replace the wrong vertex with the point 5 (if it exists) suppPointsA[badVertex-1] = suppPointsA[4]; suppPointsB[badVertex-1] = suppPointsB[4]; @@ -290,7 +291,8 @@ bool EPAAlgorithm::computePenetrationDepthAndContactPoints(const Simplex& simple TriangleEPA* face5 = triangleStore.newTriangle(points, 1, 0, 4); // If the polytope hasn't been correctly constructed - if (!(face0 && face1 && face2 && face3 && face4 && face5 && + if (!((face0 != NULL) && (face1 != NULL) && (face2 != NULL) && (face3 != NULL) + && (face4 != NULL) && (face5 != NULL) && face0->getDistSquare() > 0.0 && face1->getDistSquare() > 0.0 && face2->getDistSquare() > 0.0 && face3->getDistSquare() > 0.0 && face4->getDistSquare() > 0.0 && face5->getDistSquare() > 0.0)) { diff --git a/src/collision/narrowphase/EPA/EdgeEPA.cpp b/src/collision/narrowphase/EPA/EdgeEPA.cpp index 873c8101..8806962a 100644 --- a/src/collision/narrowphase/EPA/EdgeEPA.cpp +++ b/src/collision/narrowphase/EPA/EdgeEPA.cpp @@ -70,6 +70,7 @@ bool EdgeEPA::computeSilhouette(const Vector3* vertices, uint indexNewVertex, TrianglesStore& triangleStore) { // If the edge has not already been visited if (!mOwnerTriangle->getIsObsolete()) { + // If the triangle of this edge is not visible from the given point if (!mOwnerTriangle->isVisibleFromVertex(vertices, indexNewVertex)) { TriangleEPA* triangle = triangleStore.newTriangle(vertices, indexNewVertex, @@ -77,7 +78,7 @@ bool EdgeEPA::computeSilhouette(const Vector3* vertices, uint indexNewVertex, getSourceVertexIndex()); // If the triangle has been created - if (triangle) { + if (triangle != NULL) { halfLink(EdgeEPA(triangle, 1), *this); return true; } @@ -85,6 +86,7 @@ bool EdgeEPA::computeSilhouette(const Vector3* vertices, uint indexNewVertex, return false; } else { + // The current triangle is visible and therefore obsolete mOwnerTriangle->setIsObsolete(true); @@ -101,7 +103,7 @@ bool EdgeEPA::computeSilhouette(const Vector3* vertices, uint indexNewVertex, getSourceVertexIndex()); // If the triangle has been created - if (triangle) { + if (triangle != NULL) { halfLink(EdgeEPA(triangle, 1), *this); return true; } @@ -120,7 +122,7 @@ bool EdgeEPA::computeSilhouette(const Vector3* vertices, uint indexNewVertex, getTargetVertexIndex(), getSourceVertexIndex()); - if (triangle) { + if (triangle != NULL) { halfLink(EdgeEPA(triangle, 1), *this); return true; } diff --git a/src/collision/narrowphase/EPA/TrianglesStore.h b/src/collision/narrowphase/EPA/TrianglesStore.h index ae2b4d17..4d8cc459 100644 --- a/src/collision/narrowphase/EPA/TrianglesStore.h +++ b/src/collision/narrowphase/EPA/TrianglesStore.h @@ -118,7 +118,7 @@ inline TriangleEPA& TrianglesStore::last() { // Create a new triangle inline TriangleEPA* TrianglesStore::newTriangle(const Vector3* vertices, uint v0,uint v1, uint v2) { - TriangleEPA* newTriangle = 0; + TriangleEPA* newTriangle = NULL; // If we have not reached the maximum number of triangles if (mNbTriangles != MAX_TRIANGLES) { @@ -126,7 +126,7 @@ inline TriangleEPA* TrianglesStore::newTriangle(const Vector3* vertices, new (newTriangle) TriangleEPA(v0, v1, v2); if (!newTriangle->computeClosestPoint(vertices)) { mNbTriangles--; - newTriangle = 0; + newTriangle = NULL; } } diff --git a/src/collision/narrowphase/GJK/GJKAlgorithm.cpp b/src/collision/narrowphase/GJK/GJKAlgorithm.cpp index 33779795..bf6b8f5d 100644 --- a/src/collision/narrowphase/GJK/GJKAlgorithm.cpp +++ b/src/collision/narrowphase/GJK/GJKAlgorithm.cpp @@ -117,6 +117,7 @@ bool GJKAlgorithm::testCollision(const CollisionShape* collisionShape1, // If the objects intersect only in the margins if (simplex.isPointInSimplex(w) || distSquare - vDotw <= distSquare * REL_ERROR_SQUARE) { + // Compute the closet points of both objects (without the margins) simplex.computeClosestPointsOfAandB(pA, pB); @@ -148,6 +149,7 @@ bool GJKAlgorithm::testCollision(const CollisionShape* collisionShape1, // If the simplex is affinely dependent if (simplex.isAffinelyDependent()) { + // Compute the closet points of both objects (without the margins) simplex.computeClosestPointsOfAandB(pA, pB); @@ -177,6 +179,7 @@ bool GJKAlgorithm::testCollision(const CollisionShape* collisionShape1, // Compute the point of the simplex closest to the origin // If the computation of the closest point fail if (!simplex.computeClosestPoint(v)) { + // Compute the closet points of both objects (without the margins) simplex.computeClosestPointsOfAandB(pA, pB); @@ -290,6 +293,7 @@ bool GJKAlgorithm::computePenetrationDepthForEnlargedObjects(const CollisionShap // If the enlarge objects do not intersect if (vDotw > 0.0) { + // No intersection, we return false return false; } diff --git a/src/collision/narrowphase/GJK/Simplex.cpp b/src/collision/narrowphase/GJK/Simplex.cpp index 243feef6..0bae65df 100644 --- a/src/collision/narrowphase/GJK/Simplex.cpp +++ b/src/collision/narrowphase/GJK/Simplex.cpp @@ -120,8 +120,10 @@ unsigned int Simplex::getSimplex(Vector3* suppPointsA, Vector3* suppPointsB, // For each four point in the possible simplex for (i=0, bit=0x1; i<4; i++, bit <<=1) { + // If the current point is in the simplex if (overlap(mBitsCurrentSimplex, bit)) { + // Store the points suppPointsA[nbVertices] = this->mSuppPointsA[nbVertices]; suppPointsB[nbVertices] = this->mSuppPointsB[nbVertices]; diff --git a/src/collision/narrowphase/NarrowPhaseAlgorithm.cpp b/src/collision/narrowphase/NarrowPhaseAlgorithm.cpp index 8b2af219..d8778ce8 100644 --- a/src/collision/narrowphase/NarrowPhaseAlgorithm.cpp +++ b/src/collision/narrowphase/NarrowPhaseAlgorithm.cpp @@ -31,7 +31,7 @@ using namespace reactphysics3d; // Constructor NarrowPhaseAlgorithm::NarrowPhaseAlgorithm(MemoryPool& memoryPool) - :mMemoryPoolContactInfos(memoryPool), mCurrentOverlappingPair(0) { + :mMemoryPoolContactInfos(memoryPool), mCurrentOverlappingPair(NULL) { } diff --git a/src/collision/shapes/AABB.cpp b/src/collision/shapes/AABB.cpp index a3826c6e..e8e317fc 100644 --- a/src/collision/shapes/AABB.cpp +++ b/src/collision/shapes/AABB.cpp @@ -45,7 +45,7 @@ using namespace reactphysics3d; using namespace std; // Constructor -AABB::AABB() : mBodyPointer(0) { +AABB::AABB() : mBodyPointer(NULL) { } @@ -56,7 +56,7 @@ AABB::AABB(const Vector3& minCoordinates, const Vector3& maxCoordinates, Body* m } // Constructor -AABB::AABB(const Transform& transform, const Vector3& extents) : mBodyPointer(0) { +AABB::AABB(const Transform& transform, const Vector3& extents) : mBodyPointer(NULL) { update(transform, extents); } diff --git a/src/collision/shapes/AABB.h b/src/collision/shapes/AABB.h index f4fb9498..1c744b15 100644 --- a/src/collision/shapes/AABB.h +++ b/src/collision/shapes/AABB.h @@ -158,6 +158,6 @@ inline void AABB::update(const Transform& newTransform, const Vector3& extents) mMaxCoordinates = newTransform.getPosition() + worldExtents; } -}; // End of the ReactPhysics3D namespace +} #endif diff --git a/src/collision/shapes/BoxShape.h b/src/collision/shapes/BoxShape.h index a2aa2918..d0922c3a 100644 --- a/src/collision/shapes/BoxShape.h +++ b/src/collision/shapes/BoxShape.h @@ -112,10 +112,10 @@ inline Vector3 BoxShape::getLocalSupportPoint(const Vector3& direction, decimal assert(margin >= 0.0); return Vector3(direction.x < 0.0 ? -mExtent.x - margin : mExtent.x + margin, - direction.y < 0.0 ? -mExtent.y - margin : mExtent.y + margin, - direction.z < 0.0 ? -mExtent.z - margin : mExtent.z + margin); + direction.y < 0.0 ? -mExtent.y - margin : mExtent.y + margin, + direction.z < 0.0 ? -mExtent.z - margin : mExtent.z + margin); } -}; // End of the ReactPhysics3D namespace +} #endif diff --git a/src/collision/shapes/ConeShape.h b/src/collision/shapes/ConeShape.h index 4aaeddb7..ed43a1b1 100644 --- a/src/collision/shapes/ConeShape.h +++ b/src/collision/shapes/ConeShape.h @@ -143,6 +143,6 @@ inline void ConeShape::computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass 0.0, 0.0, 0.0, diagXZ); } -}; // End of the ReactPhysics3D namespace +} #endif diff --git a/src/collision/shapes/CylinderShape.h b/src/collision/shapes/CylinderShape.h index 97381e05..3c554180 100644 --- a/src/collision/shapes/CylinderShape.h +++ b/src/collision/shapes/CylinderShape.h @@ -133,7 +133,7 @@ inline void CylinderShape::computeLocalInertiaTensor(Matrix3x3& tensor, decimal 0.0, 0.0, diag); } -}; // End of the ReactPhysics3D namespace +} #endif diff --git a/src/collision/shapes/SphereShape.h b/src/collision/shapes/SphereShape.h index afc42bba..ac398f7a 100644 --- a/src/collision/shapes/SphereShape.h +++ b/src/collision/shapes/SphereShape.h @@ -127,6 +127,6 @@ inline void SphereShape::computeLocalInertiaTensor(Matrix3x3& tensor, decimal ma 0.0, 0.0, diag); } -}; // End of the ReactPhysics3D namespace +} #endif diff --git a/src/constraint/Constraint.h b/src/constraint/Constraint.h index 9f5d8508..4f46ee66 100644 --- a/src/constraint/Constraint.h +++ b/src/constraint/Constraint.h @@ -148,8 +148,6 @@ inline void Constraint::setCachedLambda(int index, decimal lambda) { mCachedLambdas[index] = lambda; } - - -} // End of the ReactPhysics3D namespace +} #endif diff --git a/src/engine/CollisionWorld.cpp b/src/engine/CollisionWorld.cpp index 52203b11..b0f9136c 100644 --- a/src/engine/CollisionWorld.cpp +++ b/src/engine/CollisionWorld.cpp @@ -78,6 +78,8 @@ CollisionBody* CollisionWorld::createCollisionBody(const Transform& transform, CollisionBody* collisionBody = new (mMemoryPoolCollisionBodies.allocateObject()) CollisionBody(transform, collisionShape, bodyID); + assert(collisionBody != NULL); + // Add the collision body to the world mBodies.insert(collisionBody); diff --git a/src/engine/ContactManifold.cpp b/src/engine/ContactManifold.cpp index 389a59d6..8bee1c39 100644 --- a/src/engine/ContactManifold.cpp +++ b/src/engine/ContactManifold.cpp @@ -149,6 +149,7 @@ int ContactManifold::getIndexOfDeepestPenetration(ContactPoint* newContact) cons // For each contact in the cache for (uint i=0; igetPenetrationDepth() > maxPenetrationDepth) { maxPenetrationDepth = mContactPoints[i]->getPenetrationDepth(); diff --git a/src/engine/DynamicsWorld.cpp b/src/engine/DynamicsWorld.cpp index e4b16d7c..55b8d1e7 100644 --- a/src/engine/DynamicsWorld.cpp +++ b/src/engine/DynamicsWorld.cpp @@ -111,7 +111,7 @@ void DynamicsWorld::updateRigidBodiesPositionAndOrientation() { for (set::iterator it=getRigidBodiesBeginIterator(); it != getRigidBodiesEndIterator(); ++it) { RigidBody* rigidBody = *it; - assert(rigidBody); + assert(rigidBody != NULL); // If the body is allowed to move if (rigidBody->getIsMotionEnabled()) { @@ -214,10 +214,11 @@ void DynamicsWorld::applyGravity() { for (set::iterator it=getRigidBodiesBeginIterator(); it != getRigidBodiesEndIterator(); ++it) { RigidBody* rigidBody = dynamic_cast(*it); - assert(rigidBody); + assert(rigidBody != NULL); // If the gravity force is on if(mIsGravityOn) { + // Apply the current gravity force to the body rigidBody->setExternalForce(rigidBody->getMass() * mGravity); } @@ -237,6 +238,7 @@ RigidBody* DynamicsWorld::createRigidBody(const Transform& transform, decimal ma // Create the rigid body RigidBody* rigidBody = new (mMemoryPoolRigidBodies.allocateObject()) RigidBody(transform, mass, inertiaTensorLocal, collisionShape, bodyID); + assert(rigidBody != NULL); // Add the rigid body to the physics world mBodies.insert(rigidBody); @@ -282,8 +284,8 @@ void DynamicsWorld::notifyAddedOverlappingPair(const BroadPhasePair* addedPair) // Add the pair into the set of overlapping pairs (if not there yet) OverlappingPair* newPair = new (mMemoryPoolOverlappingPairs.allocateObject()) OverlappingPair(addedPair->body1, addedPair->body2, mMemoryPoolContacts); + assert(newPair != NULL); std::pair, OverlappingPair*>::iterator, bool> check = mOverlappingPairs.insert(make_pair(indexPair, newPair)); - assert(check.second); } // Notify the world about a removed broad-phase overlapping pair @@ -304,35 +306,21 @@ void DynamicsWorld::notifyNewContact(const BroadPhasePair* broadPhasePair, const RigidBody* const rigidBody1 = dynamic_cast(broadPhasePair->body1); RigidBody* const rigidBody2 = dynamic_cast(broadPhasePair->body2); - assert(rigidBody1); - assert(rigidBody2); + assert(rigidBody1 != NULL); + assert(rigidBody2 != NULL); // Create a new contact ContactPoint* contact = new (mMemoryPoolContacts.allocateObject()) ContactPoint(rigidBody1, rigidBody2, contactInfo); - assert(contact); + assert(contact != NULL); // Get the corresponding overlapping pair pair indexPair = broadPhasePair->getBodiesIndexPair(); OverlappingPair* overlappingPair = mOverlappingPairs[indexPair]; - assert(overlappingPair); + assert(overlappingPair != NULL); // Add the contact to the contact cache of the corresponding overlapping pair overlappingPair->addContact(contact); - // TODO : Remove this - /* - // Create a contact manifold with the contact points of the two bodies - ContactManifold contactManifold; - contactManifold.nbContacts = 0; - - // Add all the contacts in the contact cache of the two bodies - // to the set of constraints in the physics world - for (uint i=0; igetNbContacts(); i++) { - contactManifold.contacts[i] = overlappingPair->getContact(i); - contactManifold.nbContacts++; - } - */ - // Add the contact manifold to the world mContactManifolds.push_back(overlappingPair->getContactManifold()); } diff --git a/src/engine/DynamicsWorld.h b/src/engine/DynamicsWorld.h index 7bddf900..e800cd7e 100644 --- a/src/engine/DynamicsWorld.h +++ b/src/engine/DynamicsWorld.h @@ -219,8 +219,6 @@ public : std::set::iterator getRigidBodiesEndIterator(); }; -// --- Inline functions --- // - // Start the physics simulation inline void DynamicsWorld::start() { mTimer.start(); @@ -283,7 +281,7 @@ inline void DynamicsWorld::addConstraint(Constraint* constraint) { inline void DynamicsWorld::removeConstraint(Constraint* constraint) { std::vector::iterator it; - assert(constraint); + assert(constraint != NULL); it = std::find(mConstraints.begin(), mConstraints.end(), constraint); assert(*it == constraint); delete *it; diff --git a/src/engine/OverlappingPair.h b/src/engine/OverlappingPair.h index d8d977eb..a0b67cb2 100644 --- a/src/engine/OverlappingPair.h +++ b/src/engine/OverlappingPair.h @@ -97,14 +97,10 @@ class OverlappingPair { void setCachedSeparatingAxis(const Vector3& axis); // Return the number of contacts in the cache - uint getNbContacts() const; + uint getNbContactPoints() const; // Return the contact manifold ContactManifold* getContactManifold(); - - // Return a contact of the cache - // TODO : Maybe remove this method - ContactPoint* getContact(uint index) const; }; // Return the pointer to first body @@ -120,26 +116,26 @@ inline CollisionBody* const OverlappingPair::getBody2() const { // Add a contact to the contact manifold inline void OverlappingPair::addContact(ContactPoint* contact) { mContactManifold.addContactPoint(contact); -} +} // Update the contact manifold inline void OverlappingPair::update() { mContactManifold.update(mBody1->getTransform(), mBody2->getTransform()); -} +} // Return the cached separating axis inline Vector3 OverlappingPair::getCachedSeparatingAxis() const { return mCachedSeparatingAxis; -} +} // Set the cached separating axis inline void OverlappingPair::setCachedSeparatingAxis(const Vector3& axis) { mCachedSeparatingAxis = axis; -} +} -// Return the number of contacts in the cache -inline uint OverlappingPair::getNbContacts() const { +// Return the number of contact points in the contact manifold +inline uint OverlappingPair::getNbContactPoints() const { return mContactManifold.getNbContactPoints(); } @@ -148,11 +144,6 @@ inline ContactManifold* OverlappingPair::getContactManifold() { return &mContactManifold; } -// Return a contact of the cache -inline ContactPoint* OverlappingPair::getContact(uint index) const { - return mContactManifold.getContactPoint(index); -} - } // End of the ReactPhysics3D namespace #endif diff --git a/src/memory/MemoryPool.h b/src/memory/MemoryPool.h index 52151193..2c4db5b3 100644 --- a/src/memory/MemoryPool.h +++ b/src/memory/MemoryPool.h @@ -131,9 +131,9 @@ template const uint MemoryPool::NB_OBJECTS_FIRST_BLOCK = 100; template MemoryPool::MemoryPool(uint capacity) throw(std::bad_alloc) : mCurrentNbObjects(0), mCapacity(capacity) { - mPBlocks = 0; - mPAllocatedUnits = 0; - mPFreeUnits = 0; + mPBlocks = NULL; + mPAllocatedUnits = NULL; + mPFreeUnits = NULL; mNbObjectsNextBlock = (capacity == 0) ? NB_OBJECTS_FIRST_BLOCK : capacity; // Allocate the first memory block if the capacity is @@ -172,12 +172,12 @@ void* MemoryPool::allocateObject() { } assert(mCurrentNbObjects < mCapacity); - assert(mPFreeUnits); + assert(mPFreeUnits != NULL); MemoryUnit* currentUnit = mPFreeUnits; mPFreeUnits = currentUnit->pNext; if (mPFreeUnits) { - mPFreeUnits->pPrevious = 0; + mPFreeUnits->pPrevious = NULL; } currentUnit->pNext = mPAllocatedUnits; @@ -206,7 +206,7 @@ void MemoryPool::freeObject(void* pObjectToFree) { MemoryUnit* currentUnit = (MemoryUnit*)((char*)pObjectToFree - sizeof(MemoryUnit)); mPAllocatedUnits = currentUnit->pNext; if (mPAllocatedUnits) { - mPAllocatedUnits->pPrevious = 0; + mPAllocatedUnits->pPrevious = NULL; } currentUnit->pNext = mPFreeUnits; @@ -232,8 +232,8 @@ void MemoryPool::allocateMemory() { // Allocate a new memory block mPBlocks = malloc(sizeBlock); - // Check that the allocation didn't fail - if (!mPBlocks) throw std::bad_alloc(); + // Check that the allocation did not fail + if (mPBlocks == NULL) throw std::bad_alloc(); MemoryBlock* block = (MemoryBlock*) mPBlocks; block->pNext = tempBlocks; @@ -245,7 +245,7 @@ void MemoryPool::allocateMemory() { MemoryUnit* currentUnit = (MemoryUnit*)( (char*)mPBlocks + i * (sizeof(T) + sizeof(MemoryUnit)) ); - currentUnit->pPrevious = 0; + currentUnit->pPrevious = NULL; currentUnit->pNext = mPFreeUnits; if (mPFreeUnits) {