mirror of
https://github.com/bulletphysics/bullet3
synced 2024-12-14 13:50:04 +00:00
Add plane shape and profile timing support in examples/Collide
Use View/Profiler in example browser, in optimized build/Release mode and look for plCollideWorld
This commit is contained in:
parent
abcaa19bc8
commit
3d9218e07d
@ -51,6 +51,17 @@ plCollisionShapeHandle plCreateSphereShape(plCollisionSdkHandle collisionSdkHand
|
||||
|
||||
}
|
||||
|
||||
plCollisionShapeHandle plCreatePlaneShape(plCollisionSdkHandle collisionSdkHandle, plCollisionWorldHandle worldHandle,
|
||||
plReal planeNormalX,
|
||||
plReal planeNormalY,
|
||||
plReal planeNormalZ,
|
||||
plReal planeConstant)
|
||||
{
|
||||
CollisionSdkInterface* sdk = (CollisionSdkInterface*) collisionSdkHandle;
|
||||
return sdk->createPlaneShape(worldHandle,planeNormalX,planeNormalY,planeNormalZ,planeConstant);
|
||||
}
|
||||
|
||||
|
||||
void plDeleteShape(plCollisionSdkHandle collisionSdkHandle, plCollisionWorldHandle worldHandle, plCollisionShapeHandle shapeHandle)
|
||||
{
|
||||
CollisionSdkInterface* sdk = (CollisionSdkInterface*) collisionSdkHandle;
|
||||
|
@ -64,7 +64,7 @@ extern "C" {
|
||||
|
||||
extern plCollisionShapeHandle plCreateSphereShape(plCollisionSdkHandle sdk, plCollisionWorldHandle worldHandle, plReal radius);
|
||||
extern plCollisionShapeHandle plNewCapsuleShape(plCollisionSdkHandle sdk, plCollisionWorldHandle worldHandle, plReal radius, plReal height);
|
||||
extern plCollisionShapeHandle plNewPlaneShape(plCollisionSdkHandle sdk, plCollisionWorldHandle worldHandle,
|
||||
extern plCollisionShapeHandle plCreatePlaneShape(plCollisionSdkHandle sdk, plCollisionWorldHandle worldHandle,
|
||||
plReal planeNormalX,
|
||||
plReal planeNormalY,
|
||||
plReal planeNormalZ,
|
||||
|
@ -15,20 +15,24 @@
|
||||
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
#include "CollisionSdkC_Api.h"
|
||||
|
||||
#include "LinearMath/btQuickprof.h"
|
||||
|
||||
///Not Invented Here link reminder http://www.joelonsoftware.com/articles/fog0000000007.html
|
||||
|
||||
///todo: use the 'userData' to prevent this use of global variables
|
||||
static int gTotalPoints = 0;
|
||||
lwContactPoint pointsOut[10];
|
||||
int pointCapacity=2;
|
||||
const int sPointCapacity = 10000;
|
||||
const int sNumSpheres = 128;
|
||||
|
||||
lwContactPoint pointsOut[sPointCapacity];
|
||||
int numNearCallbacks = 0;
|
||||
|
||||
|
||||
void myNearCallback(plCollisionSdkHandle sdkHandle, plCollisionWorldHandle worldHandle, void* userData, plCollisionObjectHandle objA, plCollisionObjectHandle objB)
|
||||
{
|
||||
int remainingCapacity = pointCapacity-gTotalPoints;
|
||||
btAssert(remainingCapacity>=0);
|
||||
numNearCallbacks++;
|
||||
int remainingCapacity = sPointCapacity-gTotalPoints;
|
||||
btAssert(remainingCapacity>0);
|
||||
|
||||
if (remainingCapacity>0)
|
||||
{
|
||||
@ -52,6 +56,7 @@ class CollisionTutorialBullet2 : public CommonExampleInterface
|
||||
|
||||
int m_stage;
|
||||
int m_counter;
|
||||
|
||||
public:
|
||||
|
||||
CollisionTutorialBullet2(GUIHelperInterface* guiHelper, int tutorialIndex)
|
||||
@ -65,50 +70,68 @@ public:
|
||||
m_timeSeriesCanvas0(0)
|
||||
{
|
||||
int numBodies = 1;
|
||||
|
||||
gTotalPoints = 0;
|
||||
m_app->setUpAxis(1);
|
||||
m_app->m_renderer->enableBlend(true);
|
||||
|
||||
switch (m_tutorialIndex)
|
||||
{
|
||||
case TUT_SPHERE_SPHERE:
|
||||
case TUT_SPHERE_SPHERE_RTB3:
|
||||
case TUT_SPHERE_SPHERE_BULLET2:
|
||||
{
|
||||
numBodies=10;
|
||||
//m_collisionSdkHandle = plCreateBullet2CollisionSdk();
|
||||
m_collisionSdkHandle = plCreateRealTimeBullet3CollisionSdk();
|
||||
if (m_tutorialIndex==TUT_SPHERE_SPHERE_BULLET2)
|
||||
{
|
||||
m_collisionSdkHandle = plCreateBullet2CollisionSdk();
|
||||
} else
|
||||
{
|
||||
m_collisionSdkHandle = plCreateRealTimeBullet3CollisionSdk();
|
||||
}
|
||||
if (m_collisionSdkHandle)
|
||||
{
|
||||
int maxNumObjsCapacity=32;
|
||||
int maxNumObjsCapacity=1024;
|
||||
int maxNumShapesCapacity=1024;
|
||||
int maxNumPairsCapacity=16384;
|
||||
|
||||
btAlignedObjectArray<plCollisionObjectHandle> colliders;
|
||||
m_collisionWorldHandle = plCreateCollisionWorld(m_collisionSdkHandle,maxNumObjsCapacity,maxNumShapesCapacity,maxNumPairsCapacity);
|
||||
//create objects, do query etc
|
||||
float radius = 1.f;
|
||||
plCollisionShapeHandle colShape = plCreateSphereShape(m_collisionSdkHandle, m_collisionWorldHandle,radius);
|
||||
void* userPointer = 0;
|
||||
btAlignedObjectArray<plCollisionObjectHandle> colliders;
|
||||
int sphereGfxShapeId = m_app->registerGraphicsUnitSphereShape(SPHERE_LOD_HIGH);//, textureIndex);
|
||||
{
|
||||
float radius = 1.f;
|
||||
plCollisionShapeHandle colShape = plCreateSphereShape(m_collisionSdkHandle, m_collisionWorldHandle,radius);
|
||||
void* userPointer = 0;
|
||||
|
||||
int sphereGfxShapeId = m_app->registerGraphicsUnitSphereShape(SPHERE_LOD_HIGH);//, textureIndex);
|
||||
|
||||
for (int i=0;i<3;i++)
|
||||
{
|
||||
btVector3 pos(0,btScalar(i*1.5),0);
|
||||
btQuaternion orn(0,0,0,1);
|
||||
for (int i=0;i<sNumSpheres;i++)
|
||||
{
|
||||
btVector3 pos(i*1.5,btScalar(0.8),0);
|
||||
btQuaternion orn(0,0,0,1);
|
||||
|
||||
btVector4 color(0,1,0,0.8);
|
||||
btVector3 scaling(radius,radius,radius);
|
||||
btVector4 color(0,1,0,0.8);
|
||||
btVector3 scaling(radius,radius,radius);
|
||||
|
||||
int gfxIndex = m_app->m_renderer->registerGraphicsInstance(sphereGfxShapeId,pos, orn,color,scaling);
|
||||
int gfxIndex = m_app->m_renderer->registerGraphicsInstance(sphereGfxShapeId,pos, orn,color,scaling);
|
||||
|
||||
plCollisionObjectHandle colObj = plCreateCollisionObject(m_collisionSdkHandle,m_collisionWorldHandle,userPointer, gfxIndex,colShape,pos,orn);
|
||||
colliders.push_back(colObj);
|
||||
plAddCollisionObject(m_collisionSdkHandle, m_collisionWorldHandle,colObj);
|
||||
}
|
||||
plCollisionObjectHandle colObj = plCreateCollisionObject(m_collisionSdkHandle,m_collisionWorldHandle,userPointer, gfxIndex,colShape,pos,orn);
|
||||
colliders.push_back(colObj);
|
||||
plAddCollisionObject(m_collisionSdkHandle, m_collisionWorldHandle,colObj);
|
||||
}
|
||||
}
|
||||
|
||||
int numContacts = plCollide(m_collisionSdkHandle,m_collisionWorldHandle,colliders[0],colliders[1],pointsOut,pointCapacity);
|
||||
{
|
||||
plCollisionShapeHandle colShape = plCreatePlaneShape(m_collisionSdkHandle, m_collisionWorldHandle,0,1,0,0);
|
||||
btVector3 pos(0,0,0);
|
||||
btQuaternion orn(0,0,0,1);
|
||||
void* userPointer = 0;
|
||||
plCollisionObjectHandle colObj = plCreateCollisionObject(m_collisionSdkHandle,m_collisionWorldHandle,userPointer, 0,colShape,pos,orn);
|
||||
colliders.push_back(colObj);
|
||||
plAddCollisionObject(m_collisionSdkHandle, m_collisionWorldHandle,colObj);
|
||||
}
|
||||
|
||||
int numContacts = plCollide(m_collisionSdkHandle,m_collisionWorldHandle,colliders[0],colliders[1],pointsOut,sPointCapacity);
|
||||
printf("numContacts = %d\n", numContacts);
|
||||
void* myUserPtr = 0;
|
||||
gTotalPoints = 0;
|
||||
|
||||
plWorldCollide(m_collisionSdkHandle,m_collisionWorldHandle,myNearCallback, myUserPtr);
|
||||
printf("total points=%d\n",gTotalPoints);
|
||||
|
||||
@ -127,7 +150,9 @@ public:
|
||||
*/
|
||||
break;
|
||||
}
|
||||
case TUT_SPHERE_PLANE:
|
||||
|
||||
case TUT_SPHERE_PLANE_RTB3:
|
||||
case TUT_SPHERE_PLANE_BULLET2:
|
||||
{
|
||||
break;
|
||||
}
|
||||
@ -142,7 +167,6 @@ public:
|
||||
|
||||
|
||||
|
||||
if (m_tutorialIndex==TUT_SPHERE_SPHERE)
|
||||
{
|
||||
|
||||
int boxId = m_app->registerCubeShape(100,1,100);
|
||||
@ -210,6 +234,21 @@ public:
|
||||
|
||||
virtual void stepSimulation(float deltaTime)
|
||||
{
|
||||
CProfileManager::Reset();
|
||||
|
||||
|
||||
|
||||
|
||||
void* myUserPtr = 0;
|
||||
|
||||
gTotalPoints = 0;
|
||||
numNearCallbacks = 0;
|
||||
{
|
||||
BT_PROFILE("plWorldCollide");
|
||||
plWorldCollide(m_collisionSdkHandle,m_collisionWorldHandle,myNearCallback, myUserPtr);
|
||||
}
|
||||
|
||||
#if 0
|
||||
switch (m_tutorialIndex)
|
||||
{
|
||||
case TUT_SPHERE_SPHERE:
|
||||
@ -230,7 +269,7 @@ public:
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
if (m_timeSeriesCanvas0)
|
||||
m_timeSeriesCanvas0->nextTick();
|
||||
@ -241,6 +280,7 @@ public:
|
||||
|
||||
|
||||
m_app->m_renderer->writeTransforms();
|
||||
CProfileManager::Increment_Frame_Counter();
|
||||
}
|
||||
virtual void renderScene()
|
||||
{
|
||||
|
@ -3,8 +3,10 @@
|
||||
|
||||
enum EnumCollisionTutorialTypes
|
||||
{
|
||||
TUT_SPHERE_SPHERE=0,
|
||||
TUT_SPHERE_PLANE,
|
||||
TUT_SPHERE_SPHERE_BULLET2=0,
|
||||
TUT_SPHERE_PLANE_BULLET2,
|
||||
TUT_SPHERE_SPHERE_RTB3,
|
||||
TUT_SPHERE_PLANE_RTB3,
|
||||
};
|
||||
|
||||
class CommonExampleInterface* CollisionTutorialBullet2CreateFunc(struct CommonExampleOptions& options);
|
||||
|
@ -65,6 +65,17 @@ plCollisionShapeHandle Bullet2CollisionSdk::createSphereShape(plCollisionWorldHa
|
||||
return (plCollisionShapeHandle) sphereShape;
|
||||
}
|
||||
|
||||
plCollisionShapeHandle Bullet2CollisionSdk::createPlaneShape(plCollisionWorldHandle worldHandle,
|
||||
plReal planeNormalX,
|
||||
plReal planeNormalY,
|
||||
plReal planeNormalZ,
|
||||
plReal planeConstant)
|
||||
{
|
||||
btStaticPlaneShape* planeShape = new btStaticPlaneShape(btVector3(planeNormalX,planeNormalY,planeNormalZ),planeConstant);
|
||||
return (plCollisionShapeHandle) planeShape;
|
||||
}
|
||||
|
||||
|
||||
void Bullet2CollisionSdk::deleteShape(plCollisionWorldHandle /*worldHandle*/, plCollisionShapeHandle shapeHandle)
|
||||
{
|
||||
btCollisionShape* shape = (btCollisionShape*) shapeHandle;
|
||||
@ -166,6 +177,7 @@ struct Bullet2ContactResultCallback : public btCollisionWorld::ContactResultCa
|
||||
int Bullet2CollisionSdk::collide(plCollisionWorldHandle worldHandle,plCollisionObjectHandle colA, plCollisionObjectHandle colB,
|
||||
lwContactPoint* pointsOut, int pointCapacity)
|
||||
{
|
||||
|
||||
btCollisionWorld* world = (btCollisionWorld*) worldHandle;
|
||||
btCollisionObject* colObjA = (btCollisionObject*) colA;
|
||||
btCollisionObject* colObjB = (btCollisionObject*) colB;
|
||||
|
@ -19,6 +19,12 @@ public:
|
||||
|
||||
virtual plCollisionShapeHandle createSphereShape(plCollisionWorldHandle worldHandle, plReal radius);
|
||||
|
||||
virtual plCollisionShapeHandle createPlaneShape(plCollisionWorldHandle worldHandle,
|
||||
plReal planeNormalX,
|
||||
plReal planeNormalY,
|
||||
plReal planeNormalZ,
|
||||
plReal planeConstant);
|
||||
|
||||
virtual void deleteShape(plCollisionWorldHandle worldHandle, plCollisionShapeHandle shape);
|
||||
|
||||
virtual void addCollisionObject(plCollisionWorldHandle world, plCollisionObjectHandle object);
|
||||
|
@ -16,6 +16,12 @@ public:
|
||||
virtual void deleteCollisionWorld(plCollisionWorldHandle worldHandle) = 0;
|
||||
|
||||
virtual plCollisionShapeHandle createSphereShape(plCollisionWorldHandle worldHandle, plReal radius) = 0;
|
||||
|
||||
virtual plCollisionShapeHandle createPlaneShape(plCollisionWorldHandle worldHandle,
|
||||
plReal planeNormalX,
|
||||
plReal planeNormalY,
|
||||
plReal planeNormalZ,
|
||||
plReal planeConstant) = 0;
|
||||
|
||||
virtual void deleteShape(plCollisionWorldHandle worldHandle, plCollisionShapeHandle shape) = 0;
|
||||
|
||||
|
@ -35,6 +35,7 @@ enum RTB3ShapeTypes
|
||||
|
||||
//we start at 1, so that the 0 index is 'invalid' just like a nullptr
|
||||
#define START_COLLIDABLE_INDEX 1
|
||||
#define START_SHAPE_INDEX 1
|
||||
|
||||
struct RTB3CollisionWorld
|
||||
{
|
||||
@ -42,16 +43,21 @@ struct RTB3CollisionWorld
|
||||
b3AlignedObjectArray<int> m_collidableUserIndices;
|
||||
b3AlignedObjectArray<b3Float4> m_collidablePositions;
|
||||
b3AlignedObjectArray<b3Quaternion> m_collidableOrientations;
|
||||
b3AlignedObjectArray<b3Transform> m_collidableTransforms;
|
||||
|
||||
b3AlignedObjectArray<b3Collidable> m_collidables;
|
||||
|
||||
b3AlignedObjectArray<b3GpuChildShape> m_childShapes;
|
||||
b3AlignedObjectArray<b3GpuFace> m_planeFaces;
|
||||
b3AlignedObjectArray<b3CompoundOverlappingPair> m_compoundOverlappingPairs;
|
||||
int m_nextFreeShapeIndex;
|
||||
int m_nextFreeCollidableIndex;
|
||||
int m_nextFreePlaneFaceIndex;
|
||||
|
||||
RTB3CollisionWorld()
|
||||
:m_nextFreeCollidableIndex(START_COLLIDABLE_INDEX),
|
||||
m_nextFreeShapeIndex(START_COLLIDABLE_INDEX)
|
||||
m_nextFreeShapeIndex(START_SHAPE_INDEX),
|
||||
m_nextFreePlaneFaceIndex(0)//this value is never exposed to the user, so we can start from 0
|
||||
{
|
||||
}
|
||||
};
|
||||
@ -78,12 +84,15 @@ RealTimeBullet3CollisionSdk::~RealTimeBullet3CollisionSdk()
|
||||
plCollisionWorldHandle RealTimeBullet3CollisionSdk::createCollisionWorld(int maxNumObjsCapacity, int maxNumShapesCapacity, int maxNumPairsCapacity)
|
||||
{
|
||||
RTB3CollisionWorld* world = new RTB3CollisionWorld();
|
||||
world->m_collidables.resize(maxNumObjsCapacity);
|
||||
world->m_collidablePositions.resize(maxNumObjsCapacity);
|
||||
world->m_collidableOrientations.resize(maxNumObjsCapacity);
|
||||
world->m_collidableUserPointers.resize(maxNumObjsCapacity);
|
||||
world->m_collidableUserIndices.resize(maxNumObjsCapacity);
|
||||
world->m_childShapes.resize(maxNumShapesCapacity);
|
||||
world->m_collidables.resize(maxNumObjsCapacity+START_COLLIDABLE_INDEX);
|
||||
world->m_collidablePositions.resize(maxNumObjsCapacity+START_COLLIDABLE_INDEX);
|
||||
world->m_collidableOrientations.resize(maxNumObjsCapacity+START_COLLIDABLE_INDEX);
|
||||
world->m_collidableTransforms.resize(maxNumObjsCapacity+START_COLLIDABLE_INDEX);
|
||||
world->m_collidableUserPointers.resize(maxNumObjsCapacity+START_COLLIDABLE_INDEX);
|
||||
world->m_collidableUserIndices.resize(maxNumObjsCapacity+START_COLLIDABLE_INDEX);
|
||||
world->m_childShapes.resize(maxNumShapesCapacity+START_SHAPE_INDEX);
|
||||
world->m_planeFaces.resize(maxNumShapesCapacity);
|
||||
|
||||
world->m_compoundOverlappingPairs.resize(maxNumPairsCapacity);
|
||||
|
||||
m_internalData->m_collisionWorlds.push_back(world);
|
||||
@ -105,6 +114,7 @@ void RealTimeBullet3CollisionSdk::deleteCollisionWorld(plCollisionWorldHandle wo
|
||||
plCollisionShapeHandle RealTimeBullet3CollisionSdk::createSphereShape(plCollisionWorldHandle worldHandle, plReal radius)
|
||||
{
|
||||
RTB3CollisionWorld* world = (RTB3CollisionWorld*) worldHandle;
|
||||
b3Assert(world->m_nextFreeShapeIndex<world->m_childShapes.size());
|
||||
if (world->m_nextFreeShapeIndex<world->m_childShapes.size())
|
||||
{
|
||||
b3GpuChildShape& shape = world->m_childShapes[world->m_nextFreeShapeIndex];
|
||||
@ -117,6 +127,29 @@ plCollisionShapeHandle RealTimeBullet3CollisionSdk::createSphereShape(plCollisio
|
||||
return 0;
|
||||
}
|
||||
|
||||
plCollisionShapeHandle RealTimeBullet3CollisionSdk::createPlaneShape(plCollisionWorldHandle worldHandle,
|
||||
plReal planeNormalX,
|
||||
plReal planeNormalY,
|
||||
plReal planeNormalZ,
|
||||
plReal planeConstant)
|
||||
{
|
||||
RTB3CollisionWorld* world = (RTB3CollisionWorld*) worldHandle;
|
||||
b3Assert(world->m_nextFreeShapeIndex < world->m_childShapes.size() && world->m_nextFreePlaneFaceIndex < world->m_planeFaces.size());
|
||||
|
||||
if (world->m_nextFreeShapeIndex < world->m_childShapes.size() && world->m_nextFreePlaneFaceIndex < world->m_planeFaces.size())
|
||||
{
|
||||
b3GpuChildShape& shape = world->m_childShapes[world->m_nextFreeShapeIndex];
|
||||
shape.m_childPosition.setZero();
|
||||
shape.m_childOrientation.setValue(0,0,0,1);
|
||||
world->m_planeFaces[world->m_nextFreePlaneFaceIndex].m_plane = b3MakeVector4(planeNormalX,planeNormalY,planeNormalZ,planeConstant);
|
||||
shape.m_shapeIndex = world->m_nextFreePlaneFaceIndex++;
|
||||
shape.m_shapeType = RTB3_SHAPE_PLANE;
|
||||
return (plCollisionShapeHandle) world->m_nextFreeShapeIndex++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void RealTimeBullet3CollisionSdk::deleteShape(plCollisionWorldHandle worldHandle, plCollisionShapeHandle shape)
|
||||
{
|
||||
///todo
|
||||
@ -140,11 +173,14 @@ plCollisionObjectHandle RealTimeBullet3CollisionSdk::createCollisionObject( plC
|
||||
plVector3 startPosition,plQuaternion startOrientation )
|
||||
{
|
||||
RTB3CollisionWorld* world = (RTB3CollisionWorld*) worldHandle;
|
||||
b3Assert(world->m_nextFreeCollidableIndex < world->m_collidables.size());
|
||||
if (world->m_nextFreeCollidableIndex < world->m_collidables.size())
|
||||
{
|
||||
b3Collidable& collidable = world->m_collidables[world->m_nextFreeCollidableIndex];
|
||||
world->m_collidablePositions[world->m_nextFreeCollidableIndex].setValue(startPosition[0],startPosition[1],startPosition[2]);
|
||||
world->m_collidableOrientations[world->m_nextFreeCollidableIndex].setValue(startOrientation[0],startOrientation[1],startOrientation[2],startOrientation[3]);
|
||||
world->m_collidableTransforms[world->m_nextFreeCollidableIndex].setOrigin(world->m_collidablePositions[world->m_nextFreeCollidableIndex]);
|
||||
world->m_collidableTransforms[world->m_nextFreeCollidableIndex].setRotation(world->m_collidableOrientations[world->m_nextFreeCollidableIndex]);
|
||||
world->m_collidableUserPointers[world->m_nextFreeCollidableIndex] = userPointer;
|
||||
world->m_collidableUserIndices[world->m_nextFreeCollidableIndex] = userIndex;
|
||||
RTB3_ShapeOpaque2Int caster;
|
||||
@ -163,7 +199,6 @@ plCollisionObjectHandle RealTimeBullet3CollisionSdk::createCollisionObject( plC
|
||||
}
|
||||
case RTB3_SHAPE_PLANE:
|
||||
{
|
||||
b3Assert(0);
|
||||
break;
|
||||
}
|
||||
case RTB3_SHAPE_COMPOUND_INTERNAL:
|
||||
@ -256,6 +291,7 @@ void ComputeClosestPointsSphereSphere(b3Scalar sphereARadius, const b3Vector3& s
|
||||
{
|
||||
lwContactPoint& pointOut = contactCache->pointsOut[contactCache->numAddedPoints];
|
||||
b3Vector3 diff = sphereAPosWorld-sphereBPosWorld;
|
||||
|
||||
b3Scalar len = diff.length();
|
||||
pointOut.m_distance = len - (sphereARadius+sphereBRadius);
|
||||
if (pointOut.m_distance<=0)
|
||||
@ -264,35 +300,52 @@ void ComputeClosestPointsSphereSphere(b3Scalar sphereARadius, const b3Vector3& s
|
||||
if (len > B3_EPSILON) {
|
||||
normOnB = diff / len;
|
||||
}
|
||||
|
||||
plVecCopy(pointOut.m_normalOnB,normOnB);
|
||||
b3Vector3 ptAWorld = sphereAPosWorld - sphereARadius*normOnB;
|
||||
plVecCopy(pointOut.m_ptOnAWorld,ptAWorld);
|
||||
plVecCopy(pointOut.m_ptOnBWorld,ptAWorld-normOnB*pointOut.m_distance);
|
||||
|
||||
contactCache->numAddedPoints++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void detectCollisionSphereSphere(RTB3CollisionWorld* world,int colA, int shapeIndexA, int colB, int shapeIndexB,
|
||||
B3_FORCE_INLINE void detectCollisionSphereSphere(RTB3CollisionWorld* world,int colA, int shapeIndexA, int colB, int shapeIndexB,
|
||||
plContactCache* contactCache)
|
||||
{
|
||||
b3Scalar radiusA = world->m_childShapes[shapeIndexA].m_radius;
|
||||
b3Scalar radiusB = world->m_childShapes[shapeIndexB].m_radius;
|
||||
b3Transform trA(world->m_collidableOrientations[colA],world->m_collidablePositions[colA]);
|
||||
|
||||
const b3Scalar radiusA = world->m_childShapes[shapeIndexA].m_radius;
|
||||
const b3Scalar radiusB = world->m_childShapes[shapeIndexB].m_radius;
|
||||
|
||||
const b3Transform& trA = world->m_collidableTransforms[colA];
|
||||
const b3Vector3& sphereALocalPos = world->m_childShapes[shapeIndexA].m_childPosition;
|
||||
b3Vector3 spherePosAWorld = trA(sphereALocalPos);
|
||||
b3Transform trB(world->m_collidableOrientations[colB],world->m_collidablePositions[colB]);
|
||||
//b3Vector3 spherePosAWorld = b3QuatRotate( world->m_collidableOrientations[colA], sphereALocalPos ) + (world->m_collidablePositions[colA]);
|
||||
|
||||
const b3Transform& trB = world->m_collidableTransforms[colB];
|
||||
const b3Vector3& sphereBLocalPos = world->m_childShapes[shapeIndexB].m_childPosition;
|
||||
b3Vector3 spherePosBWorld = trB(sphereBLocalPos);
|
||||
//b3Vector3 spherePosBWorld = b3QuatRotate( world->m_collidableOrientations[colB], sphereBLocalPos ) + (world->m_collidablePositions[colB]);
|
||||
|
||||
ComputeClosestPointsSphereSphere(radiusA,spherePosAWorld,radiusB,spherePosBWorld,contactCache);
|
||||
}
|
||||
|
||||
void detectCollisionSpherePlane(RTB3CollisionWorld* world,int colA, int shapeIndexA, int colB, int shapeIndexB,
|
||||
plContactCache* contactCache)
|
||||
{
|
||||
(void)world;
|
||||
(void)colA,(void)shapeIndexA,(void)colB,(void)shapeIndexB;
|
||||
(void)contactCache;
|
||||
const b3Transform& trA = world->m_collidableTransforms[colA];
|
||||
const b3Vector3& sphereALocalPos = world->m_childShapes[shapeIndexA].m_childPosition;
|
||||
b3Vector3 spherePosAWorld = trA(sphereALocalPos);
|
||||
|
||||
|
||||
int planeFaceIndex = world->m_childShapes[shapeIndexB].m_shapeIndex;
|
||||
b3Vector3 planeNormal = world->m_planeFaces[planeFaceIndex].m_plane;
|
||||
b3Scalar planeConstant = planeNormal[3];
|
||||
planeNormal[3] = 0.f;
|
||||
|
||||
ComputeClosestPointsPlaneSphere(planeNormal, planeConstant, spherePosAWorld,world->m_childShapes[shapeIndexA].m_radius, contactCache);
|
||||
|
||||
}
|
||||
|
||||
void detectCollisionPlaneSphere(RTB3CollisionWorld* world,int colA, int shapeIndexA, int colB, int shapeIndexB,
|
||||
@ -322,6 +375,7 @@ plDetectCollisionFunc funcTbl_detectCollision[MAX_NUM_SINGLE_SHAPE_TYPES][MAX_NU
|
||||
int RealTimeBullet3CollisionSdk::collide(plCollisionWorldHandle worldHandle,plCollisionObjectHandle colAHandle, plCollisionObjectHandle colBHandle,
|
||||
lwContactPoint* pointsOutOrg, int pointCapacity)
|
||||
{
|
||||
|
||||
RTB3CollisionWorld* world = (RTB3CollisionWorld*) worldHandle;
|
||||
RTB3_ColliderOpaque2Int caster;
|
||||
caster.m_ptrValue =colAHandle;
|
||||
@ -358,14 +412,18 @@ void RealTimeBullet3CollisionSdk::collideWorld( plCollisionWorldHandle worldHand
|
||||
RTB3CollisionWorld* world = (RTB3CollisionWorld*) worldHandle;
|
||||
if (filter)
|
||||
{
|
||||
RTB3_ColliderOpaque2Int caster;
|
||||
plCollisionObjectHandle colA;
|
||||
plCollisionObjectHandle colB;
|
||||
for (int i=START_COLLIDABLE_INDEX;i<world->m_nextFreeCollidableIndex;i++)
|
||||
{
|
||||
|
||||
for (int j=i+1;j<world->m_nextFreeCollidableIndex;j++)
|
||||
{
|
||||
RTB3_ColliderOpaque2Int caster; caster.m_intValue = i;
|
||||
plCollisionObjectHandle colA = caster.m_ptrValue;
|
||||
caster.m_intValue = i;
|
||||
colA = caster.m_ptrValue;
|
||||
caster.m_intValue = j;
|
||||
plCollisionObjectHandle colB = caster.m_ptrValue;
|
||||
colB = caster.m_ptrValue;
|
||||
filter((plCollisionSdkHandle)this,worldHandle,userData,colA,colB);
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,12 @@ public:
|
||||
virtual void deleteCollisionWorld(plCollisionWorldHandle worldHandle);
|
||||
|
||||
virtual plCollisionShapeHandle createSphereShape(plCollisionWorldHandle worldHandle, plReal radius);
|
||||
virtual plCollisionShapeHandle createPlaneShape(plCollisionWorldHandle worldHandle,
|
||||
plReal planeNormalX,
|
||||
plReal planeNormalY,
|
||||
plReal planeNormalZ,
|
||||
plReal planeConstant);
|
||||
|
||||
virtual void deleteShape(plCollisionWorldHandle worldHandle, plCollisionShapeHandle shape);
|
||||
|
||||
virtual void addCollisionObject(plCollisionWorldHandle world, plCollisionObjectHandle object);
|
||||
|
@ -117,8 +117,10 @@ static ExampleEntry gDefaultExamples[]=
|
||||
ExampleEntry(1,"Spring constraint","A rigid body with a spring constraint attached", Dof6ConstraintTutorialCreateFunc,0),
|
||||
|
||||
ExampleEntry(0,"Collision"),
|
||||
ExampleEntry(1, "Sphere-Sphere C-API", "Collision C-API using Bullet 2.x backend", CollisionTutorialBullet2CreateFunc,TUT_SPHERE_SPHERE),
|
||||
ExampleEntry(1, "Sphere-Plane C-API", "Collision C-API using Bullet 2.x backend", CollisionTutorialBullet2CreateFunc,TUT_SPHERE_PLANE),
|
||||
ExampleEntry(1, "Sphere-Sphere C-API (Bullet2)", "Collision C-API using Bullet 2.x backend", CollisionTutorialBullet2CreateFunc,TUT_SPHERE_SPHERE_BULLET2),
|
||||
ExampleEntry(1, "Sphere-Plane C-API (Bullet2)", "Collision C-API using Bullet 2.x backend", CollisionTutorialBullet2CreateFunc,TUT_SPHERE_PLANE_BULLET2),
|
||||
ExampleEntry(1, "Sphere-Sphere C-API (Bullet3)", "Collision C-API using Bullet 3.x backend", CollisionTutorialBullet2CreateFunc,TUT_SPHERE_SPHERE_RTB3),
|
||||
ExampleEntry(1, "Sphere-Plane C-API (Bullet3)", "Collision C-API using Bullet 3.x backend", CollisionTutorialBullet2CreateFunc,TUT_SPHERE_PLANE_RTB3),
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user