debugDrawObject "logic" from btCollisionWorld to btIDebugDra

Nacho
Posts: 31
Joined: Tue Mar 04, 2008 1:41 pm

debugDrawObject "logic" from btCollisionWorld to btIDebugDra

Post by Nacho »

Hi,

Should it be possible to change the draw forms of each primitive from btCollisionWorld::debugDrawObject to btIDebugDraw.

Nowadays, in btCollisionWorld::debugDrawObject there are things like:

Code: Select all

		case CAPSULE_SHAPE_PROXYTYPE:
			{
				const btCapsuleShape* capsuleShape = static_cast<const btCapsuleShape*>(shape);

				btScalar radius = capsuleShape->getRadius();
				btScalar halfHeight = capsuleShape->getHalfHeight();

				int upAxis = capsuleShape->getUpAxis();


				btVector3 capStart(0.f,0.f,0.f);
				capStart[upAxis] = -halfHeight;

				btVector3 capEnd(0.f,0.f,0.f);
				capEnd[upAxis] = halfHeight;

				// Draw the ends
				{

					btTransform childTransform = worldTransform;
					childTransform.getOrigin() = worldTransform * capStart;
					getDebugDrawer()->drawSphere(radius, childTransform, color);
				}

				{
					btTransform childTransform = worldTransform;
					childTransform.getOrigin() = worldTransform * capEnd;
					getDebugDrawer()->drawSphere(radius, childTransform, color);
				}

				// Draw some additional lines
				btVector3 start = worldTransform.getOrigin();


				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);

				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;
			}
but my proposal is:

(in btCollisionWorld::debugDrawObject)

Code: Select all

		case CAPSULE_SHAPE_PROXYTYPE:
			{
				const btCapsuleShape* capsuleShape = static_cast<const btCapsuleShape*>(shape);

				btScalar radius = capsuleShape->getRadius();
				btScalar halfHeight = capsuleShape->getHalfHeight();

				int upAxis = capsuleShape->getUpAxis();
				getDebugDrawer()->drawCapsule(radius, halfHeight, upAxis, worldTransform, color);
				break;
			}
(and in btIDebugDraw.h, copy&paste from old btCollisionWorld::debugDrawObject)

Code: Select all

	virtual void drawCapsule(btScalar radius, btScalar halfHeight, int upAxis, const btTransform& transform, const btVector3& color)
	{
		btVector3 capStart(0.f,0.f,0.f);
		capStart[upAxis] = -halfHeight;

		btVector3 capEnd(0.f,0.f,0.f);
		capEnd[upAxis] = halfHeight;

		// Draw the ends
		{

			btTransform childTransform = transform;
			childTransform.getOrigin() = transform * capStart;
			drawSphere(radius, childTransform, color);
		}

		{
			btTransform childTransform = transform;
			childTransform.getOrigin() = transform * capEnd;
			drawSphere(radius, childTransform, color);
		}

		// Draw some additional lines
		btVector3 start = transform.getOrigin();

		capStart[(upAxis+1)%3] = radius;
		capEnd[(upAxis+1)%3] = radius;
		drawLine(start+transform.getBasis() * capStart,start+transform.getBasis() * capEnd, color);
		capStart[(upAxis+1)%3] = -radius;
		capEnd[(upAxis+1)%3] = -radius;
		drawLine(start+transform.getBasis() * capStart,start+transform.getBasis() * capEnd, color);

		capStart[(upAxis+1)%3] = 0.f;
		capEnd[(upAxis+1)%3] = 0.f;

		capStart[(upAxis+2)%3] = radius;
		capEnd[(upAxis+2)%3] = radius;
		drawLine(start+transform.getBasis() * capStart,start+transform.getBasis() * capEnd, color);
		capStart[(upAxis+2)%3] = -radius;
		capEnd[(upAxis+2)%3] = -radius;
		drawLine(start+transform.getBasis() * capStart,start+transform.getBasis() * capEnd, color);
	}
Then, anyone can implement his own capsule (or other primitives) in his derived btIDebugDrawer.

I attach a path to do it with the current simple primitives in btCollisionWorld::debugDrawObject: Capsule, cylinder, cone and plane.


Nacho.
You do not have the required permissions to view the files attached to this post.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: debugDrawObject "logic" from btCollisionWorld to btIDebugDra

Post by Erwin Coumans »

That looks good, let's apply that patch. I created the issue here: http://code.google.com/p/bullet/issues/detail?id=382

Thanks a lot for the contribution,
Erwin
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: debugDrawObject "logic" from btCollisionWorld to btIDebu

Post by Erwin Coumans »

The patch has been applied in latest trunk.
http://code.google.com/p/bullet/source/detail?r=2308

Thanks!