[1963] | 1 | /* |
---|
| 2 | Bullet Continuous Collision Detection and Physics Library |
---|
| 3 | Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ |
---|
| 4 | |
---|
| 5 | This software is provided 'as-is', without any express or implied warranty. |
---|
| 6 | In no event will the authors be held liable for any damages arising from the use of this software. |
---|
| 7 | Permission is granted to anyone to use this software for any purpose, |
---|
| 8 | including commercial applications, and to alter it and redistribute it freely, |
---|
| 9 | subject to the following restrictions: |
---|
| 10 | |
---|
| 11 | 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. |
---|
| 12 | 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. |
---|
| 13 | 3. This notice may not be removed or altered from any source distribution. |
---|
| 14 | */ |
---|
| 15 | |
---|
| 16 | /* |
---|
| 17 | Draft high-level generic physics C-API. For low-level access, use the physics SDK native API's. |
---|
| 18 | Work in progress, functionality will be added on demand. |
---|
| 19 | |
---|
| 20 | If possible, use the richer Bullet C++ API, by including "btBulletDynamicsCommon.h" |
---|
| 21 | */ |
---|
| 22 | |
---|
| 23 | #ifndef BULLET_C_API_H |
---|
| 24 | #define BULLET_C_API_H |
---|
| 25 | |
---|
| 26 | #define PL_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name |
---|
| 27 | |
---|
| 28 | #ifdef BT_USE_DOUBLE_PRECISION |
---|
| 29 | typedef double plReal; |
---|
| 30 | #else |
---|
| 31 | typedef float plReal; |
---|
| 32 | #endif |
---|
| 33 | |
---|
| 34 | typedef plReal plVector3[3]; |
---|
| 35 | typedef plReal plQuaternion[4]; |
---|
| 36 | |
---|
| 37 | #ifdef __cplusplus |
---|
| 38 | extern "C" { |
---|
| 39 | #endif |
---|
| 40 | |
---|
| 41 | /* Particular physics SDK */ |
---|
| 42 | PL_DECLARE_HANDLE(plPhysicsSdkHandle); |
---|
| 43 | |
---|
| 44 | /* Dynamics world, belonging to some physics SDK */ |
---|
| 45 | PL_DECLARE_HANDLE(plDynamicsWorldHandle); |
---|
| 46 | |
---|
| 47 | /* Rigid Body that can be part of a Dynamics World */ |
---|
| 48 | PL_DECLARE_HANDLE(plRigidBodyHandle); |
---|
| 49 | |
---|
| 50 | /* Collision Shape/Geometry, property of a Rigid Body */ |
---|
| 51 | PL_DECLARE_HANDLE(plCollisionShapeHandle); |
---|
| 52 | |
---|
| 53 | /* Constraint for Rigid Bodies */ |
---|
| 54 | PL_DECLARE_HANDLE(plConstraintHandle); |
---|
| 55 | |
---|
| 56 | /* Triangle Mesh interface */ |
---|
| 57 | PL_DECLARE_HANDLE(plMeshInterfaceHandle); |
---|
| 58 | |
---|
| 59 | /* Broadphase Scene/Proxy Handles */ |
---|
| 60 | PL_DECLARE_HANDLE(plCollisionBroadphaseHandle); |
---|
| 61 | PL_DECLARE_HANDLE(plBroadphaseProxyHandle); |
---|
| 62 | PL_DECLARE_HANDLE(plCollisionWorldHandle); |
---|
| 63 | |
---|
| 64 | /* |
---|
| 65 | Create and Delete a Physics SDK |
---|
| 66 | */ |
---|
| 67 | |
---|
| 68 | extern plPhysicsSdkHandle plNewBulletSdk(); //this could be also another sdk, like ODE, PhysX etc. |
---|
| 69 | extern void plDeletePhysicsSdk(plPhysicsSdkHandle physicsSdk); |
---|
| 70 | |
---|
| 71 | /* Collision World, not strictly necessary, you can also just create a Dynamics World with Rigid Bodies which internally manages the Collision World with Collision Objects */ |
---|
| 72 | |
---|
| 73 | typedef void(*btBroadphaseCallback)(void* clientData, void* object1,void* object2); |
---|
| 74 | |
---|
| 75 | extern plCollisionBroadphaseHandle plCreateSapBroadphase(btBroadphaseCallback beginCallback,btBroadphaseCallback endCallback); |
---|
| 76 | |
---|
| 77 | extern void plDestroyBroadphase(plCollisionBroadphaseHandle bp); |
---|
| 78 | |
---|
| 79 | extern plBroadphaseProxyHandle plCreateProxy(plCollisionBroadphaseHandle bp, void* clientData, plReal minX,plReal minY,plReal minZ, plReal maxX,plReal maxY, plReal maxZ); |
---|
| 80 | |
---|
| 81 | extern void plDestroyProxy(plCollisionBroadphaseHandle bp, plBroadphaseProxyHandle proxyHandle); |
---|
| 82 | |
---|
| 83 | extern void plSetBoundingBox(plBroadphaseProxyHandle proxyHandle, plReal minX,plReal minY,plReal minZ, plReal maxX,plReal maxY, plReal maxZ); |
---|
| 84 | |
---|
| 85 | /* todo: add pair cache support with queries like add/remove/find pair */ |
---|
| 86 | |
---|
| 87 | extern plCollisionWorldHandle plCreateCollisionWorld(plPhysicsSdkHandle physicsSdk); |
---|
| 88 | |
---|
| 89 | /* todo: add/remove objects */ |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | /* Dynamics World */ |
---|
| 93 | |
---|
| 94 | extern plDynamicsWorldHandle plCreateDynamicsWorld(plPhysicsSdkHandle physicsSdk); |
---|
| 95 | |
---|
| 96 | extern void plDeleteDynamicsWorld(plDynamicsWorldHandle world); |
---|
| 97 | |
---|
| 98 | extern void plStepSimulation(plDynamicsWorldHandle, plReal timeStep); |
---|
| 99 | |
---|
| 100 | extern void plAddRigidBody(plDynamicsWorldHandle world, plRigidBodyHandle object); |
---|
| 101 | |
---|
| 102 | extern void plRemoveRigidBody(plDynamicsWorldHandle world, plRigidBodyHandle object); |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | /* Rigid Body */ |
---|
| 106 | |
---|
| 107 | extern plRigidBodyHandle plCreateRigidBody( void* user_data, float mass, plCollisionShapeHandle cshape ); |
---|
| 108 | |
---|
| 109 | extern void plDeleteRigidBody(plRigidBodyHandle body); |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | /* Collision Shape definition */ |
---|
| 113 | |
---|
| 114 | extern plCollisionShapeHandle plNewSphereShape(plReal radius); |
---|
| 115 | extern plCollisionShapeHandle plNewBoxShape(plReal x, plReal y, plReal z); |
---|
| 116 | extern plCollisionShapeHandle plNewCapsuleShape(plReal radius, plReal height); |
---|
| 117 | extern plCollisionShapeHandle plNewConeShape(plReal radius, plReal height); |
---|
| 118 | extern plCollisionShapeHandle plNewCylinderShape(plReal radius, plReal height); |
---|
| 119 | extern plCollisionShapeHandle plNewCompoundShape(); |
---|
| 120 | extern void plAddChildShape(plCollisionShapeHandle compoundShape,plCollisionShapeHandle childShape, plVector3 childPos,plQuaternion childOrn); |
---|
| 121 | |
---|
| 122 | extern void plDeleteShape(plCollisionShapeHandle shape); |
---|
| 123 | |
---|
| 124 | /* Convex Meshes */ |
---|
| 125 | extern plCollisionShapeHandle plNewConvexHullShape(); |
---|
| 126 | extern void plAddVertex(plCollisionShapeHandle convexHull, plReal x,plReal y,plReal z); |
---|
| 127 | /* Concave static triangle meshes */ |
---|
| 128 | extern plMeshInterfaceHandle plNewMeshInterface(); |
---|
| 129 | extern void plAddTriangle(plMeshInterfaceHandle meshHandle, plVector3 v0,plVector3 v1,plVector3 v2); |
---|
| 130 | extern plCollisionShapeHandle plNewStaticTriangleMeshShape(plMeshInterfaceHandle); |
---|
| 131 | |
---|
| 132 | extern void plSetScaling(plCollisionShapeHandle shape, plVector3 scaling); |
---|
| 133 | |
---|
| 134 | /* SOLID has Response Callback/Table/Management */ |
---|
| 135 | /* PhysX has Triggers, User Callbacks and filtering */ |
---|
| 136 | /* ODE has the typedef void dNearCallback (void *data, dGeomID o1, dGeomID o2); */ |
---|
| 137 | |
---|
| 138 | /* typedef void plUpdatedPositionCallback(void* userData, plRigidBodyHandle rbHandle, plVector3 pos); */ |
---|
| 139 | /* typedef void plUpdatedOrientationCallback(void* userData, plRigidBodyHandle rbHandle, plQuaternion orientation); */ |
---|
| 140 | |
---|
| 141 | /* get world transform */ |
---|
| 142 | extern void plGetOpenGLMatrix(plRigidBodyHandle object, plReal* matrix); |
---|
| 143 | extern void plGetPosition(plRigidBodyHandle object,plVector3 position); |
---|
| 144 | extern void plGetOrientation(plRigidBodyHandle object,plQuaternion orientation); |
---|
| 145 | |
---|
| 146 | /* set world transform (position/orientation) */ |
---|
| 147 | extern void plSetPosition(plRigidBodyHandle object, const plVector3 position); |
---|
| 148 | extern void plSetOrientation(plRigidBodyHandle object, const plQuaternion orientation); |
---|
| 149 | extern void plSetEuler(plReal yaw,plReal pitch,plReal roll, plQuaternion orient); |
---|
| 150 | |
---|
| 151 | typedef struct plRayCastResult { |
---|
| 152 | plRigidBodyHandle m_body; |
---|
| 153 | plCollisionShapeHandle m_shape; |
---|
| 154 | plVector3 m_positionWorld; |
---|
| 155 | plVector3 m_normalWorld; |
---|
| 156 | } plRayCastResult; |
---|
| 157 | |
---|
| 158 | extern int plRayCast(plDynamicsWorldHandle world, const plVector3 rayStart, const plVector3 rayEnd, plRayCastResult res); |
---|
| 159 | |
---|
| 160 | /* Sweep API */ |
---|
| 161 | |
---|
| 162 | /* extern plRigidBodyHandle plObjectCast(plDynamicsWorldHandle world, const plVector3 rayStart, const plVector3 rayEnd, plVector3 hitpoint, plVector3 normal); */ |
---|
| 163 | |
---|
| 164 | /* Continuous Collision Detection API */ |
---|
| 165 | |
---|
| 166 | // needed for source/blender/blenkernel/intern/collision.c |
---|
| 167 | double plNearestPoints(float p1[3], float p2[3], float p3[3], float q1[3], float q2[3], float q3[3], float *pa, float *pb, float normal[3]); |
---|
| 168 | |
---|
| 169 | #ifdef __cplusplus |
---|
| 170 | } |
---|
| 171 | #endif |
---|
| 172 | |
---|
| 173 | |
---|
| 174 | #endif //BULLET_C_API_H |
---|
| 175 | |
---|