Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Rendering correctly according to time

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2005
    Location
    Norway
    Posts
    3

    Rendering correctly according to time

    OK, here is the case:

    I am currently using the OpenInventor libraries for C++, and i want to draw a scene where something happens, e.g. a person walking.

    I know that it takes 1 second for a person to take a step forward, because i have coordinate files that tell me the exact position of the limbs at which times. The coordinates are stored on a fileformat which i read into C++ and convert into translations on the person, using the Inventor libraries.

    THe problem is the following; i do not want the scene to be rendered too fast. it is important that when i render, it takes exactly one second for the person to take that step.

    I want the highest framerate possible at all times in the animation. How do i find out how many fps i can get at a particular state of the scene? Given ofc. the resolution an color depth of the scene to be rendered.

    God, this is confusing. I'm not even sure that i understood what i just wrote here Some help or hints to how i can do this would be greatly appreciated

    - hulapupp
    andz yo kan zit hea

  2. #2
    Senior Member OpenGL Pro sqrt[-1]'s Avatar
    Join Date
    Jun 2002
    Location
    Australia
    Posts
    1,007

    Re: Rendering correctly according to time

    The standard way most games and apps do this is to use the time delta from the previous frame. (some use the average of the last x frames) This is usually clamped to prevent huge time deltas. (framerate spikes can occur depending on what you are doing)

  3. #3
    Senior Member OpenGL Guru knackered's Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    3,032

    Re: Rendering correctly according to time

    An interpolation from the previous time delta usually works well.
    Simple example:
    Code :
    static DWORD nowPrevious = GetTickCount();
    static DWORD smoothDelta = 0;
     
    #ifndef LIRP
    #define LIRP(X,Y,A) ((1.0f-(A))*(float)(X)) + ((A)*(float)(Y))
    #endif
     
    DWORD now = GetTickCount();
    DWORD nowDelta = now - nowPrevious;
    nowPrevious = now;
     
    if (smoothDelta)
      smoothDelta = LIRP(smoothDelta, nowDelta, 0.2f);
    else
      smoothDelta = nowDelta;
    smoothDelta now has a smoothed value for the number of milliseconds since the last time the code was executed.
    Convert smoothDelta to seconds:-
    float secs = float(smoothDelta)/1000.0f;

    There are better timer functions than GetTickCount, such as QueryPerformanceCounter....but they involve a bit more work.
    Knackered

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •