Blender V2.61 - r43446

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 
00042     PL_DECLARE_HANDLE(plPhysicsSdkHandle);
00043 
00045     PL_DECLARE_HANDLE(plDynamicsWorldHandle);
00046 
00048     PL_DECLARE_HANDLE(plRigidBodyHandle);
00049 
00051     PL_DECLARE_HANDLE(plCollisionShapeHandle);
00052 
00054     PL_DECLARE_HANDLE(plConstraintHandle);
00055 
00057     PL_DECLARE_HANDLE(plMeshInterfaceHandle);
00058 
00060     PL_DECLARE_HANDLE(plCollisionBroadphaseHandle);
00061     PL_DECLARE_HANDLE(plBroadphaseProxyHandle);
00062     PL_DECLARE_HANDLE(plCollisionWorldHandle);
00063 
00068     extern  plPhysicsSdkHandle  plNewBulletSdk(void); //this could be also another sdk, like ODE, PhysX etc.
00069     extern  void        plDeletePhysicsSdk(plPhysicsSdkHandle   physicsSdk);
00070 
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(void);
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(void);
00126     extern  void        plAddVertex(plCollisionShapeHandle convexHull, plReal x,plReal y,plReal z);
00127 /* Concave static triangle meshes */
00128     extern  plMeshInterfaceHandle          plNewMeshInterface(void);
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     extern  void plSetOpenGLMatrix(plRigidBodyHandle object, plReal* matrix);
00151 
00152     typedef struct plRayCastResult {
00153         plRigidBodyHandle       m_body;  
00154         plCollisionShapeHandle  m_shape;        
00155         plVector3               m_positionWorld;        
00156         plVector3               m_normalWorld;
00157     } plRayCastResult;
00158 
00159     extern  int plRayCast(plDynamicsWorldHandle world, const plVector3 rayStart, const plVector3 rayEnd, plRayCastResult res);
00160 
00161     /* Sweep API */
00162 
00163     /* extern  plRigidBodyHandle plObjectCast(plDynamicsWorldHandle world, const plVector3 rayStart, const plVector3 rayEnd, plVector3 hitpoint, plVector3 normal); */
00164 
00165     /* Continuous Collision Detection API */
00166     
00167     // needed for source/blender/blenkernel/intern/collision.c
00168     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]);
00169 
00170 #ifdef __cplusplus
00171 }
00172 #endif
00173 
00174 
00175 #endif //BULLET_C_API_H
00176