display lists & animation

Hi

I’m just beginning with programming OpenGL. I try to make small animation of stuck or LIFO but I don’t know how to move the cubes. I have made a cube with display list. First cube is folling and stopping on the bottom of the screen but I don’t know how to make 4 other cubes also to fall and stop on this first one.

My english isn’t well so maybe You better understand it from the code:

  
y=6.0f; //position from which cube is folling
yp=0.01f; //speed of falling
nrk=1;//should be a number of cube

GLvoid glRysujS()
{
  glLoadIdentity();
  glTranslatef(0.0f,-2.0f + (nrk*0.5),-1.0f + z);
  glRotatef(100.0f,1.0f,0.0f,0.0f);
  glRotatef(20.0f,0.0f,0.0f,1.0f);

  glCallList(klocek);
}
GLvoid glRysujStos()
{    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glLoadIdentity();

  glTranslatef(0.0f,0.0f,z);

  auxInitDisplayMode(AUX_DOUBLE | AUX_RGBA);
    for(loop=1;loop<6;loop++)
    {
      glTranslatef(0.0f,y,-1.0f+z);
      if(y>-2.0f + (nrk*0.5))
      {
        glPushMatrix();
        glLoadIdentity();
        y-=yp;

        glTranslatef(0.0f,y,-1.0f+z);
        glRotatef(100.0f,1.0f,0.0f,0.0f);
        glRotatef(20.0f,0.0f,0.0f,1.0f);
        glCallList(klocek);
        glPopMatrix();
        glFlush();
        auxSwapBuffers();
      }
      else
      {
        glRysujS();
      }
    }
    Sleep(1);
}

int DrawGLScene(GLvoid)
{
....
      glRysujStos();
}

Please help!!
Thanks! :slight_smile:

I am not sure I get the problem here, but you only have one Y value, if you let each cube has it’s own Y value it will be much easier to move them around.

Then it shouldn’t be to complicated to keep track of where each cube is so you can detect if one land on another.

Mikael

You got the problem! Thanks!! I didn’t think about it. I was wondering how to do this in a loop but I didn’t think about different solution. With one Y every time when I was trying to draw next cube, the screen was moving or there was nothing on!

Thanks a lot!!

Mary