Small testbed framework improvement

This is probably cheeky of me, but I've made the testbed render the shapes in a more appealing way, and sometimes more useful too.

If you replace Drawshape () with the following code in Render.cpp in the testbed, things look that much cooler, without a noticeable knock in performance.

void DrawShape(const b2Shape* shape, const Color& c, bool core)
{
switch (shape->m_type)
{
case e_circleShape:
{
const b2CircleShape* circle = (const b2CircleShape*)shape;
b2Vec2 x = circle->m_position;
float32 r = circle->m_radius;
const float32 k_segments = 16.0f;
const float32 k_increment = 2.0f * b2_pi / k_segments;
float32 theta = 0.0f;
glColor4f(c.cx*0.5f, c.cy*0.5f, c.cz*0.5f, 0.5f);
glBegin(GL_TRIANGLE_FAN);
for (int32 i = 0; i < k_segments; ++i)
{
b2Vec2 d(r * cosf(theta), r * sinf(theta));
b2Vec2 v = x + d;
glVertex2f(v.x, v.y);
theta += k_increment;
}
glEnd();

theta = 0.0f;
glColor4f(c.cx, c.cy, c.cz, 1.0f);
glBegin(GL_LINE_LOOP);
for (int32 i = 0; i < k_segments; ++i)
{
b2Vec2 d(r * cosf(theta), r * sinf(theta));
b2Vec2 v = x + d;
glVertex2f(v.x, v.y);
theta += k_increment;
}
glEnd();

glBegin(GL_LINES);
glVertex2f(x.x, x.y);
b2Vec2 ax = circle->m_R.col1;
glVertex2f(x.x + r * ax.x, x.y + r * ax.y);
glEnd();

if (core)
{
float32 r = circle->m_radius - b2_toiSlop;
float32 theta = 0.0f;
glColor4f(0.9f, 0.1f, 0.1f, 1.0f);
glBegin(GL_LINE_LOOP);
for (int32 i = 0; i < k_segments; ++i)
{
b2Vec2 d(r * cosf(theta), r * sinf(theta));
b2Vec2 v = x + d;
glVertex2f(v.x, v.y);
theta += k_increment;
}
glEnd();
}
}
break;

case e_polyShape:
{
const b2PolyShape* poly = (const b2PolyShape*)shape;

glColor4f(c.cx*0.5f, c.cy*0.5f, c.cz*0.5f, 1.0f);
glBegin(GL_TRIANGLE_FAN);
for (int32 i = 0; i < poly->m_vertexCount; ++i)
{
b2Vec2 v = poly->m_position + b2Mul(poly->m_R, poly->m_vertices[i]);
glVertex2f(v.x, v.y);
}
glEnd();

glColor4f(c.cx, c.cy, c.cz, 1.0f);
glBegin(GL_LINE_LOOP);
for (int32 i = 0; i < poly->m_vertexCount; ++i)
{
b2Vec2 v = poly->m_position + b2Mul(poly->m_R, poly->m_vertices[i]);
glVertex2f(v.x, v.y);
}
glEnd();

if (core)
{
glColor4f(0.9f, 0.1f, 0.1f, 1.0f);
glBegin(GL_LINE_LOOP);
for (int32 i = 0; i < poly->m_vertexCount; ++i)
{
b2Vec2 v = poly->m_position + b2Mul(poly->m_R, poly->m_coreVertices[i]);
glVertex2f(v.x, v.y);
}
glEnd();
}
}
break;
}
}

<cough>SVN</cough> 😉
Great! Committed to SVN.
My pleasure Erin 🙂

Original thread: https://box2d.org/forum/viewtopic.php?t=157