~ubuntu-branches/ubuntu/maverick/blender/maverick

« back to all changes in this revision

Viewing changes to extern/bullet2/src/BulletDynamics/Dynamics/Bullet-C-API.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Khashayar Naderehvandi, Khashayar Naderehvandi, Alessio Treglia
  • Date: 2009-01-22 16:53:59 UTC
  • mfrom: (14.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090122165359-v0996tn7fbit64ni
Tags: 2.48a+dfsg-1ubuntu1
[ Khashayar Naderehvandi ]
* Merge from debian experimental (LP: #320045), Ubuntu remaining changes:
  - Add patch correcting header file locations.
  - Add libvorbis-dev and libgsm1-dev to Build-Depends.
  - Use avcodec_decode_audio2() in source/blender/src/hddaudio.c

[ Alessio Treglia ]
* Add missing previous changelog entries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include "LinearMath/btAlignedAllocator.h"
26
26
 
27
27
 
 
28
 
28
29
#include "LinearMath/btVector3.h"
29
30
#include "LinearMath/btScalar.h"        
30
31
#include "LinearMath/btMatrix3x3.h"
39
40
#include "BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h"
40
41
#include "BulletCollision/NarrowPhaseCollision/btGjkEpa.h"
41
42
#include "BulletCollision/CollisionShapes/btMinkowskiSumShape.h"
42
 
#include "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h"
43
 
#include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h"
44
 
#include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h"
45
 
 
46
43
#include "BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h"
47
44
#include "BulletCollision/NarrowPhaseCollision/btSimplexSolverInterface.h"
48
45
#include "BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.h"
49
 
#include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h"
50
 
#include "BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h"
51
46
#include "LinearMath/btStackAlloc.h"
52
47
 
53
 
extern "C"
 
48
/*
 
49
        Create and Delete a Physics SDK 
 
50
*/
 
51
 
 
52
struct  btPhysicsSdk
 
53
{
 
54
 
 
55
//      btDispatcher*                           m_dispatcher;
 
56
//      btOverlappingPairCache*         m_pairCache;
 
57
//      btConstraintSolver*                     m_constraintSolver
 
58
 
 
59
        btVector3       m_worldAabbMin;
 
60
        btVector3       m_worldAabbMax;
 
61
 
 
62
 
 
63
        //todo: version, hardware/optimization settings etc?
 
64
        btPhysicsSdk()
 
65
                :m_worldAabbMin(-1000,-1000,-1000),
 
66
                m_worldAabbMax(1000,1000,1000)
 
67
        {
 
68
 
 
69
        }
 
70
 
 
71
        
 
72
};
 
73
 
 
74
plPhysicsSdkHandle      plNewBulletSdk()
 
75
{
 
76
        void* mem = btAlignedAlloc(sizeof(btPhysicsSdk),16);
 
77
        return (plPhysicsSdkHandle)new (mem)btPhysicsSdk;
 
78
}
 
79
 
 
80
void            plDeletePhysicsSdk(plPhysicsSdkHandle   physicsSdk)
 
81
{
 
82
        btPhysicsSdk* phys = reinterpret_cast<btPhysicsSdk*>(physicsSdk);
 
83
        btAlignedFree(phys);    
 
84
}
 
85
 
 
86
 
 
87
/* Dynamics World */
 
88
plDynamicsWorldHandle plCreateDynamicsWorld(plPhysicsSdkHandle physicsSdkHandle)
 
89
{
 
90
        btPhysicsSdk* physicsSdk = reinterpret_cast<btPhysicsSdk*>(physicsSdkHandle);
 
91
        void* mem = btAlignedAlloc(sizeof(btDefaultCollisionConfiguration),16);
 
92
        btDefaultCollisionConfiguration* collisionConfiguration = new (mem)btDefaultCollisionConfiguration();
 
93
        mem = btAlignedAlloc(sizeof(btCollisionDispatcher),16);
 
94
        btDispatcher*                           dispatcher = new (mem)btCollisionDispatcher(collisionConfiguration);
 
95
        mem = btAlignedAlloc(sizeof(btAxisSweep3),16);
 
96
        btBroadphaseInterface*          pairCache = new (mem)btAxisSweep3(physicsSdk->m_worldAabbMin,physicsSdk->m_worldAabbMax);
 
97
        mem = btAlignedAlloc(sizeof(btSequentialImpulseConstraintSolver),16);
 
98
        btConstraintSolver*                     constraintSolver = new(mem) btSequentialImpulseConstraintSolver();
 
99
 
 
100
        mem = btAlignedAlloc(sizeof(btDiscreteDynamicsWorld),16);
 
101
        return (plDynamicsWorldHandle) new (mem)btDiscreteDynamicsWorld(dispatcher,pairCache,constraintSolver,collisionConfiguration);
 
102
}
 
103
void           plDeleteDynamicsWorld(plDynamicsWorldHandle world)
 
104
{
 
105
        //todo: also clean up the other allocations, axisSweep, pairCache,dispatcher,constraintSolver,collisionConfiguration
 
106
        btDynamicsWorld* dynamicsWorld = reinterpret_cast< btDynamicsWorld* >(world);
 
107
        btAlignedFree(dynamicsWorld);
 
108
}
 
109
 
 
110
void    plStepSimulation(plDynamicsWorldHandle world,   plReal  timeStep)
 
111
{
 
112
        btDynamicsWorld* dynamicsWorld = reinterpret_cast< btDynamicsWorld* >(world);
 
113
        assert(dynamicsWorld);
 
114
        dynamicsWorld->stepSimulation(timeStep);
 
115
}
 
116
 
 
117
void plAddRigidBody(plDynamicsWorldHandle world, plRigidBodyHandle object)
 
118
{
 
119
        btDynamicsWorld* dynamicsWorld = reinterpret_cast< btDynamicsWorld* >(world);
 
120
        assert(dynamicsWorld);
 
121
        btRigidBody* body = reinterpret_cast< btRigidBody* >(object);
 
122
        assert(body);
 
123
 
 
124
        dynamicsWorld->addRigidBody(body);
 
125
}
 
126
 
 
127
void plRemoveRigidBody(plDynamicsWorldHandle world, plRigidBodyHandle object)
 
128
{
 
129
        btDynamicsWorld* dynamicsWorld = reinterpret_cast< btDynamicsWorld* >(world);
 
130
        assert(dynamicsWorld);
 
131
        btRigidBody* body = reinterpret_cast< btRigidBody* >(object);
 
132
        assert(body);
 
133
 
 
134
        dynamicsWorld->removeRigidBody(body);
 
135
}
 
136
 
 
137
/* Rigid Body  */
 
138
 
 
139
plRigidBodyHandle plCreateRigidBody(    void* user_data,  float mass, plCollisionShapeHandle cshape )
 
140
{
 
141
        btTransform trans;
 
142
        trans.setIdentity();
 
143
        btVector3 localInertia(0,0,0);
 
144
        btCollisionShape* shape = reinterpret_cast<btCollisionShape*>( cshape);
 
145
        assert(shape);
 
146
        if (mass)
 
147
        {
 
148
                shape->calculateLocalInertia(mass,localInertia);
 
149
        }
 
150
        void* mem = btAlignedAlloc(sizeof(btRigidBody),16);
 
151
        btRigidBody::btRigidBodyConstructionInfo rbci(mass, 0,shape,localInertia);
 
152
        btRigidBody* body = new (mem)btRigidBody(rbci);
 
153
        body->setWorldTransform(trans);
 
154
        body->setUserPointer(user_data);
 
155
        return (plRigidBodyHandle) body;
 
156
}
 
157
 
 
158
void plDeleteRigidBody(plRigidBodyHandle cbody)
 
159
{
 
160
        btRigidBody* body = reinterpret_cast< btRigidBody* >(cbody);
 
161
        assert(body);
 
162
        btAlignedFree( body);
 
163
}
 
164
 
 
165
 
 
166
/* Collision Shape definition */
 
167
 
 
168
plCollisionShapeHandle plNewSphereShape(plReal radius)
 
169
{
 
170
        void* mem = btAlignedAlloc(sizeof(btSphereShape),16);
 
171
        return (plCollisionShapeHandle) new (mem)btSphereShape(radius);
 
172
        
 
173
}
 
174
        
 
175
plCollisionShapeHandle plNewBoxShape(plReal x, plReal y, plReal z)
 
176
{
 
177
        void* mem = btAlignedAlloc(sizeof(btBoxShape),16);
 
178
        return (plCollisionShapeHandle) new (mem)btBoxShape(btVector3(x,y,z));
 
179
}
 
180
 
 
181
plCollisionShapeHandle plNewCapsuleShape(plReal radius, plReal height)
 
182
{
 
183
        //capsule is convex hull of 2 spheres, so use btMultiSphereShape
 
184
        btVector3 inertiaHalfExtents(radius,height,radius);
 
185
        const int numSpheres = 2;
 
186
        btVector3 positions[numSpheres] = {btVector3(0,height,0),btVector3(0,-height,0)};
 
187
        btScalar radi[numSpheres] = {radius,radius};
 
188
        void* mem = btAlignedAlloc(sizeof(btMultiSphereShape),16);
 
189
        return (plCollisionShapeHandle) new (mem)btMultiSphereShape(inertiaHalfExtents,positions,radi,numSpheres);
 
190
}
 
191
plCollisionShapeHandle plNewConeShape(plReal radius, plReal height)
 
192
{
 
193
        void* mem = btAlignedAlloc(sizeof(btConeShape),16);
 
194
        return (plCollisionShapeHandle) new (mem)btConeShape(radius,height);
 
195
}
 
196
 
 
197
plCollisionShapeHandle plNewCylinderShape(plReal radius, plReal height)
 
198
{
 
199
        void* mem = btAlignedAlloc(sizeof(btCylinderShape),16);
 
200
        return (plCollisionShapeHandle) new (mem)btCylinderShape(btVector3(radius,height,radius));
 
201
}
 
202
 
 
203
/* Convex Meshes */
 
204
plCollisionShapeHandle plNewConvexHullShape()
 
205
{
 
206
        void* mem = btAlignedAlloc(sizeof(btConvexHullShape),16);
 
207
        return (plCollisionShapeHandle) new (mem)btConvexHullShape();
 
208
}
 
209
 
 
210
 
 
211
/* Concave static triangle meshes */
 
212
plMeshInterfaceHandle              plNewMeshInterface()
 
213
{
 
214
        return 0;
 
215
}
 
216
 
 
217
plCollisionShapeHandle plNewCompoundShape()
 
218
{
 
219
        void* mem = btAlignedAlloc(sizeof(btCompoundShape),16);
 
220
        return (plCollisionShapeHandle) new (mem)btCompoundShape();
 
221
}
 
222
 
 
223
void    plAddChildShape(plCollisionShapeHandle compoundShapeHandle,plCollisionShapeHandle childShapeHandle, plVector3 childPos,plQuaternion childOrn)
 
224
{
 
225
        btCollisionShape* colShape = reinterpret_cast<btCollisionShape*>(compoundShapeHandle);
 
226
        btAssert(colShape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE);
 
227
        btCompoundShape* compoundShape = reinterpret_cast<btCompoundShape*>(colShape);
 
228
        btCollisionShape* childShape = reinterpret_cast<btCollisionShape*>(childShapeHandle);
 
229
        btTransform     localTrans;
 
230
        localTrans.setIdentity();
 
231
        localTrans.setOrigin(btVector3(childPos[0],childPos[1],childPos[2]));
 
232
        localTrans.setRotation(btQuaternion(childOrn[0],childOrn[1],childOrn[2],childOrn[3]));
 
233
        compoundShape->addChildShape(localTrans,childShape);
 
234
}
 
235
 
 
236
void plSetEuler(plReal yaw,plReal pitch,plReal roll, plQuaternion orient)
 
237
{
 
238
        btQuaternion orn;
 
239
        orn.setEuler(yaw,pitch,roll);
 
240
        orient[0] = orn.getX();
 
241
        orient[1] = orn.getY();
 
242
        orient[2] = orn.getZ();
 
243
        orient[3] = orn.getW();
 
244
 
 
245
}
 
246
 
 
247
 
 
248
//      extern  void            plAddTriangle(plMeshInterfaceHandle meshHandle, plVector3 v0,plVector3 v1,plVector3 v2);
 
249
//      extern  plCollisionShapeHandle plNewStaticTriangleMeshShape(plMeshInterfaceHandle);
 
250
 
 
251
 
 
252
void            plAddVertex(plCollisionShapeHandle cshape, plReal x,plReal y,plReal z)
 
253
{
 
254
        btCollisionShape* colShape = reinterpret_cast<btCollisionShape*>( cshape);
 
255
        (void)colShape;
 
256
        btAssert(colShape->getShapeType()==CONVEX_HULL_SHAPE_PROXYTYPE);
 
257
        btConvexHullShape* convexHullShape = reinterpret_cast<btConvexHullShape*>( cshape);
 
258
        convexHullShape->addPoint(btPoint3(x,y,z));
 
259
 
 
260
}
 
261
 
 
262
void plDeleteShape(plCollisionShapeHandle cshape)
 
263
{
 
264
        btCollisionShape* shape = reinterpret_cast<btCollisionShape*>( cshape);
 
265
        assert(shape);
 
266
        btAlignedFree(shape);
 
267
}
 
268
void plSetScaling(plCollisionShapeHandle cshape, plVector3 cscaling)
 
269
{
 
270
        btCollisionShape* shape = reinterpret_cast<btCollisionShape*>( cshape);
 
271
        assert(shape);
 
272
        btVector3 scaling(cscaling[0],cscaling[1],cscaling[2]);
 
273
        shape->setLocalScaling(scaling);        
 
274
}
 
275
 
 
276
 
 
277
 
 
278
void plSetPosition(plRigidBodyHandle object, const plVector3 position)
 
279
{
 
280
        btRigidBody* body = reinterpret_cast< btRigidBody* >(object);
 
281
        btAssert(body);
 
282
        btVector3 pos(position[0],position[1],position[2]);
 
283
        btTransform worldTrans = body->getWorldTransform();
 
284
        worldTrans.setOrigin(pos);
 
285
        body->setWorldTransform(worldTrans);
 
286
}
 
287
 
 
288
void plSetOrientation(plRigidBodyHandle object, const plQuaternion orientation)
 
289
{
 
290
        btRigidBody* body = reinterpret_cast< btRigidBody* >(object);
 
291
        btAssert(body);
 
292
        btQuaternion orn(orientation[0],orientation[1],orientation[2],orientation[3]);
 
293
        btTransform worldTrans = body->getWorldTransform();
 
294
        worldTrans.setRotation(orn);
 
295
        body->setWorldTransform(worldTrans);
 
296
}
 
297
 
 
298
void    plGetOpenGLMatrix(plRigidBodyHandle object, plReal* matrix)
 
299
{
 
300
        btRigidBody* body = reinterpret_cast< btRigidBody* >(object);
 
301
        btAssert(body);
 
302
        body->getWorldTransform().getOpenGLMatrix(matrix);
 
303
 
 
304
}
 
305
 
 
306
void    plGetPosition(plRigidBodyHandle object,plVector3 position)
 
307
{
 
308
        btRigidBody* body = reinterpret_cast< btRigidBody* >(object);
 
309
        btAssert(body);
 
310
        const btVector3& pos = body->getWorldTransform().getOrigin();
 
311
        position[0] = pos.getX();
 
312
        position[1] = pos.getY();
 
313
        position[2] = pos.getZ();
 
314
}
 
315
 
 
316
void plGetOrientation(plRigidBodyHandle object,plQuaternion orientation)
 
317
{
 
318
        btRigidBody* body = reinterpret_cast< btRigidBody* >(object);
 
319
        btAssert(body);
 
320
        const btQuaternion& orn = body->getWorldTransform().getRotation();
 
321
        orientation[0] = orn.getX();
 
322
        orientation[1] = orn.getY();
 
323
        orientation[2] = orn.getZ();
 
324
        orientation[3] = orn.getW();
 
325
}
 
326
 
 
327
 
 
328
 
 
329
//plRigidBodyHandle plRayCast(plDynamicsWorldHandle world, const plVector3 rayStart, const plVector3 rayEnd, plVector3 hitpoint, plVector3 normal);
 
330
 
 
331
//      extern  plRigidBodyHandle plObjectCast(plDynamicsWorldHandle world, const plVector3 rayStart, const plVector3 rayEnd, plVector3 hitpoint, plVector3 normal);
 
332
 
54
333
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])
55
334
{
56
335
        btVector3 vp(p1[0], p1[1], p1[2]);
118
397
        }
119
398
        return -1.0f;   
120
399
}
 
400