1 registered members (tomaslolo),
1,542
guests, and 12
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
framerate independent???
#416746
02/03/13 23:57
02/03/13 23:57
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
This code is framerate dependent.. However, when I add "time_step" in "accelerate", it's still framerate dependent??
function blah(){
camTiltResult = accelerate(camTiltSpeed, -dist.x * 4, 0.8);
camRollResult = accelerate(camRollSpeed, -dist.y * 4, 0.8);
camera.tilt = camTiltResult;
camera.roll = camRollResult;
}
WTF is going on? What should I do, to fix this problem? Adding time_step, makes it even worst..
|
|
|
Re: framerate independent???
[Re: MasterQ32]
#416750
02/04/13 08:31
02/04/13 08:31
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
So, basicly, I need to change:
camRollResult = accelerate(camRollSpeed, -dist.y * 4, 0.8);
camera.roll = camRollResult;
with this:
camRollResult = camRollResult + (-dist.y * 1.5 * time_step) - camRollResult * 0.2;
camRollSpeed = camRollSpeed + camRollResult * time_step;
camera.roll = camRollResult;
Right? Anyway, if I change fps_max from 60 to 20 or 500, the results are different.. So it's still framerate dependent. Edit: I tried to add it to camera with "time_step" as well... but still doesn't work. I simply can't get it! Why the hell I need to use "time_step" already two times?
Last edited by 3run; 02/04/13 08:40. Reason: 12345
|
|
|
Re: framerate independent???
[Re: 3run]
#416752
02/04/13 09:04
02/04/13 09:04
|
Joined: Oct 2011
Posts: 1,082 Germany
Ch40zzC0d3r
Serious User
|
Serious User
Joined: Oct 2011
Posts: 1,082
Germany
|
Simply use some math:
mFPS = (16/time_frame);
speedGradient = 60 / mFPS;
tiledGradient = mFPS / 60;
And multiply your time_step with this. It depends on how you want the code, so choose from my examples wisely, one will make it even more faster, one will slow it down so its always same speed Use the 60 at all if the speed on framerate 60 is the one you wish to have!
Last edited by Ch40zzC0d3r; 02/04/13 09:04.
|
|
|
Re: framerate independent???
[Re: 3run]
#416773
02/04/13 12:48
02/04/13 12:48
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
Well you subtract a value each frame without using time_step at the end of this line: camRollResult = camRollResult + (-dist.y * 1.5 * time_step) - camRollResult * 0.2;
If you smoothly want to adjust angles, use something as follows:
camera.tilt += ang(target_tilt - camera.tilt)*0.25*time_step; // the factor should be lower than 1 or if that is too fast use clamp: camera.tilt += clamp(ang(target_tilt - camera.tilt)*0.25,-5,5)*time_step;
Now the adjustment will (possibly) start at maximal speed, so you would have to use a second variable/ a different approach, for example as follows (untested, maybe needs some bugfixing):
i = ang(target_tilt - camera.tilt)*0.25; camera_tilt_speed = minv(camera_tilt_speed+0.25*time_step,minv(abs(i),5)); camera.tilt += clamp(i,-camera_tilt_speed,camera_tilt_speed)*time_step;
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: framerate independent???
[Re: Superku]
#416775
02/04/13 13:56
02/04/13 13:56
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
Well, this doesn't work as well.. Whats wrong? I can't still clearly understand.. Seems that using "time_step", doesn't help in some cases? camTiltResult = accelerate(camTiltSpeed, -dist.x * 2, 0.2); camRollResult = accelerate(camRollSpeed, -dist.y * 2, 0.2);
baseAngle.pan = 0; baseAngle.tilt += ang(camTiltResult - baseAngle.tilt) * 0.25 * time_step; baseAngle.roll += ang(camRollResult - baseAngle.roll) * 0.25 * time_step;
camera.pan = 0; camera.tilt = baseAngle.tilt; camera.roll = baseAngle.roll;
Adding "time_step" into the acceleration doesn't help as well.. What am I missing???
|
|
|
Re: framerate independent???
[Re: 3run]
#416776
02/04/13 14:10
02/04/13 14:10
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
Just don't use accelerate if you have such problems with it, I've never used it. i = ang(target_tilt - camera.tilt)*0.25; camera_tilt_speed = minv(camera_tilt_speed+0.25*time_step,minv(abs(i),5)); camera.tilt += clamp(i,-camera_tilt_speed,camera_tilt_speed)*time_step; Works fine, I've tested it now. The other examples from my previous post work, too, and framerate independent (at least as long as fps >= 16).
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: framerate independent???
[Re: 3run]
#416781
02/04/13 15:19
02/04/13 15:19
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
Ok I see I should have commented it a little. Have a look at the test code that I've written earlier:
var i;
var target_tilt = 0;
var target_counter = 48;
var camera_tilt_speed = 0;
[...]
target_counter = maxv(target_counter-time_step,0);
if(!target_counter)
{
target_tilt = -35-target_tilt; // switch between 0 and -35
target_counter = 64; // every 4 seconds
}
i = ang(target_tilt - camera.tilt)*0.25;
camera_tilt_speed = minv(camera_tilt_speed+0.25*time_step,minv(abs(i),5));
camera.tilt += clamp(i,-camera_tilt_speed,camera_tilt_speed)*time_step;
This code is useful when target_tilt only changes every now and then, f.i. in a cut scene or something like that. The line camera_tilt_speed = minv(camera_tilt_speed+0.25*time_step,minv(abs(i),5)); makes sure that the change in camera starts smoothly, not at full speed, in particular the minv(abs(i),5) "resets" the speed value to a low value without an if clause when the target angle is close. Depending on the actual purpose of your code (I'm not really sure what it will be used for) it may be a better choice to use one of the two other approaches, f.i. when the target angles change quickly.
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
|