constraintBodies is now a std::set

git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@333 92aac97c-a6ce-11dd-a772-7fcde58d38e6
This commit is contained in:
chappuis.daniel 2010-06-15 21:16:31 +00:00
parent 9695ab5556
commit 4e19ab899d
2 changed files with 9 additions and 7 deletions

View File

@ -54,8 +54,8 @@ void ConstraintSolver::allocate() {
activeConstraints.push_back(constraint); activeConstraints.push_back(constraint);
// Add the two bodies of the constraint in the constraintBodies list // Add the two bodies of the constraint in the constraintBodies list
constraintBodies.push_back(constraint->getBody1()); constraintBodies.insert(constraint->getBody1());
constraintBodies.push_back(constraint->getBody2()); constraintBodies.insert(constraint->getBody2());
// Fill in the body number maping // Fill in the body number maping
bodyNumberMapping.insert(std::pair<Body*, unsigned int>(constraint->getBody1(), bodyNumberMapping.size())); bodyNumberMapping.insert(std::pair<Body*, unsigned int>(constraint->getBody1(), bodyNumberMapping.size()));
@ -148,8 +148,9 @@ void ConstraintSolver::fillInMatrices() {
Body* body; Body* body;
Vector v(6); Vector v(6);
Vector f(6); Vector f(6);
for (uint b=0; b<nbBodies; b++) { uint b=0;
body = constraintBodies.at(b); for (std::set<Body*>::iterator it = constraintBodies.begin(); it != constraintBodies.end(); it++, b++) {
body = *it;
uint bodyNumber = bodyNumberMapping.at(body); uint bodyNumber = bodyNumberMapping.at(body);
// TODO : Use polymorphism and remove this downcasting // TODO : Use polymorphism and remove this downcasting
@ -283,8 +284,8 @@ void ConstraintSolver::solve(double dt) {
// Update the velocity of each body // Update the velocity of each body
// TODO : Put this code somewhere else // TODO : Put this code somewhere else
for (int i=0; i<nbBodies; i++) { for (std::set<Body*>::iterator it = constraintBodies.begin(); it != constraintBodies.end(); it++) {
RigidBody* body = dynamic_cast<RigidBody*>(constraintBodies.at(i)); RigidBody* body = dynamic_cast<RigidBody*>(*it);
//std::cout << "Velocity Y before : " << body->getCurrentBodyState().getLinearVelocity().getY() << std::endl; //std::cout << "Velocity Y before : " << body->getCurrentBodyState().getLinearVelocity().getY() << std::endl;
//std::cout << "Velocity Y after : " << V[bodyNumberMapping[constraintBodies.at(i)]].getValue(1) << std::endl; //std::cout << "Velocity Y after : " << V[bodyNumberMapping[constraintBodies.at(i)]].getValue(1) << std::endl;
} }

View File

@ -27,6 +27,7 @@
#include "../integration/IntegrationAlgorithm.h" // TODO : Delete this #include "../integration/IntegrationAlgorithm.h" // TODO : Delete this
#include "PhysicsWorld.h" #include "PhysicsWorld.h"
#include <map> #include <map>
#include <set>
// ReactPhysics3D namespace // ReactPhysics3D namespace
namespace reactphysics3d { namespace reactphysics3d {
@ -47,7 +48,7 @@ class ConstraintSolver {
LCPSolver* lcpSolver; // LCP Solver LCPSolver* lcpSolver; // LCP Solver
std::vector<Constraint*> activeConstraints; // Current active constraints in the physics world std::vector<Constraint*> activeConstraints; // Current active constraints in the physics world
uint nbConstraints; // Total number of constraints (with the auxiliary constraints) uint nbConstraints; // Total number of constraints (with the auxiliary constraints)
std::vector<Body*> constraintBodies; // Bodies that are implied in some constraint std::set<Body*> constraintBodies; // Bodies that are implied in some constraint
uint nbBodies; // Current number of bodies in the physics world uint nbBodies; // Current number of bodies in the physics world
std::map<Body*, uint> bodyNumberMapping; // Map a body pointer with its index number std::map<Body*, uint> bodyNumberMapping; // Map a body pointer with its index number
Body*** bodyMapping; // 2-dimensional array that contains the mapping of body reference Body*** bodyMapping; // 2-dimensional array that contains the mapping of body reference