Back to index

supertuxkart  0.5+dfsg1
Classes | Functions
Bullet-C-API.cpp File Reference
#include "Bullet-C-Api.h"
#include "btBulletDynamicsCommon.h"
#include "LinearMath/btAlignedAllocator.h"

Go to the source code of this file.

Classes

struct  btPhysicsSdk

Functions

plPhysicsSdkHandle plNewBulletSdk ()
void plDeletePhysicsSdk (plPhysicsSdkHandle physicsSdk)
plDynamicsWorldHandle plCreateDynamicsWorld (plPhysicsSdkHandle physicsSdkHandle)
void plDeleteDynamicsWorld (plDynamicsWorldHandle world)
void plStepSimulation (plDynamicsWorldHandle world, plReal timeStep)
void plAddRigidBody (plDynamicsWorldHandle world, plRigidBodyHandle object)
void plRemoveRigidBody (plDynamicsWorldHandle world, plRigidBodyHandle object)
plRigidBodyHandle plCreateRigidBody (void *user_data, float mass, plCollisionShapeHandle cshape)
void plDeleteRigidBody (plRigidBodyHandle cbody)
plCollisionShapeHandle plNewSphereShape (plReal radius)
plCollisionShapeHandle plNewBoxShape (plReal x, plReal y, plReal z)
plCollisionShapeHandle plNewCapsuleShape (plReal radius, plReal height)
plCollisionShapeHandle plNewConeShape (plReal radius, plReal height)
plCollisionShapeHandle plNewCylinderShape (plReal radius, plReal height)
plCollisionShapeHandle plNewConvexHullShape ()
plMeshInterfaceHandle plNewMeshInterface ()
plCollisionShapeHandle plNewCompoundShape ()
void plAddChildShape (plCollisionShapeHandle compoundShapeHandle, plCollisionShapeHandle childShapeHandle, plVector3 childPos, plQuaternion childOrn)
void plSetEuler (plReal yaw, plReal pitch, plReal roll, plQuaternion orient)
void plAddVertex (plCollisionShapeHandle cshape, plReal x, plReal y, plReal z)
void plDeleteShape (plCollisionShapeHandle cshape)
void plSetScaling (plCollisionShapeHandle cshape, plVector3 cscaling)
void plSetPosition (plRigidBodyHandle object, const plVector3 position)
void plSetOrientation (plRigidBodyHandle object, const plQuaternion orientation)
void plGetOpenGLMatrix (plRigidBodyHandle object, plReal *matrix)
void plGetPosition (plRigidBodyHandle object, plVector3 position)
void plGetOrientation (plRigidBodyHandle object, plQuaternion orientation)

Function Documentation

void plAddChildShape ( plCollisionShapeHandle  compoundShapeHandle,
plCollisionShapeHandle  childShapeHandle,
plVector3  childPos,
plQuaternion  childOrn 
)

Definition at line 202 of file Bullet-C-API.cpp.

{
       btCollisionShape* colShape = reinterpret_cast<btCollisionShape*>(compoundShapeHandle);
       btAssert(colShape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE);
       btCompoundShape* compoundShape = reinterpret_cast<btCompoundShape*>(colShape);
       btCollisionShape* childShape = reinterpret_cast<btCollisionShape*>(childShapeHandle);
       btTransform   localTrans;
       localTrans.setIdentity();
       localTrans.setOrigin(btVector3(childPos[0],childPos[1],childPos[2]));
       localTrans.setRotation(btQuaternion(childOrn[0],childOrn[1],childOrn[2],childOrn[3]));
       compoundShape->addChildShape(localTrans,childShape);
}

Here is the call graph for this function:

void plAddRigidBody ( plDynamicsWorldHandle  world,
plRigidBodyHandle  object 
)

Definition at line 96 of file Bullet-C-API.cpp.

{
       btDynamicsWorld* dynamicsWorld = reinterpret_cast< btDynamicsWorld* >(world);
       assert(dynamicsWorld);
       btRigidBody* body = reinterpret_cast< btRigidBody* >(object);
       assert(body);

       dynamicsWorld->addRigidBody(body);
}

Here is the call graph for this function:

void plAddVertex ( plCollisionShapeHandle  cshape,
plReal  x,
plReal  y,
plReal  z 
)

Definition at line 231 of file Bullet-C-API.cpp.

{
       btCollisionShape* colShape = reinterpret_cast<btCollisionShape*>( cshape);
       btAssert(colShape->getShapeType()==CONVEX_HULL_SHAPE_PROXYTYPE);
       btConvexHullShape* convexHullShape = reinterpret_cast<btConvexHullShape*>( cshape);
       convexHullShape->addPoint(btPoint3(x,y,z));

}

Here is the call graph for this function:

plDynamicsWorldHandle plCreateDynamicsWorld ( plPhysicsSdkHandle  physicsSdkHandle)

Definition at line 67 of file Bullet-C-API.cpp.

