-Remove unnecessary contact manifold

-Delete the BroadPhasePair class
This commit is contained in:
Daniel Chappuis 2014-11-21 21:27:09 +01:00
parent 2570d794c3
commit 5f7af61593
15 changed files with 37 additions and 243 deletions

View File

@ -79,8 +79,6 @@ SET (REACTPHYSICS3D_SOURCES
"src/collision/shapes/CylinderShape.cpp" "src/collision/shapes/CylinderShape.cpp"
"src/collision/shapes/SphereShape.h" "src/collision/shapes/SphereShape.h"
"src/collision/shapes/SphereShape.cpp" "src/collision/shapes/SphereShape.cpp"
"src/collision/BroadPhasePair.h"
"src/collision/BroadPhasePair.cpp"
"src/collision/RaycastInfo.h" "src/collision/RaycastInfo.h"
"src/collision/RaycastInfo.cpp" "src/collision/RaycastInfo.cpp"
"src/collision/ProxyShape.h" "src/collision/ProxyShape.h"

View File

@ -102,7 +102,7 @@ Scene::Scene(Viewer* viewer, const std::string& shaderFolderPath, const std::str
} }
// Create all the spheres of the scene // Create all the spheres of the scene
for (int i=0; i<NB_SPHERES; i++) { for (int i=0; i<NB_CUBES; i++) {
// Position // Position
float angle = i * 35.0f; float angle = i * 35.0f;
@ -301,15 +301,6 @@ Scene::~Scene() {
delete (*it); delete (*it);
} }
// Destroy all the visual contact points
for (std::vector<VisualContactPoint*>::iterator it = mContactPoints.begin();
it != mContactPoints.end(); ++it) {
delete (*it);
}
// Destroy the static data for the visual contact points
VisualContactPoint::destroyStaticData();
// Destroy the rigid body of the floor // Destroy the rigid body of the floor
mDynamicsWorld->destroyRigidBody(mFloor->getRigidBody()); mDynamicsWorld->destroyRigidBody(mFloor->getRigidBody());
@ -380,27 +371,6 @@ void Scene::simulate() {
(*it)->updateTransform(); (*it)->updateTransform();
} }
// Destroy all the visual contact points
for (std::vector<VisualContactPoint*>::iterator it = mContactPoints.begin();
it != mContactPoints.end(); ++it) {
delete (*it);
}
mContactPoints.clear();
// Generate the new visual contact points
const std::vector<rp3d::ContactManifold*>& manifolds = mDynamicsWorld->getContactManifolds();
for (std::vector<rp3d::ContactManifold*>::const_iterator it = manifolds.begin();
it != manifolds.end(); ++it) {
for (unsigned int i=0; i<(*it)->getNbContactPoints(); i++) {
rp3d::ContactPoint* point = (*it)->getContactPoint(i);
const rp3d::Vector3 pos = point->getWorldPointOnBody1();
openglframework::Vector3 position(pos.x, pos.y, pos.z);
VisualContactPoint* visualPoint = new VisualContactPoint(position);
mContactPoints.push_back(visualPoint);
}
}
mFloor->updateTransform(); mFloor->updateTransform();
} }
} }
@ -466,12 +436,6 @@ void Scene::render() {
(*it)->render(mPhongShader, worldToCameraMatrix); (*it)->render(mPhongShader, worldToCameraMatrix);
} }
// Render all the visual contact points
for (std::vector<VisualContactPoint*>::iterator it = mContactPoints.begin();
it != mContactPoints.end(); ++it) {
(*it)->render(mPhongShader, worldToCameraMatrix);
}
// Render the floor // Render the floor
mFloor->render(mPhongShader, worldToCameraMatrix); mFloor->render(mPhongShader, worldToCameraMatrix);

View File

