Results 1 to 7 of 7

Thread: Time Based Movement?

  1. #1
    Senior Member Regular Contributor
    Join Date
    Mar 2002
    Location
    New Zealand
    Posts
    111

    Time Based Movement?

    hi there
    i have a simple program were you walk around using the keyboard. right now it is frame based movement-you move the same distance forward every frame but now i want to change it to time based. i know how to calculate the frames per second and i thought all i had to do was: distance_moved = any_number / fps but this is not working very well
    is this the way i should be doing it???
    thanx
    jono

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: Time Based Movement?

    You don't really need the actual FPS-value, but rather the time to process last frame. You specify your movements as units per second, and to get the actual movement per frame, multiply this movement by the time taken to process last frame.

  3. #3
    Senior Member Regular Contributor
    Join Date
    Mar 2002
    Location
    New Zealand
    Posts
    111

    Re: Time Based Movement?

    ummmmmmmmmm you've lost me
    ???

  4. #4
    Senior Member Regular Contributor
    Join Date
    Nov 2000
    Location
    Sydney, NSW, Australia
    Posts
    426

    Re: Time Based Movement?

    Say your aiming for 30 fps, this is what you do:
    distance_to_move=speed*last_fps/30.0;
    last fps is the fps your program was running it when it rendered the last frame:
    1.0/time_to_render_last_frame
    that is at least one way of doing time based movement...
    :: Sleep is a poor substitute for caffeine ::

  5. #5
    Senior Member Regular Contributor
    Join Date
    Apr 2001
    Location
    Greece
    Posts
    477

    Re: Time Based Movement?

    What does fps have to do with time base movement.If you consider anything frame related into the calculation it will be (at least in part)frame based.This is real simple:say your player runs at a velocity of V units per second.Then if dt time has passed(in seconds) the player moves by dx=V*dt(simple physics).So measure the time passed since the last time you moved the player(dt) assuming of course the player is still running and calculate dx and move the player(camera whatever) by that.Simple I hope.As you might have guessed if you want the player to accelerate then dx=0.5*a*dt*dt.

  6. #6
    Junior Member Newbie
    Join Date
    May 2002
    Posts
    4

    Re: Time Based Movement?

    i was about to ask something of the same. Here is how i do it.

    is this the way to have the input and gamelogic run the same speed no matter how fast it renders the scene?
    Code :
    <code>
    QueryPerformanceCounter(&amp;ClockStart);
    if((double)ClockStart.QuadPart < Timer){
    	/* drawing */
    	DrawGLScene();					// Draw The Scene
    	SwapBuffers(hDC);				// Swap Buffers (Double Buffering)
    }else{
    	Timer += 50000;
    	/* updating logic */
    	logic();
    	/* read keys and react */
    	input();
    }
    /* fps */
    QueryPerformanceCounter(&amp;ClockFinish);
    ElapsedTime  = ( (double) ClockFinish.QuadPart - (double) ClockStart.QuadPart ) / ClockFreq.QuadPart;
    fps = 1.0f / float(ElapsedTime);
    sprintf(buffer, "Fps %f", fps);
    SetWindowText(hWnd, buffer);
    </code>

  7. #7
    Senior Member Regular Contributor
    Join Date
    Apr 2002
    Location
    St. Louis, MO USA
    Posts
    177

    Re: Time Based Movement?

    You calculate a scalar based on time. Usually you will want this to be within the range of 0 to 1. To get the scalar you take the amount of time that has passed divided by some standard time unit. Here is my function that gets the time scalar:

    double GetTimeScalar()
    {
    static unsigned int lastticks = 0;

    int ticks = SDL_GetTicks();
    int tickssince = ticks - lastticks;

    double scalar = (double)tickssince/(double)STANDARDTIMEUNIT;

    lastticks = ticks;

    return scalar;

    }

    Then I take that scalar and multiply it by my velocity (as well as factoring it into animation interpolation).

    Another note: You also need to scale accelerations. However, you cant just scale the acceleration and then also scale the final velocity. You then need to take the square root of the time scalar and multiply both the acceleration and velocity by it.

Similar Threads

  1. Replies: 3
    Last Post: 04-19-2017, 05:47 AM
  2. Time based movement problem
    By Balta66 in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 03-29-2015, 04:04 PM
  3. 3D Model Rotation abt Screen Coords based on mouse movement
    By dan81 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 10-11-2005, 06:43 AM
  4. FPS or Time based??
    By LostInTheWoods in forum OpenGL: Advanced Coding
    Replies: 21
    Last Post: 09-18-2002, 11:42 PM
  5. Skeletal or model based character movement
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-06-2000, 09:17 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