glutTimerFunc()

Hi.

I’m a little confused about how glutTimerFunc() is supposed to work. Here’s what I want to do.

  1. I want to find out if the user took less than 10 milliseconds to click the left mouse button.

  2. If yes, then I will end the animation.

  3. If no, then the animation will continue.

glutTimer(aNumber, aFunc, aValue);

  1. This is what someone told me about glutTimerFunc()…glutTimerFunc will call aFunc after aNumber time has passed but not if the user clicks the left mouse button before aNumber is up. This seems a little odd to me but I took her word for it because she knows more than I do. However, that isn’t working for me. Can anyone tell me what needs to be done?

Thanks

glutTimerFunc is a count down timer, after set time has elapsed, the target routine is called.
It may not work the way you want, let’s say your rendering function takes 100 ms to draw the screen, your 10ms timer would not be called until 100 ms since glut will wait until rendering is done before calling it.

So the timer is not absolute time past when called and is not effected by a mouse click.

glutTimerFunc( 100(time in milli seconds ,My_timer_routine, 1 )

void My_timer_routine( void )
{
// Do something after X time has past

}

Originally posted by GlutNewbie:
[b]Hi.

I’m a little confused about how glutTimerFunc() is supposed to work. Here’s what I want to do.

  1. I want to find out if the user took less than 10 milliseconds to click the left mouse button.
  1. If yes, then I will end the animation.
  1. If no, then the animation will continue.

glutTimer(aNumber, aFunc, aValue);

  1. This is what someone told me about glutTimerFunc()…glutTimerFunc will call aFunc after aNumber time has passed but not if the user clicks the left mouse button before aNumber is up. This seems a little odd to me but I took her word for it because she knows more than I do. However, that isn’t working for me. Can anyone tell me what needs to be done?

Thanks[/b]

You probably want to use glutMouseFunc, but use a system timer depending on your platform, not to call a function but to determine the time difference between the start time and the time left mouse button is pressed.

Then, in your mousefunc if time diff < interval then stop animation else continue animation and reset start time to current time.