debugDrawCircle understanding...

Official forum for the Chipmunk2D Physics Library.

debugDrawCircle understanding...

Postby abakobo » Thu Jan 12, 2017 4:50 pm

In the demo there is a debugdraw circle but when I read the code I feel like it's drawing only two triangles!

Could someone tell me what i'm missing? I thought I would see some triangle fan with a number of triangles proportional to the size of the circle...
Code: Select all
void ChipmunkDebugDrawCircle(cpVect pos, cpFloat angle, cpFloat radius, cpSpaceDebugColor outlineColor, cpSpaceDebugColor fillColor)
   Triangle *triangles = PushTriangles(2);
   cpFloat r = radius + 1.0f/ChipmunkDebugDrawPointLineScale;
   Vertex a = {{(GLfloat)(pos.x - r), (GLfloat)(pos.y - r)}, {-1.0f, -1.0f}, fillColor, outlineColor};
   Vertex b = {{(GLfloat)(pos.x - r), (GLfloat)(pos.y + r)}, {-1.0f,  1.0f}, fillColor, outlineColor};
   Vertex c = {{(GLfloat)(pos.x + r), (GLfloat)(pos.y + r)}, { 1.0f,  1.0f}, fillColor, outlineColor};
   Vertex d = {{(GLfloat)(pos.x + r), (GLfloat)(pos.y - r)}, { 1.0f, -1.0f}, fillColor, outlineColor};
   Triangle t0 = {a, b, c}; triangles[0] = t0;
   Triangle t1 = {a, c, d}; triangles[1] = t1;
   ChipmunkDebugDrawSegment(pos, cpvadd(pos, cpvmult(cpvforangle(angle), radius - ChipmunkDebugDrawPointLineScale*0.5f)), outlineColor);

Posts: 2
Joined: Thu Oct 20, 2016 5:12 am

Re: debugDrawCircle understanding...

Postby slembcke » Thu Jan 12, 2017 9:16 pm

The shader I use takes the texture coordinates and draws an anti-aliased circle. The midsection of that circle is stretched to draw segments, and it's stretched into a bunch of different pieces to draw polygons.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! ->
User avatar
Site Admin
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 3 guests