summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Demos/BspDemo/BspDemo.cpp2
-rw-r--r--Demos/OpenPL_Demo/CApi.cpp159
-rw-r--r--Demos/OpenPL_Demo/OpenPL_Demo.c44
-rw-r--r--Demos/Raytracer/Raytracer.cpp2
-rw-r--r--include/Bullet-C-Api.h123
-rw-r--r--src/BulletCollision/CollisionShapes/btConvexHullShape.cpp3
-rw-r--r--src/BulletCollision/CollisionShapes/btConvexHullShape.h5
-rw-r--r--src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp6
-rw-r--r--src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h2
-rw-r--r--src/BulletDynamics/Dynamics/btDynamicsWorld.h2
-rw-r--r--src/BulletDynamics/Dynamics/btRigidBody.h7
-rw-r--r--src/BulletDynamics/Dynamics/btSimpleDynamicsWorld.cpp5
-rw-r--r--src/BulletDynamics/Dynamics/btSimpleDynamicsWorld.h2
13 files changed, 350 insertions, 12 deletions
diff --git a/Demos/BspDemo/BspDemo.cpp b/Demos/BspDemo/BspDemo.cpp
index 28fffe36a..7f291f776 100644
--- a/Demos/BspDemo/BspDemo.cpp
+++ b/Demos/BspDemo/BspDemo.cpp
@@ -70,7 +70,7 @@ public:
startTransform.setIdentity();
startTransform.setOrigin(btVector3(0,0,-10.f));
//this create an internal copy of the vertices
- btCollisionShape* shape = new btConvexHullShape(&vertices[0],vertices.size());
+ btCollisionShape* shape = new btConvexHullShape(&(vertices[0].getX()),vertices.size());
btRigidBody* body = m_demoApp->localCreateRigidBody(mass, startTransform,shape);
}
diff --git a/Demos/OpenPL_Demo/CApi.cpp b/Demos/OpenPL_Demo/CApi.cpp
new file mode 100644
index 000000000..baec3fbe8
--- /dev/null
+++ b/Demos/OpenPL_Demo/CApi.cpp
@@ -0,0 +1,159 @@
+/*
+Bullet Continuous Collision Detection and Physics Library
+Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
+
+This software is provided 'as-is', without any express or implied warranty.
+In no event will the authors be held liable for any damages arising from the use of this software.
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it freely,
+subject to the following restrictions:
+
+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.
+2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
+3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+ Draft high-level generic physics C-API. For low-level access, use the physics SDK native API's.
+ Work in progress, functionality will be added on demand.
+
+ If possible, use the richer Bullet C++ API, by including <src/btBulletDynamicsCommon.h>
+*/
+
+#include "Bullet-C-Api.h"
+#include "btBulletDynamicsCommon.h"
+
+/*
+ Create and Delete a Physics SDK
+*/
+
+plPhysicsSdkHandle plNewBulletSdk()
+{
+ return 0;
+}
+
+void plDeletePhysicsSdk(plPhysicsSdkHandle physicsSdk)
+{
+
+}
+
+/* Dynamics World */
+plDynamicsWorldHandle plCreateDynamicsWorld(plPhysicsSdkHandle physicsSdk)
+{
+ return (plDynamicsWorldHandle) new btDiscreteDynamicsWorld;
+}
+void plDeleteDynamicsWorld(plDynamicsWorldHandle world)
+{
+ btDynamicsWorld* dynamicsWorld = reinterpret_cast< btDynamicsWorld* >(world);
+ delete dynamicsWorld;
+}
+
+void plStepSimulation(plDynamicsWorldHandle world, plReal timeStep)
+{
+ btDynamicsWorld* dynamicsWorld = reinterpret_cast< btDynamicsWorld* >(world);
+ assert(dynamicsWorld);
+ dynamicsWorld->stepSimulation(timeStep);
+}
+
+void plAddRigidBody(plDynamicsWorldHandle world, plRigidBodyHandle object)
+{
+ btDynamicsWorld* dynamicsWorld = reinterpret_cast< btDynamicsWorld* >(world);
+ assert(dynamicsWorld);
+ btRigidBody* body = reinterpret_cast< btRigidBody* >(object);
+ assert(body);
+
+ dynamicsWorld->addRigidBody(body);
+}
+
+void plRemoveRigidBody(plDynamicsWorldHandle world, plRigidBodyHandle object)
+{
+ btDynamicsWorld* dynamicsWorld = reinterpret_cast< btDynamicsWorld* >(world);
+ assert(dynamicsWorld);
+ btRigidBody* body = reinterpret_cast< btRigidBody* >(object);
+ assert(body);
+
+ dynamicsWorld->removeRigidBody(body);
+}
+
+/* Rigid Body */
+
+plRigidBodyHandle plCreateRigidBody( void* user_data, float mass, plCollisionShapeHandle cshape )
+{
+ btTransform trans;
+ trans.setIdentity();
+ btVector3 localInertia;
+ btCollisionShape* shape = reinterpret_cast<btCollisionShape*>( cshape);
+ assert(shape);
+ shape->calculateLocalInertia(mass,localInertia);
+ btRigidBody* body = new btRigidBody(mass, trans,shape,localInertia);
+ body->m_userObjectPointer = user_data;
+ return (plRigidBodyHandle) body;
+}
+
+void plDeleteRigidBody(plRigidBodyHandle cbody)
+{
+ btRigidBody* body = reinterpret_cast< btRigidBody* >(cbody);
+ assert(body);
+ delete body;
+}
+
+
+/* Collision Shape definition */
+
+plCollisionShapeHandle plNewSphereShape(plReal radius)
+{
+ return (plCollisionShapeHandle) new btSphereShape(radius);
+
+}
+
+plCollisionShapeHandle plNewBoxShape(plReal x, plReal y, plReal z)
+{
+ return (plCollisionShapeHandle) new btBoxShape(btVector3(x,y,z));
+}
+
+plCollisionShapeHandle plNewCapsuleShape(plReal radius, plReal height)
+{
+ //capsule is convex hull of 2 spheres, so use btMultiSphereShape
+ btVector3 inertiaHalfExtents(radius,height,radius);
+ const int numSpheres = 2;
+ btVector3 positions[numSpheres] = {btVector3(0,height,0),btVector3(0,-height,0)};
+ btScalar radi[numSpheres] = {radius,radius};
+ return (plCollisionShapeHandle) new btMultiSphereShape(inertiaHalfExtents,positions,radi,numSpheres);
+}
+plCollisionShapeHandle plNewConeShape(plReal radius, plReal height)
+{
+ return (plCollisionShapeHandle) new btConeShape(radius,height);
+}
+
+plCollisionShapeHandle plNewCylinderShape(plReal radius, plReal height)
+{
+ return (plCollisionShapeHandle) new btCylinderShape(btVector3(radius,height,radius));
+}
+
+void plDeleteShape(plCollisionShapeHandle cshape)
+{
+ btCollisionShape* shape = reinterpret_cast<btCollisionShape*>( cshape);
+ assert(shape);
+ delete shape;
+}
+void plSetScaling(plCollisionShapeHandle cshape, plVector3 cscaling)
+{
+ btCollisionShape* shape = reinterpret_cast<btCollisionShape*>( cshape);
+ assert(shape);
+ btVector3 scaling(cscaling[0],cscaling[1],cscaling[2]);
+ shape->setLocalScaling(scaling);
+}
+
+
+
+void plSetPosition(plRigidBodyHandle object, const plVector3 position)
+{
+}
+void plSetOrientation(plRigidBodyHandle object, const plQuaternion orientation)
+{
+}
+
+
+//plRigidBodyHandle plRayCast(plDynamicsWorldHandle world, const plVector3 rayStart, const plVector3 rayEnd, plVector3 hitpoint, plVector3 normal);
+
+// extern plRigidBodyHandle plObjectCast(plDynamicsWorldHandle world, const plVector3 rayStart, const plVector3 rayEnd, plVector3 hitpoint, plVector3 normal);
diff --git a/Demos/OpenPL_Demo/OpenPL_Demo.c b/Demos/OpenPL_Demo/OpenPL_Demo.c
new file mode 100644
index 000000000..639072a7c
--- /dev/null
+++ b/Demos/OpenPL_Demo/OpenPL_Demo.c
@@ -0,0 +1,44 @@
+
+#include "Bullet-C-Api.h"
+
+
+int main()
+{
+ float timeStep = 1.f/60.f;
+
+ /* initialize */
+ plPhysicsSdkHandle sdk = plNewBulletSdk();
+
+ plDynamicsWorldHandle world = plCreateDynamicsWorld(sdk);
+
+
+ float radius = 1.f;
+ plCollisionShapeHandle collisionShape = plNewSphereShape(radius);
+
+ void* user_data = 0;/* can point to a graphics object */
+
+ float mass = 1.f;
+
+ plRigidBodyHandle body = plCreateRigidBody(user_data, mass, collisionShape );
+
+ plAddRigidBody(world, body);
+
+
+
+ plStepSimulation(world,0.1f);
+
+ /* cleanup */
+
+ plRemoveRigidBody(world, body);
+
+
+ plDeleteRigidBody(body);
+
+ plDeleteShape( collisionShape);
+
+ plDeleteDynamicsWorld( world);
+
+ plDeletePhysicsSdk(sdk);
+
+ return 0;
+} \ No newline at end of file
diff --git a/Demos/Raytracer/Raytracer.cpp b/Demos/Raytracer/Raytracer.cpp
index c8382c1e5..d4dacdd53 100644
--- a/Demos/Raytracer/Raytracer.cpp
+++ b/Demos/Raytracer/Raytracer.cpp
@@ -114,7 +114,7 @@ void Raytracer::initPhysics()
};
// btMultiSphereShape* multiSphereShape = new btMultiSphereShape(inertiaHalfExtents,positions,radi,NUM_SPHERES);
- btConvexHullShape* convexHullShape = new btConvexHullShape(positions,3);
+ btConvexHullShape* convexHullShape = new btConvexHullShape(&positions[0].getX(),3);
//choose shape
diff --git a/include/Bullet-C-Api.h b/include/Bullet-C-Api.h
index beb504bbf..943f7612e 100644
--- a/include/Bullet-C-Api.h
+++ b/include/Bullet-C-Api.h
@@ -1,9 +1,118 @@
+/*
+Bullet Continuous Collision Detection and Physics Library
+Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
+
+This software is provided 'as-is', without any express or implied warranty.
+In no event will the authors be held liable for any damages arising from the use of this software.
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it freely,
+subject to the following restrictions:
+
+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.
+2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
+3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+ Draft high-level generic physics C-API. For low-level access, use the physics SDK native API's.
+ Work in progress, functionality will be added on demand.
+
+ If possible, use the richer Bullet C++ API, by including "btBulletDynamicsCommon.h"
+*/
+
+#ifndef BULLET_C_API_H
+#define BULLET_C_API_H
+
+#define PL_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name
+
+typedef float plReal;
+typedef plReal plVector3[3];
+typedef plReal plQuaternion[4];
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Particular physics SDK */
+ PL_DECLARE_HANDLE(plPhysicsSdkHandle);
+/* Dynamics world, belonging to some physics SDK */
+ PL_DECLARE_HANDLE(plDynamicsWorldHandle);
+/* Rigid Body that can be part of a Dynamics World */
+ PL_DECLARE_HANDLE(plRigidBodyHandle);
+/* Collision Shape/Geometry, property of a Rigid Body */
+ PL_DECLARE_HANDLE(plCollisionShapeHandle);
+/* Constraint for Rigid Bodies */
+ PL_DECLARE_HANDLE(plConstraintHandle);
+
+
+/*
+ Create and Delete a Physics SDK
+*/
+
+ extern plPhysicsSdkHandle plNewBulletSdk(); //this could be also another sdk, like ODE, PhysX etc.
+ extern void plDeletePhysicsSdk(plPhysicsSdkHandle physicsSdk);
+
+/* Dynamics World */
+
+ extern plDynamicsWorldHandle plCreateDynamicsWorld(plPhysicsSdkHandle physicsSdk);
+
+ extern void plDeleteDynamicsWorld(plDynamicsWorldHandle world);
+
+ extern void plStepSimulation(plDynamicsWorldHandle, plReal timeStep);
+
+ extern void plAddRigidBody(plDynamicsWorldHandle world, plRigidBodyHandle object);
+
+ extern void plRemoveRigidBody(plDynamicsWorldHandle world, plRigidBodyHandle object);
+
+
+/* Rigid Body */
+
+ extern plRigidBodyHandle plCreateRigidBody( void* user_data, float mass, plCollisionShapeHandle cshape );
+
+ extern void plDeleteRigidBody(plRigidBodyHandle body);
+
+
+/* Collision Shape definition */
+
+ extern plCollisionShapeHandle plNewSphereShape(plReal radius);
+ extern plCollisionShapeHandle plNewBoxShape(plReal x, plReal y, plReal z);
+ extern plCollisionShapeHandle plNewCapsuleShape(plReal radius, plReal height);
+ extern plCollisionShapeHandle plNewConeShape(plReal radius, plReal height);
+ extern plCollisionShapeHandle plNewCylinderShape(plReal radius, plReal height);
+ extern void plDeleteShape(plCollisionShapeHandle shape);
+
+ extern void plSetScaling(plCollisionShapeHandle shape, plVector3 scaling);
+
+/* SOLID has Response Callback/Table/Management */
+/* PhysX has Triggers, User Callbacks and filtering */
+/* ODE has the typedef void dNearCallback (void *data, dGeomID o1, dGeomID o2); */
-///This is just a placeholder for now.
-///
-///It will contain a C API for high-level Bullet Collision Detection and Physics library.
-///
-///for now, only C++ interface is available, see btBulletCollisionCommon.h and btBulletDynamicsCommon.h
-///
-///http://bullet.sf.net
+
+ typedef void plUpdatedPositionCallback(void* userData, plRigidBodyHandle rbHandle, plVector3 pos);
+ typedef void plUpdatedOrientationCallback(void* userData, plRigidBodyHandle rbHandle, plQuaternion orientation);
+
+ extern void plSetPosition(plRigidBodyHandle object, const plVector3 position);
+ extern void plSetOrientation(plRigidBodyHandle object, const plQuaternion orientation);
+
+ typedef struct plRayCastResult {
+ plRigidBodyHandle m_body;
+ plCollisionShapeHandle m_shape;
+ plVector3 m_positionWorld;
+ plVector3 m_normalWorld;
+ } plRayCastResult;
+
+ extern int plRayCast(plDynamicsWorldHandle world, const plVector3 rayStart, const plVector3 rayEnd, plRayCastResult res);
+
+ /* Sweep API */
+
+ /* extern plRigidBodyHandle plObjectCast(plDynamicsWorldHandle world, const plVector3 rayStart, const plVector3 rayEnd, plVector3 hitpoint, plVector3 normal); */
+
+ /* Continuous Collision Detection API */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //BULLET_C_API_H
+
diff --git a/src/BulletCollision/CollisionShapes/btConvexHullShape.cpp b/src/BulletCollision/CollisionShapes/btConvexHullShape.cpp
index d31681e6b..7a4c7ebf5 100644
--- a/src/BulletCollision/CollisionShapes/btConvexHullShape.cpp
+++ b/src/BulletCollision/CollisionShapes/btConvexHullShape.cpp
@@ -18,7 +18,8 @@ subject to the following restrictions:
#include "LinearMath/btQuaternion.h"
-btConvexHullShape ::btConvexHullShape (btPoint3* points,int numPoints,int stride)
+
+btConvexHullShape ::btConvexHullShape (const float* points,int numPoints,int stride)
{
m_points.resize(numPoints);
unsigned char* pointsBaseAddress = (unsigned char*)points;
diff --git a/src/BulletCollision/CollisionShapes/btConvexHullShape.h b/src/BulletCollision/CollisionShapes/btConvexHullShape.h
index 9cdd21dde..afe7dd8f7 100644
--- a/src/BulletCollision/CollisionShapes/btConvexHullShape.h
+++ b/src/BulletCollision/CollisionShapes/btConvexHullShape.h
@@ -30,7 +30,10 @@ class btConvexHullShape : public btPolyhedralConvexShape
std::vector<btPoint3> m_points;
public:
- btConvexHullShape(btPoint3* points,int numPoints, int stride=sizeof(btPoint3));
+ ///this constructor optionally takes in a pointer to points. Each point is assumed to be 3 consecutive float (x,y,z), the striding defines the number of bytes between each point, in memory.
+ ///It is easier to not pass any points in the constructor, and just add one point at a time, using addPoint.
+ ///btConvexHullShape make an internal copy of the points.
+ btConvexHullShape(const float* points=0,int numPoints=0, int stride=sizeof(btPoint3));
void addPoint(const btPoint3& point)
{
diff --git a/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp b/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp
index fb5024820..71cd46243 100644
--- a/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp
+++ b/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp
@@ -191,6 +191,12 @@ void btDiscreteDynamicsWorld::setGravity(const btVector3& gravity)
}
}
+
+void btDiscreteDynamicsWorld::removeRigidBody(btRigidBody* body)
+{
+ removeCollisionObject(body);
+}
+
void btDiscreteDynamicsWorld::addRigidBody(btRigidBody* body)
{
body->setGravity(m_gravity);
diff --git a/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h b/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h
index 10a460111..a5c61c357 100644
--- a/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h
+++ b/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h
@@ -126,6 +126,8 @@ public:
virtual void addRigidBody(btRigidBody* body);
+ virtual void removeRigidBody(btRigidBody* body);
+
};
#endif //BT_DISCRETE_DYNAMICS_WORLD_H
diff --git a/src/BulletDynamics/Dynamics/btDynamicsWorld.h b/src/BulletDynamics/Dynamics/btDynamicsWorld.h
index 86f25dd00..e89a6bd92 100644
--- a/src/BulletDynamics/Dynamics/btDynamicsWorld.h
+++ b/src/BulletDynamics/Dynamics/btDynamicsWorld.h
@@ -56,6 +56,8 @@ class btDynamicsWorld : public btCollisionWorld
virtual void addRigidBody(btRigidBody* body) = 0;
+ virtual void removeRigidBody(btRigidBody* body) = 0;
+
};
#endif //BT_DYNAMICS_WORLD_H
diff --git a/src/BulletDynamics/Dynamics/btRigidBody.h b/src/BulletDynamics/Dynamics/btRigidBody.h
index fab607bee..884cff188 100644
--- a/src/BulletDynamics/Dynamics/btRigidBody.h
+++ b/src/BulletDynamics/Dynamics/btRigidBody.h
@@ -88,7 +88,12 @@ public:
void applyForces(btScalar step);
void setGravity(const btVector3& acceleration);
-
+
+ const btVector3& getGravity() const
+ {
+ return m_gravity;
+ }
+
void setDamping(btScalar lin_damping, btScalar ang_damping);
inline const btCollisionShape* getCollisionShape() const {
diff --git a/src/BulletDynamics/Dynamics/btSimpleDynamicsWorld.cpp b/src/BulletDynamics/Dynamics/btSimpleDynamicsWorld.cpp
index 890d27ebf..e9fa3519b 100644
--- a/src/BulletDynamics/Dynamics/btSimpleDynamicsWorld.cpp
+++ b/src/BulletDynamics/Dynamics/btSimpleDynamicsWorld.cpp
@@ -89,6 +89,11 @@ void btSimpleDynamicsWorld::setGravity(const btVector3& gravity)
}
}
+void btSimpleDynamicsWorld::removeRigidBody(btRigidBody* body)
+{
+ removeCollisionObject(body);
+}
+
void btSimpleDynamicsWorld::addRigidBody(btRigidBody* body)
{
body->setGravity(m_gravity);
diff --git a/src/BulletDynamics/Dynamics/btSimpleDynamicsWorld.h b/src/BulletDynamics/Dynamics/btSimpleDynamicsWorld.h
index 8876078e9..86981f99e 100644
--- a/src/BulletDynamics/Dynamics/btSimpleDynamicsWorld.h
+++ b/src/BulletDynamics/Dynamics/btSimpleDynamicsWorld.h
@@ -70,6 +70,8 @@ public:
virtual void addRigidBody(btRigidBody* body);
+ virtual void removeRigidBody(btRigidBody* body);
+
virtual void updateAabbs();
};