mouse speed between sampled mouse input points

Hi everyone!

I have used the glutMouseFunc() and glutMotionFunc() to track what the user has drawn with the mouse. However, for every consecutive mouse input points these functions give me (e.g x, y), i need to find the speed in between the consecutive points.

That is to say, i need to find the distance and the time between consecutive mouse input points.

Is there a way to do that?

I have heard about using performance counter and frequency and also the multimedia timer to get the time…however, i do not know how to go about doing any of these windows functions in openGL.

Thank you to anyone replying this post!

Just measure the time between the mouse clicks.

…and use a couple of

int iOldX;
int iOldY;

to store the old mouse coordinates (from the previous frame). This way you know that the mouse has moved iNewX = x - iOldX units etc between each frame.

Just measure the time between the mouse clicks?

Sorry but I am a novice… how do i measure the time between the mouse clicks? Any function for me to invoke?

Thanks again!

if you’re in linux, you can use gettimeofday(…)

in windows the function is GetTickCount(), i think.