diff --git a/sources/reactphysics3d/engine/DynamicEngine.cpp b/sources/reactphysics3d/engine/DynamicEngine.cpp index 8515bce5..16848350 100644 --- a/sources/reactphysics3d/engine/DynamicEngine.cpp +++ b/sources/reactphysics3d/engine/DynamicEngine.cpp @@ -19,6 +19,8 @@ // Libraries #include "DynamicEngine.h" +#include "RK4.h" +#include "Euler.h" // We want to use the ReactPhysics3D namespace using namespace reactphysics3d; @@ -31,17 +33,21 @@ DynamicEngine::DynamicEngine(DynamicWorld* world, const Time& timeStep) // Throw an exception throw std::invalid_argument("Exception in PhysicsEngine constructor : World pointer cannot be NULL"); } + + // Creation of the RK4 integration algorithm + integrationAlgorithm = new RK4(); } // Copy-constructor DynamicEngine::DynamicEngine(const DynamicEngine& engine) :PhysicsEngine(engine) { - numericalIntegrator = engine.numericalIntegrator; + integrationAlgorithm = engine.integrationAlgorithm; } // Destructor DynamicEngine::~DynamicEngine() { - + // Destroy the integration algorithm + delete integrationAlgorithm; } // Update the state of a rigid body @@ -57,7 +63,7 @@ void DynamicEngine::updateBodyState(RigidBody* const rigidBody) { rigidBody->updatePreviousBodyState(); // Integrate the current body state at time t to get the next state at time t + dt - numericalIntegrator.integrate(rigidBody->getCurrentBodyState(), timer.getTime(), timer.getTimeStep()); + integrationAlgorithm->integrate(rigidBody->getCurrentBodyState(), timer.getTime(), timer.getTimeStep()); } // Update the physics simulation diff --git a/sources/reactphysics3d/engine/DynamicEngine.h b/sources/reactphysics3d/engine/DynamicEngine.h index 537cf8e5..8744498c 100644 --- a/sources/reactphysics3d/engine/DynamicEngine.h +++ b/sources/reactphysics3d/engine/DynamicEngine.h @@ -22,7 +22,7 @@ // Libraries #include "PhysicsEngine.h" -#include "NumericalIntegrator.h" +#include "IntegrationAlgorithm.h" #include "../body/Body.h" #include "../body/RigidBody.h" #include "../body/BodyState.h" @@ -41,7 +41,7 @@ namespace reactphysics3d { */ class DynamicEngine : public PhysicsEngine { protected : - NumericalIntegrator numericalIntegrator; // Numerical integrator used to solve differential equations of movement + IntegrationAlgorithm* integrationAlgorithm; // Integration algorithm used to solve differential equations of movement void updateBodyState(RigidBody* const rigidBody); // Update the state of a rigid body