私が描いている立方体を数秒ごとに「ジャンプ」するように見せようとしています。これが私のコードです:
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);
}
立方体がジャンプしているように見えるように、N 秒ごとに y 値を上げるタイマーを使用する必要があると想定していますが、これを行う方法がわかりませんか?