[ODE] Computing dt

Morgan McGuire morgan3d at yahoo.com
Mon Apr 3 11:30:53 MST 2006


FYI, G3D has a high-performance time counter for computing dt on Win32, Linux,
and OS X.  It is just a wrapper around gettimeofday (see below for the core). 
The full implementation is part of a larger class at
http://cvs.sourceforge.net/viewcvs.py/g3d-cpp/cpp/source/G3Dcpp/System.cpp?rev=1.94&view=auto
but I'm happy to rip it out into some functions for use in the ODE demos if
someone wants.

-m

RealTime System::time() { 
    init();
    #ifdef G3D_WIN32
        LARGE_INTEGER now;
        QueryPerformanceCounter(&now);

        return (RealTime)(now.QuadPart - _start.QuadPart) /
                _counterFrequency.QuadPart;
    #else
        // Linux resolution defaults to 100Hz.
        // There is no need to do a separate RDTSC call as gettimeofday
        // actually uses RDTSC when on systems that support it, otherwise
        // it uses the system clock.
        struct timeval now;
        gettimeofday(&now, NULL);

        return (now.tv_sec  - _start.tv_sec) +
               (now.tv_usec - _start.tv_usec) / 1e6;
    #endif
}




More information about the ODE mailing list