Skip to content

Commit

Permalink
Issue 406. Improved chain shape debug draw.
Browse files Browse the repository at this point in the history
  • Loading branch information
erincatto committed May 13, 2016
1 parent 76fe384 commit 2cb4e26
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 17 deletions.
3 changes: 3 additions & 0 deletions Box2D/Box2D/Common/b2Draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class b2Draw
/// @param xf a transform.
virtual void DrawTransform(const b2Transform& xf) = 0;

/// Draw a point.
virtual void DrawPoint(const b2Vec2& p, float32 size, const b2Color& color) = 0;

protected:
uint32 m_drawFlags;
};
Expand Down
20 changes: 19 additions & 1 deletion Box2D/Box2D/Dynamics/b2World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1059,14 +1059,32 @@ void b2World::DrawShape(b2Fixture* fixture, const b2Transform& xf, const b2Color
int32 count = chain->m_count;
const b2Vec2* vertices = chain->m_vertices;

b2Color ghostColor(0.75f * color.r, 0.75f * color.g, 0.75f * color.b, color.a);

b2Vec2 v1 = b2Mul(xf, vertices[0]);
g_debugDraw->DrawPoint(v1, 4.0f, color);

if (chain->m_hasPrevVertex)
{
b2Vec2 vp = b2Mul(xf, chain->m_prevVertex);
g_debugDraw->DrawSegment(vp, v1, ghostColor);
g_debugDraw->DrawCircle(vp, 0.1f, ghostColor);
}

for (int32 i = 1; i < count; ++i)
{
b2Vec2 v2 = b2Mul(xf, vertices[i]);
g_debugDraw->DrawSegment(v1, v2, color);
g_debugDraw->DrawCircle(v1, 0.05f, color);
g_debugDraw->DrawPoint(v2, 4.0f, color);
v1 = v2;
}

if (chain->m_hasNextVertex)
{
b2Vec2 vn = b2Mul(xf, chain->m_nextVertex);
g_debugDraw->DrawSegment(v1, vn, ghostColor);
g_debugDraw->DrawCircle(vn, 0.1f, ghostColor);
}
}
break;

Expand Down
30 changes: 15 additions & 15 deletions Box2D/Testbed/Framework/DebugDraw.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#ifndef DEBUGDRAW_H
#define DEBUGDRAW_H

#include <Box2D/Box2D.h>
#include "Box2D/Box2D.h"

struct b2AABB;
struct GLRenderPoints;
Expand Down Expand Up @@ -60,32 +60,32 @@ class DebugDraw : public b2Draw
void Create();
void Destroy();

void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color);
void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) override;

void DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color);
void DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) override;

void DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color);
void DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color) override;

void DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color);
void DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color) override;

void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color);
void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color) override;

void DrawTransform(const b2Transform& xf);
void DrawTransform(const b2Transform& xf) override;

void DrawPoint(const b2Vec2& p, float32 size, const b2Color& color);
void DrawPoint(const b2Vec2& p, float32 size, const b2Color& color) override;

void DrawString(int x, int y, const char* string, ...);
void DrawString(int x, int y, const char* string, ...);

void DrawString(const b2Vec2& p, const char* string, ...);
void DrawString(const b2Vec2& p, const char* string, ...);

void DrawAABB(b2AABB* aabb, const b2Color& color);
void DrawAABB(b2AABB* aabb, const b2Color& color);

void Flush();

void Flush();

private:
GLRenderPoints* m_points;
GLRenderLines* m_lines;
GLRenderTriangles* m_triangles;
GLRenderLines* m_lines;
GLRenderTriangles* m_triangles;
};

extern DebugDraw g_debugDraw;
Expand Down
2 changes: 1 addition & 1 deletion Box2D/Testbed/Tests/TestEntries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@

TestEntry g_testEntries[] =
{
{"Character Collision", CharacterCollision::Create},
{"Tiles", Tiles::Create},
{"Heavy on Light", HeavyOnLight::Create},
{"Heavy on Light Two", HeavyOnLightTwo::Create},
Expand All @@ -95,7 +96,6 @@ TestEntry g_testEntries[] =
{"Gears", Gears::Create},
{"Varying Restitution", VaryingRestitution::Create},
{"Cantilever", Cantilever::Create},
{"Character Collision", CharacterCollision::Create},
{"Edge Test", EdgeTest::Create},
{"Body Types", BodyTypes::Create},
{"Shape Editing", ShapeEditing::Create},
Expand Down

0 comments on commit 2cb4e26

Please sign in to comment.