mirror of
https://github.com/bulletphysics/bullet3
synced 2024-12-13 21:30:09 +00:00
although still not implemented, IMU enum had wrong value, thanks JF
This commit is contained in:
parent
3d3830962a
commit
21b7a47129
@ -40,10 +40,10 @@ void plDeleteShape(plCollisionSdkHandle collisionSdkHandle, plCollisionShapeHand
|
||||
sdk->deleteShape(shapeHandle);
|
||||
}
|
||||
|
||||
plCollisionObjectHandle plCreateCollisionObject( plCollisionSdkHandle collisionSdkHandle, void* user_data, plCollisionShapeHandle cshape )
|
||||
plCollisionObjectHandle plCreateCollisionObject( plCollisionSdkHandle collisionSdkHandle, void* user_data, plCollisionShapeHandle cshape ,plVector3 childPos,plQuaternion childOrn)
|
||||
{
|
||||
CollisionSdkInterface* sdk = (CollisionSdkInterface*) collisionSdkHandle;
|
||||
return sdk->createCollisionObject(user_data, cshape);
|
||||
return sdk->createCollisionObject(user_data, cshape, childPos, childOrn);
|
||||
|
||||
}
|
||||
|
||||
@ -64,63 +64,17 @@ void plRemoveCollisionObject(plCollisionSdkHandle collisionSdkHandle, plCollisio
|
||||
sdk->removeCollisionObject(world,object);
|
||||
}
|
||||
|
||||
/* Collision Queries */
|
||||
int plCollide(plCollisionSdkHandle collisionSdkHandle, plCollisionWorldHandle worldHandle, plCollisionObjectHandle colA, plCollisionObjectHandle colB,
|
||||
lwContactPoint* pointsOut, int pointCapacity)
|
||||
{
|
||||
CollisionSdkInterface* sdk = (CollisionSdkInterface*) collisionSdkHandle;
|
||||
return sdk->collide(worldHandle, colA,colB,pointsOut,pointCapacity);
|
||||
}
|
||||
|
||||
//plCollisionSdkHandle plCreateRealTimeBullet3CollisionSdk();
|
||||
//plCollisionSdkHandle plCreateCustomCollisionSdk();
|
||||
|
||||
|
||||
#if 0
|
||||
extern void plDeleteCollisionWorld(plCollisionWorldHandle world);
|
||||
|
||||
|
||||
extern void plAddCollisionObject(plCollisionWorldHandle world, plCollisionObjectHandle object);
|
||||
extern void plRemoveCollisionObject(plCollisionWorldHandle world, plCollisionObjectHandle object);
|
||||
|
||||
|
||||
/* Collision Object */
|
||||
|
||||
extern plCollisionObjectHandle plCreateCollisionObject( plCollisionSdkHandle sdk, void* user_data, plCollisionShapeHandle cshape );
|
||||
extern void plDeleteCollisionObject(plCollisionSdkHandle sdk, plCollisionObjectHandle body);
|
||||
|
||||
|
||||
/* Collision Shape definition */
|
||||
|
||||
extern plCollisionShapeHandle plNewSphereShape(plCollisionSdkHandle sdk, plReal radius);
|
||||
extern plCollisionShapeHandle plNewCapsuleShape(plCollisionSdkHandle sdk, plReal radius, plReal height);
|
||||
extern plCollisionShapeHandle plNewPlaneShape(plCollisionSdkHandle sdk, plReal planeNormalX,
|
||||
plReal planeNormalY,
|
||||
plReal planeNormalZ,
|
||||
plReal planeConstant);
|
||||
extern plCollisionShapeHandle plNewCompoundShape(plCollisionSdkHandle sdk);
|
||||
extern void plAddChildShape(plCollisionShapeHandle compoundShape,plCollisionShapeHandle childShape, plVector3 childPos,plQuaternion childOrn);
|
||||
|
||||
extern void plDeleteShape(plCollisionShapeHandle shape);
|
||||
|
||||
|
||||
|
||||
/* Contact Results */
|
||||
|
||||
struct lwContactPoint
|
||||
{
|
||||
plVector3 m_ptOnAWorld;
|
||||
plVector3 m_ptOnBWorld;
|
||||
plVector3 m_normalOnB;
|
||||
plReal m_distance;
|
||||
};
|
||||
|
||||
/* Collision Filtering */
|
||||
typedef void(*plNearCallback)(plCollisionSdkHandle sdk, void* userData, plCollisionObjectHandle objA, plCollisionObjectHandle objB);
|
||||
|
||||
|
||||
/* Collision Queries */
|
||||
extern int plCollide(plCollisionSdkHandle sdk, plCollisionObjectHandle colA, plCollisionObjectHandle colB,
|
||||
lwContactPoint* pointsOut, int pointCapacity);
|
||||
|
||||
extern void plWorldCollide(plCollisionWorldHandle world,
|
||||
plNearCallback filter, void* userData);
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
void plWorldCollide(plCollisionSdkHandle collisionSdkHandle, plCollisionWorldHandle world,
|
||||
plNearCallback filter, void* userData)
|
||||
{
|
||||
CollisionSdkInterface* sdk = (CollisionSdkInterface*) collisionSdkHandle;
|
||||
sdk->collideWorld(world,filter,userData);
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ extern "C" {
|
||||
|
||||
/* Collision Object */
|
||||
|
||||
extern plCollisionObjectHandle plCreateCollisionObject( plCollisionSdkHandle sdkHandle, void* user_data, plCollisionShapeHandle cshape );
|
||||
extern plCollisionObjectHandle plCreateCollisionObject( plCollisionSdkHandle sdkHandle, void* user_data, plCollisionShapeHandle cshape , plVector3 startPosition,plQuaternion startOrientation);
|
||||
extern void plDeleteCollisionObject(plCollisionSdkHandle sdkHandle, plCollisionObjectHandle body);
|
||||
|
||||
|
||||
@ -85,10 +85,10 @@ extern "C" {
|
||||
|
||||
|
||||
/* Collision Queries */
|
||||
extern int plCollide(plCollisionSdkHandle sdk, plCollisionObjectHandle colA, plCollisionObjectHandle colB,
|
||||
extern int plCollide(plCollisionSdkHandle sdkHandle, plCollisionWorldHandle worldHandle, plCollisionObjectHandle colA, plCollisionObjectHandle colB,
|
||||
lwContactPoint* pointsOut, int pointCapacity);
|
||||
|
||||
extern void plWorldCollide(plCollisionWorldHandle world,
|
||||
extern void plWorldCollide(plCollisionSdkHandle sdkHandle, plCollisionWorldHandle world,
|
||||
plNearCallback filter, void* userData);
|
||||
|
||||
|
||||
|
@ -17,6 +17,13 @@
|
||||
#include "CollisionSdkC_Api.h"
|
||||
|
||||
|
||||
static int myCounter=0;
|
||||
|
||||
void myNearCallback(plCollisionSdkHandle sdk, void* userData, plCollisionObjectHandle objA, plCollisionObjectHandle objB)
|
||||
{
|
||||
myCounter++;
|
||||
}
|
||||
|
||||
class CollisionTutorialBullet2 : public CommonExampleInterface
|
||||
{
|
||||
CommonGraphicsApp* m_app;
|
||||
@ -59,11 +66,29 @@ public:
|
||||
float radius = 1.f;
|
||||
plCollisionShapeHandle colShape = plCreateSphereShape(m_collisionSdkHandle, radius);
|
||||
void* userData = 0;
|
||||
plCollisionObjectHandle colObj = plCreateCollisionObject(m_collisionSdkHandle,userData,colShape);
|
||||
plAddCollisionObject(m_collisionSdkHandle, m_collisionWorldHandle,colObj);
|
||||
plRemoveCollisionObject(m_collisionSdkHandle,m_collisionWorldHandle,colObj);
|
||||
plDeleteCollisionObject(m_collisionSdkHandle,colObj);
|
||||
plDeleteShape(m_collisionSdkHandle,colShape);
|
||||
btAlignedObjectArray<plCollisionObjectHandle> colliders;
|
||||
|
||||
for (int i=0;i<3;i++)
|
||||
{
|
||||
btVector3 pos(0,i*1,0);
|
||||
btQuaternion orn(0,0,0,1);
|
||||
plCollisionObjectHandle colObj = plCreateCollisionObject(m_collisionSdkHandle,userData,colShape,pos,orn);
|
||||
colliders.push_back(colObj);
|
||||
plAddCollisionObject(m_collisionSdkHandle, m_collisionWorldHandle,colObj);
|
||||
}
|
||||
lwContactPoint pointsOut[10];
|
||||
int pointCapacity=10;
|
||||
|
||||
int numContacts = plCollide(m_collisionSdkHandle,m_collisionWorldHandle,colliders[0],colliders[1],pointsOut,pointCapacity);
|
||||
printf("numContacts = %d\n", numContacts);
|
||||
void* myUserPtr = 0;
|
||||
myCounter = 0;
|
||||
plWorldCollide(m_collisionSdkHandle,m_collisionWorldHandle,myNearCallback, myUserPtr);
|
||||
printf("myCounter=%d\n",myCounter);
|
||||
|
||||
//plRemoveCollisionObject(m_collisionSdkHandle,m_collisionWorldHandle,colObj);
|
||||
//plDeleteCollisionObject(m_collisionSdkHandle,colObj);
|
||||
//plDeleteShape(m_collisionSdkHandle,colShape);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -91,7 +91,9 @@ void Bullet2CollisionSdk::removeCollisionObject(plCollisionWorldHandle worldHand
|
||||
}
|
||||
}
|
||||
|
||||
plCollisionObjectHandle Bullet2CollisionSdk::createCollisionObject( void* user_data, plCollisionShapeHandle shapeHandle )
|
||||
plCollisionObjectHandle Bullet2CollisionSdk::createCollisionObject( void* user_data, plCollisionShapeHandle shapeHandle ,
|
||||
plVector3 startPosition,plQuaternion startOrientation )
|
||||
|
||||
{
|
||||
btCollisionShape* colShape = (btCollisionShape*) shapeHandle;
|
||||
btAssert(colShape);
|
||||
@ -99,7 +101,10 @@ plCollisionObjectHandle Bullet2CollisionSdk::createCollisionObject( void* user_
|
||||
{
|
||||
btCollisionObject* colObj= new btCollisionObject;
|
||||
colObj->setCollisionShape(colShape);
|
||||
colObj->setWorldTransform(btTransform::getIdentity());
|
||||
btTransform tr;
|
||||
tr.setOrigin(btVector3(startPosition[0],startPosition[1],startPosition[2]));
|
||||
tr.setRotation(btQuaternion(startOrientation[0],startOrientation[1],startOrientation[2],startOrientation[3]));
|
||||
colObj->setWorldTransform(tr);
|
||||
return (plCollisionObjectHandle) colObj;
|
||||
}
|
||||
return 0;
|
||||
@ -111,6 +116,70 @@ void Bullet2CollisionSdk::deleteCollisionObject(plCollisionObjectHandle bodyHand
|
||||
delete colObj;
|
||||
}
|
||||
|
||||
struct Bullet2ContactResultCallback : public btCollisionWorld::ContactResultCallback
|
||||
{
|
||||
int m_numContacts;
|
||||
lwContactPoint* m_pointsOut;
|
||||
int m_pointCapacity;
|
||||
|
||||
Bullet2ContactResultCallback() :m_numContacts(0)
|
||||
{
|
||||
}
|
||||
virtual btScalar addSingleResult(btManifoldPoint& cp, const btCollisionObjectWrapper* colObj0Wrap,int partId0,int index0,const btCollisionObjectWrapper* colObj1Wrap,int partId1,int index1)
|
||||
{
|
||||
if (m_numContacts<m_pointCapacity)
|
||||
{
|
||||
lwContactPoint& ptOut = m_pointsOut[m_numContacts];
|
||||
ptOut.m_distance = cp.m_distance1;
|
||||
ptOut.m_normalOnB[0] = cp.m_normalWorldOnB.getX();
|
||||
ptOut.m_normalOnB[1] = cp.m_normalWorldOnB.getY();
|
||||
ptOut.m_normalOnB[2] = cp.m_normalWorldOnB.getZ();
|
||||
m_numContacts++;
|
||||
}
|
||||
|
||||
return 1.f;
|
||||
}
|
||||
};
|
||||
|
||||
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;
|
||||
btAssert(world && colObjA && colObjB);
|
||||
if (world == m_internalData->m_collisionWorld && colObjA && colObjB)
|
||||
{
|
||||
Bullet2ContactResultCallback cb;
|
||||
world->contactPairTest(colObjA,colObjB,cb);
|
||||
return cb.m_numContacts;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static plNearCallback gTmpFilter;
|
||||
static int gContactCount = 0;
|
||||
|
||||
void Bullet2NearCallback(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, const btDispatcherInfo& dispatchInfo)
|
||||
{
|
||||
if (gTmpFilter)
|
||||
{
|
||||
gContactCount++;
|
||||
}
|
||||
}
|
||||
|
||||
void Bullet2CollisionSdk::collideWorld( plCollisionWorldHandle worldHandle,
|
||||
plNearCallback filter, void* userData)
|
||||
{
|
||||
btCollisionWorld* world = (btCollisionWorld*) worldHandle;
|
||||
//chain the near-callback
|
||||
gTmpFilter = filter;
|
||||
gContactCount = 0;
|
||||
|
||||
m_internalData->m_dispatcher->setNearCallback(Bullet2NearCallback);
|
||||
world->performDiscreteCollisionDetection();
|
||||
gTmpFilter = 0;
|
||||
}
|
||||
|
||||
plCollisionSdkHandle Bullet2CollisionSdk::createBullet2SdkHandle()
|
||||
{
|
||||
|
@ -24,10 +24,16 @@ public:
|
||||
virtual void addCollisionObject(plCollisionWorldHandle world, plCollisionObjectHandle object);
|
||||
virtual void removeCollisionObject(plCollisionWorldHandle world, plCollisionObjectHandle object);
|
||||
|
||||
virtual plCollisionObjectHandle createCollisionObject( void* user_data, plCollisionShapeHandle cshape );
|
||||
virtual void deleteCollisionObject(plCollisionObjectHandle body);
|
||||
virtual plCollisionObjectHandle createCollisionObject( void* user_data, plCollisionShapeHandle cshape ,
|
||||
plVector3 startPosition,plQuaternion startOrientation );
|
||||
virtual void deleteCollisionObject(plCollisionObjectHandle body);
|
||||
|
||||
virtual int collide(plCollisionWorldHandle world,plCollisionObjectHandle colA, plCollisionObjectHandle colB,
|
||||
lwContactPoint* pointsOut, int pointCapacity);
|
||||
|
||||
virtual void collideWorld( plCollisionWorldHandle world,
|
||||
plNearCallback filter, void* userData);
|
||||
|
||||
static plCollisionSdkHandle createBullet2SdkHandle();
|
||||
};
|
||||
|
||||
|
@ -22,8 +22,15 @@ public:
|
||||
virtual void addCollisionObject(plCollisionWorldHandle world, plCollisionObjectHandle object)=0;
|
||||
virtual void removeCollisionObject(plCollisionWorldHandle world, plCollisionObjectHandle object)=0;
|
||||
|
||||
virtual plCollisionObjectHandle createCollisionObject( void* user_data, plCollisionShapeHandle cshape )=0;
|
||||
virtual plCollisionObjectHandle createCollisionObject( void* user_data, plCollisionShapeHandle cshape ,
|
||||
plVector3 startPosition,plQuaternion startOrientation )=0;
|
||||
virtual void deleteCollisionObject(plCollisionObjectHandle body)=0;
|
||||
|
||||
virtual int collide(plCollisionWorldHandle world,plCollisionObjectHandle colA, plCollisionObjectHandle colB,
|
||||
lwContactPoint* pointsOut, int pointCapacity)=0;
|
||||
|
||||
virtual void collideWorld( plCollisionWorldHandle world,
|
||||
plNearCallback filter, void* userData)=0;
|
||||
|
||||
|
||||
};
|
||||
|
@ -178,7 +178,7 @@ struct SendActualStateArgs
|
||||
enum EnumSensorTypes
|
||||
{
|
||||
SENSOR_FORCE_TORQUE=1,
|
||||
SENSOR_IMU=1,
|
||||
SENSOR_IMU=2,
|
||||
};
|
||||
|
||||
struct CreateSensorArgs
|
||||
|
Loading…
Reference in New Issue
Block a user