本文介绍了OpenGl让对象“跳”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作我正在绘制的立方体似乎每隔几秒就跳一次。这是我的代码:



I am trying to make cubes that I am drawing appear to "jump" every few seconds. Here is my code:

for (int i=0; i<25; i++)
{
    if(j<rows)
    {

        //Timer used in vibration calculation when drawing cubes
        float time = (std::clock() - timer);
        //Calculate the amount of simulated vibration based on amount of distortion (intensity)
        float offset = sin(1.0f * 3.14159265359f * time) * shake;

        //Draw cubes right and left of centre point
        drawCube((x+xShift), y, (-300 +depth), 1.0f, cubeColour, offset);
        drawCube((x-xShift), y, (-300 +depth), 1.0f, cubeColour, offset);
        xShift -= gap;
    }
}





而drawCube代码是:





And the drawCube code is:

void drawCube(float x, float y, float z, float opacity, float col[], float offset)
{
    //Draw cube taking into account any offset caused by simulated vibration
    glTranslatef((-x+offset), (-y+offset), -z);
    glColor4f(col[0], col[1], col[2], opacity);
    glutWireCube(20);
    glTranslatef((x-offset), (y-offset), z);

}





我假设我需要使用一个可以提高y值的计时器N秒,所以立方体似乎跳了但不确定如何做到这一点?

基本上每N秒我想要一排立方体上升和下降的快速序列,所以它看起来像是反弹。所以我想我希望它们在y轴上升到10.0f左右然后回落到原来的位置。我希望每N秒触发一次此动作。

谢谢



I''m assuming that I need to use a timer that raises the y value every N seconds so the cube appears to jump but am unsure how to do this?
Basically every N seconds I want the row of cubes to rise and fall in a quick sequence, so it looks like they bounce. So i guess I want them to rise 10.0f or so on the y-axis then fall back down to their original position. I want this action to be triggered every N seconds.
Thanks

推荐答案


这篇关于OpenGl让对象“跳”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 00:11