PDA

View Full Version : Elapsed Time Help



whileAwesome
11-06-2010, 04:50 AM
Sorry, I am new here and I tried the search function...

I actually want this ball to go down 1 meter for every second.
I know I should use glutTimerFunc, but I really google-ed
for any reference and I couldn't find any that could help me. and the falling speed should double at every second.

Any example or reference is greatly appreciated..

Ryuzaki
11-06-2010, 12:12 PM
You can use glutGet(GLUT_ELAPSED_TIME)
It returns the number of milliseconds since glutInit was called.

bcthund
11-06-2010, 03:16 PM
In SDL you can use SDL_GetTicks() as another option. Same thing as glut, it returns the milliseconds since SDL was initialized.

I created a very simple class to track up to 100 timers with SDL which I use for debugging execution speeds for code blocks:


class Timer
{
private:
//The clock time when the timer started
float startTicks[99];

public:
//Clock time when the timer was stopped
float splitTicks[99];

//The various clock actions
void start(int type);
void stop(int type);
};

void Timer::start(int type) {
//Get the current clock time
startTicks[type] = SDL_GetTicks();
}

void Timer::stop(int type) {
//Set the stop time
splitTicks[type]=SDL_GetTicks() - startTicks[type];
}


I have a much more complex version that has many more features, but this is just to give an example.