2015-10-19 06:43:37 +00:00
|
|
|
#define BLAAT
|
2015-10-18 21:01:25 +00:00
|
|
|
#include "RealTimeBullet3CollisionSdk.h"
|
|
|
|
#include "Bullet3Common/b3AlignedObjectArray.h"
|
|
|
|
#include "Bullet3Collision/NarrowPhaseCollision/shared/b3Collidable.h"
|
2015-10-19 06:43:37 +00:00
|
|
|
#include "Bullet3Collision/NarrowPhaseCollision/shared/b3ConvexPolyhedronData.h"
|
2015-10-24 21:00:53 +00:00
|
|
|
#include "Bullet3Collision/BroadPhaseCollision/shared/b3Aabb.h"
|
2015-10-19 06:43:37 +00:00
|
|
|
|
2015-10-20 01:21:45 +00:00
|
|
|
//convert the opaque pointer to int
|
|
|
|
struct RTB3_ColliderOpaque2Int
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
union {
|
|
|
|
plCollisionObjectHandle m_ptrValue;
|
|
|
|
int m_intValue;
|
|
|
|
};
|
2015-10-20 01:21:45 +00:00
|
|
|
};
|
|
|
|
struct RTB3_ShapeOpaque2Int
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
union {
|
|
|
|
plCollisionShapeHandle m_ptrValue;
|
|
|
|
int m_intValue;
|
|
|
|
};
|
2015-10-20 01:21:45 +00:00
|
|
|
};
|
|
|
|
|
2015-10-19 06:43:37 +00:00
|
|
|
enum RTB3ShapeTypes
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
RTB3_SHAPE_SPHERE = 0,
|
2015-10-19 06:43:37 +00:00
|
|
|
RTB3_SHAPE_PLANE,
|
2015-10-28 18:48:36 +00:00
|
|
|
RTB3_SHAPE_CAPSULE,
|
2015-10-19 06:43:37 +00:00
|
|
|
MAX_NUM_SINGLE_SHAPE_TYPES,
|
2015-10-28 18:48:36 +00:00
|
|
|
RTB3_SHAPE_COMPOUND_INTERNAL,
|
2015-10-19 06:43:37 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
//we start at 1, so that the 0 index is 'invalid' just like a nullptr
|
|
|
|
#define START_COLLIDABLE_INDEX 1
|
2015-10-21 01:30:43 +00:00
|
|
|
#define START_SHAPE_INDEX 1
|
2015-10-18 21:01:25 +00:00
|
|
|
|
|
|
|
struct RTB3CollisionWorld
|
|
|
|
{
|
2015-10-19 06:43:37 +00:00
|
|
|
b3AlignedObjectArray<void*> m_collidableUserPointers;
|
|
|
|
b3AlignedObjectArray<int> m_collidableUserIndices;
|
|
|
|
b3AlignedObjectArray<b3Float4> m_collidablePositions;
|
|
|
|
b3AlignedObjectArray<b3Quaternion> m_collidableOrientations;
|
2015-10-21 01:30:43 +00:00
|
|
|
b3AlignedObjectArray<b3Transform> m_collidableTransforms;
|
|
|
|
|
2015-10-18 21:01:25 +00:00
|
|
|
b3AlignedObjectArray<b3Collidable> m_collidables;
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2015-10-18 21:01:25 +00:00
|
|
|
b3AlignedObjectArray<b3GpuChildShape> m_childShapes;
|
2018-09-23 21:17:31 +00:00
|
|
|
b3AlignedObjectArray<b3Aabb> m_localSpaceAabbs;
|
|
|
|
b3AlignedObjectArray<b3Aabb> m_worldSpaceAabbs;
|
2015-10-19 06:43:37 +00:00
|
|
|
b3AlignedObjectArray<b3GpuFace> m_planeFaces;
|
2015-10-18 21:01:25 +00:00
|
|
|
b3AlignedObjectArray<b3CompoundOverlappingPair> m_compoundOverlappingPairs;
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
union {
|
2017-01-16 06:26:11 +00:00
|
|
|
int m_nextFreeShapeIndex;
|
|
|
|
void* m_nextFreeShapePtr;
|
|
|
|
};
|
2015-10-18 21:01:25 +00:00
|
|
|
int m_nextFreeCollidableIndex;
|
2015-10-21 01:30:43 +00:00
|
|
|
int m_nextFreePlaneFaceIndex;
|
2015-10-18 21:01:25 +00:00
|
|
|
|
|
|
|
RTB3CollisionWorld()
|
2018-09-23 21:17:31 +00:00
|
|
|
: m_nextFreeShapeIndex(START_SHAPE_INDEX),
|
|
|
|
m_nextFreeCollidableIndex(START_COLLIDABLE_INDEX),
|
|
|
|
m_nextFreePlaneFaceIndex(0) //this value is never exposed to the user, so we can start from 0
|
2015-10-18 21:01:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct RealTimeBullet3CollisionSdkInternalData
|
|
|
|
{
|
|
|
|
b3AlignedObjectArray<RTB3CollisionWorld*> m_collisionWorlds;
|
|
|
|
};
|
|
|
|
|
|
|
|
RealTimeBullet3CollisionSdk::RealTimeBullet3CollisionSdk()
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
// int szCol = sizeof(b3Collidable);
|
|
|
|
// int szShap = sizeof(b3GpuChildShape);
|
|
|
|
// int szComPair = sizeof(b3CompoundOverlappingPair);
|
2015-10-18 21:01:25 +00:00
|
|
|
m_internalData = new RealTimeBullet3CollisionSdkInternalData;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2015-10-18 21:01:25 +00:00
|
|
|
RealTimeBullet3CollisionSdk::~RealTimeBullet3CollisionSdk()
|
|
|
|
{
|
|
|
|
delete m_internalData;
|
2018-09-23 21:17:31 +00:00
|
|
|
m_internalData = 0;
|
2015-10-18 21:01:25 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2015-10-18 21:01:25 +00:00
|
|
|
plCollisionWorldHandle RealTimeBullet3CollisionSdk::createCollisionWorld(int maxNumObjsCapacity, int maxNumShapesCapacity, int maxNumPairsCapacity)
|
|
|
|
{
|
|
|
|
RTB3CollisionWorld* world = new RTB3CollisionWorld();
|
2018-09-23 21:17:31 +00:00
|
|
|
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);
|
2015-10-21 01:30:43 +00:00
|
|
|
world->m_planeFaces.resize(maxNumShapesCapacity);
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2015-10-18 21:01:25 +00:00
|
|
|
world->m_compoundOverlappingPairs.resize(maxNumPairsCapacity);
|
|
|
|
|
|
|
|
m_internalData->m_collisionWorlds.push_back(world);
|
2018-09-23 21:17:31 +00:00
|
|
|
return (plCollisionWorldHandle)world;
|
2015-10-18 21:01:25 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2015-10-18 21:01:25 +00:00
|
|
|
void RealTimeBullet3CollisionSdk::deleteCollisionWorld(plCollisionWorldHandle worldHandle)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
RTB3CollisionWorld* world = (RTB3CollisionWorld*)worldHandle;
|
2015-10-18 21:01:25 +00:00
|
|
|
int loc = m_internalData->m_collisionWorlds.findLinearSearch(world);
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Assert(loc >= 0 && loc < m_internalData->m_collisionWorlds.size());
|
|
|
|
if (loc >= 0 && loc < m_internalData->m_collisionWorlds.size())
|
2015-10-18 21:01:25 +00:00
|
|
|
{
|
|
|
|
m_internalData->m_collisionWorlds.remove(world);
|
|
|
|
delete world;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
plCollisionShapeHandle RealTimeBullet3CollisionSdk::createSphereShape(plCollisionWorldHandle worldHandle, plReal radius)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
RTB3CollisionWorld* world = (RTB3CollisionWorld*)worldHandle;
|
|
|
|
b3Assert(world->m_nextFreeShapeIndex < world->m_childShapes.size());
|
|
|
|
if (world->m_nextFreeShapeIndex < world->m_childShapes.size())
|
2015-10-19 06:43:37 +00:00
|
|
|
{
|
|
|
|
b3GpuChildShape& shape = world->m_childShapes[world->m_nextFreeShapeIndex];
|
|
|
|
shape.m_childPosition.setZero();
|
2018-09-23 21:17:31 +00:00
|
|
|
shape.m_childOrientation.setValue(0, 0, 0, 1);
|
2015-10-19 06:43:37 +00:00
|
|
|
shape.m_radius = radius;
|
|
|
|
shape.m_shapeType = RTB3_SHAPE_SPHERE;
|
2017-01-16 06:26:11 +00:00
|
|
|
world->m_nextFreeShapeIndex++;
|
2018-09-23 21:17:31 +00:00
|
|
|
return (plCollisionShapeHandle)world->m_nextFreeShapePtr;
|
2015-10-19 06:43:37 +00:00
|
|
|
}
|
|
|
|
return 0;
|
2015-10-18 21:01:25 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
plCollisionShapeHandle RealTimeBullet3CollisionSdk::createPlaneShape(plCollisionWorldHandle worldHandle,
|
|
|
|
plReal planeNormalX,
|
|
|
|
plReal planeNormalY,
|
|
|
|
plReal planeNormalZ,
|
|
|
|
plReal planeConstant)
|
|
|
|
{
|
|
|
|
RTB3CollisionWorld* world = (RTB3CollisionWorld*)worldHandle;
|
2015-10-21 01:30:43 +00:00
|
|
|
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();
|
2018-09-23 21:17:31 +00:00
|
|
|
shape.m_childOrientation.setValue(0, 0, 0, 1);
|
|
|
|
world->m_planeFaces[world->m_nextFreePlaneFaceIndex].m_plane = b3MakeVector4(planeNormalX, planeNormalY, planeNormalZ, planeConstant);
|
2015-10-21 01:30:43 +00:00
|
|
|
shape.m_shapeIndex = world->m_nextFreePlaneFaceIndex++;
|
|
|
|
shape.m_shapeType = RTB3_SHAPE_PLANE;
|
2017-01-16 06:26:11 +00:00
|
|
|
world->m_nextFreeShapeIndex++;
|
2018-09-23 21:17:31 +00:00
|
|
|
return (plCollisionShapeHandle)world->m_nextFreeShapePtr;
|
2015-10-21 01:30:43 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
plCollisionShapeHandle RealTimeBullet3CollisionSdk::createCapsuleShape(plCollisionWorldHandle worldHandle,
|
|
|
|
plReal radius,
|
|
|
|
plReal height,
|
|
|
|
int capsuleAxis)
|
2015-10-28 18:48:36 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
RTB3CollisionWorld* world = (RTB3CollisionWorld*)worldHandle;
|
2015-10-28 18:48:36 +00:00
|
|
|
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();
|
2018-09-23 21:17:31 +00:00
|
|
|
shape.m_childOrientation.setValue(0, 0, 0, 1);
|
2015-10-28 18:48:36 +00:00
|
|
|
shape.m_radius = radius;
|
|
|
|
shape.m_height = height;
|
|
|
|
shape.m_shapeIndex = capsuleAxis;
|
|
|
|
shape.m_shapeType = RTB3_SHAPE_CAPSULE;
|
2017-01-16 06:26:11 +00:00
|
|
|
world->m_nextFreeShapeIndex++;
|
2018-09-23 21:17:31 +00:00
|
|
|
return (plCollisionShapeHandle)world->m_nextFreeShapePtr;
|
2015-10-28 18:48:36 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
plCollisionShapeHandle RealTimeBullet3CollisionSdk::createCompoundShape(plCollisionWorldHandle worldHandle)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
RTB3CollisionWorld* world = (RTB3CollisionWorld*)worldHandle;
|
2015-10-28 18:48:36 +00:00
|
|
|
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();
|
2018-09-23 21:17:31 +00:00
|
|
|
shape.m_childOrientation.setValue(0, 0, 0, 1);
|
2015-10-28 18:48:36 +00:00
|
|
|
shape.m_numChildShapes = 0;
|
|
|
|
shape.m_shapeType = RTB3_SHAPE_COMPOUND_INTERNAL;
|
2017-01-16 06:26:11 +00:00
|
|
|
world->m_nextFreeShapeIndex++;
|
2018-09-23 21:17:31 +00:00
|
|
|
return (plCollisionShapeHandle)world->m_nextFreeShapePtr;
|
2015-10-28 18:48:36 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2015-10-21 01:30:43 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void RealTimeBullet3CollisionSdk::addChildShape(plCollisionWorldHandle worldHandle, plCollisionShapeHandle compoundShape, plCollisionShapeHandle childShape, plVector3 childPos, plQuaternion childOrn)
|
2015-10-28 18:48:36 +00:00
|
|
|
{
|
|
|
|
}
|
2015-10-18 21:01:25 +00:00
|
|
|
void RealTimeBullet3CollisionSdk::deleteShape(plCollisionWorldHandle worldHandle, plCollisionShapeHandle shape)
|
|
|
|
{
|
2015-10-19 06:43:37 +00:00
|
|
|
///todo
|
2015-10-18 21:01:25 +00:00
|
|
|
//deleting shapes would involve a garbage collection phase, and mess up all user indices
|
|
|
|
//this would be solved by one more in-direction, at some performance penalty for certain operations
|
|
|
|
//for now, we don't delete and eventually run out-of-shapes
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2015-10-18 21:01:25 +00:00
|
|
|
void RealTimeBullet3CollisionSdk::addCollisionObject(plCollisionWorldHandle world, plCollisionObjectHandle object)
|
|
|
|
{
|
2015-10-19 06:43:37 +00:00
|
|
|
///createCollisionObject already adds it to the world
|
2015-10-18 21:01:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RealTimeBullet3CollisionSdk::removeCollisionObject(plCollisionWorldHandle world, plCollisionObjectHandle object)
|
|
|
|
{
|
2015-10-19 06:43:37 +00:00
|
|
|
///todo, see deleteShape
|
2015-10-18 21:01:25 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
plCollisionObjectHandle RealTimeBullet3CollisionSdk::createCollisionObject(plCollisionWorldHandle worldHandle, void* userPointer,
|
|
|
|
int userIndex, plCollisionShapeHandle shapeHandle,
|
|
|
|
plVector3 startPosition, plQuaternion startOrientation)
|
2015-10-18 21:01:25 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
RTB3CollisionWorld* world = (RTB3CollisionWorld*)worldHandle;
|
2015-10-21 01:30:43 +00:00
|
|
|
b3Assert(world->m_nextFreeCollidableIndex < world->m_collidables.size());
|
2015-10-19 06:43:37 +00:00
|
|
|
if (world->m_nextFreeCollidableIndex < world->m_collidables.size())
|
|
|
|
{
|
|
|
|
b3Collidable& collidable = world->m_collidables[world->m_nextFreeCollidableIndex];
|
2018-09-23 21:17:31 +00:00
|
|
|
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]);
|
2015-10-21 01:30:43 +00:00
|
|
|
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]);
|
2015-10-19 06:43:37 +00:00
|
|
|
world->m_collidableUserPointers[world->m_nextFreeCollidableIndex] = userPointer;
|
|
|
|
world->m_collidableUserIndices[world->m_nextFreeCollidableIndex] = userIndex;
|
2018-09-23 21:17:31 +00:00
|
|
|
RTB3_ShapeOpaque2Int caster;
|
|
|
|
caster.m_ptrValue = shapeHandle;
|
|
|
|
int shapeIndex = caster.m_intValue;
|
|
|
|
collidable.m_shapeIndex = shapeIndex;
|
2015-10-19 06:43:37 +00:00
|
|
|
b3GpuChildShape& shape = world->m_childShapes[shapeIndex];
|
|
|
|
collidable.m_shapeType = shape.m_shapeType;
|
|
|
|
collidable.m_numChildShapes = 1;
|
|
|
|
|
|
|
|
switch (collidable.m_shapeType)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
case RTB3_SHAPE_SPHERE:
|
2015-10-19 06:43:37 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
case RTB3_SHAPE_PLANE:
|
2015-10-19 06:43:37 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
case RTB3_SHAPE_COMPOUND_INTERNAL:
|
2015-10-19 06:43:37 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
default:
|
2015-10-19 06:43:37 +00:00
|
|
|
{
|
|
|
|
b3Assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*case SHAPE_COMPOUND_OF_CONVEX_HULLS:
|
|
|
|
case SHAPE_COMPOUND_OF_SPHERES:
|
|
|
|
case SHAPE_COMPOUND_OF_CAPSULES:
|
|
|
|
{
|
|
|
|
collidable.m_numChildShapes = shape.m_numChildShapes;
|
|
|
|
collidable.m_shapeIndex = shape.m_shapeIndex;
|
|
|
|
break;
|
|
|
|
*/
|
2017-01-16 06:26:11 +00:00
|
|
|
world->m_nextFreeCollidableIndex++;
|
|
|
|
return (plCollisionObjectHandle)world->m_nextFreeShapePtr;
|
2015-10-19 06:43:37 +00:00
|
|
|
}
|
2015-10-18 21:01:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2015-10-18 21:01:25 +00:00
|
|
|
void RealTimeBullet3CollisionSdk::deleteCollisionObject(plCollisionObjectHandle body)
|
|
|
|
{
|
2015-10-19 06:43:37 +00:00
|
|
|
///todo, see deleteShape
|
2015-10-18 21:01:25 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2015-10-19 06:43:37 +00:00
|
|
|
void RealTimeBullet3CollisionSdk::setCollisionObjectTransform(plCollisionWorldHandle world, plCollisionObjectHandle body,
|
2018-09-23 21:17:31 +00:00
|
|
|
plVector3 position, plQuaternion orientation)
|
2015-10-18 21:01:25 +00:00
|
|
|
{
|
|
|
|
}
|
2015-10-19 06:43:37 +00:00
|
|
|
|
|
|
|
struct plContactCache
|
|
|
|
{
|
|
|
|
lwContactPoint* pointsOut;
|
|
|
|
int pointCapacity;
|
|
|
|
int numAddedPoints;
|
|
|
|
};
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
typedef void (*plDetectCollisionFunc)(RTB3CollisionWorld* world, int colA, int shapeIndexA, int colB, int shapeIndexB,
|
|
|
|
plContactCache* contactCache);
|
2015-10-19 06:43:37 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void detectCollisionDummy(RTB3CollisionWorld* world, int colA, int shapeIndexA, int colB, int shapeIndexB,
|
|
|
|
plContactCache* contactCache)
|
2015-10-19 06:43:37 +00:00
|
|
|
{
|
|
|
|
(void)world;
|
2018-09-23 21:17:31 +00:00
|
|
|
(void)colA, (void)colB;
|
2015-10-19 06:43:37 +00:00
|
|
|
(void)contactCache;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void plVecCopy(float* dst, const b3Vector3& src)
|
2015-10-18 21:01:25 +00:00
|
|
|
{
|
2015-10-19 06:43:37 +00:00
|
|
|
dst[0] = src.x;
|
|
|
|
dst[1] = src.y;
|
|
|
|
dst[2] = src.z;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
void plVecCopy(double* dst, const b3Vector3& src)
|
2015-10-20 01:21:45 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
dst[0] = src.x;
|
|
|
|
dst[1] = src.y;
|
|
|
|
dst[2] = src.z;
|
2015-10-20 01:21:45 +00:00
|
|
|
}
|
2015-10-19 06:43:37 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void ComputeClosestPointsPlaneSphere(const b3Vector3& planeNormalWorld, b3Scalar planeConstant, const b3Vector3& spherePosWorld, b3Scalar sphereRadius, plContactCache* contactCache)
|
2015-10-19 06:43:37 +00:00
|
|
|
{
|
|
|
|
if (contactCache->numAddedPoints < contactCache->pointCapacity)
|
|
|
|
{
|
|
|
|
lwContactPoint& pointOut = contactCache->pointsOut[contactCache->numAddedPoints];
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Scalar t = -(spherePosWorld.dot(-planeNormalWorld) + planeConstant);
|
|
|
|
b3Vector3 intersectionPoint = spherePosWorld + t * -planeNormalWorld;
|
|
|
|
b3Scalar distance = t - sphereRadius;
|
|
|
|
if (distance <= 0)
|
2015-10-19 06:43:37 +00:00
|
|
|
{
|
|
|
|
pointOut.m_distance = distance;
|
2018-09-23 21:17:31 +00:00
|
|
|
plVecCopy(pointOut.m_ptOnBWorld, intersectionPoint);
|
|
|
|
plVecCopy(pointOut.m_ptOnAWorld, spherePosWorld + sphereRadius * -planeNormalWorld);
|
|
|
|
plVecCopy(pointOut.m_normalOnB, planeNormalWorld);
|
2015-10-19 06:43:37 +00:00
|
|
|
contactCache->numAddedPoints++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void ComputeClosestPointsSphereSphere(b3Scalar sphereARadius, const b3Vector3& sphereAPosWorld, b3Scalar sphereBRadius, const b3Vector3& sphereBPosWorld, plContactCache* contactCache)
|
|
|
|
{
|
2015-10-19 06:43:37 +00:00
|
|
|
if (contactCache->numAddedPoints < contactCache->pointCapacity)
|
|
|
|
{
|
|
|
|
lwContactPoint& pointOut = contactCache->pointsOut[contactCache->numAddedPoints];
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Vector3 diff = sphereAPosWorld - sphereBPosWorld;
|
2015-10-21 01:30:43 +00:00
|
|
|
|
2015-10-19 06:43:37 +00:00
|
|
|
b3Scalar len = diff.length();
|
2018-09-23 21:17:31 +00:00
|
|
|
pointOut.m_distance = len - (sphereARadius + sphereBRadius);
|
|
|
|
if (pointOut.m_distance <= 0)
|
2015-10-19 06:43:37 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Vector3 normOnB = b3MakeVector3(1, 0, 0);
|
|
|
|
if (len > B3_EPSILON)
|
|
|
|
{
|
2015-10-19 06:43:37 +00:00
|
|
|
normOnB = diff / len;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
plVecCopy(pointOut.m_normalOnB, normOnB);
|
|
|
|
b3Vector3 ptAWorld = sphereAPosWorld - sphereARadius * normOnB;
|
|
|
|
plVecCopy(pointOut.m_ptOnAWorld, ptAWorld);
|
|
|
|
plVecCopy(pointOut.m_ptOnBWorld, ptAWorld - normOnB * pointOut.m_distance);
|
|
|
|
|
2015-10-19 06:43:37 +00:00
|
|
|
contactCache->numAddedPoints++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
B3_FORCE_INLINE void detectCollisionSphereSphere(RTB3CollisionWorld* world, int colA, int shapeIndexA, int colB, int shapeIndexB,
|
|
|
|
plContactCache* contactCache)
|
2015-10-19 06:43:37 +00:00
|
|
|
{
|
2015-10-21 01:30:43 +00:00
|
|
|
const b3Scalar radiusA = world->m_childShapes[shapeIndexA].m_radius;
|
|
|
|
const b3Scalar radiusB = world->m_childShapes[shapeIndexB].m_radius;
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2015-10-21 01:30:43 +00:00
|
|
|
const b3Transform& trA = world->m_collidableTransforms[colA];
|
2015-10-19 06:43:37 +00:00
|
|
|
const b3Vector3& sphereALocalPos = world->m_childShapes[shapeIndexA].m_childPosition;
|
|
|
|
b3Vector3 spherePosAWorld = trA(sphereALocalPos);
|
2015-10-21 01:30:43 +00:00
|
|
|
//b3Vector3 spherePosAWorld = b3QuatRotate( world->m_collidableOrientations[colA], sphereALocalPos ) + (world->m_collidablePositions[colA]);
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2015-10-21 01:30:43 +00:00
|
|
|
const b3Transform& trB = world->m_collidableTransforms[colB];
|
2015-10-19 06:43:37 +00:00
|
|
|
const b3Vector3& sphereBLocalPos = world->m_childShapes[shapeIndexB].m_childPosition;
|
2015-10-20 01:21:45 +00:00
|
|
|
b3Vector3 spherePosBWorld = trB(sphereBLocalPos);
|
2015-10-21 01:30:43 +00:00
|
|
|
//b3Vector3 spherePosBWorld = b3QuatRotate( world->m_collidableOrientations[colB], sphereBLocalPos ) + (world->m_collidablePositions[colB]);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
ComputeClosestPointsSphereSphere(radiusA, spherePosAWorld, radiusB, spherePosBWorld, contactCache);
|
2015-10-19 06:43:37 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void detectCollisionSpherePlane(RTB3CollisionWorld* world, int colA, int shapeIndexA, int colB, int shapeIndexB,
|
|
|
|
plContactCache* contactCache)
|
2015-10-19 06:43:37 +00:00
|
|
|
{
|
2015-10-21 01:30:43 +00:00
|
|
|
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;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
ComputeClosestPointsPlaneSphere(planeNormal, planeConstant, spherePosAWorld, world->m_childShapes[shapeIndexA].m_radius, contactCache);
|
2015-10-19 06:43:37 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void detectCollisionPlaneSphere(RTB3CollisionWorld* world, int colA, int shapeIndexA, int colB, int shapeIndexB,
|
|
|
|
plContactCache* contactCache)
|
2015-10-19 06:43:37 +00:00
|
|
|
{
|
|
|
|
(void)world;
|
2018-09-23 21:17:31 +00:00
|
|
|
(void)colA, (void)shapeIndexA, (void)colB, (void)shapeIndexB;
|
2015-10-19 06:43:37 +00:00
|
|
|
(void)contactCache;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef RTB3_SHAPE_CAPSULE
|
2018-09-23 21:17:31 +00:00
|
|
|
plDetectCollisionFunc funcTbl_detectCollision[MAX_NUM_SINGLE_SHAPE_TYPES, ][MAX_NUM_SINGLE_SHAPE_TYPES, ] = {
|
|
|
|
{detectCollisionSphereSphere, detectCollisionSpherePlane, detectCollisionSphereCapsule},
|
|
|
|
{detectCollisionPlaneSphere, detectCollisionDummy, detectCollisionPlaneCapsule},
|
|
|
|
{detectCollisionCapsuleSphere, detectCollisionCapsulePlane, detectCollisionCapsuleCapsule},
|
2015-10-19 06:43:37 +00:00
|
|
|
};
|
|
|
|
#else
|
|
|
|
plDetectCollisionFunc funcTbl_detectCollision[MAX_NUM_SINGLE_SHAPE_TYPES][MAX_NUM_SINGLE_SHAPE_TYPES] = {
|
2018-09-23 21:17:31 +00:00
|
|
|
{detectCollisionSphereSphere, detectCollisionSpherePlane},
|
|
|
|
{detectCollisionPlaneSphere, detectCollisionDummy},
|
2015-10-19 06:43:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int RealTimeBullet3CollisionSdk::collide(plCollisionWorldHandle worldHandle, plCollisionObjectHandle colAHandle, plCollisionObjectHandle colBHandle,
|
|
|
|
lwContactPoint* pointsOutOrg, int pointCapacity)
|
|
|
|
{
|
|
|
|
RTB3CollisionWorld* world = (RTB3CollisionWorld*)worldHandle;
|
|
|
|
RTB3_ColliderOpaque2Int caster;
|
|
|
|
caster.m_ptrValue = colAHandle;
|
|
|
|
int colAIndex = caster.m_intValue;
|
|
|
|
caster.m_ptrValue = colBHandle;
|
|
|
|
int colBIndex = caster.m_intValue;
|
|
|
|
const b3Collidable& colA = world->m_collidables[colAIndex];
|
2015-10-19 06:43:37 +00:00
|
|
|
const b3Collidable& colB = world->m_collidables[colBIndex];
|
|
|
|
|
|
|
|
plContactCache contactCache;
|
|
|
|
contactCache.pointCapacity = pointCapacity;
|
|
|
|
contactCache.pointsOut = pointsOutOrg;
|
|
|
|
contactCache.numAddedPoints = 0;
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < colA.m_numChildShapes; i++)
|
2015-10-19 06:43:37 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int j = 0; j < colB.m_numChildShapes; j++)
|
2015-10-19 06:43:37 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (contactCache.numAddedPoints < pointCapacity)
|
2015-10-19 06:43:37 +00:00
|
|
|
{
|
2015-10-28 18:48:36 +00:00
|
|
|
//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);
|
2015-10-19 06:43:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return contactCache.numAddedPoints;
|
|
|
|
}
|
|
|
|
|
2015-10-18 21:01:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2015-10-20 01:21:45 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void RealTimeBullet3CollisionSdk::collideWorld(plCollisionWorldHandle worldHandle,
|
|
|
|
plNearCallback filter, void* userData)
|
2015-10-18 21:01:25 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
RTB3CollisionWorld* world = (RTB3CollisionWorld*)worldHandle;
|
2015-10-19 06:43:37 +00:00
|
|
|
if (filter)
|
|
|
|
{
|
2015-10-21 01:30:43 +00:00
|
|
|
RTB3_ColliderOpaque2Int caster;
|
|
|
|
plCollisionObjectHandle colA;
|
|
|
|
plCollisionObjectHandle colB;
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = START_COLLIDABLE_INDEX; i < world->m_nextFreeCollidableIndex; i++)
|
2015-10-19 06:43:37 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int j = i + 1; j < world->m_nextFreeCollidableIndex; j++)
|
2015-10-19 06:43:37 +00:00
|
|
|
{
|
2015-10-21 01:30:43 +00:00
|
|
|
caster.m_intValue = i;
|
2018-09-23 21:17:31 +00:00
|
|
|
colA = caster.m_ptrValue;
|
|
|
|
caster.m_intValue = j;
|
2015-10-21 01:30:43 +00:00
|
|
|
colB = caster.m_ptrValue;
|
2018-09-23 21:17:31 +00:00
|
|
|
filter((plCollisionSdkHandle)this, worldHandle, userData, colA, colB);
|
2015-10-19 06:43:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-18 21:01:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
plCollisionSdkHandle RealTimeBullet3CollisionSdk::createRealTimeBullet3CollisionSdkHandle()
|
|
|
|
{
|
|
|
|
return (plCollisionSdkHandle) new RealTimeBullet3CollisionSdk();
|
|
|
|
}
|