From dc4aacb03b7ffed877841a1f87e7e9c4d9cf6c89 Mon Sep 17 00:00:00 2001 From: ejcoumans Date: Thu, 1 Nov 2007 18:21:17 +0000 Subject: [PATCH] add ability for user pair callback, this can be used to keep track of objects, overlapping a certain AABB/shape. --- .../BroadphaseCollision/btAxisSweep3.h | 25 ++++++++++++- .../btOverlappingPairCallback.h | 37 +++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 src/BulletCollision/BroadphaseCollision/btOverlappingPairCallback.h diff --git a/src/BulletCollision/BroadphaseCollision/btAxisSweep3.h b/src/BulletCollision/BroadphaseCollision/btAxisSweep3.h index c7721aca4..d36df6e66 100644 --- a/src/BulletCollision/BroadphaseCollision/btAxisSweep3.h +++ b/src/BulletCollision/BroadphaseCollision/btAxisSweep3.h @@ -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::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::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::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::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::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 diff --git a/src/BulletCollision/BroadphaseCollision/btOverlappingPairCallback.h b/src/BulletCollision/BroadphaseCollision/btOverlappingPairCallback.h new file mode 100644 index 000000000..b8d967dc4 --- /dev/null +++ b/src/BulletCollision/BroadphaseCollision/btOverlappingPairCallback.h @@ -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 \ No newline at end of file