GLUT animation problem.

Hi. I'm having a problem making an animation of the cylider drawn with quadrics.
It draws it fine but it will not move. I previously did some animation using glutSphere and glutCube objects and there was no problem. What am I doing wrong here? This is my function in which I draw the cylinder(with top and bottom discs closing it). I'll appreciate any hints.

void drawCylinder{
glPushMatrix();//1

glRotatef(timeElapsed, 0, 1, 0);
glTranslatef(0,3,0);

glPushMatrix(); //2
glColor3f(1,0,0);
glTranslatef(0,1,0);
glRotatef(90,1,0,0);
gluCylinder(quadratic,0.1f,0.1f,1.0f,32,32);
glPopMatrix(); //2

glPushMatrix(); //3
glTranslatef(0,1,0);
glRotatef(90,1,0,0);
gluDisk(quadratic,0.0f,0.1f,32,32);
glPopMatrix(); //3


glPushMatrix(); //4
glTranslatef(0,0,0);
glRotatef(90,1,0,0);
gluDisk(quadratic,0.0f,0.1f,32,32);
glPopMatrix(); //4

glPopMatrix(); //1
}

Last edited on
Without getting to deep into code (btw, use the code tags please) - you have 4 matrixes pushes and 3 pops (one missing after gluDisk). That might be your problem (and you would get a stack overflow error if you'd use glGetError and gluErrorString - error handling is a good idea in general).
Unfortunately, it's not the problem. I just deleted that line by mistake while copying the code to the post.
There might be several causes for that behavior. But one thing: if you substitute gluCylinder call with gluSphere - the animation works fine?
No it didn't and I just worked it out. I tried to copy and paste this code to my program where I was animating the cubes and spheres and it did work there. So I figured out what was the difference, but I it makes no sense to me.

This is how I count time elapsed:
const double t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
const double s = t*60.0;
And I have it declared globally. But in this case, I also copied that 2 lines into my drawCylinder() function and it made it work.

So basically, I have the same thing declared twice in my code (once globally and once inside a function). And I can not remove the one declared globally as I need it in other functions, that have no problems using it...

Thanks for your posts btw KRAKatau :)
Last edited on
Topic archived. No new replies allowed.