{
       btPhysicsSdk* physicsSdk = reinterpret_cast<btPhysicsSdk*>(physicsSdkHandle);
       void* mem = btAlignedAlloc(sizeof(btDefaultCollisionConfiguration),16);
       btDefaultCollisionConfiguration* collisionConfiguration = new (mem)btDefaultCollisionConfiguration();
       mem = btAlignedAlloc(sizeof(btCollisionDispatcher),16);
       btDispatcher*                      dispatcher = new (mem)btCollisionDispatcher(collisionConfiguration);
       mem = btAlignedAlloc(sizeof(btAxisSweep3),16);
       btBroadphaseInterface*             pairCache = new (mem)btAxisSweep3(physicsSdk->m_worldAabbMin,physicsSdk->m_worldAabbMax);
       mem = btAlignedAlloc(sizeof(btSequentialImpulseConstraintSolver),16);
       btConstraintSolver*                constraintSolver = new(mem) btSequentialImpulseConstraintSolver();

       mem = btAlignedAlloc(sizeof(btDiscreteDynamicsWorld),16);
       return (plDynamicsWorldHandle) new (mem)btDiscreteDynamicsWorld(dispatcher,pairCache,constraintSolver,collisionConfiguration);
}
plRigidBodyHandle plCreateRigidBody ( void *  user_data,
float  mass,
plCollisionShapeHandle  cshape 
)

Definition at line 118 of file Bullet-C-API.cpp.

{
       btTransform trans;
       trans.setIdentity();
       btVector3 localInertia(0,0,0);
       btCollisionShape* shape = reinterpret_cast<btCollisionShape*>( cshape);
       assert(shape);
       if (mass)
       {
              shape->calculateLocalInertia(mass,localInertia);
       }
       void* mem = btAlignedAlloc(sizeof(btRigidBody),16);
       btRigidBody::btRigidBodyConstructionInfo rbci(mass, 0,shape,localInertia);
       btRigidBody* body = new (mem)btRigidBody(rbci);
       body->setWorldTransform(trans);
       body->setUserPointer(user_data);
       return (plRigidBodyHandle) body;
}

Here is the call graph for this function:

void plDeleteDynamicsWorld ( plDynamicsWorldHandle  world)

Definition at line 82 of file Bullet-C-API.cpp.

{
       //todo: also clean up the other allocations, axisSweep, pairCache,dispatcher,constraintSolver,collisionConfiguration
       btDynamicsWorld* dynamicsWorld = reinterpret_cast< btDynamicsWorld* >(world);
       btAlignedFree(dynamicsWorld);
}
void plDeletePhysicsSdk ( plPhysicsSdkHandle  physicsSdk)

Definition at line 59 of file Bullet-C-API.cpp.

{
       btPhysicsSdk* phys = reinterpret_cast<btPhysicsSdk*>(physicsSdk);
       btAlignedFree(phys); 
}
void plDeleteRigidBody ( plRigidBodyHandle  cbody)

Definition at line 137 of file Bullet-C-API.cpp.

{
       btRigidBody* body = reinterpret_cast< btRigidBody* >(cbody);
       assert(body);
       btAlignedFree( body);
}
void plDeleteShape ( plCollisionShapeHandle  cshape)

Definition at line 240 of file Bullet-C-API.cpp.

{
       btCollisionShape* shape = reinterpret_cast<btCollisionShape*>( cshape);
       assert(shape);
       btAlignedFree(shape);
}
void plGetOpenGLMatrix ( plRigidBodyHandle  object,
plReal matrix 
)

Definition at line 276 of file Bullet-C-API.cpp.

{
       btRigidBody* body = reinterpret_cast< btRigidBody* >(object);
       btAssert(body);
       body->getWorldTransform().getOpenGLMatrix(matrix);

}
void plGetOrientation ( plRigidBodyHandle  object,
plQuaternion  orientation 
)

Definition at line 294 of file Bullet-C-API.cpp.

{
       btRigidBody* body = reinterpret_cast< btRigidBody* >(object);
       btAssert(body);
       const btQuaternion& orn = body->getWorldTransform().getRotation();
       orientation[0] = orn.getX();
       orientation[1] = orn.getY();
       orientation[2] = orn.getZ();
       orientation[3] = orn.getW();
}

Here is the call graph for this function:

void plGetPosition ( plRigidBodyHandle  object,
plVector3  position 
)

Definition at line 284 of file Bullet-C-API.cpp.

{
       btRigidBody* body = reinterpret_cast< btRigidBody* >(object);
       btAssert(body);
       const btVector3& pos = body->getWorldTransform().getOrigin();
       position[0] = pos.getX();
       position[1] = pos.getY();
       position[2] = pos.getZ();
}

Here is the call graph for this function:

plCollisionShapeHandle plNewBoxShape ( plReal  x,
plReal  y,
plReal  z 
)

Definition at line 154 of file Bullet-C-API.cpp.

{
       void* mem = btAlignedAlloc(sizeof(btBoxShape),16);
       return (plCollisionShapeHandle) new (mem)btBoxShape(btVector3(x,y,z));
}
plPhysicsSdkHandle plNewBulletSdk ( )

Definition at line 53 of file Bullet-C-API.cpp.

