How to calculate time

Dear all,

I have to calculate time elapsed from the begining of the simulation.

Is any data type similar to (SbTime in OPENINVENTOR) in OPENGL.

Please write to me.

iris_raj
Graphics Research Group

Don’t know about openinventor (isn’t there any other best forum for that program ?).

But you can use OS dependant code for that. Here is a function I had inside a class I was using for several years in order to take time:

#include <stdlib.h>
#ifdef WIN32
#include <sys/timeb.h>
#else
#include <sys/time.h>
#endif

#ifndef WIN32
const double clock_frequency=0.000001;
#else
const double clock_frequency=0.001;
#endif

double system_clock;

const double Chrono()
{
#ifndef WIN32
   struct timeval tv;
   gettimeofday (&tv, null);
   system_clock =tv.tv_sec;
   system_clock+=tv.tv_usec*clock_frequency;
#else
   struct _timeb tm;
   _ftime (&tm);
   system_clock= tm.time;
   system_clock+=tm.millitm*clock_frequency;
#endif
   
   return system_clock;
}

This is somewhat suffisant even if the w32 version is less precise. But almost all ways to do time is enough with 1/1000 sec. For non W32, this code should work on almost all unix (Linux).

Hope that helps.

Hi, if you are using windows you could use GetTickCount(), one at the start and one at the end then substract the first one from the last one and you will get the amount of time that has passed

also GetSystemTime in windows.

Originally posted by zukko:
Hi, if you are using windows you could use GetTickCount(), one at the start and one at the end then substract the first one from the last one and you will get the amount of time that has passed