From 76f066f0d330583cdfa0c33825bededa9d112808 Mon Sep 17 00:00:00 2001 From: "chappuis.daniel" Date: Mon, 19 Jul 2010 19:35:35 +0000 Subject: [PATCH] Modification of the update() method git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@361 92aac97c-a6ce-11dd-a772-7fcde58d38e6 --- .../reactphysics3d/engine/PhysicsEngine.cpp | 90 ++++--------------- sources/reactphysics3d/engine/PhysicsEngine.h | 1 - 2 files changed, 18 insertions(+), 73 deletions(-) diff --git a/sources/reactphysics3d/engine/PhysicsEngine.cpp b/sources/reactphysics3d/engine/PhysicsEngine.cpp index 85f061e6..a4619ab2 100644 --- a/sources/reactphysics3d/engine/PhysicsEngine.cpp +++ b/sources/reactphysics3d/engine/PhysicsEngine.cpp @@ -32,98 +32,44 @@ PhysicsEngine::PhysicsEngine(PhysicsWorld* world, const Time& timeStep) throw (s // Throw an exception throw std::invalid_argument("Exception in PhysicsEngine constructor : World pointer cannot be NULL"); } - - // Creation of the Semi-Implicit Euler integration algorithm - integrationAlgorithm = new SemiImplicitEuler(); } // Destructor PhysicsEngine::~PhysicsEngine() { - delete integrationAlgorithm; + } void PhysicsEngine::update() { - updateCollision(); -} + bool existCollision = false; -/* -// TODO : Delete this method -// Update the physics simulation -void PhysicsEngine::updateDynamic() { - // Check if the physics simulation is running if (timer.getIsRunning()) { + // Apply the gravity force to all bodies + applyGravity(); + // While the time accumulator is not empty while(timer.getAccumulator() >= timer.getTimeStep().getValue()) { - // For each body in the dynamic world - for(std::vector::const_iterator it = world->getBodiesBeginIterator(); it != world->getBodiesEndIterator(); ++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, timer.getTimeStep()); - } + existCollision = false; + // Compute the collision detection + if (collisionDetection.computeCollisionDetection()) { + existCollision = true; + + // Solve constraints + constraintSolver.solve(timer.getTimeStep().getValue()); } // Update the timer timer.update(); - } - // For each body in the dynamic world - for(std::vector::const_iterator it = world->getBodiesBeginIterator(); it != world->getBodiesEndIterator(); ++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 interpolation factor of the rigid body - // This one will be used to compute the interpolated state - rigidBody->setInterpolationFactor(timer.getInterpolationFactor()); + // Update the position and orientation of each body + updateAllBodiesMotion(); + + // Free the allocated memory of the constraint solver + if (existCollision) { + constraintSolver.freeMemory(); } } } } -*/ - -// TODO : Delethe this method -// Update the physics simulation -void PhysicsEngine::updateCollision() { - bool existCollision = false; - - // Apply the gravity force to all bodies - applyGravity(); - - // While the time accumulator is not empty - while(timer.getAccumulator() >= timer.getTimeStep().getValue()) { - existCollision = false; - // Compute the collision detection - if (collisionDetection.computeCollisionDetection()) { - existCollision = true; - - // Solve constraints - constraintSolver.solve(timer.getTimeStep().getValue()); - } - - // Update the timer - timer.update(); - - // Update the position and orientation of each body - updateAllBodiesMotion(); - - // Free the allocated memory of the constraint solver - if (existCollision) { - constraintSolver.freeMemory(); - } - } - - /* - // For each body in the the dynamic world - for(std::vector::const_iterator it = world->getBodiesBeginIterator(); it != world->getBodiesEndIterator(); ++it) { - // If the body is a RigidBody and if the rigid body motion is enabled - RigidBody* rigidBody = dynamic_cast(*it); - if (rigidBody) { - - } - } - */ -} // Compute the motion of all bodies and update their positions and orientations // First this method compute the vector V2 = V_constraint + V_forces + V1 where diff --git a/sources/reactphysics3d/engine/PhysicsEngine.h b/sources/reactphysics3d/engine/PhysicsEngine.h index 19bbc786..93f94ef2 100644 --- a/sources/reactphysics3d/engine/PhysicsEngine.h +++ b/sources/reactphysics3d/engine/PhysicsEngine.h @@ -41,7 +41,6 @@ class PhysicsEngine { protected : PhysicsWorld* world; // Pointer to the physics world of the physics engine Timer timer; // Timer of the physics engine - IntegrationAlgorithm* integrationAlgorithm; // Integration algorithm used to solve differential equations of movement CollisionDetection collisionDetection; // Collision detection ConstraintSolver constraintSolver; // Constraint solver