{
       void* mem = btAlignedAlloc(sizeof(btPhysicsSdk),16);
       return (plPhysicsSdkHandle)new (mem)btPhysicsSdk;
}
plCollisionShapeHandle plNewCapsuleShape ( plReal  radius,
plReal  height 
)

Definition at line 160 of file Bullet-C-API.cpp.

{
       //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};
       void* mem = btAlignedAlloc(sizeof(btMultiSphereShape),16);
       return (plCollisionShapeHandle) new (mem)btMultiSphereShape(inertiaHalfExtents,positions,radi,numSpheres);
}
plCollisionShapeHandle plNewCompoundShape ( )

Definition at line 196 of file Bullet-C-API.cpp.

{
       void* mem = btAlignedAlloc(sizeof(btCompoundShape),16);
       return (plCollisionShapeHandle) new (mem)btCompoundShape();
}
plCollisionShapeHandle plNewConeShape ( plReal  radius,
plReal  height 
)

Definition at line 170 of file Bullet-C-API.cpp.

{
       void* mem = btAlignedAlloc(sizeof(btConeShape),16);
       return (plCollisionShapeHandle) new (mem)btConeShape(radius,height);
}
plCollisionShapeHandle plNewConvexHullShape ( )

Definition at line 183 of file Bullet-C-API.cpp.

{
       void* mem = btAlignedAlloc(sizeof(btConvexHullShape),16);
       return (plCollisionShapeHandle) new (mem)btConvexHullShape();
}
plCollisionShapeHandle plNewCylinderShape ( plReal  radius,
plReal  height 
)

Definition at line 176 of file Bullet-C-API.cpp.

{
       void* mem = btAlignedAlloc(sizeof(btCylinderShape),16);
       return (plCollisionShapeHandle) new (mem)btCylinderShape(btVector3(radius,height,radius));
}
plMeshInterfaceHandle plNewMeshInterface ( )

Definition at line 191 of file Bullet-C-API.cpp.

{
       return 0;
}
plCollisionShapeHandle plNewSphereShape ( plReal  radius)

Definition at line 147 of file Bullet-C-API.cpp.

{
       void* mem = btAlignedAlloc(sizeof(btSphereShape),16);
       return (plCollisionShapeHandle) new (mem)btSphereShape(radius);
       
}
void plRemoveRigidBody ( plDynamicsWorldHandle  world,
plRigidBodyHandle  object 
)

Definition at line 106 of file Bullet-C-API.cpp.

{
       btDynamicsWorld* dynamicsWorld = reinterpret_cast< btDynamicsWorld* >(world);
       assert(dynamicsWorld);
       btRigidBody* body = reinterpret_cast< btRigidBody* >(object);
       assert(body);

       dynamicsWorld->removeRigidBody(body);
}

Here is the call graph for this function:

void plSetEuler ( plReal  yaw,
plReal  pitch,
plReal  roll,
plQuaternion  orient 
)

Definition at line 215 of file Bullet-C-API.cpp.

{
       btQuaternion orn;
       orn.setEuler(yaw,pitch,roll);
       orient[0] = orn.getX();
       orient[1] = orn.getY();
       orient[2] = orn.getZ();
       orient[3] = orn.getW();

}

Here is the call graph for this function:

void plSetOrientation ( plRigidBodyHandle  object,
const plQuaternion  orientation 
)

Definition at line 266 of file Bullet-C-API.cpp.

{
       btRigidBody* body = reinterpret_cast< btRigidBody* >(object);
       btAssert(body);
       btQuaternion orn(orientation[0],orientation[1],orientation[2],orientation[3]);
       btTransform worldTrans = body->getWorldTransform();
       worldTrans.setRotation(orn);
       body->setWorldTransform(worldTrans);
}

Here is the call graph for this function:

void plSetPosition ( plRigidBodyHandle  object,
const plVector3  position 
)

Definition at line 256 of file Bullet-C-API.cpp.

{
       btRigidBody* body = reinterpret_cast< btRigidBody* >(object);
       btAssert(body);
       btVector3 pos(position[0],position[1],position[2]);
       btTransform worldTrans = body->getWorldTransform();
       worldTrans.setOrigin(pos);
       body->setWorldTransform(worldTrans);
}

Here is the call graph for this function:

void plSetScaling ( plCollisionShapeHandle  cshape,
plVector3  cscaling 
)

Definition at line 246 of file Bullet-C-API.cpp.

{
       btCollisionShape* shape = reinterpret_cast<btCollisionShape*>( cshape);
       assert(shape);
       btVector3 scaling(cscaling[0],cscaling[1],cscaling[2]);
       shape->setLocalScaling(scaling);   
}

Here is the call graph for this function:

void plStepSimulation ( plDynamicsWorldHandle  world,
plReal  timeStep 
)

Definition at line 89 of file Bullet-C-API.cpp.

{
       btDynamicsWorld* dynamicsWorld = reinterpret_cast< btDynamicsWorld* >(world);
       assert(dynamicsWorld);
       dynamicsWorld->stepSimulation(timeStep);
}

Here is the call graph for this function: