[1963] | 1 | /* |
---|
[8284] | 2 | Bullet Continuous Collision Detection and Physics Library |
---|
| 3 | Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org |
---|
[1963] | 4 | |
---|
[8284] | 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: |
---|
[1963] | 10 | |
---|
[8284] | 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. |
---|
[1963] | 14 | */ |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | #ifndef IDEBUG_DRAW__H |
---|
| 18 | #define IDEBUG_DRAW__H |
---|
| 19 | |
---|
| 20 | #include "btVector3.h" |
---|
[2882] | 21 | #include "btTransform.h" |
---|
[1963] | 22 | |
---|
| 23 | |
---|
| 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. |
---|
[8284] | 27 | ///For color arguments the X,Y,Z components refer to Red, Green and Blue each in the range [0..1] |
---|
[1963] | 28 | class btIDebugDraw |
---|
| 29 | { |
---|
| 30 | public: |
---|
| 31 | |
---|
| 32 | enum DebugDrawModes |
---|
| 33 | { |
---|
| 34 | DBG_NoDebug=0, |
---|
| 35 | DBG_DrawWireframe = 1, |
---|
| 36 | DBG_DrawAabb=2, |
---|
| 37 | DBG_DrawFeaturesText=4, |
---|
| 38 | DBG_DrawContactPoints=8, |
---|
| 39 | DBG_NoDeactivation=16, |
---|
| 40 | DBG_NoHelpText = 32, |
---|
| 41 | DBG_DrawText=64, |
---|
| 42 | DBG_ProfileTimings = 128, |
---|
| 43 | DBG_EnableSatComparison = 256, |
---|
| 44 | DBG_DisableBulletLCP = 512, |
---|
| 45 | DBG_EnableCCD = 1024, |
---|
[2882] | 46 | DBG_DrawConstraints = (1 << 11), |
---|
| 47 | DBG_DrawConstraintLimits = (1 << 12), |
---|
[8284] | 48 | DBG_FastWireframe = (1<<13), |
---|
[1963] | 49 | DBG_MAX_DEBUG_DRAW_MODE |
---|
| 50 | }; |
---|
| 51 | |
---|
| 52 | virtual ~btIDebugDraw() {}; |
---|
| 53 | |
---|
[8284] | 54 | virtual void drawLine(const btVector3& from,const btVector3& to,const btVector3& color)=0; |
---|
| 55 | |
---|
[2882] | 56 | virtual void drawLine(const btVector3& from,const btVector3& to, const btVector3& fromColor, const btVector3& toColor) |
---|
| 57 | { |
---|
[8284] | 58 | (void) toColor; |
---|
[2882] | 59 | drawLine (from, to, fromColor); |
---|
| 60 | } |
---|
| 61 | |
---|
[8284] | 62 | virtual void drawSphere(btScalar radius, const btTransform& transform, const btVector3& color) |
---|
[2882] | 63 | { |
---|
[8284] | 64 | btVector3 start = transform.getOrigin(); |
---|
| 65 | |
---|
| 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); |
---|
| 69 | |
---|
| 70 | // XY |
---|
| 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); |
---|
| 75 | |
---|
| 76 | // XZ |
---|
| 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); |
---|
| 81 | |
---|
| 82 | // YZ |
---|
| 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); |
---|
[2882] | 87 | } |
---|
[8284] | 88 | |
---|
[2882] | 89 | virtual void drawSphere (const btVector3& p, btScalar radius, const btVector3& color) |
---|
| 90 | { |
---|
[8284] | 91 | btTransform tr; |
---|
| 92 | tr.setIdentity(); |
---|
| 93 | tr.setOrigin(p); |
---|
| 94 | drawSphere(radius,tr,color); |
---|
[2882] | 95 | } |
---|
[1963] | 96 | |
---|
| 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) |
---|
| 98 | { |
---|
| 99 | drawTriangle(v0,v1,v2,color,alpha); |
---|
| 100 | } |
---|
| 101 | virtual void drawTriangle(const btVector3& v0,const btVector3& v1,const btVector3& v2,const btVector3& color, btScalar /*alpha*/) |
---|
| 102 | { |
---|
| 103 | drawLine(v0,v1,color); |
---|
| 104 | drawLine(v1,v2,color); |
---|
| 105 | drawLine(v2,v0,color); |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | virtual void drawContactPoint(const btVector3& PointOnB,const btVector3& normalOnB,btScalar distance,int lifeTime,const btVector3& color)=0; |
---|
| 109 | |
---|
| 110 | virtual void reportErrorWarning(const char* warningString) = 0; |
---|
| 111 | |
---|
| 112 | virtual void draw3dText(const btVector3& location,const char* textString) = 0; |
---|
| 113 | |
---|
| 114 | virtual void setDebugMode(int debugMode) =0; |
---|
| 115 | |
---|
| 116 | virtual int getDebugMode() const = 0; |
---|
| 117 | |
---|
[8284] | 118 | virtual void drawAabb(const btVector3& from,const btVector3& to,const btVector3& color) |
---|
[1963] | 119 | { |
---|
| 120 | |
---|
| 121 | btVector3 halfExtents = (to-from)* 0.5f; |
---|
| 122 | btVector3 center = (to+from) *0.5f; |
---|
| 123 | int i,j; |
---|
| 124 | |
---|
| 125 | btVector3 edgecoord(1.f,1.f,1.f),pa,pb; |
---|
| 126 | for (i=0;i<4;i++) |
---|
| 127 | { |
---|
| 128 | for (j=0;j<3;j++) |
---|
| 129 | { |
---|
| 130 | pa = btVector3(edgecoord[0]*halfExtents[0], edgecoord[1]*halfExtents[1], |
---|
| 131 | edgecoord[2]*halfExtents[2]); |
---|
| 132 | pa+=center; |
---|
| 133 | |
---|
| 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]); |
---|
| 138 | pb+=center; |
---|
| 139 | |
---|
| 140 | drawLine(pa,pb,color); |
---|
| 141 | } |
---|
| 142 | edgecoord = btVector3(-1.f,-1.f,-1.f); |
---|
| 143 | if (i<3) |
---|
| 144 | edgecoord[i]*=-1.f; |
---|
| 145 | } |
---|
| 146 | } |
---|
[8284] | 147 | virtual void drawTransform(const btTransform& transform, btScalar orthoLen) |
---|
[2882] | 148 | { |
---|
| 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)); |
---|
| 153 | } |
---|
| 154 | |
---|
[8284] | 155 | virtual void drawArc(const btVector3& center, const btVector3& normal, const btVector3& axis, btScalar radiusA, btScalar radiusB, btScalar minAngle, btScalar maxAngle, |
---|
[2882] | 156 | const btVector3& color, bool drawSect, btScalar stepDegrees = btScalar(10.f)) |
---|
| 157 | { |
---|
| 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); |
---|
| 164 | if(drawSect) |
---|
| 165 | { |
---|
| 166 | drawLine(center, prev, color); |
---|
| 167 | } |
---|
| 168 | for(int i = 1; i <= nSteps; i++) |
---|
| 169 | { |
---|
| 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); |
---|
| 173 | prev = next; |
---|
| 174 | } |
---|
| 175 | if(drawSect) |
---|
| 176 | { |
---|
| 177 | drawLine(center, prev, color); |
---|
| 178 | } |
---|
| 179 | } |
---|
[8284] | 180 | virtual void drawSpherePatch(const btVector3& center, const btVector3& up, const btVector3& axis, btScalar radius, |
---|
[2882] | 181 | btScalar minTh, btScalar maxTh, btScalar minPs, btScalar maxPs, const btVector3& color, btScalar stepDegrees = btScalar(10.f)) |
---|
| 182 | { |
---|
| 183 | btVector3 vA[74]; |
---|
| 184 | btVector3 vB[74]; |
---|
| 185 | btVector3 *pvA = vA, *pvB = vB, *pT; |
---|
| 186 | btVector3 npole = center + up * radius; |
---|
| 187 | btVector3 spole = center - up * radius; |
---|
| 188 | btVector3 arcStart; |
---|
| 189 | btScalar step = stepDegrees * SIMD_RADS_PER_DEG; |
---|
| 190 | const btVector3& kv = up; |
---|
| 191 | const btVector3& iv = axis; |
---|
| 192 | btVector3 jv = kv.cross(iv); |
---|
| 193 | bool drawN = false; |
---|
| 194 | bool drawS = false; |
---|
| 195 | if(minTh <= -SIMD_HALF_PI) |
---|
| 196 | { |
---|
| 197 | minTh = -SIMD_HALF_PI + step; |
---|
| 198 | drawN = true; |
---|
| 199 | } |
---|
| 200 | if(maxTh >= SIMD_HALF_PI) |
---|
| 201 | { |
---|
| 202 | maxTh = SIMD_HALF_PI - step; |
---|
| 203 | drawS = true; |
---|
| 204 | } |
---|
| 205 | if(minTh > maxTh) |
---|
| 206 | { |
---|
| 207 | minTh = -SIMD_HALF_PI + step; |
---|
| 208 | maxTh = SIMD_HALF_PI - step; |
---|
| 209 | drawN = drawS = true; |
---|
| 210 | } |
---|
| 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; |
---|
| 215 | if(minPs > maxPs) |
---|
| 216 | { |
---|
| 217 | minPs = -SIMD_PI + step; |
---|
| 218 | maxPs = SIMD_PI; |
---|
| 219 | isClosed = true; |
---|
| 220 | } |
---|
| 221 | else if((maxPs - minPs) >= SIMD_PI * btScalar(2.f)) |
---|
| 222 | { |
---|
| 223 | isClosed = true; |
---|
| 224 | } |
---|
| 225 | else |
---|
| 226 | { |
---|
| 227 | isClosed = false; |
---|
| 228 | } |
---|
| 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++) |
---|
| 233 | { |
---|
| 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++) |
---|
| 238 | { |
---|
| 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; |
---|
| 243 | if(i) |
---|
| 244 | { |
---|
| 245 | drawLine(pvA[j], pvB[j], color); |
---|
| 246 | } |
---|
| 247 | else if(drawS) |
---|
| 248 | { |
---|
| 249 | drawLine(spole, pvB[j], color); |
---|
| 250 | } |
---|
| 251 | if(j) |
---|
| 252 | { |
---|
| 253 | drawLine(pvB[j-1], pvB[j], color); |
---|
| 254 | } |
---|
| 255 | else |
---|
| 256 | { |
---|
| 257 | arcStart = pvB[j]; |
---|
| 258 | } |
---|
| 259 | if((i == (n_hor - 1)) && drawN) |
---|
| 260 | { |
---|
| 261 | drawLine(npole, pvB[j], color); |
---|
| 262 | } |
---|
| 263 | if(isClosed) |
---|
| 264 | { |
---|
| 265 | if(j == (n_vert-1)) |
---|
| 266 | { |
---|
| 267 | drawLine(arcStart, pvB[j], color); |
---|
| 268 | } |
---|
| 269 | } |
---|
| 270 | else |
---|
| 271 | { |
---|
| 272 | if(((!i) || (i == (n_hor-1))) && ((!j) || (j == (n_vert-1)))) |
---|
| 273 | { |
---|
| 274 | drawLine(center, pvB[j], color); |
---|
| 275 | } |
---|
| 276 | } |
---|
| 277 | } |
---|
| 278 | pT = pvA; pvA = pvB; pvB = pT; |
---|
| 279 | } |
---|
| 280 | } |
---|
| 281 | |
---|
[8284] | 282 | virtual void drawBox(const btVector3& bbMin, const btVector3& bbMax, const btVector3& color) |
---|
[2882] | 283 | { |
---|
| 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); |
---|
| 296 | } |
---|
[8284] | 297 | virtual void drawBox(const btVector3& bbMin, const btVector3& bbMax, const btTransform& trans, const btVector3& color) |
---|
[2882] | 298 | { |
---|
| 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); |
---|
| 311 | } |
---|
[1963] | 312 | }; |
---|
| 313 | |
---|
| 314 | |
---|
| 315 | #endif //IDEBUG_DRAW__H |
---|
| 316 | |
---|