2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
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:
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.
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.
20 If possible, use the richer Bullet C++ API, by including "btBulletDynamicsCommon.h"
23 #ifndef BULLET_C_API_H
24 #define BULLET_C_API_H
26 #define PL_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name
28 #ifdef BT_USE_DOUBLE_PRECISION
29 typedef double plReal;
34 typedef plReal plVector3[3];
35 typedef plReal plQuaternion[4];
41 /** Particular physics SDK (C-API) */
42 PL_DECLARE_HANDLE(plPhysicsSdkHandle);
44 /** Dynamics world, belonging to some physics SDK (C-API)*/
45 PL_DECLARE_HANDLE(plDynamicsWorldHandle);
47 /** Rigid Body that can be part of a Dynamics World (C-API)*/
48 PL_DECLARE_HANDLE(plRigidBodyHandle);
50 /** Collision Shape/Geometry, property of a Rigid Body (C-API)*/
51 PL_DECLARE_HANDLE(plCollisionShapeHandle);
53 /** Constraint for Rigid Bodies (C-API)*/
54 PL_DECLARE_HANDLE(plConstraintHandle);
56 /** Triangle Mesh interface (C-API)*/
57 PL_DECLARE_HANDLE(plMeshInterfaceHandle);
59 /** Broadphase Scene/Proxy Handles (C-API)*/
60 PL_DECLARE_HANDLE(plCollisionBroadphaseHandle);
61 PL_DECLARE_HANDLE(plBroadphaseProxyHandle);
62 PL_DECLARE_HANDLE(plCollisionWorldHandle);
65 Create and Delete a Physics SDK
68 extern plPhysicsSdkHandle plNewBulletSdk(void); //this could be also another sdk, like ODE, PhysX etc.
69 extern void plDeletePhysicsSdk(plPhysicsSdkHandle physicsSdk);
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 */
73 typedef void(*btBroadphaseCallback)(void* clientData, void* object1,void* object2);
75 extern plCollisionBroadphaseHandle plCreateSapBroadphase(btBroadphaseCallback beginCallback,btBroadphaseCallback endCallback);
77 extern void plDestroyBroadphase(plCollisionBroadphaseHandle bp);
79 extern plBroadphaseProxyHandle plCreateProxy(plCollisionBroadphaseHandle bp, void* clientData, plReal minX,plReal minY,plReal minZ, plReal maxX,plReal maxY, plReal maxZ);
81 extern void plDestroyProxy(plCollisionBroadphaseHandle bp, plBroadphaseProxyHandle proxyHandle);
83 extern void plSetBoundingBox(plBroadphaseProxyHandle proxyHandle, plReal minX,plReal minY,plReal minZ, plReal maxX,plReal maxY, plReal maxZ);
85 /* todo: add pair cache support with queries like add/remove/find pair */
87 extern plCollisionWorldHandle plCreateCollisionWorld(plPhysicsSdkHandle physicsSdk);
89 /* todo: add/remove objects */
94 extern plDynamicsWorldHandle plCreateDynamicsWorld(plPhysicsSdkHandle physicsSdk);
96 extern void plDeleteDynamicsWorld(plDynamicsWorldHandle world);
98 extern void plStepSimulation(plDynamicsWorldHandle, plReal timeStep);
100 extern void plAddRigidBody(plDynamicsWorldHandle world, plRigidBodyHandle object);
102 extern void plRemoveRigidBody(plDynamicsWorldHandle world, plRigidBodyHandle object);
107 extern plRigidBodyHandle plCreateRigidBody( void* user_data, float mass, plCollisionShapeHandle cshape );
109 extern void plDeleteRigidBody(plRigidBodyHandle body);
112 /* Collision Shape definition */
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(void);
120 extern void plAddChildShape(plCollisionShapeHandle compoundShape,plCollisionShapeHandle childShape, plVector3 childPos,plQuaternion childOrn);
122 extern void plDeleteShape(plCollisionShapeHandle shape);
125 extern plCollisionShapeHandle plNewConvexHullShape(void);
126 extern void plAddVertex(plCollisionShapeHandle convexHull, plReal x,plReal y,plReal z);
127 /* Concave static triangle meshes */
128 extern plMeshInterfaceHandle plNewMeshInterface(void);
129 extern void plAddTriangle(plMeshInterfaceHandle meshHandle, plVector3 v0,plVector3 v1,plVector3 v2);
130 extern plCollisionShapeHandle plNewStaticTriangleMeshShape(plMeshInterfaceHandle);
132 extern void plSetScaling(plCollisionShapeHandle shape, plVector3 scaling);
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); */
138 /* typedef void plUpdatedPositionCallback(void* userData, plRigidBodyHandle rbHandle, plVector3 pos); */
139 /* typedef void plUpdatedOrientationCallback(void* userData, plRigidBodyHandle rbHandle, plQuaternion orientation); */
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);
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 extern void plSetOpenGLMatrix(plRigidBodyHandle object, plReal* matrix);
152 typedef struct plRayCastResult {
153 plRigidBodyHandle m_body;
154 plCollisionShapeHandle m_shape;
155 plVector3 m_positionWorld;
156 plVector3 m_normalWorld;
159 extern int plRayCast(plDynamicsWorldHandle world, const plVector3 rayStart, const plVector3 rayEnd, plRayCastResult res);
163 /* extern plRigidBodyHandle plObjectCast(plDynamicsWorldHandle world, const plVector3 rayStart, const plVector3 rayEnd, plVector3 hitpoint, plVector3 normal); */
165 /* Continuous Collision Detection API */
167 // needed for source/blender/blenkernel/intern/collision.c
168 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]);
175 #endif //BULLET_C_API_H