2
Bullet Continuous Collision Detection and Physics Library
3
Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
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
#ifndef BT_IDEBUG_DRAW__H
18
#define BT_IDEBUG_DRAW__H
20
#include "btVector3.h"
21
#include "btTransform.h"
24
///The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations.
25
///Typical use case: create a debug drawer object, and assign it to a btCollisionWorld or btDynamicsWorld using setDebugDrawer and call debugDrawWorld.
26
///A class that implements the btIDebugDraw interface has to implement the drawLine method at a minimum.
27
///For color arguments the X,Y,Z components refer to Red, Green and Blue each in the range [0..1]
35
DBG_DrawWireframe = 1,
37
DBG_DrawFeaturesText=4,
38
DBG_DrawContactPoints=8,
39
DBG_NoDeactivation=16,
42
DBG_ProfileTimings = 128,
43
DBG_EnableSatComparison = 256,
44
DBG_DisableBulletLCP = 512,
46
DBG_DrawConstraints = (1 << 11),
47
DBG_DrawConstraintLimits = (1 << 12),
48
DBG_FastWireframe = (1<<13),
49
DBG_MAX_DEBUG_DRAW_MODE
52
virtual ~btIDebugDraw() {};
54
virtual void drawLine(const btVector3& from,const btVector3& to,const btVector3& color)=0;
56
virtual void drawLine(const btVector3& from,const btVector3& to, const btVector3& fromColor, const btVector3& toColor)
59
drawLine (from, to, fromColor);
62
virtual void drawSphere(btScalar radius, const btTransform& transform, const btVector3& color)
64
btVector3 start = transform.getOrigin();
66
const btVector3 xoffs = transform.getBasis() * btVector3(radius,0,0);
67
const btVector3 yoffs = transform.getBasis() * btVector3(0,radius,0);
68
const btVector3 zoffs = transform.getBasis() * btVector3(0,0,radius);
71
drawLine(start-xoffs, start+yoffs, color);
72
drawLine(start+yoffs, start+xoffs, color);
73
drawLine(start+xoffs, start-yoffs, color);
74
drawLine(start-yoffs, start-xoffs, color);
77
drawLine(start-xoffs, start+zoffs, color);
78
drawLine(start+zoffs, start+xoffs, color);
79
drawLine(start+xoffs, start-zoffs, color);
80
drawLine(start-zoffs, start-xoffs, color);
83
drawLine(start-yoffs, start+zoffs, color);
84
drawLine(start+zoffs, start+yoffs, color);
85
drawLine(start+yoffs, start-zoffs, color);
86
drawLine(start-zoffs, start-yoffs, color);
89
virtual void drawSphere (const btVector3& p, btScalar radius, const btVector3& color)
94
drawSphere(radius,tr,color);
97
virtual void drawTriangle(const btVector3& v0,const btVector3& v1,const btVector3& v2,const btVector3& /*n0*/,const btVector3& /*n1*/,const btVector3& /*n2*/,const btVector3& color, btScalar alpha)
99
drawTriangle(v0,v1,v2,color,alpha);
101
virtual void drawTriangle(const btVector3& v0,const btVector3& v1,const btVector3& v2,const btVector3& color, btScalar /*alpha*/)
103
drawLine(v0,v1,color);
104
drawLine(v1,v2,color);
105
drawLine(v2,v0,color);
108
virtual void drawContactPoint(const btVector3& PointOnB,const btVector3& normalOnB,btScalar distance,int lifeTime,const btVector3& color)=0;
110
virtual void reportErrorWarning(const char* warningString) = 0;
112
virtual void draw3dText(const btVector3& location,const char* textString) = 0;
114
virtual void setDebugMode(int debugMode) =0;
116
virtual int getDebugMode() const = 0;
118
virtual void drawAabb(const btVector3& from,const btVector3& to,const btVector3& color)
121
btVector3 halfExtents = (to-from)* 0.5f;
122
btVector3 center = (to+from) *0.5f;
125
btVector3 edgecoord(1.f,1.f,1.f),pa,pb;
130
pa = btVector3(edgecoord[0]*halfExtents[0], edgecoord[1]*halfExtents[1],
131
edgecoord[2]*halfExtents[2]);
134
int othercoord = j%3;
135
edgecoord[othercoord]*=-1.f;
136
pb = btVector3(edgecoord[0]*halfExtents[0], edgecoord[1]*halfExtents[1],
137
edgecoord[2]*halfExtents[2]);
140
drawLine(pa,pb,color);
142
edgecoord = btVector3(-1.f,-1.f,-1.f);
147
virtual void drawTransform(const btTransform& transform, btScalar orthoLen)
149
btVector3 start = transform.getOrigin();
150
drawLine(start, start+transform.getBasis() * btVector3(orthoLen, 0, 0), btVector3(0.7f,0,0));
151
drawLine(start, start+transform.getBasis() * btVector3(0, orthoLen, 0), btVector3(0,0.7f,0));
152
drawLine(start, start+transform.getBasis() * btVector3(0, 0, orthoLen), btVector3(0,0,0.7f));
155
virtual void drawArc(const btVector3& center, const btVector3& normal, const btVector3& axis, btScalar radiusA, btScalar radiusB, btScalar minAngle, btScalar maxAngle,
156
const btVector3& color, bool drawSect, btScalar stepDegrees = btScalar(10.f))
158
const btVector3& vx = axis;
159
btVector3 vy = normal.cross(axis);
160
btScalar step = stepDegrees * SIMD_RADS_PER_DEG;
161
int nSteps = (int)((maxAngle - minAngle) / step);
162
if(!nSteps) nSteps = 1;
163
btVector3 prev = center + radiusA * vx * btCos(minAngle) + radiusB * vy * btSin(minAngle);
166
drawLine(center, prev, color);
168
for(int i = 1; i <= nSteps; i++)
170
btScalar angle = minAngle + (maxAngle - minAngle) * btScalar(i) / btScalar(nSteps);
171
btVector3 next = center + radiusA * vx * btCos(angle) + radiusB * vy * btSin(angle);
172
drawLine(prev, next, color);
177
drawLine(center, prev, color);
180
virtual void drawSpherePatch(const btVector3& center, const btVector3& up, const btVector3& axis, btScalar radius,
181
btScalar minTh, btScalar maxTh, btScalar minPs, btScalar maxPs, const btVector3& color, btScalar stepDegrees = btScalar(10.f))
185
btVector3 *pvA = vA, *pvB = vB, *pT;
186
btVector3 npole = center + up * radius;
187
btVector3 spole = center - up * radius;
189
btScalar step = stepDegrees * SIMD_RADS_PER_DEG;
190
const btVector3& kv = up;
191
const btVector3& iv = axis;
192
btVector3 jv = kv.cross(iv);
195
if(minTh <= -SIMD_HALF_PI)
197
minTh = -SIMD_HALF_PI + step;
200
if(maxTh >= SIMD_HALF_PI)
202
maxTh = SIMD_HALF_PI - step;
207
minTh = -SIMD_HALF_PI + step;
208
maxTh = SIMD_HALF_PI - step;
209
drawN = drawS = true;
211
int n_hor = (int)((maxTh - minTh) / step) + 1;
212
if(n_hor < 2) n_hor = 2;
213
btScalar step_h = (maxTh - minTh) / btScalar(n_hor - 1);
214
bool isClosed = false;
217
minPs = -SIMD_PI + step;
221
else if((maxPs - minPs) >= SIMD_PI * btScalar(2.f))
229
int n_vert = (int)((maxPs - minPs) / step) + 1;
230
if(n_vert < 2) n_vert = 2;
231
btScalar step_v = (maxPs - minPs) / btScalar(n_vert - 1);
232
for(int i = 0; i < n_hor; i++)
234
btScalar th = minTh + btScalar(i) * step_h;
235
btScalar sth = radius * btSin(th);
236
btScalar cth = radius * btCos(th);
237
for(int j = 0; j < n_vert; j++)
239
btScalar psi = minPs + btScalar(j) * step_v;
240
btScalar sps = btSin(psi);
241
btScalar cps = btCos(psi);
242
pvB[j] = center + cth * cps * iv + cth * sps * jv + sth * kv;
245
drawLine(pvA[j], pvB[j], color);
249
drawLine(spole, pvB[j], color);
253
drawLine(pvB[j-1], pvB[j], color);
259
if((i == (n_hor - 1)) && drawN)
261
drawLine(npole, pvB[j], color);
267
drawLine(arcStart, pvB[j], color);
272
if(((!i) || (i == (n_hor-1))) && ((!j) || (j == (n_vert-1))))
274
drawLine(center, pvB[j], color);
278
pT = pvA; pvA = pvB; pvB = pT;
282
virtual void drawBox(const btVector3& bbMin, const btVector3& bbMax, const btVector3& color)
284
drawLine(btVector3(bbMin[0], bbMin[1], bbMin[2]), btVector3(bbMax[0], bbMin[1], bbMin[2]), color);
285
drawLine(btVector3(bbMax[0], bbMin[1], bbMin[2]), btVector3(bbMax[0], bbMax[1], bbMin[2]), color);
286
drawLine(btVector3(bbMax[0], bbMax[1], bbMin[2]), btVector3(bbMin[0], bbMax[1], bbMin[2]), color);
287
drawLine(btVector3(bbMin[0], bbMax[1], bbMin[2]), btVector3(bbMin[0], bbMin[1], bbMin[2]), color);
288
drawLine(btVector3(bbMin[0], bbMin[1], bbMin[2]), btVector3(bbMin[0], bbMin[1], bbMax[2]), color);
289
drawLine(btVector3(bbMax[0], bbMin[1], bbMin[2]), btVector3(bbMax[0], bbMin[1], bbMax[2]), color);
290
drawLine(btVector3(bbMax[0], bbMax[1], bbMin[2]), btVector3(bbMax[0], bbMax[1], bbMax[2]), color);
291
drawLine(btVector3(bbMin[0], bbMax[1], bbMin[2]), btVector3(bbMin[0], bbMax[1], bbMax[2]), color);
292
drawLine(btVector3(bbMin[0], bbMin[1], bbMax[2]), btVector3(bbMax[0], bbMin[1], bbMax[2]), color);
293
drawLine(btVector3(bbMax[0], bbMin[1], bbMax[2]), btVector3(bbMax[0], bbMax[1], bbMax[2]), color);
294
drawLine(btVector3(bbMax[0], bbMax[1], bbMax[2]), btVector3(bbMin[0], bbMax[1], bbMax[2]), color);
295
drawLine(btVector3(bbMin[0], bbMax[1], bbMax[2]), btVector3(bbMin[0], bbMin[1], bbMax[2]), color);
297
virtual void drawBox(const btVector3& bbMin, const btVector3& bbMax, const btTransform& trans, const btVector3& color)
299
drawLine(trans * btVector3(bbMin[0], bbMin[1], bbMin[2]), trans * btVector3(bbMax[0], bbMin[1], bbMin[2]), color);
300
drawLine(trans * btVector3(bbMax[0], bbMin[1], bbMin[2]), trans * btVector3(bbMax[0], bbMax[1], bbMin[2]), color);
301
drawLine(trans * btVector3(bbMax[0], bbMax[1], bbMin[2]), trans * btVector3(bbMin[0], bbMax[1], bbMin[2]), color);
302
drawLine(trans * btVector3(bbMin[0], bbMax[1], bbMin[2]), trans * btVector3(bbMin[0], bbMin[1], bbMin[2]), color);
303
drawLine(trans * btVector3(bbMin[0], bbMin[1], bbMin[2]), trans * btVector3(bbMin[0], bbMin[1], bbMax[2]), color);
304
drawLine(trans * btVector3(bbMax[0], bbMin[1], bbMin[2]), trans * btVector3(bbMax[0], bbMin[1], bbMax[2]), color);
305
drawLine(trans * btVector3(bbMax[0], bbMax[1], bbMin[2]), trans * btVector3(bbMax[0], bbMax[1], bbMax[2]), color);
306
drawLine(trans * btVector3(bbMin[0], bbMax[1], bbMin[2]), trans * btVector3(bbMin[0], bbMax[1], bbMax[2]), color);
307
drawLine(trans * btVector3(bbMin[0], bbMin[1], bbMax[2]), trans * btVector3(bbMax[0], bbMin[1], bbMax[2]), color);
308
drawLine(trans * btVector3(bbMax[0], bbMin[1], bbMax[2]), trans * btVector3(bbMax[0], bbMax[1], bbMax[2]), color);
309
drawLine(trans * btVector3(bbMax[0], bbMax[1], bbMax[2]), trans * btVector3(bbMin[0], bbMax[1], bbMax[2]), color);
310
drawLine(trans * btVector3(bbMin[0], bbMax[1], bbMax[2]), trans * btVector3(bbMin[0], bbMin[1], bbMax[2]), color);
313
virtual void drawCapsule(btScalar radius, btScalar halfHeight, int upAxis, const btTransform& transform, const btVector3& color)
315
btVector3 capStart(0.f,0.f,0.f);
316
capStart[upAxis] = -halfHeight;
318
btVector3 capEnd(0.f,0.f,0.f);
319
capEnd[upAxis] = halfHeight;
324
btTransform childTransform = transform;
325
childTransform.getOrigin() = transform * capStart;
326
drawSphere(radius, childTransform, color);
330
btTransform childTransform = transform;
331
childTransform.getOrigin() = transform * capEnd;
332
drawSphere(radius, childTransform, color);
335
// Draw some additional lines
336
btVector3 start = transform.getOrigin();
338
capStart[(upAxis+1)%3] = radius;
339
capEnd[(upAxis+1)%3] = radius;
340
drawLine(start+transform.getBasis() * capStart,start+transform.getBasis() * capEnd, color);
341
capStart[(upAxis+1)%3] = -radius;
342
capEnd[(upAxis+1)%3] = -radius;
343
drawLine(start+transform.getBasis() * capStart,start+transform.getBasis() * capEnd, color);
345
capStart[(upAxis+1)%3] = 0.f;
346
capEnd[(upAxis+1)%3] = 0.f;
348
capStart[(upAxis+2)%3] = radius;
349
capEnd[(upAxis+2)%3] = radius;
350
drawLine(start+transform.getBasis() * capStart,start+transform.getBasis() * capEnd, color);
351
capStart[(upAxis+2)%3] = -radius;
352
capEnd[(upAxis+2)%3] = -radius;
353
drawLine(start+transform.getBasis() * capStart,start+transform.getBasis() * capEnd, color);
356
virtual void drawCylinder(btScalar radius, btScalar halfHeight, int upAxis, const btTransform& transform, const btVector3& color)
358
btVector3 start = transform.getOrigin();
359
btVector3 offsetHeight(0,0,0);
360
offsetHeight[upAxis] = halfHeight;
361
btVector3 offsetRadius(0,0,0);
362
offsetRadius[(upAxis+1)%3] = radius;
363
drawLine(start+transform.getBasis() * (offsetHeight+offsetRadius),start+transform.getBasis() * (-offsetHeight+offsetRadius),color);
364
drawLine(start+transform.getBasis() * (offsetHeight-offsetRadius),start+transform.getBasis() * (-offsetHeight-offsetRadius),color);
366
// Drawing top and bottom caps of the cylinder
367
btVector3 yaxis(0,0,0);
368
yaxis[upAxis] = btScalar(1.0);
369
btVector3 xaxis(0,0,0);
370
xaxis[(upAxis+1)%3] = btScalar(1.0);
371
drawArc(start-transform.getBasis()*(offsetHeight),transform.getBasis()*yaxis,transform.getBasis()*xaxis,radius,radius,0,SIMD_2_PI,color,false,btScalar(10.0));
372
drawArc(start+transform.getBasis()*(offsetHeight),transform.getBasis()*yaxis,transform.getBasis()*xaxis,radius,radius,0,SIMD_2_PI,color,false,btScalar(10.0));
375
virtual void drawCone(btScalar radius, btScalar height, int upAxis, const btTransform& transform, const btVector3& color)
378
btVector3 start = transform.getOrigin();
380
btVector3 offsetHeight(0,0,0);
381
offsetHeight[upAxis] = height * btScalar(0.5);
382
btVector3 offsetRadius(0,0,0);
383
offsetRadius[(upAxis+1)%3] = radius;
384
btVector3 offset2Radius(0,0,0);
385
offset2Radius[(upAxis+2)%3] = radius;
387
drawLine(start+transform.getBasis() * (offsetHeight),start+transform.getBasis() * (-offsetHeight+offsetRadius),color);
388
drawLine(start+transform.getBasis() * (offsetHeight),start+transform.getBasis() * (-offsetHeight-offsetRadius),color);
389
drawLine(start+transform.getBasis() * (offsetHeight),start+transform.getBasis() * (-offsetHeight+offset2Radius),color);
390
drawLine(start+transform.getBasis() * (offsetHeight),start+transform.getBasis() * (-offsetHeight-offset2Radius),color);
392
// Drawing the base of the cone
393
btVector3 yaxis(0,0,0);
394
yaxis[upAxis] = btScalar(1.0);
395
btVector3 xaxis(0,0,0);
396
xaxis[(upAxis+1)%3] = btScalar(1.0);
397
drawArc(start-transform.getBasis()*(offsetHeight),transform.getBasis()*yaxis,transform.getBasis()*xaxis,radius,radius,0,SIMD_2_PI,color,false,10.0);
400
virtual void drawPlane(const btVector3& planeNormal, btScalar planeConst, const btTransform& transform, const btVector3& color)
402
btVector3 planeOrigin = planeNormal * planeConst;
404
btPlaneSpace1(planeNormal,vec0,vec1);
405
btScalar vecLen = 100.f;
406
btVector3 pt0 = planeOrigin + vec0*vecLen;
407
btVector3 pt1 = planeOrigin - vec0*vecLen;
408
btVector3 pt2 = planeOrigin + vec1*vecLen;
409
btVector3 pt3 = planeOrigin - vec1*vecLen;
410
drawLine(transform*pt0,transform*pt1,color);
411
drawLine(transform*pt2,transform*pt3,color);
416
#endif //BT_IDEBUG_DRAW__H