Results 1 to 7 of 7

Thread: Effective Time-Keeper

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2002
    Posts
    19

    Effective Time-Keeper

    Hi dudes,
    I am trying to create a simulation program, in that i need an effective time keeping using the glutTimerFunc for a 30fps.

    can i call this timer function from my RenderScene function?

    if possible try to explain me how it works? i mean for 30fps it take 33millisec to wait n return to the timerfunction to execute.

    the objective of my program is to create a driving simulation with rain effect. here droplet is fed into the windowpane and it begin to flow down. i wrote the code for everything but the timer not function properly.

    if any clever head like 2 gimme some idea?

    thanx
    regards

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Nov 2002
    Location
    Latvia
    Posts
    626

    Re: Effective Time-Keeper

    You should get time in miliseconds and compare (time==n*(1/33))?proceed:sleep; But I'm working with MSVC++ 6.0 and I havn't found way how to get time in miliseconds & get sleep to work, it seems that computer simply hangs If you'll find out about those functions, please let me know.

  3. #3
    Junior Member Newbie
    Join Date
    Sep 2002
    Posts
    19

    Re: Effective Time-Keeper

    thanx dude... will let u know, if it works fine.

  4. #4
    Junior Member Newbie
    Join Date
    Sep 2002
    Posts
    19

    Re: Effective Time-Keeper

    If guys ready to gimme suggestion regarding the timer function, pls do it so...

    thanx.

  5. #5
    Senior Member Frequent Contributor
    Join Date
    Nov 2002
    Location
    Latvia
    Posts
    626

    Re: Effective Time-Keeper

    I think that I've found solution -> www.gametutorials.com There was somthing about time based movement, unfortunately it uses additional lib.
    Is there realy no way to record milisecond in MSVC. like time.ti_hund in Borland Builder (HATE THAT THNG)

  6. #6
    Senior Member Frequent Contributor marcus256's Avatar
    Join Date
    Aug 2001
    Location
    Sweden
    Posts
    764

    Re: Effective Time-Keeper

    GLFW - sub microsecond resolution. Check the source for how it's done (lib/win32/time.c).

    Almost all example programs that are included use time-based movement, and some (which use differential equations to propagate movement) also have special handling for low frame rates (which can lead to unstable simulations).

    It's quite simple, basically:

    Code :
    #define MAX_DELTA_T 1.0e-3   // Maximum propagation = 1 ms
     
      double t, t_old, dt_total, dt;
     
      t = glfwGetTime();
      dt_total = t - t_old;
      t_old = t;
      while( dt_total > 0.0 )
      {
        dt = dt_total > MAX_DELTA_T ? MAX_DELTA_T : dt_total;
        dt_total -= dt;
        UpdateState( dt );
      }
    ...where UpdateState is your physics propagation, collision detection etc. (NO rendering!)

    In this example, we will propagate the simulation exactly the amount of time that has passed since we last updated the state (=realtime). If the elapsed time between two rendered frames is too large (limit here is 1 ms), then we iterate in 1 ms steps until we have completed dt_total seconds. That way we avoid an unstable simulation when the system can not maintain a high enough rendering speed, like some dude trying to run the simulation in 1600x1200 fullscreen with software OpenGL rendering (=zero point nought FPS).

    Note that glfwGetTime() returns the time in seconds as a double precision floating point value. The timer resolution is usually better than 1 us. Bonus: it's portable (!)


    [This message has been edited by marcus256 (edited 12-12-2002).]

  7. #7
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: Effective Time-Keeper

    If you just want Win32 functions to get milliseconds, you can look at timeGetTime, or the more accurate functions QueryPerformanceCounter and QueryPerformanceFrequency.

    For a more portable method, you can use ftime(), which uses a timeb struct that contains seconds and milliseconds. I don't think that the accuracy of this method is that great, though.
    Deiussum
    Software Engineer and OpenGL enthusiast

Similar Threads

  1. Is there effective way of storing distance data?
    By imported_epsxk82 in forum OpenGL: Advanced Coding
    Replies: 6
    Last Post: 06-13-2011, 07:10 PM
  2. Effective multitexturing
    By NekoChan in forum OpenGL: General
    Replies: 3
    Last Post: 07-09-2008, 03:46 PM
  3. Similation Time-Keeper -- URGENTLY NEED HELP!!!
    By ajmrm in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 12-03-2002, 03:30 AM
  4. Effective Time-Keeper
    By ajmrm in forum OpenGL: General
    Replies: 3
    Last Post: 12-01-2002, 02:25 AM
  5. alpha value not effective
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-13-2002, 10:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean