I just switched to using the built-in bullet debug drawing, but some shapes aren't displayed as I would like .
Currently I only replaced cylinder and capsule rendering (not using the rest).
This is the change that included patch makes (before/after):
Code: Select all
Index: btDiscreteDynamicsWorld.cpp
===================================================================
--- btDiscreteDynamicsWorld.cpp (revision 1713)
+++ btDiscreteDynamicsWorld.cpp (working copy)
@@ -1034,52 +1034,48 @@
btScalar radius = capsuleShape->getRadius();
btScalar halfHeight = capsuleShape->getHalfHeight();
-
+
int upAxis = capsuleShape->getUpAxis();
+ btVector3 start = worldTransform.getOrigin();
-
- btVector3 capStart(0.f,0.f,0.f);
- capStart[upAxis] = -halfHeight;
+ btVector3 offsetHeight(0,0,0);
+ offsetHeight[upAxis] = halfHeight;
+ btVector3 offsetRadius(0,0,0);
- btVector3 capEnd(0.f,0.f,0.f);
- capEnd[upAxis] = halfHeight;
+ const int detail = 5; // do not change if using fake trig
+ const btScalar ratio = 2.*3.1415926 / detail;
+ const int up1 = (upAxis+1)%3;
+ const int up2 = (upAxis+2)%3;
+ const btScalar fakeCos[detail] = { 1, 0.309, -0.809, -0.809, 0.309 };
+ const btScalar fakeSin[detail] = { 0, 0.951, 0.588, -0.588, -0.951 };
- // Draw the ends
- {
-
- btTransform childTransform = worldTransform;
- childTransform.getOrigin() = worldTransform * capStart;
- debugDrawSphere(radius, childTransform, color);
- }
+ btVector3 offsetNext(0,0,0);
+ offsetNext[up1] = radius;
+ btVector3 offsetCap(0,0,0);
+ offsetCap[upAxis] = radius;
+
+ for ( int i = 0; i < detail; i++ )
{
- btTransform childTransform = worldTransform;
- childTransform.getOrigin() = worldTransform * capEnd;
- debugDrawSphere(radius, childTransform, color);
- }
+ offsetRadius[up1] = offsetNext[up1];
+ offsetRadius[up2] = offsetNext[up2];
- // Draw some additional lines
- btVector3 start = worldTransform.getOrigin();
+ /* using trig
+ btScalar nxt = ((i + 1) % detail) * ratio;
+ offsetNext[up1] = btCos(nxt) * radius;
+ offsetNext[up2] = btSin(nxt) * radius;
+ */
+ int nxt = (i + 1) % detail;
+ offsetNext[up1] = fakeCos[nxt] * radius;
+ offsetNext[up2] = fakeSin[nxt] * radius;
-
- capStart[(upAxis+1)%3] = radius;
- capEnd[(upAxis+1)%3] = radius;
- getDebugDrawer()->drawLine(start+worldTransform.getBasis() * capStart,start+worldTransform.getBasis() * capEnd, color);
- capStart[(upAxis+1)%3] = -radius;
- capEnd[(upAxis+1)%3] = -radius;
- getDebugDrawer()->drawLine(start+worldTransform.getBasis() * capStart,start+worldTransform.getBasis() * capEnd, color);
+ getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight+offsetRadius),start+worldTransform.getBasis() * (-offsetHeight+offsetRadius),color);
+ getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight+offsetRadius),start+worldTransform.getBasis() * (offsetHeight+offsetNext),color);
+ getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (-offsetHeight+offsetRadius),start+worldTransform.getBasis() * (-offsetHeight+offsetNext),color);
+ getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight+offsetRadius),start+worldTransform.getBasis() * (offsetHeight+offsetCap),color);
+ getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (-offsetHeight+offsetRadius),start+worldTransform.getBasis() * (-offsetHeight-offsetCap),color);
+ }
- capStart[(upAxis+1)%3] = 0.f;
- capEnd[(upAxis+1)%3] = 0.f;
-
- capStart[(upAxis+2)%3] = radius;
- capEnd[(upAxis+2)%3] = radius;
- getDebugDrawer()->drawLine(start+worldTransform.getBasis() * capStart,start+worldTransform.getBasis() * capEnd, color);
- capStart[(upAxis+2)%3] = -radius;
- capEnd[(upAxis+2)%3] = -radius;
- getDebugDrawer()->drawLine(start+worldTransform.getBasis() * capStart,start+worldTransform.getBasis() * capEnd, color);
-
-
break;
}
case CONE_SHAPE_PROXYTYPE:
@@ -1119,9 +1115,36 @@
btVector3 offsetHeight(0,0,0);
offsetHeight[upAxis] = halfHeight;
btVector3 offsetRadius(0,0,0);
- offsetRadius[(upAxis+1)%3] = radius;
- getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight+offsetRadius),start+worldTransform.getBasis() * (-offsetHeight+offsetRadius),color);
- getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight-offsetRadius),start+worldTransform.getBasis() * (-offsetHeight-offsetRadius),color);
+
+ const int detail = 5; // do not change if using fake trig
+ const btScalar ratio = 2.*3.1415926 / detail;
+ const int up1 = (upAxis+1)%3;
+ const int up2 = (upAxis+2)%3;
+ const btScalar fakeCos[detail] = { 1, 0.309, -0.809, -0.809, 0.309 };
+ const btScalar fakeSin[detail] = { 0, 0.951, 0.588, -0.588, -0.951 };
+
+ btVector3 offsetNext(0,0,0);
+ offsetNext[up1] = radius;
+
+ for ( int i = 0; i < detail; i++ )
+ {
+ offsetRadius[up1] = offsetNext[up1];
+ offsetRadius[up2] = offsetNext[up2];
+
+ /* using trig
+ btScalar nxt = ((i + 1) % detail) * ratio;
+ offsetNext[up1] = btCos(nxt) * radius;
+ offsetNext[up2] = btSin(nxt) * radius;
+ */
+ int nxt = (i + 1) % detail;
+ offsetNext[up1] = fakeCos[nxt] * radius;
+ offsetNext[up2] = fakeSin[nxt] * radius;
+
+ getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight+offsetRadius),start+worldTransform.getBasis() * (-offsetHeight+offsetRadius),color);
+ getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight+offsetRadius),start+worldTransform.getBasis() * (offsetHeight+offsetNext),color);
+ getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (-offsetHeight+offsetRadius),start+worldTransform.getBasis() * (-offsetHeight+offsetNext),color);
+ }
+
break;
}