git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@206 92aac97c-a6ce-11dd-a772-7fcde58d38e6
This commit is contained in:
parent
ef629b355d
commit
2640f92755
|
@ -27,7 +27,6 @@ using namespace reactphysics3d;
|
||||||
// Constructor
|
// Constructor
|
||||||
CollisionEngine::CollisionEngine(CollisionWorld* world, const Time& timeStep)
|
CollisionEngine::CollisionEngine(CollisionWorld* world, const Time& timeStep)
|
||||||
:DynamicEngine(world, timeStep) {
|
:DynamicEngine(world, timeStep) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
|
@ -37,34 +36,20 @@ CollisionEngine::~CollisionEngine() {
|
||||||
|
|
||||||
// Update the physics simulation
|
// Update the physics simulation
|
||||||
void CollisionEngine::update() {
|
void CollisionEngine::update() {
|
||||||
|
|
||||||
CollisionWorld* collisionWorld = dynamic_cast<CollisionWorld*>(world);
|
CollisionWorld* collisionWorld = dynamic_cast<CollisionWorld*>(world);
|
||||||
assert(collisionWorld != 0);
|
assert(collisionWorld != 0);
|
||||||
|
|
||||||
// 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()) {
|
||||||
|
|
||||||
// Remove all old collision contact constraints
|
// Remove all old collision contact constraints
|
||||||
collisionWorld->removeAllContactConstraints();
|
collisionWorld->removeAllContactConstraints();
|
||||||
|
|
||||||
Time timeFirst(0); // First collision time
|
|
||||||
Time timeLast(DBL_MAX); // Last collision separation time
|
|
||||||
|
|
||||||
// Compute the collision detection
|
// Compute the collision detection
|
||||||
if (collisionDetection.computeCollisionDetection(collisionWorld, timer.getTimeStep(), timeFirst)) {
|
if (collisionDetection.computeCollisionDetection(collisionWorld)) {
|
||||||
// For each body in the dynamic world
|
// TODO : Do collision response here
|
||||||
for(std::vector<Body*>::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<RigidBody*>(*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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// For each body in the dynamic world
|
// For each body in the dynamic world
|
||||||
for(std::vector<Body*>::const_iterator it = world->getBodyListStartIterator(); it != world->getBodyListEndIterator(); ++it) {
|
for(std::vector<Body*>::const_iterator it = world->getBodyListStartIterator(); it != world->getBodyListEndIterator(); ++it) {
|
||||||
// If the body is a RigidBody and if the rigid body motion is enabled
|
// If the body is a RigidBody and if the rigid body motion is enabled
|
||||||
|
@ -72,8 +57,6 @@ void CollisionEngine::update() {
|
||||||
if (rigidBody && rigidBody->getIsMotionEnabled()) {
|
if (rigidBody && rigidBody->getIsMotionEnabled()) {
|
||||||
// Update the state of the rigid body with an entire time step
|
// Update the state of the rigid body with an entire time step
|
||||||
updateBodyState(rigidBody, timer.getTimeStep());
|
updateBodyState(rigidBody, timer.getTimeStep());
|
||||||
std::cout << "NO NO NO" << std::endl; // TODO : DELETE THIS
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +64,7 @@ void CollisionEngine::update() {
|
||||||
timer.update();
|
timer.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
// For each body in the dynamic world
|
// For each body in the the dynamic world
|
||||||
for(std::vector<Body*>::const_iterator it = world->getBodyListStartIterator(); it != world->getBodyListEndIterator(); ++it) {
|
for(std::vector<Body*>::const_iterator it = world->getBodyListStartIterator(); it != world->getBodyListEndIterator(); ++it) {
|
||||||
// If the body is a RigidBody and if the rigid body motion is enabled
|
// If the body is a RigidBody and if the rigid body motion is enabled
|
||||||
RigidBody* rigidBody = dynamic_cast<RigidBody*>(*it);
|
RigidBody* rigidBody = dynamic_cast<RigidBody*>(*it);
|
||||||
|
|
|
@ -19,8 +19,7 @@
|
||||||
|
|
||||||
// Libraries
|
// Libraries
|
||||||
#include "DynamicEngine.h"
|
#include "DynamicEngine.h"
|
||||||
#include "RK4.h"
|
#include "integration/RungeKutta.h"
|
||||||
#include "Euler.h"
|
|
||||||
|
|
||||||
// We want to use the ReactPhysics3D namespace
|
// We want to use the ReactPhysics3D namespace
|
||||||
using namespace reactphysics3d;
|
using namespace reactphysics3d;
|
||||||
|
@ -35,7 +34,7 @@ DynamicEngine::DynamicEngine(DynamicWorld* world, const Time& timeStep)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creation of the RK4 integration algorithm
|
// Creation of the RK4 integration algorithm
|
||||||
integrationAlgorithm = new RK4();
|
integrationAlgorithm = new RungeKutta4();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy-constructor
|
// 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
|
// If the body state has changed, we have to update some informations in the rigid body
|
||||||
rigidBody->update();
|
rigidBody->update();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the physics simulation
|
// Update the physics simulation
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
// Libraries
|
// Libraries
|
||||||
#include "PhysicsEngine.h"
|
#include "PhysicsEngine.h"
|
||||||
#include "IntegrationAlgorithm.h"
|
#include "../integration/IntegrationAlgorithm.h"
|
||||||
#include "../body/Body.h"
|
#include "../body/Body.h"
|
||||||
#include "../body/RigidBody.h"
|
#include "../body/RigidBody.h"
|
||||||
#include "../body/BodyState.h"
|
#include "../body/BodyState.h"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user