add ability for user pair callback, this can be used to keep track of objects, overlapping a certain AABB/shape.
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
#include "btOverlappingPairCache.h"
|
||||
#include "btBroadphaseInterface.h"
|
||||
#include "btBroadphaseProxy.h"
|
||||
|
||||
#include "btOverlappingPairCallback.h"
|
||||
|
||||
//#define DEBUG_BROADPHASE 1
|
||||
|
||||
@@ -82,6 +82,10 @@ protected:
|
||||
Edge* m_pEdges[3]; // edge arrays for the 3 axes (each array has m_maxHandles * 2 + 2 sentinel entries)
|
||||
|
||||
btOverlappingPairCache* m_pairCache;
|
||||
|
||||
///btOverlappingPairCallback is an additional optional user callback for adding/removing overlapping pairs, similar interface to btOverlappingPairCache.
|
||||
btOverlappingPairCallback* m_userPairCallback;
|
||||
|
||||
bool m_ownsPairCache;
|
||||
|
||||
int m_invalidPair;
|
||||
@@ -139,7 +143,14 @@ public:
|
||||
return m_pairCache;
|
||||
}
|
||||
|
||||
|
||||
void setOverlappingPairUserCallback(btOverlappingPairCallback* pairCallback)
|
||||
{
|
||||
m_userPairCallback = pairCallback;
|
||||
}
|
||||
const btOverlappingPairCallback* getOverlappingPairUserCallback() const
|
||||
{
|
||||
return m_userPairCallback;
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@@ -209,6 +220,7 @@ btAxisSweep3Internal<BP_FP_INT_TYPE>::btAxisSweep3Internal(const btPoint3& world
|
||||
:m_bpHandleMask(handleMask),
|
||||
m_handleSentinel(handleSentinel),
|
||||
m_pairCache(pairCache),
|
||||
m_userPairCallback(0),
|
||||
m_ownsPairCache(false),
|
||||
m_invalidPair(0)
|
||||
{
|
||||
@@ -658,6 +670,8 @@ void btAxisSweep3Internal<BP_FP_INT_TYPE>::sortMinDown(int axis, BP_FP_INT_TYPE
|
||||
if (updateOverlaps && testOverlap(axis,pHandleEdge, pHandlePrev))
|
||||
{
|
||||
m_pairCache->addOverlappingPair(pHandleEdge,pHandlePrev);
|
||||
if (m_userPairCallback)
|
||||
m_userPairCallback->addOverlappingPair(pHandleEdge,pHandlePrev);
|
||||
|
||||
//AddOverlap(pEdge->m_handle, pPrev->m_handle);
|
||||
|
||||
@@ -709,6 +723,9 @@ void btAxisSweep3Internal<BP_FP_INT_TYPE>::sortMinUp(int axis, BP_FP_INT_TYPE ed
|
||||
Handle* handle1 = getHandle(pNext->m_handle);
|
||||
|
||||
m_pairCache->removeOverlappingPair(handle0,handle1,dispatcher);
|
||||
if (m_userPairCallback)
|
||||
m_userPairCallback->removeOverlappingPair(handle0,handle1);
|
||||
|
||||
}
|
||||
#endif //USE_LAZY_REMOVAL
|
||||
|
||||
@@ -756,6 +773,8 @@ void btAxisSweep3Internal<BP_FP_INT_TYPE>::sortMaxDown(int axis, BP_FP_INT_TYPE
|
||||
Handle* handle0 = getHandle(pEdge->m_handle);
|
||||
Handle* handle1 = getHandle(pPrev->m_handle);
|
||||
m_pairCache->removeOverlappingPair(handle0,handle1,dispatcher);
|
||||
if (m_userPairCallback)
|
||||
m_userPairCallback->removeOverlappingPair(handle0,handle1);
|
||||
|
||||
#endif //USE_LAZY_REMOVAL
|
||||
|
||||
@@ -806,6 +825,8 @@ void btAxisSweep3Internal<BP_FP_INT_TYPE>::sortMaxUp(int axis, BP_FP_INT_TYPE ed
|
||||
Handle* handle0 = getHandle(pEdge->m_handle);
|
||||
Handle* handle1 = getHandle(pNext->m_handle);
|
||||
m_pairCache->addOverlappingPair(handle0,handle1);
|
||||
if (m_userPairCallback)
|
||||
m_userPairCallback->addOverlappingPair(handle0,handle1);
|
||||
}
|
||||
|
||||
// update edge reference in other handle
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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 OVERLAPPING_PAIR_CALLBACK_H
|
||||
#define OVERLAPPING_PAIR_CALLBACK_H
|
||||
|
||||
///btOverlappingPairCallback provides user callback to keep track of overlap between objects, like a collision sensor
|
||||
class btOverlappingPairCallback
|
||||
{
|
||||
public:
|
||||
virtual ~btOverlappingPairCallback()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
virtual void addOverlappingPair(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1) = 0;
|
||||
|
||||
virtual void removeOverlappingPair(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1) = 0;
|
||||
|
||||
virtual void removeOverlappingPairsContainingProxy(btBroadphaseProxy* proxy0) = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif //OVERLAPPING_PAIR_CALLBACK_H
|
||||
Reference in New Issue
Block a user