fixes in debug drawer: always use rgba color with each component in range [0..1]

use sphere/box rendering of debug drawer
Thanks accodejockey for the report: See http://code.google.com/p/bullet/issues/detail?id=280
Also see http://code.google.com/p/bullet/issues/detail?id=279
This commit is contained in:
erwin.coumans
2010-01-19 19:38:18 +00:00
parent c6df06c6a1
commit 96d73d642d
8 changed files with 68 additions and 61 deletions

View File

@@ -24,6 +24,7 @@ subject to the following restrictions:
///The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations.
///Typical use case: create a debug drawer object, and assign it to a btCollisionWorld or btDynamicsWorld using setDebugDrawer and call debugDrawWorld.
///A class that implements the btIDebugDraw interface has to implement the drawLine method at a minimum.
///For color arguments the X,Y,Z components refer to Red, Green and Blue each in the range [0..1]
class btIDebugDraw
{
public:
@@ -50,23 +51,48 @@ class btIDebugDraw
virtual ~btIDebugDraw() {};
virtual void drawLine(const btVector3& from,const btVector3& to,const btVector3& color)=0;
virtual void drawLine(const btVector3& from,const btVector3& to, const btVector3& fromColor, const btVector3& toColor)
{
(void) fromColor; (void) toColor;
(void) toColor;
drawLine (from, to, fromColor);
}
virtual void drawBox (const btVector3& boxMin, const btVector3& boxMax, const btVector3& color, btScalar alpha)
void drawSphere(btScalar radius, const btTransform& transform, const btVector3& color)
{
(void) boxMin; (void) boxMax; (void) color; (void) alpha;
}
btVector3 start = transform.getOrigin();
const btVector3 xoffs = transform.getBasis() * btVector3(radius,0,0);
const btVector3 yoffs = transform.getBasis() * btVector3(0,radius,0);
const btVector3 zoffs = transform.getBasis() * btVector3(0,0,radius);
// XY
drawLine(start-xoffs, start+yoffs, color);
drawLine(start+yoffs, start+xoffs, color);
drawLine(start+xoffs, start-yoffs, color);
drawLine(start-yoffs, start-xoffs, color);
// XZ
drawLine(start-xoffs, start+zoffs, color);
drawLine(start+zoffs, start+xoffs, color);
drawLine(start+xoffs, start-zoffs, color);
drawLine(start-zoffs, start-xoffs, color);
// YZ
drawLine(start-yoffs, start+zoffs, color);
drawLine(start+zoffs, start+yoffs, color);
drawLine(start+yoffs, start-zoffs, color);
drawLine(start-zoffs, start-yoffs, color);
}
virtual void drawSphere (const btVector3& p, btScalar radius, const btVector3& color)
{
(void) p; (void) radius; (void) color; (void) color;
btTransform tr;
tr.setIdentity();
tr.setOrigin(p);
drawSphere(radius,tr,color);
}
virtual void drawLine(const btVector3& from,const btVector3& to,const btVector3& color)=0;
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)
{
@@ -89,7 +115,7 @@ class btIDebugDraw
virtual int getDebugMode() const = 0;
inline void drawAabb(const btVector3& from,const btVector3& to,const btVector3& color)
virtual void drawAabb(const btVector3& from,const btVector3& to,const btVector3& color)
{
btVector3 halfExtents = (to-from)* 0.5f;
@@ -118,7 +144,7 @@ class btIDebugDraw
edgecoord[i]*=-1.f;
}
}
void drawTransform(const btTransform& transform, btScalar orthoLen)
virtual void drawTransform(const btTransform& transform, btScalar orthoLen)
{
btVector3 start = transform.getOrigin();
drawLine(start, start+transform.getBasis() * btVector3(orthoLen, 0, 0), btVector3(0.7f,0,0));
@@ -126,7 +152,7 @@ class btIDebugDraw
drawLine(start, start+transform.getBasis() * btVector3(0, 0, orthoLen), btVector3(0,0,0.7f));
}
void drawArc(const btVector3& center, const btVector3& normal, const btVector3& axis, btScalar radiusA, btScalar radiusB, btScalar minAngle, btScalar maxAngle,
virtual void drawArc(const btVector3& center, const btVector3& normal, const btVector3& axis, btScalar radiusA, btScalar radiusB, btScalar minAngle, btScalar maxAngle,
const btVector3& color, bool drawSect, btScalar stepDegrees = btScalar(10.f))
{
const btVector3& vx = axis;
@@ -151,7 +177,7 @@ class btIDebugDraw
drawLine(center, prev, color);
}
}
void drawSpherePatch(const btVector3& center, const btVector3& up, const btVector3& axis, btScalar radius,
virtual void drawSpherePatch(const btVector3& center, const btVector3& up, const btVector3& axis, btScalar radius,
btScalar minTh, btScalar maxTh, btScalar minPs, btScalar maxPs, const btVector3& color, btScalar stepDegrees = btScalar(10.f))
{
btVector3 vA[74];
@@ -253,7 +279,7 @@ class btIDebugDraw
}
}
void drawBox(const btVector3& bbMin, const btVector3& bbMax, const btVector3& color)
virtual void drawBox(const btVector3& bbMin, const btVector3& bbMax, const btVector3& color)
{
drawLine(btVector3(bbMin[0], bbMin[1], bbMin[2]), btVector3(bbMax[0], bbMin[1], bbMin[2]), color);
drawLine(btVector3(bbMax[0], bbMin[1], bbMin[2]), btVector3(bbMax[0], bbMax[1], bbMin[2]), color);
@@ -268,7 +294,7 @@ class btIDebugDraw
drawLine(btVector3(bbMax[0], bbMax[1], bbMax[2]), btVector3(bbMin[0], bbMax[1], bbMax[2]), color);
drawLine(btVector3(bbMin[0], bbMax[1], bbMax[2]), btVector3(bbMin[0], bbMin[1], bbMax[2]), color);
}
void drawBox(const btVector3& bbMin, const btVector3& bbMax, const btTransform& trans, const btVector3& color)
virtual void drawBox(const btVector3& bbMin, const btVector3& bbMax, const btTransform& trans, const btVector3& color)
{
drawLine(trans * btVector3(bbMin[0], bbMin[1], bbMin[2]), trans * btVector3(bbMax[0], bbMin[1], bbMin[2]), color);
drawLine(trans * btVector3(bbMax[0], bbMin[1], bbMin[2]), trans * btVector3(bbMax[0], bbMax[1], bbMin[2]), color);