Results 1 to 2 of 2

Thread: Use of TimerFunction, glPushMatrix(); , and glPopmatrix();

  1. #1
    Newbie Newbie
    Join Date
    Jan 2014
    Posts
    1

    Use of TimerFunction, glPushMatrix(); , and glPopmatrix();

    Greetings! I encounter some problems while learning openGL.
    Here is my problem:
    I use 241 points to draw a curve as track.
    Then draw a cylinder move on the track(241 points) at the same time rotate about axis which parallel to x-axis.
    rotate rate:9 degrees per step
    I want to use TimerFunction(or any other ways) to make the cylinder move but remain the track fixed, but they will rotate together.
    Could anyone tell me how to use TimerFunction, glPushMatrix(); , and glPopmatrix(); ?
    Here is my code: use visual C++ 6.0

    Code :
     
    //draw a cylinder
     
    GLUquadricObj *quadratic;
    quadratic=gluNewQuadric();
    glPushMatrix();
    glTranslatef(-2.0f,-2.0f,0.0f);
    glColor3f(1.0f,0.0f,0.0f);
    gluDisk(quadratic,0.0f,0.05f,32,32);			
    glColor3f(0.9f,0.91f,0.98f);	
    gluCylinder(quadratic,0.05f,0.05f,0.5f,32,32);    
    glTranslatef(0.0f,0.0f,0.5f);
    glColor3f(0.0f,0.0f,1.0f);
    gluDisk(quadratic,0.0f,0.05f,32,32);
    glPopMatrix();
    glutSwapBuffers();
     
    //draw the curve
    glBegin(GL_LINE_LOOP);
    glVertex2f(-2.0f,-2.0f);
    glVertex2f(-1.94109f,-2.05415f);
    glEnd();
     
    //I simply post on all 241 points to draw the curve.
     
    glFlush(); 
    }
     
     
     
    void TimerFunction(int value)
    {
        glTranslatef(241 points);
        glRotatef(9,1.0,0.0,0.0);
        glutPostRedisplay();                  
        glutTimerFunc(33,TimerFunction,1);
    }

    Thank you very much.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,658
    Quote Originally Posted by Cquest View Post
    I want to use TimerFunction(or any other ways) to make the cylinder move but remain the track fixed, but they will rotate together.
    Could anyone tell me how to use TimerFunction, glPushMatrix(); , and glPopmatrix(); ?
    Sounds like two separate questions. First, how to make the cylinder move without affecting the track. Second, if/how TimerFunction should play a role in this. As to the first question, push/pop transforms around the cylinder and draw the track outside of this push/pop. That way, the local MODELING transform applied to the cylinder won't affect the track.

    As to the second, this is a somewhat messy way to modify transforms because you're outside of your display function. Who knows what transform (if any) is active on the MODELVIEW stack at this point. A cleaner method might be to have TimerFunction bump some variable(s) indicating what the new rotate and translate should be next time the display function runs, but don't actually make the GL calls right there. Another option is to just make your display function (or a rtn it calls) smarter so that it knows how to continuously advance the transform.

Similar Threads

  1. glpushmatrix and glpopmatrix
    By jesh in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 03-18-2003, 05:42 AM
  2. glPopMatrix, glPushMatrix??
    By sar22 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-24-2002, 02:10 AM
  3. glPushMatrix and glPopMatrix?
    By newmannium in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-01-2001, 12:02 PM
  4. glPushMatrix() and glPopMatrix
    By zzapatista in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 02-19-2001, 02:45 AM
  5. glPushMatrix() & glPopMatrix()
    By glbeginner in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 01-07-2001, 10:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean