timestep uses linear interpolation and still jitters

tgrodger

26-03-2008 17:04:49

Hello, I know this is a subject that has been beaten to near death, but apparently I'm missing something. This is the time step method I am using, which seems identical to the gaffer method as far as I can tell, but my coworker complains of jittering. If I increase simulationTimeStep, he complains it gets worse. It runs about 50 fps on his machine.

Maybe we're imagining it. If you want to see it for yourself, download http://downloads.tournamentgames.com/tgpinball_41.exe

const NxReal simulationTimeStep = (float)1.0 / 50.0f;
NxReal timeToSimulate = 0.0f;
NxReal deltaTime;

Ogre::Timer* s = new Timer();

while ( !mShutdownNow )
{
deltaTime = s->getMicroseconds()*1.0e-6;
s->reset();
timeToSimulate += deltaTime;

while (timeToSimulate>=simulationTimeStep)
{
mWorld->getPhysXDriver()->simulate(simulationTimeStep);
timeToSimulate -= simulationTimeStep;
}

mWorld->getPhysXDriver()->render(deltaTime);
pinballFrame(deltaTime); //game logic, nothing movement/render related
mRenderer->getRoot()->renderOneFrame();
}

betajaen

26-03-2008 17:21:23

Two questions:

- You are using Bleeding, aren't you?
- All of the bodies are in interpolation mode? setInterpolation(I_Linear) ?

tgrodger

26-03-2008 18:30:42

I'm using 0.9-38 with v2.7.3

I do not see a setInterpolation function.. is that new to the bleeding version?

That gives me an idea though... will try it and let you know if it works

betajaen

26-03-2008 18:56:56

Your bodies have to be in "interpolation" mode for them to interpolate.

[Edit]

It's much easier to do this in '20 of bleeding.

OgreMage

10-05-2008 07:23:57

Hello, I am using NxOgre 0.9 with PhysX. I am also using a very simlar timeStep approach, as the code in this thread, for consistent physics across different framerates on different CPUs.

My question is about the "setInterpolation(I_Linear)" comment. Should I be using this? As mentioned in this thread, I do not see it in Body*. The thread continues to say that it is much easier in Bleeding, but does not explain how it is done in 0.9. However much I would like to upgrade to Bleeding, it is not an option for my current project at this stage due to a diverse amount of reasons.

Is it necessary to reduce jitter with timeStepped physics by setting bodies to interpolate, and how do I do it with 0.9? I have become fairly savy accessing the PhysX classes directly if that is the issue.

I do move objects in my scene where appropriate with the LERP Graphic Gems function. That is not what we are talking about here, is it?

#define LERP(a,l,h) ((l)+(((h)-(l))*(a)))
(An example using it):
destPos.x = LERP( CLAMP(2.0*elapsedTime,0,1), currentPos.x, liftPos.x );
destPos.y = LERP( CLAMP(2.0*elapsedTime,0,1), currentPos.y, liftPos.y );
destPos.z = LERP( CLAMP(2.0*elapsedTime,0,1), currentPos.z, liftPos.z );


For fun, I am going to post my physics timestep simulation code, that is in fact based on the one here. It differs a bit in that it sets a max amount of iterations, so that if it cannot catch up it will give up and reset:

const Real simulationTimeStep = 1.0 / 60.0;
int maxIterations = 0;
timeToSimulate += elapsedGameTime();

while( (timeToSimulate >= simulationTimeStep) && (maxIterations++ < 8) )
{
mWorld->simulate( simulationTimeStep );
timeToSimulate -= simulationTimeStep;
}
if( maxIterations > 8 )
timeToSimulate = 0.0;

mWorld->render( elapsedGameTime() );

luis

10-05-2008 08:54:31

I've implemented Gaffer's method (wich is just the standard linear interpolation) successfully.
Read:
http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=6616

In that thread I explained my conlusions:
1- interpolation in NxOgre 0.9 doesn't work
2- interpolation in NxOgre 1.0-21 doesn't work (see my last post and link)

The interface changes from 0.9 to 1.0-18 are not that much so you could port you app to 1.0-18 and apply the patch I submited or make a diff and see what changes i've done in SVN trunk and do it by your self in any NxOgre version you want ;)

SVN -> Update to revision.....

betajaen

10-05-2008 09:06:26

2- interpolation in NxOgre 1.0-21 doesn't work (see my last post and link).

I don't know why that doesn't work. Since I implemented your patch.

luis

10-05-2008 09:25:29

I don't know why that doesn't work. Since I implemented your patch.

Oh i though you already knew it isn't working.....

I explained why it isn't working in 1.0-21 thread:
http://www.ogre3d.org/phpBB2addons/view ... 0344#40344

The last pose is beeing saved each frame, and it should be done only when a simulation step is done that's why it isn't working... i post the correct code in that thread.

betajaen

10-05-2008 09:38:42

I didn't know. I must of missed your posts, or forgot about them.

I've added your change anyway, I can't test it, as I'm currently implementing a Red/Black Tree class for BetajaenCC, which is currently causing over 1410 errors in NxOgre at the moment. ;)

NickM

10-05-2008 19:45:47

I too can't/don't want to yet, change to using bleeding, I intend to eventually try to add interpolation to 0.9 for my own benefit but that could be some time away, if anyone does it sooner and fancies sharing the code, I'd be most greatful. :D

BloodyFanatic

10-05-2008 19:55:44

I too can't/don't want to yet, change to using bleeding, I intend to eventually try to add interpolation to 0.9 for my own benefit but that could be some time away, if anyone does it sooner and fancies sharing the code, I'd be most greatful. :D

erm, you could use 1.0'18, it is virtually 0.9 with interpolation ;)

look at the changelog if you don't believe it:

Changes of NxOgre

1.0'18
> Scene Controller

+ added getAlphaValue to SceneController
> Scene
+ added getLastAlphaValue

> Added proper code for interpolation (I_Linear) in Body and Wheel

<Betajaen: 05-Decemeber-2007>

1.0'17

> Version Bump

> First Code Dump

<Betajaen: 05-December-2007>


===================================================================================
Major Version bump: Was 0.9, Now 1.0
===================================================================================

0.9-39

[...]


i use it and it works ;)

luis

10-05-2008 22:38:45

BloodyFanatic is right, 1.0-18 is almost the same than 0.9....

i use it and it works
are you using the patch and works? (if yes) i'm happy to hear that.

betajaen

10-05-2008 23:02:08

No it isn't. It's based on 0.9, but it's not the same. If I remember correctly '17 was a massive release I did.

Anyway, your using the old shape system that it has. Which to be fair is rubbish and doesn't work with any custom parameters.

BloodyFanatic

11-05-2008 09:21:42

No it isn't. It's based on 0.9, but it's not the same. If I remember correctly '17 was a massive release I did.

Anyway, your using the old shape system that it has. Which to be fair is rubbish and doesn't work with any custom parameters.


you'r right, but there are only a few interface changes - compared to '21...
in addition you don't have to precook all shapes, which i really doesn't like, especially when it isn't working correctly ( i haven't tested it though.. )


are you using the patch and works? (if yes) i'm happy to hear that.

no, i'm using '18 only, no patch needed ;)

edit: atleast i think so since i don't remember having it patched ^^