From 1685729b80ac86c2f294a76ad5a9ce8ebe6d8dbb Mon Sep 17 00:00:00 2001 From: "erwin.coumans" Date: Wed, 11 Sep 2013 05:52:19 +0000 Subject: [PATCH] Show how to use the btBroadphaseInterface::aabbTest, it collects all objects that overlap with a given bounding box This fixes old Issue 114 Removed 2 warnings --- Demos/BasicDemo/BasicDemo.cpp | 31 +++++++++++++++++++ .../BulletWorldImporter/btWorldImporter.cpp | 2 +- .../btBulletXmlWorldImporter.cpp | 2 +- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Demos/BasicDemo/BasicDemo.cpp b/Demos/BasicDemo/BasicDemo.cpp index ae223626f..3528ed257 100644 --- a/Demos/BasicDemo/BasicDemo.cpp +++ b/Demos/BasicDemo/BasicDemo.cpp @@ -35,9 +35,31 @@ subject to the following restrictions: #include //printf debugging #include "GLDebugDrawer.h" +#include "LinearMath/btAabbUtil2.h" static GLDebugDrawer gDebugDraw; +///The MyOverlapCallback is used to show how to collect object that overlap with a given bounding box defined by aabbMin and aabbMax. +///See m_dynamicsWorld->getBroadphase()->aabbTest. +struct MyOverlapCallback : public btBroadphaseAabbCallback +{ + btVector3 m_queryAabbMin; + btVector3 m_queryAabbMax; + + int m_numOverlap; + MyOverlapCallback(const btVector3& aabbMin, const btVector3& aabbMax ) : m_queryAabbMin(aabbMin),m_queryAabbMax(aabbMax),m_numOverlap(0) {} + virtual bool process(const btBroadphaseProxy* proxy) + { + btVector3 proxyAabbMin,proxyAabbMax; + btCollisionObject* colObj0 = (btCollisionObject*)proxy->m_clientObject; + colObj0->getCollisionShape()->getAabb(colObj0->getWorldTransform(),proxyAabbMin,proxyAabbMax); + if (TestAabbAgainstAabb2(proxyAabbMin,proxyAabbMax,m_queryAabbMin,m_queryAabbMax)) + { + m_numOverlap++; + } + return true; + } +}; void BasicDemo::clientMoveAndDisplay() { @@ -52,6 +74,15 @@ void BasicDemo::clientMoveAndDisplay() m_dynamicsWorld->stepSimulation(ms / 1000000.f); //optional but useful: debug drawing m_dynamicsWorld->debugDrawWorld(); + + btVector3 aabbMin(1,1,1); + btVector3 aabbMax(2,2,2); + + MyOverlapCallback aabbOverlap(aabbMin,aabbMax); + m_dynamicsWorld->getBroadphase()->aabbTest(aabbMin,aabbMax,aabbOverlap); + + if (aabbOverlap.m_numOverlap) + printf("#aabb overlap = %d\n", aabbOverlap.m_numOverlap); } renderme(); diff --git a/Extras/Serialize/BulletWorldImporter/btWorldImporter.cpp b/Extras/Serialize/BulletWorldImporter/btWorldImporter.cpp index 584b9d519..2224f42f5 100644 --- a/Extras/Serialize/BulletWorldImporter/btWorldImporter.cpp +++ b/Extras/Serialize/BulletWorldImporter/btWorldImporter.cpp @@ -552,7 +552,7 @@ void btWorldImporter::convertConstraint(btTypedConstraintData* constraintData,bt } if (hingeData->m_enableAngularMotor) { - hinge->enableAngularMotor(true,hingeData->m_motorTargetVelocity,hingeData->m_maxMotorImpulse); + hinge->enableAngularMotor(true,(btScalar)hingeData->m_motorTargetVelocity,(btScalar)hingeData->m_maxMotorImpulse); } hinge->setAngularOnly(hingeData->m_angularOnly!=0); hinge->setLimit(btScalar(hingeData->m_lowerLimit),btScalar(hingeData->m_upperLimit),btScalar(hingeData->m_limitSoftness),btScalar(hingeData->m_biasFactor),btScalar(hingeData->m_relaxationFactor)); diff --git a/Extras/Serialize/BulletXmlWorldImporter/btBulletXmlWorldImporter.cpp b/Extras/Serialize/BulletXmlWorldImporter/btBulletXmlWorldImporter.cpp index 54195720b..91653a7b8 100644 --- a/Extras/Serialize/BulletXmlWorldImporter/btBulletXmlWorldImporter.cpp +++ b/Extras/Serialize/BulletXmlWorldImporter/btBulletXmlWorldImporter.cpp @@ -72,7 +72,7 @@ void stringToFloatArray(const std::string& string, btAlignedObjectArray& btAlignedObjectArray pieces; bullet_utils::split( pieces, string, " "); - for (unsigned int i = 0; i < pieces.size(); ++i) + for ( int i = 0; i < pieces.size(); ++i) { assert(pieces[i]!=""); floats.push_back((float)atof(pieces[i].c_str()));