diff --git a/sources/reactphysics3d/engine/PhysicsWorld.cpp b/sources/reactphysics3d/engine/PhysicsWorld.cpp index ba3a5550..0be49688 100644 --- a/sources/reactphysics3d/engine/PhysicsWorld.cpp +++ b/sources/reactphysics3d/engine/PhysicsWorld.cpp @@ -29,13 +29,6 @@ PhysicsWorld::PhysicsWorld(const Vector3D& gravity) } -// Copy-constructor -PhysicsWorld::PhysicsWorld(const PhysicsWorld& world) { - bodyList = world.bodyList; - gravity = world.gravity; - isGravityOn = world.isGravityOn; -} - // Destructor PhysicsWorld::~PhysicsWorld() { @@ -87,3 +80,35 @@ void PhysicsWorld::removeBody(Body const* const body) throw(std::invalid_argumen throw std::invalid_argument("Exception in PhysicsWorld::removeBody() : The argument pointer cannot be NULL"); } } + +// Add a constraint into the physics world +void PhysicsWorld::addConstraint(Constraint* constraint) throw(std::invalid_argument) { + assert(constraint != 0); + constraintList.push_back(constraint); +} + +// Remove a constraint +void PhysicsWorld::removeConstraint(Constraint* constraint) throw(std::invalid_argument) { + // TODO : Implement this method +} + +// Remove all collision contacts constraints +void PhysicsWorld::removeAllContactConstraints() { + // For all constraints + for (std::vector::iterator it = constraintList.begin(); it != constraintList.end(); ) { + + // Try a downcasting + Contact* contact = dynamic_cast(*it); + + // If the constraint is a contact + if (contact != 0) { + // Delete the contact + delete (*it); + it = constraintList.erase(it); + } + else { + ++it; + } + } +} + diff --git a/sources/reactphysics3d/engine/PhysicsWorld.h b/sources/reactphysics3d/engine/PhysicsWorld.h index 6ecb15ff..664e9392 100644 --- a/sources/reactphysics3d/engine/PhysicsWorld.h +++ b/sources/reactphysics3d/engine/PhysicsWorld.h @@ -31,20 +31,20 @@ namespace reactphysics3d { /* ------------------------------------------------------------------- Class PhysicsWorld : - This is an (abstract) class that represents the world of the - physics engine. A physics world contains all the bodies of the physics + This class represents the world of the + physics engine. The physics world contains all the bodies of the physics engine. ------------------------------------------------------------------- */ class PhysicsWorld { protected : std::vector bodyList; // list that contains all bodies of the physics world + std::vector constraintList; // List that contains all the current constraints Vector3D gravity; // Gravity vector of the world bool isGravityOn; // True if the gravity force is on public : PhysicsWorld(const Vector3D& gravity); // Constructor - PhysicsWorld(const PhysicsWorld&); // Copy-constructor virtual ~PhysicsWorld(); // Destructor void addBody(Body* body) throw(std::invalid_argument); // Add a body to the physics world @@ -54,6 +54,11 @@ class PhysicsWorld { void setIsGratityOn(bool isGravityOn); // Set the isGravityOn attribute std::vector::const_iterator getBodyListStartIterator() const; // Return a start iterator on the body list std::vector::const_iterator getBodyListEndIterator() const; // Return a end iterator on the body list + 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::const_iterator getConstraintListStartIterator() const; // Return a start iterator on the constraint list + std::vector::const_iterator getConstraintListEndIterator() const; // Return a end iterator on the constraint list }; // --- Inline functions --- //