OpenGL: glutIdleFunc and animation

This is a discussion on OpenGL: glutIdleFunc and animation within the Game Programming forums, part of the General Programming Boards category; Im trying to impliment some basic equation based animation. Using glutGet for the time and idle to keep it animating ...

  1. #1
    Registered User gazsux's Avatar
    Join Date
    Mar 2002
    Posts
    72

    OpenGL: glutIdleFunc and animation

    Im trying to impliment some basic equation based animation. Using glutGet for the time and idle to keep it animating at a steady pace. Ive been told to not put any drawing type code in the idle function itself, also opengl should realise when the function is idle and call its own idle function. But im not sure if i have this right. Only when i impliment it, the animation doesnt occur. Here's some code, do i need to call the idle func from the display one? (surely that will just be based on the computer speed if i did that)

    if you have any ideas of where im going wrong, please help me

    Code:
    void idle(void)
    {
    float fTime, fSimTime;
    float static fLastIdleTime=0;
    
    fTime=glutGet(GLUT_ELAPSED_TIME)/1000;
    
    fSimTime=fTime-fLastIdleTime;
    
    animation(fSimTime);
    
    fLastIdleTime=fTime;
    
    glutPostRedisplay();
    }
    
    void visible(int iVis)
    {
    if(iVis==GLUT_VISIBLE)
    	glutIdleFunc(idle);
    else
    	glutIdleFunc(NULL);
    
    return;
    }
    
    void animation(float fSimTime)
    {
    float fAngle;
    
    glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
    glEnable(GL_COLOR_MATERIAL);
    
    fAngle=fSimTime*iSpeed; 
    
    glTranslatef( 26.00f, 2.00f, 18.95f);
    glRotatef(fAngle, 0, 0, 1);
    glColor3ub(100, 100, 100);
    glCallList(cog);
    glRotatef(-fAngle, 0, 0, 1);
    glTranslatef(-26.00f,-2.00f,-18.95f);
    
    glTranslatef( 23.00f, 2.00f, 18.95f);
    glRotatef(fAngle+25, 0, 0, 1);
    glColor3ub(100, 100, 100);
    glCallList(cog);
    glRotatef(-fAngle-25, 0, 0, 1);
    glTranslatef(-23.00f,-2.00f,-18.95f);
    
    glDisable(GL_COLOR_MATERIAL);
    
    }

  2. #2
    Registered User gazsux's Avatar
    Join Date
    Mar 2002
    Posts
    72
    its ok, i got it sorted now.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21