diff --git a/sources/reactphysics3d/engine/ConstraintSolver.cpp b/sources/reactphysics3d/engine/ConstraintSolver.cpp index 7f90bd42..0c286d74 100644 --- a/sources/reactphysics3d/engine/ConstraintSolver.cpp +++ b/sources/reactphysics3d/engine/ConstraintSolver.cpp @@ -23,6 +23,7 @@ #include "../body/RigidBody.h" using namespace reactphysics3d; +using namespace std; // Constructor ConstraintSolver::ConstraintSolver(PhysicsWorld* world) @@ -41,7 +42,7 @@ void ConstraintSolver::allocate() { Constraint* constraint; // For each constraint - std::vector::iterator it; + vector::iterator it; for (it = physicsWorld->getConstraintsBeginIterator(); it != physicsWorld->getConstraintsEndIterator(); it++) { constraint = *it; @@ -57,8 +58,8 @@ void ConstraintSolver::allocate() { constraintBodies.insert(constraint->getBody2()); // Fill in the body number maping - bodyNumberMapping.insert(std::pair(constraint->getBody1(), bodyNumberMapping.size())); - bodyNumberMapping.insert(std::pair(constraint->getBody2(), bodyNumberMapping.size())); + bodyNumberMapping.insert(pair(constraint->getBody1(), bodyNumberMapping.size())); + bodyNumberMapping.insert(pair(constraint->getBody2(), bodyNumberMapping.size())); // Update the size of the jacobian matrix nbConstraints += (1 + constraint->getNbAuxConstraints()); @@ -174,7 +175,7 @@ void ConstraintSolver::fillInMatrices() { Vector v(6); Vector f(6); uint b=0; - for (std::set::iterator it = constraintBodies.begin(); it != constraintBodies.end(); it++, b++) { + for (set::iterator it = constraintBodies.begin(); it != constraintBodies.end(); it++, b++) { body = *it; uint bodyNumber = bodyNumberMapping.at(body); @@ -222,6 +223,7 @@ void ConstraintSolver::freeMemory() { delete[] bodyMapping[i]; delete[] J_sp[i]; } + delete[] bodyMapping; delete[] J_sp; delete[] B_sp[0]; @@ -299,7 +301,7 @@ void ConstraintSolver::updateContactCache() { Contact* contact = dynamic_cast(activeConstraints.at(c)); if (contact) { // Create a new ContactCachingInfo - ContactCachingInfo contactInfo(contact->getBody1(), contact->getBody2(), contact->getPoint(), lambda.getValue(noConstraint)); + ContactCachingInfo* contactInfo = new ContactCachingInfo(contact->getBody1(), contact->getBody2(), contact->getPoint(), lambda.getValue(noConstraint)); // Add it to the contact cache contactCache.addContactCachingInfo(contactInfo); diff --git a/sources/reactphysics3d/engine/ContactCache.cpp b/sources/reactphysics3d/engine/ContactCache.cpp index 8fa3c14e..56c07389 100644 --- a/sources/reactphysics3d/engine/ContactCache.cpp +++ b/sources/reactphysics3d/engine/ContactCache.cpp @@ -40,17 +40,17 @@ void ContactCache::clear() { } // Add a new contact caching info in the cache -void ContactCache::addContactCachingInfo(const ContactCachingInfo& info) { +void ContactCache::addContactCachingInfo(ContactCachingInfo* info) { // Check if there is already an entry for that pair of body in the cache - map, vector >::iterator entry = cache.find(make_pair(info.body1, info.body2)); + map, vector >::iterator entry = cache.find(make_pair(info->body1, info->body2)); if (entry != cache.end()) { (*entry).second.push_back(info); } else { // Add a new entry in the cache - vector vec; + vector vec; vec.push_back(info); - cache.insert(make_pair(make_pair(info.body1, info.body2), vec)); + cache.insert(make_pair(make_pair(info->body1, info->body2), vec)); } } @@ -59,9 +59,9 @@ void ContactCache::addContactCachingInfo(const ContactCachingInfo& info) { // compatible (with approximatively the same position), this method returns NULL. ContactCachingInfo* ContactCache::getContactCachingInfo(Body* body1, Body* body2, const Vector3D& position) { // Check if there is an entry for that pair of body in the cache - map, vector >::iterator entry = cache.find(make_pair(body1, body2)); + map, vector >::iterator entry = cache.find(make_pair(body1, body2)); if (entry != cache.end()) { - vector vec = (*entry).second; + vector vec = (*entry).second; assert((*entry).first.first == body1); assert((*entry).first.second == body2); @@ -70,13 +70,13 @@ ContactCachingInfo* ContactCache::getContactCachingInfo(Body* body1, Body* body2 double posZ = position.getZ(); // Check among all the old contacts for this pair of body if there is an approximative match for the contact position - for(vector::iterator it = vec.begin(); it != vec.end(); it++) { - Vector3D& contactPos = (*it).position; + for(vector::iterator it = vec.begin(); it != vec.end(); it++) { + Vector3D& contactPos = (*it)->position; if (posX <= contactPos.getX() + POSITION_TOLERANCE && posX >= contactPos.getX() - POSITION_TOLERANCE && posY <= contactPos.getY() + POSITION_TOLERANCE && posY >= contactPos.getY() - POSITION_TOLERANCE && posZ <= contactPos.getZ() + POSITION_TOLERANCE && posZ >= contactPos.getZ() - POSITION_TOLERANCE) { // Return the ContactCachingInfo - return &(*it); + return *it; } } } diff --git a/sources/reactphysics3d/engine/ContactCache.h b/sources/reactphysics3d/engine/ContactCache.h index 950952cf..5aa38b66 100644 --- a/sources/reactphysics3d/engine/ContactCache.h +++ b/sources/reactphysics3d/engine/ContactCache.h @@ -42,14 +42,14 @@ const double POSITION_TOLERANCE = 0.01 ; // Tolerance used to consider two */ class ContactCache { private: - std::map, std::vector > cache; + std::map, std::vector > cache; public: - ContactCache(); // Constructor - ~ContactCache(); // Destructor - void clear(); // Remove all the contact caching info of the cache - void addContactCachingInfo(const ContactCachingInfo& contactCachingInfo); // Add a new contact caching info in the cache - ContactCachingInfo* getContactCachingInfo(Body* body1, Body* body2, const Vector3D& position); // Return the ContactCachingInfo (if exists) corresponding to the arguments + ContactCache(); // Constructor + ~ContactCache(); // Destructor + void clear(); // Remove all the contact caching info of the cache + void addContactCachingInfo(ContactCachingInfo* contactCachingInfo); // Add a new contact caching info in the cache + ContactCachingInfo* getContactCachingInfo(Body* body1, Body* body2, const Vector3D& position); // Return the ContactCachingInfo (if exists) corresponding to the arguments }; } // End of the ReactPhysics3D namespace