PDA

View Full Version : How to calculate time



iris_raj
04-27-2005, 12:39 AM
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

jide
04-27-2005, 01:03 AM
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 (&amp;tv, null);
system_clock =tv.tv_sec;
system_clock+=tv.tv_usec*clock_frequency;
#else
struct _timeb tm;
_ftime (&amp;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.

zukko
04-27-2005, 07:06 PM
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

zero_t9
04-27-2005, 09:07 PM
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