Bullet Collision Detection & Physics Library
Bullet-C-Api.h
Go to the documentation of this file.
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 
42  PL_DECLARE_HANDLE(plPhysicsSdkHandle);
43 
45  PL_DECLARE_HANDLE(plDynamicsWorldHandle);
46 
48  PL_DECLARE_HANDLE(plRigidBodyHandle);
49 
51  PL_DECLARE_HANDLE(plCollisionShapeHandle);
52 
54  PL_DECLARE_HANDLE(plConstraintHandle);
55 
57  PL_DECLARE_HANDLE(plMeshInterfaceHandle);
58 
60  PL_DECLARE_HANDLE(plCollisionBroadphaseHandle);
61  PL_DECLARE_HANDLE(plBroadphaseProxyHandle);
62  PL_DECLARE_HANDLE(plCollisionWorldHandle);
63 
68  extern plPhysicsSdkHandle plNewBulletSdk(void); //this could be also another sdk, like ODE, PhysX etc.
69  extern void plDeletePhysicsSdk(plPhysicsSdkHandle physicsSdk);
70 
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(void);
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(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);
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  extern void plSetOpenGLMatrix(plRigidBodyHandle object, plReal* matrix);
151 
152  typedef struct plRayCastResult {
153  plRigidBodyHandle m_body;
154  plCollisionShapeHandle m_shape;
157  } plRayCastResult;
158 
159  extern int plRayCast(plDynamicsWorldHandle world, const plVector3 rayStart, const plVector3 rayEnd, plRayCastResult res);
160 
161  /* Sweep API */
162 
163  /* extern plRigidBodyHandle plObjectCast(plDynamicsWorldHandle world, const plVector3 rayStart, const plVector3 rayEnd, plVector3 hitpoint, plVector3 normal); */
164 
165  /* Continuous Collision Detection API */
166 
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]);
169 
170 #ifdef __cplusplus
171 }
172 #endif
173 
174 
175 #endif //BULLET_C_API_H
176 
plBroadphaseProxyHandle plCreateProxy(plCollisionBroadphaseHandle bp, void *clientData, plReal minX, plReal minY, plReal minZ, plReal maxX, plReal maxY, plReal maxZ)
plRigidBodyHandle plCreateRigidBody(void *user_data, float mass, plCollisionShapeHandle cshape)
plRigidBodyHandle m_body
Definition: Bullet-C-Api.h:153
float plReal
Definition: Bullet-C-Api.h:31
plDynamicsWorldHandle plCreateDynamicsWorld(plPhysicsSdkHandle physicsSdk)
int plRayCast(plDynamicsWorldHandle world, const plVector3 rayStart, const plVector3 rayEnd, plRayCastResult res)
void plDestroyProxy(plCollisionBroadphaseHandle bp, plBroadphaseProxyHandle proxyHandle)
plCollisionShapeHandle plNewBoxShape(plReal x, plReal y, plReal z)
plVector3 m_normalWorld
Definition: Bullet-C-Api.h:156
void plSetOpenGLMatrix(plRigidBodyHandle object, plReal *matrix)
void plAddChildShape(plCollisionShapeHandle compoundShape, plCollisionShapeHandle childShape, plVector3 childPos, plQuaternion childOrn)
void plAddVertex(plCollisionShapeHandle convexHull, plReal x, plReal y, plReal z)
plCollisionShapeHandle plNewConeShape(plReal radius, plReal height)
void plStepSimulation(plDynamicsWorldHandle, plReal timeStep)
void plSetOrientation(plRigidBodyHandle object, const plQuaternion orientation)
void plDeleteShape(plCollisionShapeHandle shape)
struct plRayCastResult plRayCastResult
plReal plVector3[3]
Definition: Bullet-C-Api.h:34
plMeshInterfaceHandle plNewMeshInterface(void)
void(* btBroadphaseCallback)(void *clientData, void *object1, void *object2)
Collision World, not strictly necessary, you can also just create a Dynamics World with Rigid Bodies ...
Definition: Bullet-C-Api.h:73
#define PL_DECLARE_HANDLE(name)
Definition: Bullet-C-Api.h:26
plCollisionWorldHandle plCreateCollisionWorld(plPhysicsSdkHandle physicsSdk)
plVector3 m_positionWorld
Definition: Bullet-C-Api.h:155
plCollisionShapeHandle plNewCylinderShape(plReal radius, plReal height)
void plDeleteDynamicsWorld(plDynamicsWorldHandle world)
void plGetPosition(plRigidBodyHandle object, plVector3 position)
void plDestroyBroadphase(plCollisionBroadphaseHandle bp)
void plGetOrientation(plRigidBodyHandle object, plQuaternion orientation)
plCollisionShapeHandle plNewCompoundShape(void)
plPhysicsSdkHandle plNewBulletSdk(void)
Create and Delete a Physics SDK.
plCollisionShapeHandle plNewCapsuleShape(plReal radius, plReal height)
void plRemoveRigidBody(plDynamicsWorldHandle world, plRigidBodyHandle object)
void plSetScaling(plCollisionShapeHandle shape, plVector3 scaling)
void plSetEuler(plReal yaw, plReal pitch, plReal roll, plQuaternion orient)
void plDeleteRigidBody(plRigidBodyHandle body)
plCollisionBroadphaseHandle plCreateSapBroadphase(btBroadphaseCallback beginCallback, btBroadphaseCallback endCallback)
void plAddRigidBody(plDynamicsWorldHandle world, plRigidBodyHandle object)
plCollisionShapeHandle plNewStaticTriangleMeshShape(plMeshInterfaceHandle)
plCollisionShapeHandle plNewSphereShape(plReal radius)
plCollisionShapeHandle plNewConvexHullShape(void)
plCollisionShapeHandle m_shape
Definition: Bullet-C-Api.h:154
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])
plReal plQuaternion[4]
Definition: Bullet-C-Api.h:35
void plSetPosition(plRigidBodyHandle object, const plVector3 position)
void plSetBoundingBox(plBroadphaseProxyHandle proxyHandle, plReal minX, plReal minY, plReal minZ, plReal maxX, plReal maxY, plReal maxZ)
void plDeletePhysicsSdk(plPhysicsSdkHandle physicsSdk)
void plGetOpenGLMatrix(plRigidBodyHandle object, plReal *matrix)
void plAddTriangle(plMeshInterfaceHandle meshHandle, plVector3 v0, plVector3 v1, plVector3 v2)