Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: DirectInput Limiting Movement

  1. #11

    DirectInput Limiting Movement

    Glad i could help
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  2. #12

    DirectInput Limiting Movement

    can you show your code about frequency?

    using this without interval dont will use 100% of CPU?
    Knowledge is power.

  3. #13

    Re: DirectInput Limiting Movement

    bringing back a dead post to save creating a new thread. again similar problem only i was working on a new 3d engine.

    i've been working on it for a long time, but only noticed this problem due to the fps changing.

    vars:

    [code=delphi]
    iMoveSpeed: Single = 1;
    iFrameRate: Cardinal; //obviously the fps
    [/code]

    [code=delphi]
    if (buffer[DIK_A] and $80) <> 0 then begin
    Cam.x := Cam.x + cos(Cam.RotX + PI/2) * (iMoveSpeed / iFrameRate);
    Cam.z := Cam.z + sin(Cam.RotX + PI/2) * (iMoveSpeed / iFrameRate);
    end else if (buffer[DIK_D] and $80) <> 0 then begin
    Cam.x := Cam.x + cos(Cam.RotX - PI/2) * (iMoveSpeed / iFrameRate);
    Cam.z := Cam.z + sin(Cam.RotX - PI/2) * (iMoveSpeed / iFrameRate);
    end;

    if (buffer[DIK_W] and $80) <> 0 then begin
    Cam.x := Cam.x + cos(Cam.RotX) * (iMoveSpeed / iFrameRate);
    Cam.y := Cam.y - cos(Cam.RotY + PI/2) * (iMoveSpeed / iFrameRate);
    Cam.z := Cam.z + sin(Cam.RotX) * (iMoveSpeed / iFrameRate);
    end else if (buffer[DIK_S] and $80) <> 0 then begin
    Cam.x := Cam.x - cos(Cam.RotX) * (iMoveSpeed / iFrameRate);
    Cam.y := Cam.y + cos(Cam.RotY + PI/2) * (iMoveSpeed / iFrameRate);
    Cam.z := Cam.z - sin(Cam.RotX) * (iMoveSpeed / iFrameRate);
    end;
    [/code]

    this works for moving around, however depending on framerate, it goes faster or slower.. i cant figure out how to keep it steady, note i use queryperformance for my counter/fps calculation.

    thanks in advance.

    ;MM;

  4. #14

    Re: DirectInput Limiting Movement

    My guess is that you only update iFrameRate every second or so I would do it like this:

    [pascal]
    iMoveSpeed: single = 1; //Units/second
    fDeltaTime: single; //fraction of second

    LastTick, Tick: Cardinal; //Just use GetTickCount. It's precise enough and you don't get problems with changing frequencies
    [/pascal]

    Every frame before calculating positions do:
    [pascal]
    Tick := GetTickCount;
    fDeltaTime := (Tick-LastTick)/1000;
    LastTick := Tick;
    [/pascal]

    [pascal]
    if (buffer[DIK_A] and $80) <> 0 then begin
    Cam.x := Cam.x + cos(Cam.RotX + PI/2) * (iMoveSpeed * fDeltaTime);
    Cam.z := Cam.z + sin(Cam.RotX + PI/2) * (iMoveSpeed * fDeltaTime);
    end else if (buffer[DIK_D] and $80) <> 0 then begin
    Cam.x := Cam.x + cos(Cam.RotX - PI/2) * (iMoveSpeed * fDeltaTime);
    Cam.z := Cam.z + sin(Cam.RotX - PI/2) * (iMoveSpeed * fDeltaTime);
    end;

    if (buffer[DIK_W] and $80) <> 0 then begin
    Cam.x := Cam.x + cos(Cam.RotX) * (iMoveSpeed * fDeltaTime);
    Cam.y := Cam.y - cos(Cam.RotY + PI/2) * (iMoveSpeed * fDeltaTime);
    Cam.z := Cam.z + sin(Cam.RotX) * (iMoveSpeed * fDeltaTime);
    end else if (buffer[DIK_S] and $80) <> 0 then begin
    Cam.x := Cam.x - cos(Cam.RotX) * (iMoveSpeed * fDeltaTime);
    Cam.y := Cam.y + cos(Cam.RotY + PI/2) * (iMoveSpeed * fDeltaTime);
    Cam.z := Cam.z - sin(Cam.RotX) * (iMoveSpeed * fDeltaTime);
    end;
    [/pascal]
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  5. #15

    Re: DirectInput Limiting Movement

    yes you were right my problem was my performance counter. thanks.

    i will keep gettickcount in mind, i however am still using query counter, the problem was how i was doing it, adding the delta time was the solution

    F_DeltaTime := (F_ThisTime - F_LastTime) / 1000;


    thanks again jsoftware

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

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