2012-10-03 19:00:17 +00:00
|
|
|
/********************************************************************************
|
|
|
|
* ReactPhysics3D physics library, http://code.google.com/p/reactphysics3d/ *
|
2013-03-02 15:26:18 +00:00
|
|
|
* Copyright (c) 2010-2013 Daniel Chappuis *
|
2012-10-03 19:00:17 +00:00
|
|
|
*********************************************************************************
|
|
|
|
* *
|
|
|
|
* 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. *
|
|
|
|
* *
|
|
|
|
********************************************************************************/
|
|
|
|
|
2013-04-18 20:54:36 +00:00
|
|
|
#ifndef REACTPHYSICS3D_COLLISION_WORLD_H
|
|
|
|
#define REACTPHYSICS3D_COLLISION_WORLD_H
|
2012-10-03 19:00:17 +00:00
|
|
|
|
|
|
|
// Libraries
|
|
|
|
#include <vector>
|
|
|
|
#include <set>
|
2013-04-22 19:25:40 +00:00
|
|
|
#include <list>
|
2012-10-03 19:00:17 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include "../mathematics/mathematics.h"
|
2013-03-26 20:37:55 +00:00
|
|
|
#include "Profiler.h"
|
2012-10-03 19:00:17 +00:00
|
|
|
#include "../body/CollisionBody.h"
|
|
|
|
#include "OverlappingPair.h"
|
|
|
|
#include "../collision/CollisionDetection.h"
|
2013-09-07 08:57:58 +00:00
|
|
|
#include "../constraint/Joint.h"
|
2013-02-26 21:43:45 +00:00
|
|
|
#include "../constraint/ContactPoint.h"
|
2013-04-01 21:43:50 +00:00
|
|
|
#include "../memory/MemoryAllocator.h"
|
2013-09-10 19:33:52 +00:00
|
|
|
#include "EventListener.h"
|
2012-10-03 19:00:17 +00:00
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Namespace reactphysics3d
|
2012-10-03 19:00:17 +00:00
|
|
|
namespace reactphysics3d {
|
2013-03-05 22:09:50 +00:00
|
|
|
|
|
|
|
// Class CollisionWorld
|
|
|
|
/**
|
|
|
|
* This class represent a world where it is possible to move bodies
|
|
|
|
* by hand and to test collision between each other. In this kind of
|
|
|
|
* world, the bodies movement is not computed using the laws of physics.
|
|
|
|
*/
|
2012-10-03 19:00:17 +00:00
|
|
|
class CollisionWorld {
|
|
|
|
|
|
|
|
protected :
|
|
|
|
|
2012-10-09 20:21:02 +00:00
|
|
|
// -------------------- Attributes -------------------- //
|
2012-10-03 19:00:17 +00:00
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Reference to the collision detection
|
2012-10-09 20:21:02 +00:00
|
|
|
CollisionDetection mCollisionDetection;
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// All the bodies (rigid and soft) of the world
|
2012-10-09 20:21:02 +00:00
|
|
|
std::set<CollisionBody*> mBodies;
|
|
|
|
|
2013-04-22 19:25:40 +00:00
|
|
|
/// All the collision shapes of the world
|
|
|
|
std::list<CollisionShape*> mCollisionShapes;
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Broad-phase overlapping pairs of bodies
|
2012-10-09 20:21:02 +00:00
|
|
|
std::map<bodyindexpair, OverlappingPair*> mOverlappingPairs;
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Current body ID
|
2012-10-09 20:21:02 +00:00
|
|
|
bodyindex mCurrentBodyID;
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// List of free ID for rigid bodies
|
2012-10-09 20:21:02 +00:00
|
|
|
std::vector<luint> mFreeBodiesIDs;
|
|
|
|
|
2013-04-01 21:43:50 +00:00
|
|
|
/// Memory allocator
|
|
|
|
MemoryAllocator mMemoryAllocator;
|
|
|
|
|
2012-10-09 20:21:02 +00:00
|
|
|
// -------------------- Methods -------------------- //
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Private copy-constructor
|
2012-10-09 20:21:02 +00:00
|
|
|
CollisionWorld(const CollisionWorld& world);
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Private assignment operator
|
2012-10-09 20:21:02 +00:00
|
|
|
CollisionWorld& operator=(const CollisionWorld& world);
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Notify the world about a new narrow-phase contact
|
2014-04-11 21:50:00 +00:00
|
|
|
virtual void notifyNewContact(const OverlappingPair* pair,
|
2013-09-10 19:33:52 +00:00
|
|
|
const ContactPointInfo* contactInfo);
|
2012-10-09 20:21:02 +00:00
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Update the overlapping pair
|
2014-04-11 21:50:00 +00:00
|
|
|
virtual void updateOverlappingPair(const OverlappingPair* pair);
|
2012-10-09 20:21:02 +00:00
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Return the next available body ID
|
2012-10-09 20:21:02 +00:00
|
|
|
bodyindex computeNextAvailableBodyID();
|
2012-10-03 19:00:17 +00:00
|
|
|
|
2013-04-22 19:25:40 +00:00
|
|
|
/// Remove a collision shape.
|
|
|
|
void removeCollisionShape(CollisionShape* collisionShape);
|
|
|
|
|
2014-04-11 21:50:00 +00:00
|
|
|
/// Create a new collision shape in the world.
|
|
|
|
CollisionShape* createCollisionShape(const CollisionShape& collisionShape);
|
|
|
|
|
2012-10-03 19:00:17 +00:00
|
|
|
public :
|
2012-10-09 20:21:02 +00:00
|
|
|
|
2013-04-22 19:25:40 +00:00
|
|
|
// -------------------- Methods -------------------- //
|
2012-10-09 20:21:02 +00:00
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Constructor
|
2012-10-09 20:21:02 +00:00
|
|
|
CollisionWorld();
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Destructor
|
2012-10-09 20:21:02 +00:00
|
|
|
virtual ~CollisionWorld();
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Return an iterator to the beginning of the bodies of the physics world
|
2012-10-09 20:21:02 +00:00
|
|
|
std::set<CollisionBody*>::iterator getBodiesBeginIterator();
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Return an iterator to the end of the bodies of the physics world
|
2012-10-09 20:21:02 +00:00
|
|
|
std::set<CollisionBody*>::iterator getBodiesEndIterator();
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Create a collision body
|
2012-10-03 19:00:17 +00:00
|
|
|
CollisionBody* createCollisionBody(const Transform& transform,
|
2012-10-09 20:21:02 +00:00
|
|
|
CollisionShape* collisionShape);
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Destroy a collision body
|
2012-10-09 20:21:02 +00:00
|
|
|
void destroyCollisionBody(CollisionBody* collisionBody);
|
|
|
|
|
2013-04-22 19:25:40 +00:00
|
|
|
// -------------------- Friends -------------------- //
|
2012-10-03 19:00:17 +00:00
|
|
|
|
|
|
|
friend class CollisionDetection;
|
2014-04-11 21:50:00 +00:00
|
|
|
friend class CollisionBody;
|
|
|
|
friend class RigidBody;
|
2012-10-03 19:00:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Return an iterator to the beginning of the bodies of the physics world
|
|
|
|
inline std::set<CollisionBody*>::iterator CollisionWorld::getBodiesBeginIterator() {
|
2012-10-09 20:21:02 +00:00
|
|
|
return mBodies.begin();
|
2012-10-03 19:00:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return an iterator to the end of the bodies of the physics world
|
|
|
|
inline std::set<CollisionBody*>::iterator CollisionWorld::getBodiesEndIterator() {
|
2012-10-09 20:21:02 +00:00
|
|
|
return mBodies.end();
|
2012-10-03 19:00:17 +00:00
|
|
|
}
|
|
|
|
|
2013-03-02 15:26:18 +00:00
|
|
|
}
|
2012-10-03 19:00:17 +00:00
|
|
|
|
|
|
|
#endif
|