Skip to content

Instantly share code, notes, and snippets.

@satoruhiga
Created August 10, 2011 16:10
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save satoruhiga/1137294 to your computer and use it in GitHub Desktop.
PolygonArc
class PolygonArc
{
public:
PolygonArc()
{
curveResolution = 4;
}
void draw()
{
glPushMatrix();
angle = ofClamp(angle, -360, 360);
const float res = curveResolution;
const float d = res / angle * (fabs(angle) / 360.);
const float step = fabs(angle / res);
float phase = 0;
glBegin(GL_TRIANGLE_STRIP);
for (int i = 0; i <= step; i++)
{
float xx = cos(phase * TWO_PI);
float yy = sin(phase * TWO_PI);
glVertex3f(xx * inner, yy * inner, 0);
glVertex3f(xx * outer, yy * outer, 0);
phase += d;
}
glEnd();
glPopMatrix();
}
float getInner() { return inner; }
void setInner(float v)
{
inner = v;
}
float getOuter() { return outer; }
void setOuter(float v)
{
outer = v;
}
float getAngle() { return angle; }
void setAngle(float v)
{
angle = v;
}
private:
float inner, outer;
float angle;
float curveResolution;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment