Back to index

supertuxkart  0.5+dfsg1
Bullet-C-Api.h
Go to the documentation of this file.
00001 /*
00002 Bullet Continuous Collision Detection and Physics Library
00003 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
00004 
00005 This software is provided 'as-is', without any express or implied warranty.
00006 In no event will the authors be held liable for any damages arising from the use of this software.
00007 Permission is granted to anyone to use this software for any purpose, 
00008 including commercial applications, and to alter it and redistribute it freely, 
00009 subject to the following restrictions:
00010 
00011 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.
00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
00013 3. This notice may not be removed or altered from any source distribution.
00014 */
00015 
00016 /*
00017        Draft high-level generic physics C-API. For low-level access, use the physics SDK native API's.
00018        Work in progress, functionality will be added on demand.
00019 
00020        If possible, use the richer Bullet C++ API, by including "btBulletDynamicsCommon.h"
00021 */
00022 
00023 #ifndef BULLET_C_API_H
00024 #define BULLET_C_API_H
00025 
00026 #define PL_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name
00027 
00028 #ifdef BT_USE_DOUBLE_PRECISION
00029 typedef double       plReal;
00030 #else
00031 typedef float plReal;
00032 #endif
00033 
00034 typedef plReal       plVector3[3];
00035 typedef plReal       plQuaternion[4];
00036 
00037 #ifdef __cplusplus
00038 extern "C" { 
00039 #endif
00040 
00041 /*     Particular physics SDK */
00042        PL_DECLARE_HANDLE(plPhysicsSdkHandle);
00043 
00044 /*     Dynamics world, belonging to some physics SDK */
00045        PL_DECLARE_HANDLE(plDynamicsWorldHandle);
00046 
00047 /* Rigid Body that can be part of a Dynamics World */   
00048        PL_DECLARE_HANDLE(plRigidBodyHandle);
00049 
00050 /*     Collision Shape/Geometry, property of a Rigid Body */
00051        PL_DECLARE_HANDLE(plCollisionShapeHandle);
00052 
00053 /* Constraint for Rigid Bodies */
00054        PL_DECLARE_HANDLE(plConstraintHandle);
00055 
00056 /* Triangle Mesh interface */
00057        PL_DECLARE_HANDLE(plMeshInterfaceHandle);
00058 
00059 /* Broadphase Scene/Proxy Handles */
00060        PL_DECLARE_HANDLE(plCollisionBroadphaseHandle);
00061        PL_DECLARE_HANDLE(plBroadphaseProxyHandle);
00062        PL_DECLARE_HANDLE(plCollisionWorldHandle);
00063 
00064 /*
00065        Create and Delete a Physics SDK    
00066 */
00067 
00068        extern plPhysicsSdkHandle   plNewBulletSdk(); //this could be also another sdk, like ODE, PhysX etc.
00069        extern void          plDeletePhysicsSdk(plPhysicsSdkHandle     physicsSdk);
00070 
00071 /* 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 */
00072 
00073        typedef void(*btBroadphaseCallback)(void* clientData, void* object1,void* object2);
00074 
00075        extern plCollisionBroadphaseHandle plCreateSapBroadphase(btBroadphaseCallback beginCallback,btBroadphaseCallback endCallback);
00076 
00077        extern void   plDestroyBroadphase(plCollisionBroadphaseHandle bp);
00078 
00079        extern        plBroadphaseProxyHandle plCreateProxy(plCollisionBroadphaseHandle bp, void* clientData, plReal minX,plReal minY,plReal minZ, plReal maxX,plReal maxY, plReal maxZ);
00080 
00081        extern void plDestroyProxy(plCollisionBroadphaseHandle bp, plBroadphaseProxyHandle proxyHandle);
00082 
00083        extern void plSetBoundingBox(plBroadphaseProxyHandle proxyHandle, plReal minX,plReal minY,plReal minZ, plReal maxX,plReal maxY, plReal maxZ);
00084 
00085 /* todo: add pair cache support with queries like add/remove/find pair */
00086        
00087        extern plCollisionWorldHandle plCreateCollisionWorld(plPhysicsSdkHandle physicsSdk);
00088 
00089 /* todo: add/remove objects */
00090        
00091 
00092 /* Dynamics World */
00093 
00094        extern  plDynamicsWorldHandle plCreateDynamicsWorld(plPhysicsSdkHandle physicsSdk);
00095 
00096        extern  void           plDeleteDynamicsWorld(plDynamicsWorldHandle world);
00097 
00098        extern void   plStepSimulation(plDynamicsWorldHandle,   plReal timeStep);
00099 
00100        extern  void plAddRigidBody(plDynamicsWorldHandle world, plRigidBodyHandle object);
00101 
00102        extern  void plRemoveRigidBody(plDynamicsWorldHandle world, plRigidBodyHandle object);
00103 
00104 
00105 /* Rigid Body  */
00106 
00107        extern  plRigidBodyHandle plCreateRigidBody(     void* user_data,  float mass, plCollisionShapeHandle cshape );
00108 
00109        extern  void plDeleteRigidBody(plRigidBodyHandle body);
00110 
00111 
00112 /* Collision Shape definition */
00113 
00114        extern  plCollisionShapeHandle plNewSphereShape(plReal radius);
00115        extern  plCollisionShapeHandle plNewBoxShape(plReal x, plReal y, plReal z);
00116        extern  plCollisionShapeHandle plNewCapsuleShape(plReal radius, plReal height);     
00117        extern  plCollisionShapeHandle plNewConeShape(plReal radius, plReal height);
00118        extern  plCollisionShapeHandle plNewCylinderShape(plReal radius, plReal height);
00119        extern plCollisionShapeHandle plNewCompoundShape();
00120        extern void   plAddChildShape(plCollisionShapeHandle compoundShape,plCollisionShapeHandle childShape, plVector3 childPos,plQuaternion childOrn);
00121 
00122        extern  void plDeleteShape(plCollisionShapeHandle shape);
00123 
00124        /* Convex Meshes */
00125        extern  plCollisionShapeHandle plNewConvexHullShape();
00126        extern  void         plAddVertex(plCollisionShapeHandle convexHull, plReal x,plReal y,plReal z);
00127 /* Concave static triangle meshes */
00128        extern  plMeshInterfaceHandle                plNewMeshInterface();
00129        extern  void         plAddTriangle(plMeshInterfaceHandle meshHandle, plVector3 v0,plVector3 v1,plVector3 v2);
00130        extern  plCollisionShapeHandle plNewStaticTriangleMeshShape(plMeshInterfaceHandle);
00131 
00132        extern  void plSetScaling(plCollisionShapeHandle shape, plVector3 scaling);
00133 
00134 /* SOLID has Response Callback/Table/Management */
00135 /* PhysX has Triggers, User Callbacks and filtering */
00136 /* ODE has the typedef void dNearCallback (void *data, dGeomID o1, dGeomID o2); */
00137 
00138 /*     typedef void plUpdatedPositionCallback(void* userData, plRigidBodyHandle     rbHandle, plVector3 pos); */
00139 /*     typedef void plUpdatedOrientationCallback(void* userData, plRigidBodyHandle  rbHandle, plQuaternion orientation); */
00140 
00141        /* get world transform */
00142        extern void   plGetOpenGLMatrix(plRigidBodyHandle object, plReal* matrix);
00143        extern void   plGetPosition(plRigidBodyHandle object,plVector3 position);
00144        extern void plGetOrientation(plRigidBodyHandle object,plQuaternion orientation);
00145 
00146        /* set world transform (position/orientation) */
00147        extern  void plSetPosition(plRigidBodyHandle object, const plVector3 position);
00148        extern  void plSetOrientation(plRigidBodyHandle object, const plQuaternion orientation);
00149        extern void plSetEuler(plReal yaw,plReal pitch,plReal roll, plQuaternion orient);
00150 
00151        typedef struct plRayCastResult {
00152               plRigidBodyHandle           m_body;  
00153               plCollisionShapeHandle      m_shape;             
00154               plVector3                          m_positionWorld;            
00155               plVector3                          m_normalWorld;
00156        } plRayCastResult;
00157 
00158        extern  int plRayCast(plDynamicsWorldHandle world, const plVector3 rayStart, const plVector3 rayEnd, plRayCastResult res);
00159 
00160        /* Sweep API */
00161 
00162        /* extern  plRigidBodyHandle plObjectCast(plDynamicsWorldHandle world, const plVector3 rayStart, const plVector3 rayEnd, plVector3 hitpoint, plVector3 normal); */
00163 
00164        /* Continuous Collision Detection API */
00165 
00166 #ifdef __cplusplus
00167 }
00168 #endif
00169 
00170 #endif //BULLET_C_API_H
00171