2011-10-18 22:03:05 +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 *
|
2011-10-18 22:03:05 +00:00
|
|
|
*********************************************************************************
|
|
|
|
* *
|
2011-11-13 17:49:03 +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. *
|
2011-10-18 22:03:05 +00:00
|
|
|
* *
|
2011-11-13 17:49:03 +00:00
|
|
|
* 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. *
|
2011-10-18 22:03:05 +00:00
|
|
|
* *
|
|
|
|
********************************************************************************/
|
|
|
|
|
2013-04-18 20:54:36 +00:00
|
|
|
#ifndef REACTPHYSICS3D_OVERLAPPING_PAIR_H
|
|
|
|
#define REACTPHYSICS3D_OVERLAPPING_PAIR_H
|
2011-10-18 22:03:05 +00:00
|
|
|
|
|
|
|
// Libraries
|
2013-02-26 21:43:45 +00:00
|
|
|
#include "ContactManifold.h"
|
2014-04-11 21:50:00 +00:00
|
|
|
#include "../collision/shapes/CollisionShape.h"
|
2011-10-18 22:03:05 +00:00
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// ReactPhysics3D namespace
|
2011-10-18 22:03:05 +00:00
|
|
|
namespace reactphysics3d {
|
|
|
|
|
2014-04-11 21:50:00 +00:00
|
|
|
// Type for the overlapping pair ID
|
|
|
|
typedef std::pair<uint, uint> overlappingpairid;
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
// Class OverlappingPair
|
|
|
|
/**
|
2014-04-11 21:50:00 +00:00
|
|
|
* This class represents a pair of two proxy collision shapes that are overlapping
|
2013-03-05 22:09:50 +00:00
|
|
|
* during the broad-phase collision detection. It is created when
|
2014-04-11 21:50:00 +00:00
|
|
|
* the two proxy collision shapes start to overlap and is destroyed when they do not
|
2013-03-05 22:09:50 +00:00
|
|
|
* overlap anymore. This class contains a contact manifold that
|
|
|
|
* store all the contact points between the two bodies.
|
|
|
|
*/
|
2011-10-18 22:03:05 +00:00
|
|
|
class OverlappingPair {
|
2012-10-09 20:21:02 +00:00
|
|
|
|
2011-10-18 22:03:05 +00:00
|
|
|
private:
|
2012-10-09 20:21:02 +00:00
|
|
|
|
|
|
|
// -------------------- Attributes -------------------- //
|
|
|
|
|
2014-04-11 21:50:00 +00:00
|
|
|
/// Pointer to the first proxy collision shape
|
|
|
|
ProxyShape* mShape1;
|
2012-10-09 20:21:02 +00:00
|
|
|
|
2014-04-11 21:50:00 +00:00
|
|
|
/// Pointer to the second proxy collision shape
|
|
|
|
ProxyShape* mShape2;
|
2012-10-09 20:21:02 +00:00
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Persistent contact manifold
|
2013-02-26 21:43:45 +00:00
|
|
|
ContactManifold mContactManifold;
|
2012-10-09 20:21:02 +00:00
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Cached previous separating axis
|
2012-10-09 20:21:02 +00:00
|
|
|
Vector3 mCachedSeparatingAxis;
|
2011-10-18 22:03:05 +00:00
|
|
|
|
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
|
|
|
OverlappingPair(const OverlappingPair& pair);
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Private assignment operator
|
2012-10-09 20:21:02 +00:00
|
|
|
OverlappingPair& operator=(const OverlappingPair& pair);
|
|
|
|
|
2011-10-18 22:03:05 +00:00
|
|
|
public:
|
2012-10-09 20:21:02 +00:00
|
|
|
|
|
|
|
// -------------------- Methods -------------------- //
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Constructor
|
2014-04-11 21:50:00 +00:00
|
|
|
OverlappingPair(ProxyShape* shape1, ProxyShape* shape2, MemoryAllocator& memoryAllocator);
|
2012-10-09 20:21:02 +00:00
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Destructor
|
2012-10-09 20:21:02 +00:00
|
|
|
~OverlappingPair();
|
2011-10-18 22:03:05 +00:00
|
|
|
|
2014-04-11 21:50:00 +00:00
|
|
|
/// Return the pointer to first proxy collision shape
|
|
|
|
ProxyShape* const getShape1() const;
|
2012-10-09 20:21:02 +00:00
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Return the pointer to second body
|
2014-04-11 21:50:00 +00:00
|
|
|
ProxyShape* const getShape2() const;
|
2012-10-09 20:21:02 +00:00
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Add a contact to the contact cache
|
2013-02-26 21:43:45 +00:00
|
|
|
void addContact(ContactPoint* contact);
|
2012-10-09 20:21:02 +00:00
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Update the contact cache
|
2012-10-09 20:21:02 +00:00
|
|
|
void update();
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Return the cached separating axis
|
2012-10-09 20:21:02 +00:00
|
|
|
Vector3 getCachedSeparatingAxis() const;
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Set the cached separating axis
|
2014-04-11 21:50:00 +00:00
|
|
|
// TODO : Check that this variable is correctly used allong the collision detection process
|
2012-10-09 20:21:02 +00:00
|
|
|
void setCachedSeparatingAxis(const Vector3& axis);
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Return the number of contacts in the cache
|
2013-02-28 18:50:52 +00:00
|
|
|
uint getNbContactPoints() const;
|
2012-10-09 20:21:02 +00:00
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Return the contact manifold
|
2013-02-26 21:43:45 +00:00
|
|
|
ContactManifold* getContactManifold();
|
2013-08-26 19:28:48 +00:00
|
|
|
|
2014-04-11 21:50:00 +00:00
|
|
|
/// Return the pair of bodies index
|
|
|
|
static overlappingpairid computeID(ProxyShape* shape1, ProxyShape* shape2);
|
|
|
|
|
|
|
|
/// Return the pair of bodies index of the pair
|
|
|
|
static bodyindexpair computeBodiesIndexPair(CollisionBody* body1, CollisionBody* body2);
|
|
|
|
|
2013-08-26 19:28:48 +00:00
|
|
|
// -------------------- Friendship -------------------- //
|
|
|
|
|
|
|
|
friend class DynamicsWorld;
|
2011-10-18 22:03:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Return the pointer to first body
|
2014-04-11 21:50:00 +00:00
|
|
|
inline ProxyShape* const OverlappingPair::getShape1() const {
|
|
|
|
return mShape1;
|
2011-10-18 22:03:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return the pointer to second body
|
2014-04-11 21:50:00 +00:00
|
|
|
inline ProxyShape* const OverlappingPair::getShape2() const {
|
|
|
|
return mShape2;
|
2011-10-18 22:03:05 +00:00
|
|
|
}
|
|
|
|
|
2013-02-26 21:43:45 +00:00
|
|
|
// Add a contact to the contact manifold
|
|
|
|
inline void OverlappingPair::addContact(ContactPoint* contact) {
|
|
|
|
mContactManifold.addContactPoint(contact);
|
2013-02-28 18:50:52 +00:00
|
|
|
}
|
2011-10-18 22:03:05 +00:00
|
|
|
|
2013-02-26 21:43:45 +00:00
|
|
|
// Update the contact manifold
|
2011-10-18 22:03:05 +00:00
|
|
|
inline void OverlappingPair::update() {
|
2014-04-11 21:50:00 +00:00
|
|
|
mContactManifold.update(mShape1->getBody()->getTransform(), mShape2->getBody()->getTransform());
|
2013-02-28 18:50:52 +00:00
|
|
|
}
|
2011-10-18 22:03:05 +00:00
|
|
|
|
|
|
|
// Return the cached separating axis
|
|
|
|
inline Vector3 OverlappingPair::getCachedSeparatingAxis() const {
|
2012-10-09 20:21:02 +00:00
|
|
|
return mCachedSeparatingAxis;
|
2013-02-28 18:50:52 +00:00
|
|
|
}
|
2012-01-27 22:41:26 +00:00
|
|
|
|
|
|
|
// Set the cached separating axis
|
|
|
|
inline void OverlappingPair::setCachedSeparatingAxis(const Vector3& axis) {
|
2012-10-09 20:21:02 +00:00
|
|
|
mCachedSeparatingAxis = axis;
|
2013-02-28 18:50:52 +00:00
|
|
|
}
|
2011-10-18 22:03:05 +00:00
|
|
|
|
|
|
|
|
2013-02-28 18:50:52 +00:00
|
|
|
// Return the number of contact points in the contact manifold
|
|
|
|
inline uint OverlappingPair::getNbContactPoints() const {
|
2013-02-26 21:43:45 +00:00
|
|
|
return mContactManifold.getNbContactPoints();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the contact manifold
|
|
|
|
inline ContactManifold* OverlappingPair::getContactManifold() {
|
|
|
|
return &mContactManifold;
|
2011-10-18 22:03:05 +00:00
|
|
|
}
|
|
|
|
|
2014-04-11 21:50:00 +00:00
|
|
|
// Return the pair of bodies index
|
|
|
|
inline overlappingpairid OverlappingPair::computeID(ProxyShape* shape1, ProxyShape* shape2) {
|
|
|
|
assert(shape1->mBroadPhaseID >= 0 && shape2->mBroadPhaseID >= 0);
|
|
|
|
|
|
|
|
// Construct the pair of body index
|
|
|
|
overlappingpairid pairID = shape1->mBroadPhaseID < shape2->mBroadPhaseID ?
|
|
|
|
std::make_pair(shape1->mBroadPhaseID, shape2->mBroadPhaseID) :
|
|
|
|
std::make_pair(shape2->mBroadPhaseID, shape1->mBroadPhaseID);
|
|
|
|
assert(pairID.first != pairID.second);
|
|
|
|
return pairID;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the pair of bodies index
|
|
|
|
inline bodyindexpair OverlappingPair::computeBodiesIndexPair(CollisionBody* body1,
|
|
|
|
CollisionBody* body2) {
|
|
|
|
|
|
|
|
// Construct the pair of body index
|
|
|
|
bodyindexpair indexPair = body1->getID() < body2->getID() ?
|
|
|
|
std::make_pair(body1->getID(), body2->getID()) :
|
|
|
|
std::make_pair(body2->getID(), body1->getID());
|
|
|
|
assert(indexPair.first != indexPair.second);
|
|
|
|
return indexPair;
|
|
|
|
}
|
|
|
|
|
2013-03-02 15:26:18 +00:00
|
|
|
}
|
2011-10-18 22:03:05 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|