我正在研究一個應用程序,在這個應用程序中,我繪製了一個循環的進度指示器,它慢慢變得「充滿」,在這裏您可以看到a couple of images。我正在使用中間模式,並且我只通過在每個幀更新時繪製頂點來繪製該圓形(請參閱下面的代碼)。當圓圈填滿白色和灰色之間的邊界線時有點閃爍,我想知道如何讓它更平滑。如何使用openGL獲得真正流暢的移動對象
這是一個具體的例子,但總的來說,我想知道如何獲得最平滑的運動,即使使用非常簡單的lineair插值?當我在iphone上瀏覽頁面時看到動作時,它非常平滑,這讓我想知道如何在我的(快速)mac上實現這一點?
感謝
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;
}
OpenGL默認爲雙緩衝 – doc 2010-08-03 16:37:11
@doc:OpenGL對單一緩衝區和雙緩衝區的瞭解不多 - 這就是窗口系統接口的工作,比如wgl或glx。這就是爲什麼人們通常會調用'glutSwapBuffers',而不是神話般的'glSwapBuffers', – 2010-08-04 02:52:50
@doc:不是,它取決於你初始化它的方式。 @Eric:+1 – Calvin1602 2010-08-04 07:15:27