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)
{
float time = (std::clock() - timer);
float offset = sin(1.0f * 3.14159265359f * time) * shake;
drawCube((x+xShift), y, (-300 +depth), 1.0f, cubeColour, offset);
drawCube((x-xShift), y, (-300 +depth), 1.0f, cubeColour, offset);
xShift -= gap;
}
}
And the drawCube code is:
void drawCube(float x, float y, float z, float opacity, float col[], float offset)
{
glTranslatef((-x+offset), (-y+offset), -z);
glColor4f(col[0], col[1], col[2], opacity);
glutWireCube(20);
glTranslatef((x-offset), (y-offset), z);
}
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