Got a new problem now though.
I've implemented fixed rate physics with independant rate rendering. Just a block bouncing round the screen.
It jitters. It jitters real bad.
markr - could you give me a bit more detail on this stuff about interpolating based on an average? I'm not sure what you mean exactly.
Does tihs mean calculating the actual position when I do the physics, then working out an interpolated position to actually draw an object when I render?
Wouldn't this mean that every object has to effectively carry two states around with it - its previous and its current?
[EDIT]
My test app is
here.
My main loop code looks like this:
CResult CEngine::Cycle(){ static float Accumulator=0; Accumulator+=Timer.Get(); // returns time since last called as proportion of second from 0.0f to 1.0f while(Accumulator>=PhysicsDelta) { CResult R=CurrentMode()->Physics(); if(R!=rsOk) return R; Accumulator-=PhysicsDelta; } Dev.BeginScene(); CResult R=CurrentMode()->Render(Dev,Qu); if(R!=rsOk) return R; Dev.EndScene(); Dev.Present(); return rsOk;}
If anyone has time to download the exe, you notice every two or three seconds the block jitters really badly. I reckon that would look awful if it was a whole screen of a moving map and various objects.
Any ideas would be appreciated.
[EDIT]
I've just tried storing the old X and Y of the Block in the physics function before update, then passing the remainder of the accumulator into the Render function and doing:
CResult CGameMode::Render(float Time,CDevice &Dev,CQuadBuffer &Qu){ float Alpha=Time/PhysicsDelta; float x=X*Alpha+Ox*(1.0f-Alpha); float y=Y*Alpha+Oy*(1.0f-Alpha); Dev.Clear(Col); Qu.Begin(); Qu.Add(x,y,40,40,D3DFLOATRECT(),D3DCOLOR_ARGB(255,128,0,0)); Qu.End(); Dev.Draw(Qu); return rsOk;}
That does actually make it a hell of a lot smoother, although I have no idea how this would apply to velocity varibles. Would I actually need to perform any alpha blending of velocities, or would it just literally be the positions like above?
Blimey. Surely you can write a Mario style platformer on a modern PC without all this complication?
[EDIT]
It would appear that velocity calculations do not need to be affected, just purely the position you render at each frame. Makes sense I guess.
So I guess I need to come up with a way of wrapping all this horrible maths into an object that all moving objects can contain. Might work.
[Edited by - EasilyConfused on November 29, 2006 2:42:58 PM]