From 259d2df0c4f6ab8a018ad6fb6c33ad8f27b7be00 Mon Sep 17 00:00:00 2001 From: enn0x Date: Sun, 16 Feb 2014 21:58:40 +0000 Subject: [PATCH] Added utility function BulletWorld::test_filter --- panda/src/bullet/bulletWorld.cxx | 45 +++++++++++++++++++++++++++++--- panda/src/bullet/bulletWorld.h | 2 ++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/panda/src/bullet/bulletWorld.cxx b/panda/src/bullet/bulletWorld.cxx index 14502a40af..1a01ffb79b 100644 --- a/panda/src/bullet/bulletWorld.cxx +++ b/panda/src/bullet/bulletWorld.cxx @@ -715,10 +715,46 @@ sweep_test_closest(BulletShape *shape, const TransformState &from_ts, const Tran return cb; } +//////////////////////////////////////////////////////////////////// +// Function: BulletWorld::filter_test +// Access: Published +// Description: Performs a test if two bodies should collide or +// not, based on the collision filter setting. +//////////////////////////////////////////////////////////////////// +bool BulletWorld:: +filter_test(PandaNode *node0, PandaNode *node1) const { + + nassertr(node0, false); + nassertr(node1, false); + nassertr(_filter_cb, false); + + btCollisionObject *obj0 = get_collision_object(node0); + btCollisionObject *obj1 = get_collision_object(node1); + + nassertr(obj0, false); + nassertr(obj1, false); + + btBroadphaseProxy *proxy0 = obj0->getBroadphaseHandle(); + btBroadphaseProxy *proxy1 = obj1->getBroadphaseHandle(); + + nassertr(proxy0, false); + nassertr(proxy1, false); + + return _filter_cb->needBroadphaseCollision(proxy0, proxy1); +} + //////////////////////////////////////////////////////////////////// // Function: BulletWorld::contact_test // Access: Published -// Description: +// Description: Performas a test for all bodies which are +// currently in contact with the given body. +// The test returns a BulletContactResult object +// which may contain zero, one or more contacts. +// +// If the optional parameter use_filter is set to +// TRUE this test will consider filter settings. +// Otherwise all objects in contact are reported, +// no matter if they would collide or not. //////////////////////////////////////////////////////////////////// BulletContactResult BulletWorld:: contact_test(PandaNode *node, bool use_filter) const { @@ -742,7 +778,10 @@ contact_test(PandaNode *node, bool use_filter) const { //////////////////////////////////////////////////////////////////// // Function: BulletWorld::contact_pair_test // Access: Published -// Description: +// Description: Performas a test if the two bodies given as +// parameters are in contact or not. +// The test returns a BulletContactResult object +// which may contain zero or one contacts. //////////////////////////////////////////////////////////////////// BulletContactResult BulletWorld:: contact_test_pair(PandaNode *node0, PandaNode *node1) const { @@ -815,7 +854,7 @@ set_group_collision_flag(unsigned int group1, unsigned int group2, bool enable) } //////////////////////////////////////////////////////////////////// -// Function: BulletWorld::get_collision_object +// Function: BulletWorld::get_group_collision_flag // Access: Public // Description: //////////////////////////////////////////////////////////////////// diff --git a/panda/src/bullet/bulletWorld.h b/panda/src/bullet/bulletWorld.h index 3b57138c0f..6a798cde7f 100644 --- a/panda/src/bullet/bulletWorld.h +++ b/panda/src/bullet/bulletWorld.h @@ -126,6 +126,8 @@ PUBLISHED: BulletContactResult contact_test(PandaNode *node, bool use_filter=false) const; BulletContactResult contact_test_pair(PandaNode *node0, PandaNode *node1) const; + bool filter_test(PandaNode *node0, PandaNode *node1) const; + // Manifolds INLINE int get_num_manifolds() const; BulletPersistentManifold *get_manifold(int idx) const;