From c56557898f685d9dbe6b1ee52351e9b760ac5127 Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Mon, 9 Feb 2015 22:37:36 +0100 Subject: [PATCH] Small modifications --- examples/common/opengl-framework/src/Shader.h | 6 ++-- src/body/CollisionBody.cpp | 2 -- src/collision/CollisionDetection.cpp | 8 ++++- .../broadphase/BroadPhaseAlgorithm.cpp | 34 +++++++++---------- .../broadphase/BroadPhaseAlgorithm.h | 27 +++++---------- src/engine/DynamicsWorld.cpp | 4 --- src/engine/OverlappingPair.h | 1 - 7 files changed, 35 insertions(+), 47 deletions(-) diff --git a/examples/common/opengl-framework/src/Shader.h b/examples/common/opengl-framework/src/Shader.h index 82f1b98a..52a206bc 100644 --- a/examples/common/opengl-framework/src/Shader.h +++ b/examples/common/opengl-framework/src/Shader.h @@ -158,10 +158,8 @@ inline int Shader::getUniformLocation(const std::string& variableName) const { // Clear the shader inline void Shader::destroy() { - if (mProgramObjectID != 0) { - glDeleteShader(mProgramObjectID); - mProgramObjectID = 0; - } + glDeleteProgram(mProgramObjectID); + mProgramObjectID = 0; } // Set a float uniform value to this shader (be careful if the uniform is not diff --git a/src/body/CollisionBody.cpp b/src/body/CollisionBody.cpp index c9ab7a91..2b8af243 100644 --- a/src/body/CollisionBody.cpp +++ b/src/body/CollisionBody.cpp @@ -145,8 +145,6 @@ void CollisionBody::removeCollisionShape(const ProxyShape* proxyShape) { // Remove all the collision shapes void CollisionBody::removeAllCollisionShapes() { - // TODO : Remove all the contact manifolds at the end of this call - ProxyShape* current = mProxyCollisionShapes; // Look for the proxy shape that contains the collision shape in parameter diff --git a/src/collision/CollisionDetection.cpp b/src/collision/CollisionDetection.cpp index 0c17520f..0471c9c9 100644 --- a/src/collision/CollisionDetection.cpp +++ b/src/collision/CollisionDetection.cpp @@ -134,7 +134,7 @@ void CollisionDetection::reportCollisionBetweenShapes(CollisionCallback* callbac // Delete and remove the contact info from the memory allocator contactInfo->~ContactPointInfo(); - mWorld->mMemoryAllocator.release(contactInfo, sizeof(ContactPointInfo)); + mWorld->mMemoryAllocator.release(contactInfo, sizeof(ContactPointInfo)); } } } @@ -181,6 +181,8 @@ void CollisionDetection::computeNarrowPhase() { std::map::iterator itToRemove = it; ++it; + // TODO : Remove all the contact manifold of the overlapping pair from the contact manifolds list of the two bodies involved + // Destroy the overlapping pair itToRemove->second->~OverlappingPair(); mWorld->mMemoryAllocator.release(itToRemove->second, sizeof(OverlappingPair)); @@ -287,6 +289,8 @@ void CollisionDetection::computeNarrowPhaseBetweenShapes(CollisionCallback* call std::map::iterator itToRemove = it; ++it; + // TODO : Remove all the contact manifold of the overlapping pair from the contact manifolds list of the two bodies involved + // Destroy the overlapping pair itToRemove->second->~OverlappingPair(); mWorld->mMemoryAllocator.release(itToRemove->second, sizeof(OverlappingPair)); @@ -380,6 +384,8 @@ void CollisionDetection::removeProxyCollisionShape(ProxyShape* proxyShape) { std::map::iterator itToRemove = it; ++it; + // TODO : Remove all the contact manifold of the overlapping pair from the contact manifolds list of the two bodies involved + // Destroy the overlapping pair itToRemove->second->~OverlappingPair(); mWorld->mMemoryAllocator.release(itToRemove->second, sizeof(OverlappingPair)); diff --git a/src/collision/broadphase/BroadPhaseAlgorithm.cpp b/src/collision/broadphase/BroadPhaseAlgorithm.cpp index 9de9e27e..e0747d49 100644 --- a/src/collision/broadphase/BroadPhaseAlgorithm.cpp +++ b/src/collision/broadphase/BroadPhaseAlgorithm.cpp @@ -37,19 +37,19 @@ BroadPhaseAlgorithm::BroadPhaseAlgorithm(CollisionDetection& collisionDetection) mNbNonUsedMovedShapes(0), mNbPotentialPairs(0), mNbAllocatedPotentialPairs(8), mCollisionDetection(collisionDetection) { - // Allocate memory for the array of non-static bodies IDs + // Allocate memory for the array of non-static proxy shapes IDs mMovedShapes = (int*) malloc(mNbAllocatedMovedShapes * sizeof(int)); assert(mMovedShapes != NULL); // Allocate memory for the array of potential overlapping pairs - mPotentialPairs = (BroadPair*) malloc(mNbAllocatedPotentialPairs * sizeof(BroadPair)); + mPotentialPairs = (BroadPhasePair*) malloc(mNbAllocatedPotentialPairs * sizeof(BroadPhasePair)); assert(mPotentialPairs != NULL); } // Destructor BroadPhaseAlgorithm::~BroadPhaseAlgorithm() { - // Release the memory for the array of non-static bodies IDs + // Release the memory for the array of non-static proxy shapes IDs free(mMovedShapes); // Release the memory for the array of potential overlapping pairs @@ -60,7 +60,7 @@ BroadPhaseAlgorithm::~BroadPhaseAlgorithm() { // and that need to be tested again for broad-phase overlapping. void BroadPhaseAlgorithm::addMovedCollisionShape(int broadPhaseID) { - // Allocate more elements in the array of bodies that have moved if necessary + // Allocate more elements in the array of shapes that have moved if necessary if (mNbAllocatedMovedShapes == mNbMovedShapes) { mNbAllocatedMovedShapes *= 2; int* oldArray = mMovedShapes; @@ -70,7 +70,7 @@ void BroadPhaseAlgorithm::addMovedCollisionShape(int broadPhaseID) { free(oldArray); } - // Store the broad-phase ID into the array of bodies that have moved + // Store the broad-phase ID into the array of shapes that have moved assert(mNbMovedShapes < mNbAllocatedMovedShapes); assert(mMovedShapes != NULL); mMovedShapes[mNbMovedShapes] = broadPhaseID; @@ -83,7 +83,7 @@ void BroadPhaseAlgorithm::removeMovedCollisionShape(int broadPhaseID) { assert(mNbNonUsedMovedShapes <= mNbMovedShapes); - // If less than the quarter of allocated elements of the non-static bodies IDs array + // If less than the quarter of allocated elements of the non-static shapes IDs array // are used, we release some allocated memory if ((mNbMovedShapes - mNbNonUsedMovedShapes) < mNbAllocatedMovedShapes / 4 && mNbAllocatedMovedShapes > 8) { @@ -133,7 +133,7 @@ void BroadPhaseAlgorithm::removeProxyCollisionShape(ProxyShape* proxyShape) { // Remove the collision shape from the dynamic AABB tree mDynamicAABBTree.removeObject(broadPhaseID); - // Remove the collision shape into the array of bodies that have moved (or have been created) + // Remove the collision shape into the array of shapes that have moved (or have been created) // during the last simulation step removeMovedCollisionShape(broadPhaseID); } @@ -153,7 +153,7 @@ void BroadPhaseAlgorithm::updateProxyCollisionShape(ProxyShape* proxyShape, cons // into the tree). if (hasBeenReInserted) { - // Add the collision shape into the array of bodies that have moved (or have been created) + // Add the collision shape into the array of shapes that have moved (or have been created) // during the last simulation step addMovedCollisionShape(broadPhaseID); } @@ -186,7 +186,7 @@ void BroadPhaseAlgorithm::computeOverlappingPairs() { mNbMovedShapes = 0; // Sort the array of potential overlapping pairs in order to remove duplicate pairs - std::sort(mPotentialPairs, mPotentialPairs + mNbPotentialPairs, BroadPair::smallerThan); + std::sort(mPotentialPairs, mPotentialPairs + mNbPotentialPairs, BroadPhasePair::smallerThan); // Check all the potential overlapping pairs avoiding duplicates to report unique // overlapping pairs @@ -194,7 +194,7 @@ void BroadPhaseAlgorithm::computeOverlappingPairs() { while (i < mNbPotentialPairs) { // Get a potential overlapping pair - BroadPair* pair = mPotentialPairs + i; + BroadPhasePair* pair = mPotentialPairs + i; i++; // Get the two collision shapes of the pair @@ -208,7 +208,7 @@ void BroadPhaseAlgorithm::computeOverlappingPairs() { while (i < mNbPotentialPairs) { // Get the next pair - BroadPair* nextPair = mPotentialPairs + i; + BroadPhasePair* nextPair = mPotentialPairs + i; // If the next pair is different from the previous one, we stop skipping pairs if (nextPair->collisionShape1ID != pair->collisionShape1ID || @@ -224,11 +224,11 @@ void BroadPhaseAlgorithm::computeOverlappingPairs() { if (mNbPotentialPairs < mNbAllocatedPotentialPairs / 4 && mNbPotentialPairs > 8) { // Reduce the number of allocated potential overlapping pairs - BroadPair* oldPairs = mPotentialPairs; + BroadPhasePair* oldPairs = mPotentialPairs; mNbAllocatedPotentialPairs /= 2; - mPotentialPairs = (BroadPair*) malloc(mNbAllocatedPotentialPairs * sizeof(BroadPair)); + mPotentialPairs = (BroadPhasePair*) malloc(mNbAllocatedPotentialPairs * sizeof(BroadPhasePair)); assert(mPotentialPairs); - memcpy(mPotentialPairs, oldPairs, mNbPotentialPairs * sizeof(BroadPair)); + memcpy(mPotentialPairs, oldPairs, mNbPotentialPairs * sizeof(BroadPhasePair)); free(oldPairs); } } @@ -243,11 +243,11 @@ void BroadPhaseAlgorithm::notifyOverlappingPair(int node1ID, int node2ID) { if (mNbPotentialPairs == mNbAllocatedPotentialPairs) { // Allocate more memory for the array of potential pairs - BroadPair* oldPairs = mPotentialPairs; + BroadPhasePair* oldPairs = mPotentialPairs; mNbAllocatedPotentialPairs *= 2; - mPotentialPairs = (BroadPair*) malloc(mNbAllocatedPotentialPairs * sizeof(BroadPair)); + mPotentialPairs = (BroadPhasePair*) malloc(mNbAllocatedPotentialPairs * sizeof(BroadPhasePair)); assert(mPotentialPairs); - memcpy(mPotentialPairs, oldPairs, mNbPotentialPairs * sizeof(BroadPair)); + memcpy(mPotentialPairs, oldPairs, mNbPotentialPairs * sizeof(BroadPhasePair)); free(oldPairs); } diff --git a/src/collision/broadphase/BroadPhaseAlgorithm.h b/src/collision/broadphase/BroadPhaseAlgorithm.h index 1227b750..c89917a1 100644 --- a/src/collision/broadphase/BroadPhaseAlgorithm.h +++ b/src/collision/broadphase/BroadPhaseAlgorithm.h @@ -38,20 +38,12 @@ namespace reactphysics3d { // Declarations class CollisionDetection; -// TODO : Check that when a kinematic or static body is manually moved, the dynamic aabb tree -// is correctly updated - -// TODO : Replace the names "body, bodies" by "collision shapes" - -// TODO : Remove the pair manager - -// TODO : RENAME THIS -// Structure BroadPair +// Structure BroadPhasePair /** - * This structure represent a potential overlapping pair during the broad-phase collision - * detection. + * This structure represent a potential overlapping pair during the + * broad-phase collision detection. */ -struct BroadPair { +struct BroadPhasePair { // -------------------- Attributes -------------------- // @@ -64,13 +56,13 @@ struct BroadPair { // -------------------- Methods -------------------- // /// Method used to compare two pairs for sorting algorithm - static bool smallerThan(const BroadPair& pair1, const BroadPair& pair2); + static bool smallerThan(const BroadPhasePair& pair1, const BroadPhasePair& pair2); }; // Class BroadPhaseAlgorithm /** * This class represents the broad-phase collision detection. The - * goal of the broad-phase collision detection is to compute the pairs of bodies + * goal of the broad-phase collision detection is to compute the pairs of proxy shapes * 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. @@ -102,7 +94,7 @@ class BroadPhaseAlgorithm { uint mNbNonUsedMovedShapes; /// Temporary array of potential overlapping pairs (with potential duplicates) - BroadPair* mPotentialPairs; + BroadPhasePair* mPotentialPairs; /// Number of potential overlapping pairs uint mNbPotentialPairs; @@ -164,7 +156,7 @@ class BroadPhaseAlgorithm { }; // Method used to compare two pairs for sorting algorithm -inline bool BroadPair::smallerThan(const BroadPair& pair1, const BroadPair& pair2) { +inline bool BroadPhasePair::smallerThan(const BroadPhasePair& pair1, const BroadPhasePair& pair2) { if (pair1.collisionShape1ID < pair2.collisionShape1ID) return true; if (pair1.collisionShape1ID == pair2.collisionShape1ID) { @@ -185,8 +177,7 @@ inline bool BroadPhaseAlgorithm::testOverlappingShapes(const ProxyShape* shape1, } // Ray casting method -inline void BroadPhaseAlgorithm::raycast(const Ray& ray, - RaycastTest& raycastTest, +inline void BroadPhaseAlgorithm::raycast(const Ray& ray, RaycastTest& raycastTest, unsigned short raycastWithCategoryMaskBits) const { mDynamicAABBTree.raycast(ray, raycastTest, raycastWithCategoryMaskBits); } diff --git a/src/engine/DynamicsWorld.cpp b/src/engine/DynamicsWorld.cpp index 01660643..c541e3eb 100644 --- a/src/engine/DynamicsWorld.cpp +++ b/src/engine/DynamicsWorld.cpp @@ -190,10 +190,6 @@ void DynamicsWorld::integrateRigidBodiesPositions() { mConstrainedOrientations[indexArray] = currentOrientation + Quaternion(0, newAngVelocity) * currentOrientation * decimal(0.5) * dt; - - // TODO : DELETE THIS - Vector3 newPos = mConstrainedPositions[indexArray]; - Quaternion newOrientation = mConstrainedOrientations[indexArray]; } } } diff --git a/src/engine/OverlappingPair.h b/src/engine/OverlappingPair.h index 0397f93b..51103284 100644 --- a/src/engine/OverlappingPair.h +++ b/src/engine/OverlappingPair.h @@ -97,7 +97,6 @@ class OverlappingPair { Vector3 getCachedSeparatingAxis() const; /// Set the cached separating axis - // TODO : Check that this variable is correctly used allong the collision detection process void setCachedSeparatingAxis(const Vector3& axis); /// Return the number of contacts in the cache