PDA

View Full Version : problem with glutTimerFunc()



couplezz
03-14-2013, 11:34 PM
try to rotate object with this code.


main()
{
.
.
.
NextRotate(left);
.
.
.
}


NextRoate(move where)
{
.
.
.
.
.

glutTimerFunc(33,TimerFunctionroateEach, where);
}

TimerFunctionroateEach(where)
{
..
.
left? angle goes down (angle-=1)
right? angle goes up (angle+=1)


//slowly move until angle have been moved 90'

if(angle%90!=0)
TimerFunctionroateEach(angle);
.
.
}

RenderScen()
{
..
.
.
glRotatef(angle,1.0,0.0,0.0);
.
.
.
}






above code works well.
it shows how object rotate slowly, not just show how it become.

BUT when i try to rotate more than 2, like below code.






main()
{
.
.
.
NextRotate(left);
NextRotate(left);
NextRotate(right);
.
.
.
}

// other code are same.


it's not work like function to function.

i expected to rotate left first, AND THEN left again, AND THEN right rotate.

BUT it works like all NextRoate() functions works at once, so i just can see part of last rotate (right).

want to rotate one by one. plz help me...

carsten neumann
03-15-2013, 08:35 AM
Please use [ code], [ /code] tags around source snippets (no space after '[').

Images are only rendered after you've entered the glut main loop and even then only in response to certain OS events (e.g. window resize, etc.) or when requested with glutPostRedisplay(). Instead of a timer function you should probably use an idle function (i.e. one that is registered with glutIdleFunc). That function increments/decrements the angle, reverses direction if you hit +/- 90 degrees and ends with a call to glutPostRedisplay().