Modification of the update() method

git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@361 92aac97c-a6ce-11dd-a772-7fcde58d38e6
This commit is contained in:
chappuis.daniel 2010-07-19 19:35:35 +00:00
parent 5f2b65a8b8
commit 76f066f0d3
2 changed files with 18 additions and 73 deletions

View File

@ -32,98 +32,44 @@ PhysicsEngine::PhysicsEngine(PhysicsWorld* world, const Time& timeStep) throw (s
// Throw an exception // Throw an exception
throw std::invalid_argument("Exception in PhysicsEngine constructor : World pointer cannot be NULL"); 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 // Destructor
PhysicsEngine::~PhysicsEngine() { PhysicsEngine::~PhysicsEngine() {
delete integrationAlgorithm;
} }
void PhysicsEngine::update() { 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()) { if (timer.getIsRunning()) {
// Apply the gravity force to all bodies
applyGravity();
// While the time accumulator is not empty // While the time accumulator is not empty
while(timer.getAccumulator() >= timer.getTimeStep().getValue()) { while(timer.getAccumulator() >= timer.getTimeStep().getValue()) {
// For each body in the dynamic world existCollision = false;
for(std::vector<Body*>::const_iterator it = world->getBodiesBeginIterator(); it != world->getBodiesEndIterator(); ++it) { // Compute the collision detection
// If the body is a RigidBody and if the rigid body motion is enabled if (collisionDetection.computeCollisionDetection()) {
RigidBody* rigidBody = dynamic_cast<RigidBody*>(*it); existCollision = true;
if (rigidBody && rigidBody->getIsMotionEnabled()) {
// Update the state of the rigid body // Solve constraints
//updateBodyState(rigidBody, timer.getTimeStep()); constraintSolver.solve(timer.getTimeStep().getValue());
}
} }
// Update the timer // Update the timer
timer.update(); timer.update();
}
// For each body in the dynamic world // Update the position and orientation of each body
for(std::vector<Body*>::const_iterator it = world->getBodiesBeginIterator(); it != world->getBodiesEndIterator(); ++it) { updateAllBodiesMotion();
// If the body is a RigidBody and if the rigid body motion is enabled
RigidBody* rigidBody = dynamic_cast<RigidBody*>(*it); // Free the allocated memory of the constraint solver
if (rigidBody && rigidBody->getIsMotionEnabled()) { if (existCollision) {
// Update the interpolation factor of the rigid body constraintSolver.freeMemory();
// This one will be used to compute the interpolated state
rigidBody->setInterpolationFactor(timer.getInterpolationFactor());
} }
} }
} }
} }
*/
// 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<Body*>::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<RigidBody*>(*it);
if (rigidBody) {
}
}
*/
}
// Compute the motion of all bodies and update their positions and orientations // 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 // First this method compute the vector V2 = V_constraint + V_forces + V1 where

View File

@ -41,7 +41,6 @@ class PhysicsEngine {
protected : protected :
PhysicsWorld* world; // Pointer to the physics world of the physics engine PhysicsWorld* world; // Pointer to the physics world of the physics engine
Timer timer; // Timer 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 CollisionDetection collisionDetection; // Collision detection
ConstraintSolver constraintSolver; // Constraint solver ConstraintSolver constraintSolver; // Constraint solver