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
This commit is contained in:
erwin.coumans
2013-09-11 05:52:19 +00:00
parent a197c58935
commit 1685729b80
3 changed files with 33 additions and 2 deletions

View File

@@ -35,9 +35,31 @@ subject to the following restrictions:
#include <stdio.h> //printf debugging #include <stdio.h> //printf debugging
#include "GLDebugDrawer.h" #include "GLDebugDrawer.h"
#include "LinearMath/btAabbUtil2.h"
static GLDebugDrawer gDebugDraw; 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() void BasicDemo::clientMoveAndDisplay()
{ {
@@ -52,6 +74,15 @@ void BasicDemo::clientMoveAndDisplay()
m_dynamicsWorld->stepSimulation(ms / 1000000.f); m_dynamicsWorld->stepSimulation(ms / 1000000.f);
//optional but useful: debug drawing //optional but useful: debug drawing
m_dynamicsWorld->debugDrawWorld(); 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(); renderme();

View File

@@ -552,7 +552,7 @@ void btWorldImporter::convertConstraint(btTypedConstraintData* constraintData,bt
} }
if (hingeData->m_enableAngularMotor) 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->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)); hinge->setLimit(btScalar(hingeData->m_lowerLimit),btScalar(hingeData->m_upperLimit),btScalar(hingeData->m_limitSoftness),btScalar(hingeData->m_biasFactor),btScalar(hingeData->m_relaxationFactor));

View File

@@ -72,7 +72,7 @@ void stringToFloatArray(const std::string& string, btAlignedObjectArray<float>&
btAlignedObjectArray<std::string> pieces; btAlignedObjectArray<std::string> pieces;
bullet_utils::split( pieces, string, " "); 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]!=""); assert(pieces[i]!="");
floats.push_back((float)atof(pieces[i].c_str())); floats.push_back((float)atof(pieces[i].c_str()));