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 <src/btBulletDynamicsCommon.h>
23 #include "Bullet-C-Api.h"
24 #include "btBulletDynamicsCommon.h"
27 Create and Delete a Physics SDK
30 plPhysicsSdkHandle plNewBulletSdk()
35 void plDeletePhysicsSdk(plPhysicsSdkHandle physicsSdk)
41 plDynamicsWorldHandle plCreateDynamicsWorld(plPhysicsSdkHandle physicsSdk)
43 return (plDynamicsWorldHandle) new btDiscreteDynamicsWorld;
45 void plDeleteDynamicsWorld(plDynamicsWorldHandle world)
47 btDynamicsWorld* dynamicsWorld = reinterpret_cast< btDynamicsWorld* >(world);
51 void plStepSimulation(plDynamicsWorldHandle world, plReal timeStep)
53 btDynamicsWorld* dynamicsWorld = reinterpret_cast< btDynamicsWorld* >(world);
54 assert(dynamicsWorld);
55 dynamicsWorld->stepSimulation(timeStep);
58 void plAddRigidBody(plDynamicsWorldHandle world, plRigidBodyHandle object)
60 btDynamicsWorld* dynamicsWorld = reinterpret_cast< btDynamicsWorld* >(world);
61 assert(dynamicsWorld);
62 btRigidBody* body = reinterpret_cast< btRigidBody* >(object);
65 dynamicsWorld->addRigidBody(body);
68 void plRemoveRigidBody(plDynamicsWorldHandle world, plRigidBodyHandle object)
70 btDynamicsWorld* dynamicsWorld = reinterpret_cast< btDynamicsWorld* >(world);
71 assert(dynamicsWorld);
72 btRigidBody* body = reinterpret_cast< btRigidBody* >(object);
75 dynamicsWorld->removeRigidBody(body);
80 plRigidBodyHandle plCreateRigidBody( void* user_data, float mass, plCollisionShapeHandle cshape )
84 btVector3 localInertia;
85 btCollisionShape* shape = reinterpret_cast<btCollisionShape*>( cshape);
87 shape->calculateLocalInertia(mass,localInertia);
88 btRigidBody* body = new btRigidBody(mass, trans,shape,localInertia);
89 body->m_userObjectPointer = user_data;
90 return (plRigidBodyHandle) body;
93 void plDeleteRigidBody(plRigidBodyHandle cbody)
95 btRigidBody* body = reinterpret_cast< btRigidBody* >(cbody);
101 /* Collision Shape definition */
103 plCollisionShapeHandle plNewSphereShape(plReal radius)
105 return (plCollisionShapeHandle) new btSphereShape(radius);
109 plCollisionShapeHandle plNewBoxShape(plReal x, plReal y, plReal z)
111 return (plCollisionShapeHandle) new btBoxShape(btVector3(x,y,z));
114 plCollisionShapeHandle plNewCapsuleShape(plReal radius, plReal height)
116 //capsule is convex hull of 2 spheres, so use btMultiSphereShape
117 btVector3 inertiaHalfExtents(radius,height,radius);
118 const int numSpheres = 2;
119 btVector3 positions[numSpheres] = {btVector3(0,height,0),btVector3(0,-height,0)};
120 btScalar radi[numSpheres] = {radius,radius};
121 return (plCollisionShapeHandle) new btMultiSphereShape(inertiaHalfExtents,positions,radi,numSpheres);
123 plCollisionShapeHandle plNewConeShape(plReal radius, plReal height)
125 return (plCollisionShapeHandle) new btConeShape(radius,height);
128 plCollisionShapeHandle plNewCylinderShape(plReal radius, plReal height)
130 return (plCollisionShapeHandle) new btCylinderShape(btVector3(radius,height,radius));
133 void plDeleteShape(plCollisionShapeHandle cshape)
135 btCollisionShape* shape = reinterpret_cast<btCollisionShape*>( cshape);
139 void plSetScaling(plCollisionShapeHandle cshape, plVector3 cscaling)
141 btCollisionShape* shape = reinterpret_cast<btCollisionShape*>( cshape);
143 btVector3 scaling(cscaling[0],cscaling[1],cscaling[2]);
144 shape->setLocalScaling(scaling);
149 void plSetPosition(plRigidBodyHandle object, const plVector3 position)
152 void plSetOrientation(plRigidBodyHandle object, const plQuaternion orientation)
157 //plRigidBodyHandle plRayCast(plDynamicsWorldHandle world, const plVector3 rayStart, const plVector3 rayEnd, plVector3 hitpoint, plVector3 normal);
159 // extern plRigidBodyHandle plObjectCast(plDynamicsWorldHandle world, const plVector3 rayStart, const plVector3 rayEnd, plVector3 hitpoint, plVector3 normal);