git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@180 92aac97c-a6ce-11dd-a772-7fcde58d38e6

This commit is contained in:
chappuis.daniel 2009-07-21 20:31:18 +00:00
parent 7dca618ce0
commit ffd4efcca0
6 changed files with 43 additions and 12 deletions

View File

@ -19,6 +19,7 @@
// Libraries
#include "CollisionWorld.h"
#include "../constraint/Contact.h"
// We want to use the ReactPhysics3D namespace
using namespace reactphysics3d;
@ -31,7 +32,10 @@ CollisionWorld::CollisionWorld(const Vector3D& gravity)
// Destructor
CollisionWorld::~CollisionWorld() {
// Delete all the constraint
for (std::vector<Constraint*>::iterator it = constraintList.begin(); it != constraintList.end(); ) {
delete (*it);
}
}
// Add a constraint
@ -43,3 +47,23 @@ void CollisionWorld::addConstraint(Constraint* constraint) throw(std::invalid_ar
void CollisionWorld::removeConstraint(Constraint* constraint) throw(std::invalid_argument) {
// TODO : Implement this method
}
// Remove all collision contacts constraints
void CollisionWorld::removeAllContactConstraints() {
// For all constraints
for (std::vector<Constraint*>::iterator it = constraintList.begin(); it != constraintList.end(); ) {
// Try a downcasting
Contact* contact = dynamic_cast<Contact*>(*it);
// If the constraint is a contact
if (contact != 0) {
// Delete the contact
delete (*it);
it = constraintList.erase(it);
}
else {
++it;
}
}
}

View File

@ -47,6 +47,7 @@ class CollisionWorld : public DynamicWorld {
void addConstraint(Constraint* constraint) throw(std::invalid_argument); // Add a constraint
void removeConstraint(Constraint* constraint) throw(std::invalid_argument); // Remove a constraint
void removeAllContactConstraints(); // Remove all collision contacts constraints
std::vector<Constraint*>::const_iterator getConstraintListStartIterator() const; // Return a start iterator on the constraint list
std::vector<Constraint*>::const_iterator getConstraintListEndIterator() const; // Return a end iterator on the constraint list
};

View File

@ -51,7 +51,7 @@ DynamicEngine::~DynamicEngine() {
}
// Update the state of a rigid body
void DynamicEngine::updateBodyState(RigidBody* const rigidBody) {
void DynamicEngine::updateBodyState(RigidBody* const rigidBody, const Time& timeStep) {
// If the gravity force is on
if(world->getIsGravityOn()) {
@ -63,12 +63,15 @@ 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
integrationAlgorithm->integrate(rigidBody->getCurrentBodyState(), timer.getTime(), timer.getTimeStep());
integrationAlgorithm->integrate(rigidBody->getCurrentBodyState(), timer.getTime(), timeStep);
// If the body state has changed, we have to update some informations in the rigid body
rigidBody->update();
}
// Update the physics simulation
void DynamicEngine::update() {
// Check if the physics simulation is running
if (timer.getIsRunning()) {
// While the time accumulator is not empty
@ -79,7 +82,7 @@ void DynamicEngine::update() {
RigidBody* rigidBody = dynamic_cast<RigidBody*>(*it);
if (rigidBody && rigidBody->getIsMotionEnabled()) {
// Update the state of the rigid body
updateBodyState(rigidBody);
updateBodyState(rigidBody, timer.getTimeStep());
}
}

View File

@ -43,14 +43,14 @@ class DynamicEngine : public PhysicsEngine {
protected :
IntegrationAlgorithm* integrationAlgorithm; // Integration algorithm used to solve differential equations of movement
void updateBodyState(RigidBody* const rigidBody); // Update the state of a rigid body
void updateBodyState(RigidBody* const rigidBody, const Time& timeStep); // Update the state of a rigid body
public :
DynamicEngine(DynamicWorld* world, const Time& timeStep); // Constructor
DynamicEngine(const DynamicEngine& engine); // Copy-constructor
virtual ~DynamicEngine(); // Destructor
void update(); // Update the physics simulation
virtual void update(); // Update the physics simulation
};
}

View File

@ -58,7 +58,7 @@ inline void PhysicsEngine::start() {
}
inline void PhysicsEngine::stop() {
// TODO : Implement this method
timer.setIsRunning(false);
}
// Initialize the display time

View File

@ -112,12 +112,15 @@ inline void Timer::setCurrentDisplayTime(const Time& currentDisplayTime) {
// Update the timer
inline void Timer::update() {
// Check if the timer is running
if (isRunning) {
// Update the current time of the physics engine
time.setValue(time.getValue() + timeStep.getValue());
// Update the accumulator value
accumulator -= timeStep.getValue();
}
}
// Compute and return the interpolation factor between two body states
inline double Timer::getInterpolationFactor() const {