Created
August 10, 2011 16:10
-
-
Save satoruhiga/1137294 to your computer and use it in GitHub Desktop.
PolygonArc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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