I can't get independent from fps

Morgoth

06-09-2006 17:37:53

I'm working on a space-shooter using ogreode, lastly i tried to run it in release mode and realised that it's working much faster (i mean moving and accelerations is faster, not only fps :) )
so i tried almost every stepper, from simplest quickstepper to FixedStepInterpolatedQuickStepper and nothing changed, all the time release build moves few times faster than debug :/

i've read http://www.gaffer.org/articles/Timestep.html from OgreOdeStepper.h include, it says that using this technique "... you ensure that there will not be any visual stuttering when your display and physics framerates are out of sync" but smth here isn't working like it should:/

what should i also do to make physics independent from frames per sec.?

tuan kuranes

06-09-2006 17:41:54

Are you sure you do not have any fps dependant code in your code ?
If you add Force in a framestarted/frameended for instance ?

Morgoth

06-09-2006 23:16:26

I add forces in framestart/end but are they zeroed after each step or framestart/end too?
I thought that it's done betwen frames, so when I i.e. press 'forward' button i add force at framestart and it's zeroed at frameend - am I wrong?

and if so, how should I add forces and torques to my spaceship?

kongkana

07-09-2006 04:48:15

you should add forces in preStep() function.

tuan kuranes

07-09-2006 07:43:07

If code is in framestarted test with :
_addForceUpdate += evt.timeSinceLastFrame;
if (_addForceUpdate > _myUpdateRate)
{
addForces()
}

with

_myUpdateRate = 1.0/60;

if min fps accepted is 60

Morgoth

07-09-2006 11:20:16

thanks for responses but

@tuan: AFAIK your approach will work only if fps will be higher than physics rate, in oposite case forces would be added per frame (or maybe few times per frame with some modyfications) and i'd like this game to be stable in all cases

BTW wouldn't be helpful if ode allowed us to decide whether set forces/torques to zero per step or per frame? in practice you almost always check inputs in frame start/end and run few physics steps per frame, so you need to set _the_same_ forces per step and then zero them after each step(internally by ode) - i mean kongkana approach here

it would be nice to tell ode once about forces attached to each body in this frame and then just run few steps

am i wrong?

luis

08-09-2006 11:48:03

@tuan: AFAIK your approach will work only if fps will be higher than physics rate, in oposite case forces would be added per frame (or maybe few times per frame with some modyfications) and i'd like this game to be stable in all cases

You could use a lower fixed frame rate like 15 instead of 60 and change force magnitude accordingly, you wont notice any difference i think.
Usually none will run a game or any realtime app at 15fps or bellow ;)

BTW wouldn't be helpful if ode allowed us to decide whether set forces/torques to zero per step or per frame?

You allready have the choice to do that... from what I understand ODE sets forces to zero after each physics step, so you have the choice to make the step in frameended, framestarted or use StepListener::preStep and call ForwardFixedQuickStepper::step manually etc etc..

If you want to apply a force for an arbitrary period of time this is something your app should take care of.
For example, in a game i'm doing the AI has a very low update rate (5Hz), on each update AI changes forces (or input like throttle & steering in prefab::Vehicle) and in the rest of the frames AI just sends last state.

In that way all bodies have a force each frame (and force magnitude could be zero or any other value) but the AI response time is limited to 5Hz.