Page 1 of 1

debugDrawCircle understanding...

Posted: Thu Jan 12, 2017 4:50 pm
by abakobo
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);
}
thx

Re: debugDrawCircle understanding...

Posted: Thu Jan 12, 2017 9:16 pm
by slembcke
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.