【问题标题】:Fade in and fade out object on a specific time在特定时间淡入和淡出对象
【发布时间】:2018-12-27 12:38:32
【问题描述】:
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

【问题讨论】:

  • turbines_visible = !turbines_visible; 应该是换场景时的位置,而不是update

标签: c++ opengl glut


【解决方案1】:

我希望它在第一个场景中可见,在第二个场景中不可见,在第三个场景中再次可见。

turbines_visible 的条件必须是

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多