在特定时间淡入和淡出对象

Fade in and fade out object on a specific time

int state = 1;
bool turbines_visible = true;

// move the hot air balloon up
// make the square go up
void update(int value) {
    // 1 : move up
    if (state == 1) {
        squareY += 1.0f;
        if (squareY > 650.0) {
            state = 2;
            squareX = -400.0f;
            squareY = 200.0f;
        }
    }
    // 2 : move right
    else if (state == 2) {
        squareX += 1.0f;
        if (squareX > 500.0) {
            state = 3;
            squareX = 0.0f;
            squareY = 600.0f;
        }
    }
    // 3 : move down
    else if (state == 3) {
        squareY -= 1.0f;
        if (squareY < 0.0) {
            state = 0;
        }
    }
    glutTimerFunc(25, update, 0);
    turbines_visible = !turbines_visible;
}

void display() {
    glClear(GL_COLOR_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    switch (state) {
    case 0:
        drawBackground1();
        break;
    case 1:
        drawBackground1();
        break;
    case 2:
        drawBackground2();
        break;
    case 3:
        drawBackground1();
        break;
    }
    glPushMatrix();
    glTranslatef(squareX, squareY, squareZ);
    // display spray
    drawSpray();
    // display hot air balloon
    drawAirBalloon();
    glPopMatrix();  
    if (turbines_visible) {
        // display first (left) wind turbine
        drawLeftTurbine();
        // display first (right) wind turbine
        drawRightTurbine();
    }
    // display rain
    drawRain();
    calcFPS();
    counter++;
    glFlush();
    glutSwapBuffers();
    glutPostRedisplay();
}

热气球升空很好,但风力涡轮机的淡入淡出速度非常快,这是我不想要的。我希望它在第一个场景中可见,在第二个场景中不可见,在第三个场景中再次可见。我知道问题出在 glutTimerFunc 代码上,因为它使用了 25 毫秒,但我的热气球需要它。如果有人能帮我解决这个问题,我将不胜感激。

Click here to see the full code

场景 1

Click here to see GIF

场景 2

Click here to see GIF

场景 3

Click here to see GIF

I want it to be visible in the first scene, invisible in the second scene, and visible again in the third scene.

turbines_visible 的条件必须是

turbines_visible = !turbines_visible;
turbines_visible = state != 2;