make the compiler happy with Collision example

This commit is contained in:
Erwin Coumans
2015-10-19 18:21:45 -07:00
parent 5a21424662
commit abcaa19bc8
4 changed files with 53 additions and 21 deletions

View File

@@ -4,6 +4,7 @@
#define PL_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name #define PL_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name
#ifdef BT_USE_DOUBLE_PRECISION #ifdef BT_USE_DOUBLE_PRECISION
typedef double plReal; typedef double plReal;
#else #else

View File

@@ -95,8 +95,8 @@ public:
btVector3 pos(0,btScalar(i*1.5),0); btVector3 pos(0,btScalar(i*1.5),0);
btQuaternion orn(0,0,0,1); btQuaternion orn(0,0,0,1);
b3Vector4 color = b3MakeVector4(0,1,0,0.8); btVector4 color(0,1,0,0.8);
b3Vector3 scaling = b3MakeVector3(radius,radius,radius); 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);
@@ -258,8 +258,8 @@ public:
for (int i=0;i<gTotalPoints;i++) for (int i=0;i<gTotalPoints;i++)
{ {
const lwContactPoint& contact = pointsOut[i]; const lwContactPoint& contact = pointsOut[i];
b3Vector3 color=b3MakeVector3(1,1,0); btVector3 color(1,1,0);
float lineWidth=3; btScalar lineWidth=3;
if (contact.m_distance<0) if (contact.m_distance<0)
{ {
color.setValue(1,0,0); color.setValue(1,0,0);

View File

@@ -4,6 +4,24 @@
#include "Bullet3Collision/NarrowPhaseCollision/shared/b3Collidable.h" #include "Bullet3Collision/NarrowPhaseCollision/shared/b3Collidable.h"
#include "Bullet3Collision/NarrowPhaseCollision/shared/b3ConvexPolyhedronData.h" #include "Bullet3Collision/NarrowPhaseCollision/shared/b3ConvexPolyhedronData.h"
//convert the opaque pointer to int
struct RTB3_ColliderOpaque2Int
{
union
{
plCollisionObjectHandle m_ptrValue;
int m_intValue;
};
};
struct RTB3_ShapeOpaque2Int
{
union
{
plCollisionShapeHandle m_ptrValue;
int m_intValue;
};
};
enum RTB3ShapeTypes enum RTB3ShapeTypes
{ {
RTB3_SHAPE_SPHERE=0, RTB3_SHAPE_SPHERE=0,
@@ -45,9 +63,9 @@ struct RealTimeBullet3CollisionSdkInternalData
RealTimeBullet3CollisionSdk::RealTimeBullet3CollisionSdk() RealTimeBullet3CollisionSdk::RealTimeBullet3CollisionSdk()
{ {
int szCol = sizeof(b3Collidable); // int szCol = sizeof(b3Collidable);
int szShap = sizeof(b3GpuChildShape); // int szShap = sizeof(b3GpuChildShape);
int szComPair = sizeof(b3CompoundOverlappingPair); // int szComPair = sizeof(b3CompoundOverlappingPair);
m_internalData = new RealTimeBullet3CollisionSdkInternalData; m_internalData = new RealTimeBullet3CollisionSdkInternalData;
} }
@@ -129,8 +147,10 @@ plCollisionObjectHandle RealTimeBullet3CollisionSdk::createCollisionObject( plC
world->m_collidableOrientations[world->m_nextFreeCollidableIndex].setValue(startOrientation[0],startOrientation[1],startOrientation[2],startOrientation[3]); world->m_collidableOrientations[world->m_nextFreeCollidableIndex].setValue(startOrientation[0],startOrientation[1],startOrientation[2],startOrientation[3]);
world->m_collidableUserPointers[world->m_nextFreeCollidableIndex] = userPointer; world->m_collidableUserPointers[world->m_nextFreeCollidableIndex] = userPointer;
world->m_collidableUserIndices[world->m_nextFreeCollidableIndex] = userIndex; world->m_collidableUserIndices[world->m_nextFreeCollidableIndex] = userIndex;
int shapeIndex = (int)shapeHandle; RTB3_ShapeOpaque2Int caster;
collidable.m_shapeIndex = shapeIndex; caster.m_ptrValue = shapeHandle;
int shapeIndex = caster.m_intValue;
collidable.m_shapeIndex = shapeIndex;
b3GpuChildShape& shape = world->m_childShapes[shapeIndex]; b3GpuChildShape& shape = world->m_childShapes[shapeIndex];
collidable.m_shapeType = shape.m_shapeType; collidable.m_shapeType = shape.m_shapeType;
collidable.m_numChildShapes = 1; collidable.m_numChildShapes = 1;
@@ -198,12 +218,18 @@ void detectCollisionDummy(RTB3CollisionWorld* world,int colA, int shapeIndexA, i
(void)contactCache; (void)contactCache;
} }
void plVecCopy(b3Scalar* dst,const b3Vector3& src) void plVecCopy(float* dst,const b3Vector3& src)
{ {
dst[0] = src.x; dst[0] = src.x;
dst[1] = src.y; dst[1] = src.y;
dst[2] = src.z; dst[2] = src.z;
} }
void plVecCopy(double* dst,const b3Vector3& src)
{
dst[0] = src.x;
dst[1] = src.y;
dst[2] = src.z;
}
void ComputeClosestPointsPlaneSphere(const b3Vector3& planeNormalWorld, b3Scalar planeConstant, const b3Vector3& spherePosWorld,b3Scalar sphereRadius, plContactCache* contactCache) void ComputeClosestPointsPlaneSphere(const b3Vector3& planeNormalWorld, b3Scalar planeConstant, const b3Vector3& spherePosWorld,b3Scalar sphereRadius, plContactCache* contactCache)
{ {
@@ -257,7 +283,7 @@ void detectCollisionSphereSphere(RTB3CollisionWorld* world,int colA, int shapeIn
b3Vector3 spherePosAWorld = trA(sphereALocalPos); b3Vector3 spherePosAWorld = trA(sphereALocalPos);
b3Transform trB(world->m_collidableOrientations[colB],world->m_collidablePositions[colB]); b3Transform trB(world->m_collidableOrientations[colB],world->m_collidablePositions[colB]);
const b3Vector3& sphereBLocalPos = world->m_childShapes[shapeIndexB].m_childPosition; const b3Vector3& sphereBLocalPos = world->m_childShapes[shapeIndexB].m_childPosition;
b3Vector3 spherePosBWorld = trB(sphereALocalPos); b3Vector3 spherePosBWorld = trB(sphereBLocalPos);
ComputeClosestPointsSphereSphere(radiusA,spherePosAWorld,radiusB,spherePosBWorld,contactCache); ComputeClosestPointsSphereSphere(radiusA,spherePosAWorld,radiusB,spherePosBWorld,contactCache);
} }
@@ -297,24 +323,25 @@ int RealTimeBullet3CollisionSdk::collide(plCollisionWorldHandle worldHandle,plCo
lwContactPoint* pointsOutOrg, int pointCapacity) lwContactPoint* pointsOutOrg, int pointCapacity)
{ {
RTB3CollisionWorld* world = (RTB3CollisionWorld*) worldHandle; RTB3CollisionWorld* world = (RTB3CollisionWorld*) worldHandle;
int colAIndex = (int) colAHandle; RTB3_ColliderOpaque2Int caster;
int colBIndex = (int) colBHandle; caster.m_ptrValue =colAHandle;
const b3Collidable& colA = world->m_collidables[colAIndex]; int colAIndex = caster.m_intValue;
caster.m_ptrValue = colBHandle;
int colBIndex = caster.m_intValue;
const b3Collidable& colA = world->m_collidables[colAIndex];
const b3Collidable& colB = world->m_collidables[colBIndex]; const b3Collidable& colB = world->m_collidables[colBIndex];
plContactCache contactCache; plContactCache contactCache;
contactCache.pointCapacity = pointCapacity; contactCache.pointCapacity = pointCapacity;
contactCache.pointsOut = pointsOutOrg; contactCache.pointsOut = pointsOutOrg;
contactCache.numAddedPoints = 0; contactCache.numAddedPoints = 0;
int remainingCapacity = pointCapacity;
for (int i=0;i<colA.m_numChildShapes;i++) for (int i=0;i<colA.m_numChildShapes;i++)
{ {
for (int j=0;j<colB.m_numChildShapes;j++) for (int j=0;j<colB.m_numChildShapes;j++)
{ {
if (contactCache.numAddedPoints<pointCapacity) if (contactCache.numAddedPoints<pointCapacity)
{ {
lwContactPoint* curPointsOut = &pointsOutOrg[contactCache.numAddedPoints];
funcTbl_detectCollision[world->m_childShapes[colA.m_shapeIndex+i].m_shapeType] funcTbl_detectCollision[world->m_childShapes[colA.m_shapeIndex+i].m_shapeType]
[world->m_childShapes[colB.m_shapeIndex+j].m_shapeType](world,colAIndex,colA.m_shapeIndex+i,colBIndex,colB.m_shapeIndex+j,&contactCache); [world->m_childShapes[colB.m_shapeIndex+j].m_shapeType](world,colAIndex,colA.m_shapeIndex+i,colBIndex,colB.m_shapeIndex+j,&contactCache);
} }
@@ -324,7 +351,7 @@ int RealTimeBullet3CollisionSdk::collide(plCollisionWorldHandle worldHandle,plCo
return 0; return 0;
} }
void RealTimeBullet3CollisionSdk::collideWorld( plCollisionWorldHandle worldHandle, void RealTimeBullet3CollisionSdk::collideWorld( plCollisionWorldHandle worldHandle,
plNearCallback filter, void* userData) plNearCallback filter, void* userData)
{ {
@@ -335,9 +362,11 @@ void RealTimeBullet3CollisionSdk::collideWorld( plCollisionWorldHandle worldHand
{ {
for (int j=i+1;j<world->m_nextFreeCollidableIndex;j++) for (int j=i+1;j<world->m_nextFreeCollidableIndex;j++)
{ {
plCollisionObjectHandle colA = (plCollisionObjectHandle)i; RTB3_ColliderOpaque2Int caster; caster.m_intValue = i;
plCollisionObjectHandle colB = (plCollisionObjectHandle)j; plCollisionObjectHandle colA = caster.m_ptrValue;
filter((plCollisionSdkHandle)this,worldHandle,userData,colA,colB); caster.m_intValue = j;
plCollisionObjectHandle colB = caster.m_ptrValue;
filter((plCollisionSdkHandle)this,worldHandle,userData,colA,colB);
} }
} }
} }

View File

@@ -38,6 +38,8 @@ SET(App_ExampleBrowser_SRCS
../Collision/Internal/Bullet2CollisionSdk.cpp ../Collision/Internal/Bullet2CollisionSdk.cpp
../Collision/Internal/Bullet2CollisionSdk.h ../Collision/Internal/Bullet2CollisionSdk.h
../Collision/Internal/CollisionSdkInterface.h ../Collision/Internal/CollisionSdkInterface.h
../Collision/Internal/RealTimeBullet3CollisionSdk.cpp
../Collision/Internal/RealTimeBullet3CollisionSdk.h
../GyroscopicDemo/GyroscopicSetup.cpp ../GyroscopicDemo/GyroscopicSetup.cpp
../GyroscopicDemo/GyroscopicSetup.h ../GyroscopicDemo/GyroscopicSetup.h
../Planar2D/Planar2D.cpp ../Planar2D/Planar2D.cpp