diff --git a/sources/reactphysics3d/engine/CollisionEngine.cpp b/sources/reactphysics3d/engine/CollisionEngine.cpp index c1bd50e3..772d1490 100644 --- a/sources/reactphysics3d/engine/CollisionEngine.cpp +++ b/sources/reactphysics3d/engine/CollisionEngine.cpp @@ -27,7 +27,6 @@ using namespace reactphysics3d; // Constructor CollisionEngine::CollisionEngine(CollisionWorld* world, const Time& timeStep) :DynamicEngine(world, timeStep) { - } // Destructor @@ -37,43 +36,27 @@ CollisionEngine::~CollisionEngine() { // Update the physics simulation void CollisionEngine::update() { - CollisionWorld* collisionWorld = dynamic_cast(world); assert(collisionWorld != 0); // While the time accumulator is not empty while(timer.getAccumulator() >= timer.getTimeStep().getValue()) { + // Remove all old collision contact constraints collisionWorld->removeAllContactConstraints(); - Time timeFirst(0); // First collision time - Time timeLast(DBL_MAX); // Last collision separation time - // Compute the collision detection - if (collisionDetection.computeCollisionDetection(collisionWorld, timer.getTimeStep(), timeFirst)) { - // For each body in the dynamic world - for(std::vector::const_iterator it = world->getBodyListStartIterator(); it != world->getBodyListEndIterator(); ++it) { - // If the body is a RigidBody and if the rigid body motion is enabled - RigidBody* rigidBody = dynamic_cast(*it); - if (rigidBody && rigidBody->getIsMotionEnabled()) { - // Update the state of the rigid body - updateBodyState(rigidBody, timeFirst); - } - - // Stop the body (TO DELETE) - rigidBody->setIsMotionEnabled(false); // TODO : DELETE THIS - } + if (collisionDetection.computeCollisionDetection(collisionWorld)) { + // TODO : Do collision response here } - else { - // For each body in the dynamic world - for(std::vector::const_iterator it = world->getBodyListStartIterator(); it != world->getBodyListEndIterator(); ++it) { - // If the body is a RigidBody and if the rigid body motion is enabled - RigidBody* rigidBody = dynamic_cast(*it); - if (rigidBody && rigidBody->getIsMotionEnabled()) { - // Update the state of the rigid body with an entire time step - updateBodyState(rigidBody, timer.getTimeStep()); - std::cout << "NO NO NO" << std::endl; // TODO : DELETE THIS - } + + // For each body in the dynamic world + for(std::vector::const_iterator it = world->getBodyListStartIterator(); it != world->getBodyListEndIterator(); ++it) { + // If the body is a RigidBody and if the rigid body motion is enabled + RigidBody* rigidBody = dynamic_cast(*it); + if (rigidBody && rigidBody->getIsMotionEnabled()) { + // Update the state of the rigid body with an entire time step + updateBodyState(rigidBody, timer.getTimeStep()); } } @@ -81,7 +64,7 @@ void CollisionEngine::update() { timer.update(); } - // For each body in the dynamic world + // For each body in the the dynamic world for(std::vector::const_iterator it = world->getBodyListStartIterator(); it != world->getBodyListEndIterator(); ++it) { // If the body is a RigidBody and if the rigid body motion is enabled RigidBody* rigidBody = dynamic_cast(*it); diff --git a/sources/reactphysics3d/engine/CollisionEngine.h b/sources/reactphysics3d/engine/CollisionEngine.h index 96125210..d9bf99b8 100644 --- a/sources/reactphysics3d/engine/CollisionEngine.h +++ b/sources/reactphysics3d/engine/CollisionEngine.h @@ -36,7 +36,7 @@ namespace reactphysics3d { class CollisionEngine : public DynamicEngine { private : CollisionDetection collisionDetection; // Collision detection - // ConstraintSolver constraintSolver; // Constraint solver + // ConstraintSolver constraintSolver; // Constraint solver public : CollisionEngine(CollisionWorld* world, const Time& timeStep); // Constructor diff --git a/sources/reactphysics3d/engine/DynamicEngine.cpp b/sources/reactphysics3d/engine/DynamicEngine.cpp index e829c6a4..ee33b051 100644 --- a/sources/reactphysics3d/engine/DynamicEngine.cpp +++ b/sources/reactphysics3d/engine/DynamicEngine.cpp @@ -19,8 +19,7 @@ // Libraries #include "DynamicEngine.h" -#include "RK4.h" -#include "Euler.h" +#include "integration/RungeKutta.h" // We want to use the ReactPhysics3D namespace using namespace reactphysics3d; @@ -35,7 +34,7 @@ DynamicEngine::DynamicEngine(DynamicWorld* world, const Time& timeStep) } // Creation of the RK4 integration algorithm - integrationAlgorithm = new RK4(); + integrationAlgorithm = new RungeKutta4(); } // Copy-constructor @@ -67,7 +66,6 @@ void DynamicEngine::updateBodyState(RigidBody* const rigidBody, const Time& time // If the body state has changed, we have to update some informations in the rigid body rigidBody->update(); - } // Update the physics simulation diff --git a/sources/reactphysics3d/engine/DynamicEngine.h b/sources/reactphysics3d/engine/DynamicEngine.h index 92886e6e..ef27d6ef 100644 --- a/sources/reactphysics3d/engine/DynamicEngine.h +++ b/sources/reactphysics3d/engine/DynamicEngine.h @@ -22,7 +22,7 @@ // Libraries #include "PhysicsEngine.h" -#include "IntegrationAlgorithm.h" +#include "../integration/IntegrationAlgorithm.h" #include "../body/Body.h" #include "../body/RigidBody.h" #include "../body/BodyState.h"