Dear reader,
I'm working on an application where I draw a circular progress indicator which slowly gets "filled", here you can see a couple of images. I'm using intermediate mode and I'm only drawing this circular shape by drawing the vertices at each frame update (see code below). When the circle fills up the border line between the white and gray is a bit flickery and I'm wondering how I can make it more smooth.
This is a concrete example, but in general I'm wondering how to get the smoothest motion even when using very simple lineair interpolation? When I look at the motion when I flip between pages on my iphone it's just so extremelly smooth which makes me wonder how I would achieve this on my (fast) mac?
Thanks
Roxlu
PhotoBoothCountdown::PhotoBoothCountdown(float fMillisDuration)
:duration(fMillisDuration)
,start_time(0)
{
setActionCommand("take_picture");
}
void PhotoBoothCountdown::update() {
if(start_time != 0) {
float cur = ofGetElapsedTimeMillis();
perc = (cur-start_time)/duration;
}
}
void PhotoBoothCountdown::draw() {
float resolution = 150;
int parts_filled = resolution * perc;
int parts_unfilled = (resolution - parts_filled);
float part_angle = TWO_PI/resolution;
//printf("filled: %i/%i/%i\n", parts_filled, parts_unfilled, (parts_filled+parts_unfilled));
float radius = 300.0f;
float width = 100;
float radius_inner = radius-width;
float center_x = ofGetWidth()/2;
float center_y = ofGetHeight()/2;
float angle = 0;
glBegin(GL_TRIANGLE_STRIP);
glColor4f(0.2f, 0.2f, 0.2f,0.9f);
for(int i = 0; i <= parts_filled; ++i) {
float cosa = cos(angle);
float sina = sin(angle);
glVertex2f(center_x + cosa * radius,center_y + sina * radius);
glVertex2f(center_x + cosa * radius_inner,center_y + sina * radius_inner);
angle += part_angle;
}
glEnd();
glBegin(GL_TRIANGLE_STRIP);
glColor4f(1.0f, 1.0f, 1.0f,0.9f);
angle -= part_angle;
for(int i = 0; i <= parts_unfilled; ++i) {
float cosa = cos(angle);
float sina = sin(angle);
glVertex2f(center_x + cosa * radius,center_y + sina * radius);
glVertex2f(center_x + cosa * radius_inner,center_y + sina * radius_inner);
angle += part_angle;
}
glEnd();
if(perc >= 1) {
printf("should fire");
fireEvent();
reset();
}
}
void PhotoBoothCountdown::start() {
start_time = ofGetElapsedTimeMillis();
end_time = start_time + duration;
}
void PhotoBoothCountdown::reset() {
start_time = 0;
end_time = 0;
perc = 0;
}