我正在試圖讓我繪製的多維數據集每隔幾秒就會「跳」出來。這裏是我的代碼:OpenGl讓對象每隔N秒「跳」
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代碼:
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秒計時器但我不確定如何做到這一點?
我不知道如何使它「跳」不是。 「跳」是什麼意思?你究竟想看到什麼? – 2013-04-22 13:41:59
基本上每隔N秒鐘我就要一排立方體以快速的順序上升和下降,所以它看起來像是在反彈。所以我想我想讓他們在Y軸上升到10.0f左右,然後回落到原來的位置。我希望每N秒觸發一次該動作。 – user1356791 2013-04-22 15:16:42