@ -41,7 +41,7 @@
// Constants // Constants
const int NB_BOXES = 2; const int NB_BOXES = 2;
const int NB_SPHERES = 1; const int NB_CUBES = 1;
const int NB_CONES = 3; const int NB_CONES = 3;
const int NB_CYLINDERS = 2; const int NB_CYLINDERS = 2;
const int NB_CAPSULES = 1; const int NB_CAPSULES = 1;
@ -97,9 +97,6 @@ class Scene {
/// All the dumbbell of the scene /// All the dumbbell of the scene
std::vector<Dumbbell*> mDumbbells; std::vector<Dumbbell*> mDumbbells;
/// All the visual contact points
std::vector<VisualContactPoint*> mContactPoints;
/// Box for the floor /// Box for the floor
Box* mFloor; Box* mFloor;

View File

@ -60,7 +60,7 @@ Scene::Scene(Viewer* viewer, const std::string& shaderFolderPath)
float radius = 2.0f; float radius = 2.0f;
// Create all the cubes of the scene // Create all the cubes of the scene
for (int i=0; i<NB_SPHERES; i++) { for (int i=0; i<NB_CUBES; i++) {
// Position of the cubes // Position of the cubes
float angle = i * 30.0f; float angle = i * 30.0f;
@ -132,7 +132,9 @@ void Scene::simulate() {
if (mIsRunning) { if (mIsRunning) {
counter++; counter++;
if (counter == 1000) mIsRunning = false; if (counter == 400) {
//mIsRunning = false;
}
// Take a simulation step // Take a simulation step
mDynamicsWorld->update(); mDynamicsWorld->update();

View File

@ -33,7 +33,7 @@
#include "Viewer.h" #include "Viewer.h"
// Constants // Constants
const int NB_SPHERES = 200; // Number of boxes in the scene const int NB_CUBES = 200; // Number of boxes in the scene
const openglframework::Vector3 BOX_SIZE(2, 2, 2); // Box dimensions in meters const openglframework::Vector3 BOX_SIZE(2, 2, 2); // Box dimensions in meters
const openglframework::Vector3 FLOOR_SIZE(50, 0.5f, 50); // Floor dimensions in meters const openglframework::Vector3 FLOOR_SIZE(50, 0.5f, 50); // Floor dimensions in meters
const float BOX_MASS = 1.0f; // Box mass in kilograms const float BOX_MASS = 1.0f; // Box mass in kilograms

View File

@ -246,10 +246,30 @@ void CollisionBody::askForBroadPhaseCollisionCheck() const {
// For all the proxy collision shapes of the body // For all the proxy collision shapes of the body
for (ProxyShape* shape = mProxyCollisionShapes; shape != NULL; shape = shape->mNext) { for (ProxyShape* shape = mProxyCollisionShapes; shape != NULL; shape = shape->mNext) {
mWorld.mCollisionDetection.askForBroadPhaseCollisionCheck(shape); mWorld.mCollisionDetection.askForBroadPhaseCollisionCheck(shape);
} }
} }
// Reset the mIsAlreadyInIsland variable of the body and contact manifolds.
/// This method also returns the number of contact manifolds of the body.
int CollisionBody::resetIsAlreadyInIslandAndCountManifolds() {
mIsAlreadyInIsland = false;
int nbManifolds = 0;
// Reset the mIsAlreadyInIsland variable of the contact manifolds for
// this body
ContactManifoldListElement* currentElement = mContactManifoldsList;
while (currentElement != NULL) {
currentElement->contactManifold->mIsAlreadyInIsland = false;
currentElement = currentElement->next;
nbManifolds++;
}
return nbManifolds;
}
// Return true if a point is inside the collision body // Return true if a point is inside the collision body
bool CollisionBody::testPointInside(const Vector3& worldPoint) const { bool CollisionBody::testPointInside(const Vector3& worldPoint) const {

View File

@ -118,6 +118,9 @@ class CollisionBody : public Body {
/// (as if the body has moved). /// (as if the body has moved).
void askForBroadPhaseCollisionCheck() const; void askForBroadPhaseCollisionCheck() const;
/// Reset the mIsAlreadyInIsland variable of the body and contact manifolds
int resetIsAlreadyInIslandAndCountManifolds();
public : public :
// -------------------- Methods -------------------- // // -------------------- Methods -------------------- //

View File

@ -1,40 +0,0 @@
/********************************************************************************
* ReactPhysics3D physics library, http://code.google.com/p/reactphysics3d/ *
* Copyright (c) 2010-2013 Daniel Chappuis *
*********************************************************************************
* *
* This software is provided 'as-is', without any express or implied warranty. *
* In no event will the authors be held liable for any damages arising from the *
* use of this software. *
* *
* Permission is granted to anyone to use this software for any purpose, *
* including commercial applications, and to alter it and redistribute it *
* freely, subject to the following restrictions: *
* *
* 1. The origin of this software must not be misrepresented; you must not claim *
* that you wrote the original software. If you use this software in a *
* product, an acknowledgment in the product documentation would be *
* appreciated but is not required. *
* *
* 2. Altered source versions must be plainly marked as such, and must not be *
* misrepresented as being the original software. *
* *
* 3. This notice may not be removed or altered from any source distribution. *
* *
********************************************************************************/
// Libraries
#include "BroadPhasePair.h"
using namespace reactphysics3d;
// Constructor
BroadPhasePair::BroadPhasePair(CollisionBody* body1, CollisionBody* body2)
: body1(body1), body2(body2), previousSeparatingAxis(Vector3(1,1,1)) {
}
// Destructor
BroadPhasePair::~BroadPhasePair() {
}

View File

@ -1,111 +0,0 @@
/********************************************************************************
* ReactPhysics3D physics library, http://code.google.com/p/reactphysics3d/ *
* Copyright (c) 2010-2013 Daniel Chappuis *
*********************************************************************************
* *
* This software is provided 'as-is', without any express or implied warranty. *
* In no event will the authors be held liable for any damages arising from the *
* use of this software. *
* *
* Permission is granted to anyone to use this software for any purpose, *
* including commercial applications, and to alter it and redistribute it *
* freely, subject to the following restrictions: *
* *
* 1. The origin of this software must not be misrepresented; you must not claim *
* that you wrote the original software. If you use this software in a *
* product, an acknowledgment in the product documentation would be *
* appreciated but is not required. *
* *
* 2. Altered source versions must be plainly marked as such, and must not be *
* misrepresented as being the original software. *
* *
* 3. This notice may not be removed or altered from any source distribution. *
* *
********************************************************************************/
#ifndef REACTPHYSICS3D_BROAD_PHASE_PAIR_H
#define REACTPHYSICS3D_BROAD_PHASE_PAIR_H
// Libraries
#include "body/CollisionBody.h"
/// ReactPhysics3D namespace
namespace reactphysics3d {
// TODO : DELETE THIS CLASS
// Structure BroadPhasePair
/**
* This structure represents a pair of bodies
* during the broad-phase collision detection.
*/
struct BroadPhasePair {
public:
// -------------------- Attributes -------------------- //
/// Pointer to the first body
CollisionBody* body1;
/// Pointer to the second body
CollisionBody* body2;
/// Previous cached separating axis
Vector3 previousSeparatingAxis;
// -------------------- Methods -------------------- //
/// Constructor
BroadPhasePair(CollisionBody* body1, CollisionBody* body2);
/// Destructor
~BroadPhasePair();
/// Return the pair of bodies index
static bodyindexpair computeBodiesIndexPair(CollisionBody* body1, CollisionBody* body2);
/// Return the pair of bodies index
bodyindexpair getBodiesIndexPair() const;
/// Smaller than operator
bool operator<(const BroadPhasePair& broadPhasePair2) const;
/// Larger than operator
bool operator>(const BroadPhasePair& broadPhasePair2) const;
/// Equal operator
bool operator==(const BroadPhasePair& broadPhasePair2) const;
/// Not equal operator
bool operator!=(const BroadPhasePair& broadPhasePair2) const;
};
// Return the pair of bodies index
inline bodyindexpair BroadPhasePair::getBodiesIndexPair() const {
return computeBodiesIndexPair(body1, body2);
}
// Smaller than operator
inline bool BroadPhasePair::operator<(const BroadPhasePair& broadPhasePair2) const {
return (body1 < broadPhasePair2.body1 ? true : (body2 < broadPhasePair2.body2));
}
// Larger than operator
inline bool BroadPhasePair::operator>(const BroadPhasePair& broadPhasePair2) const {
return (body1 > broadPhasePair2.body1 ? true : (body2 > broadPhasePair2.body2));
}
// Equal operator
inline bool BroadPhasePair::operator==(const BroadPhasePair& broadPhasePair2) const {
return (body1 == broadPhasePair2.body1 && body2 == broadPhasePair2.body2);
}
// Not equal operator
inline bool BroadPhasePair::operator!=(const BroadPhasePair& broadPhasePair2) const {
return (body1 != broadPhasePair2.body1 || body2 != broadPhasePair2.body2);
}
}
#endif

View File

@ -220,9 +220,6 @@ void CollisionDetection::createContact(OverlappingPair* overlappingPair,
// Add the contact to the contact cache of the corresponding overlapping pair // Add the contact to the contact cache of the corresponding overlapping pair
overlappingPair->addContact(contact); overlappingPair->addContact(contact);
// Add the contact manifold to the list of contact manifolds
mContactManifolds.push_back(overlappingPair->getContactManifold());
// Add the contact manifold into the list of contact manifolds // Add the contact manifold into the list of contact manifolds
// of the two bodies involved in the contact // of the two bodies involved in the contact
addContactManifoldToBody(overlappingPair->getContactManifold(), addContactManifoldToBody(overlappingPair->getContactManifold(),

View File

@ -80,10 +80,6 @@ class CollisionDetection {
/// True if some collision shapes have been added previously /// True if some collision shapes have been added previously
bool mIsCollisionShapesAdded; bool mIsCollisionShapesAdded;
/// All the contact constraints
// TODO : Remove this variable (we will use the ones in the island now)
std::vector<ContactManifold*> mContactManifolds;
// -------------------- Methods -------------------- // // -------------------- Methods -------------------- //
/// Private copy-constructor /// Private copy-constructor

View File

@ -66,9 +66,6 @@ class CollisionWorld {
/// All the collision shapes of the world /// All the collision shapes of the world
std::list<CollisionShape*> mCollisionShapes; std::list<CollisionShape*> mCollisionShapes;
/// Broad-phase overlapping pairs of bodies
std::map<bodyindexpair, OverlappingPair*> mOverlappingPairs;
/// Current body ID /// Current body ID
bodyindex mCurrentBodyID; bodyindex mCurrentBodyID;

View File

@ -210,6 +210,7 @@ class ContactManifold {
friend class DynamicsWorld; friend class DynamicsWorld;
friend class Island; friend class Island;
friend class CollisionBody;
}; };
// Return a pointer to the first body of the contact manifold // Return a pointer to the first body of the contact manifold

View File

@ -57,14 +57,6 @@ DynamicsWorld::DynamicsWorld(const Vector3 &gravity, decimal timeStep = DEFAULT_
// Destructor // Destructor
DynamicsWorld::~DynamicsWorld() { DynamicsWorld::~DynamicsWorld() {
// Delete the remaining overlapping pairs
map<std::pair<bodyindex, bodyindex>, OverlappingPair*>::iterator it;
for (it = mOverlappingPairs.begin(); it != mOverlappingPairs.end(); it++) {
// Delete the overlapping pair
(*it).second->OverlappingPair::~OverlappingPair();
mMemoryAllocator.release((*it).second, sizeof(OverlappingPair));
}
// Release the memory allocated for the islands // Release the memory allocated for the islands
for (uint i=0; i<mNbIslands; i++) { for (uint i=0; i<mNbIslands; i++) {
@ -117,9 +109,6 @@ void DynamicsWorld::update() {
// While the time accumulator is not empty // While the time accumulator is not empty
while(mTimer.isPossibleToTakeStep()) { while(mTimer.isPossibleToTakeStep()) {
// Remove all contact manifolds
mCollisionDetection.mContactManifolds.clear();
// Reset all the contact manifolds lists of each body // Reset all the contact manifolds lists of each body
resetContactManifoldListsOfBodies(); resetContactManifoldListsOfBodies();
@ -676,13 +665,12 @@ void DynamicsWorld::computeIslands() {
} }
mNbIslands = 0; mNbIslands = 0;
int nbContactManifolds = 0;
// Reset all the isAlreadyInIsland variables of bodies, joints and contact manifolds // Reset all the isAlreadyInIsland variables of bodies, joints and contact manifolds
for (std::set<RigidBody*>::iterator it = mRigidBodies.begin(); it != mRigidBodies.end(); ++it) { for (std::set<RigidBody*>::iterator it = mRigidBodies.begin(); it != mRigidBodies.end(); ++it) {
(*it)->mIsAlreadyInIsland = false; int nbBodyManifolds = (*it)->resetIsAlreadyInIslandAndCountManifolds();
} nbContactManifolds += nbBodyManifolds;
for (std::vector<ContactManifold*>::iterator it = mCollisionDetection.mContactManifolds.begin();
it != mCollisionDetection.mContactManifolds.end(); ++it) {
(*it)->mIsAlreadyInIsland = false;
} }
for (std::set<Joint*>::iterator it = mJoints.begin(); it != mJoints.end(); ++it) { for (std::set<Joint*>::iterator it = mJoints.begin(); it != mJoints.end(); ++it) {
(*it)->mIsAlreadyInIsland = false; (*it)->mIsAlreadyInIsland = false;
@ -715,7 +703,7 @@ void DynamicsWorld::computeIslands() {
// Create the new island // Create the new island
void* allocatedMemoryIsland = mMemoryAllocator.allocate(sizeof(Island)); void* allocatedMemoryIsland = mMemoryAllocator.allocate(sizeof(Island));
mIslands[mNbIslands] = new (allocatedMemoryIsland) Island(nbBodies, mIslands[mNbIslands] = new (allocatedMemoryIsland) Island(nbBodies,
mCollisionDetection.mContactManifolds.size(), nbContactManifolds,
mJoints.size(), mMemoryAllocator); mJoints.size(), mMemoryAllocator);
// While there are still some bodies to visit in the stack // While there are still some bodies to visit in the stack

View File

@ -242,9 +242,6 @@ class DynamicsWorld : public CollisionWorld {
/// Return the number of joints in the world /// Return the number of joints in the world
uint getNbJoints() const; uint getNbJoints() const;
/// Return the number of contact manifolds in the world
uint getNbContactManifolds() const;
/// Return the current physics time (in seconds) /// Return the current physics time (in seconds)
long double getPhysicsTime() const; long double getPhysicsTime() const;
@ -254,9 +251,6 @@ class DynamicsWorld : public CollisionWorld {
/// Return an iterator to the end of the rigid bodies of the physics world /// Return an iterator to the end of the rigid bodies of the physics world
std::set<RigidBody*>::iterator getRigidBodiesEndIterator(); std::set<RigidBody*>::iterator getRigidBodiesEndIterator();
/// Return a reference to the contact manifolds of the world
const std::vector<ContactManifold*>& getContactManifolds() const;
/// Return true if the sleeping technique is enabled /// Return true if the sleeping technique is enabled
bool isSleepingEnabled() const; bool isSleepingEnabled() const;
@ -382,18 +376,6 @@ inline std::set<RigidBody*>::iterator DynamicsWorld::getRigidBodiesEndIterator()
return mRigidBodies.end(); return mRigidBodies.end();
} }
// Return a reference to the contact manifolds of the world
// TODO : DELETE THIS METHOD AND USE EVENT LISTENER IN EXAMPLES INSTEAD
inline const std::vector<ContactManifold*>& DynamicsWorld::getContactManifolds() const {
return mCollisionDetection.mContactManifolds;
}
// Return the number of contact manifolds in the world
// TODO : DELETE THIS METHOD AND USE EVENT LISTENER IN EXAMPLES INSTEAD
inline uint DynamicsWorld::getNbContactManifolds() const {
return mCollisionDetection.mContactManifolds.size();
}
// Return the current physics time (in seconds) // Return the current physics time (in seconds)
inline long double DynamicsWorld::getPhysicsTime() const { inline long double DynamicsWorld::getPhysicsTime() const {
return mTimer.getPhysicsTime(); return mTimer.getPhysicsTime();