How can I render-tween with BlitzMax?

BlitzMax Forums/BlitzMax Programming/How can I render-tween with BlitzMax?

SofaKng(Posted 2007) [#1]
I'm going to use fixed-timestep logic for my game but I'm confused on how to implement render-tweening.

According to the articles on gaffer.org, it is easy to use linear interpolation based on the amount left in the accumulator.

So, for example...

Let's say I have a ball moving in a circle at a rate of 4 seconds per full rotation.

After 2 seconds the ball is halfway around the circle.

My accumulator (eg. the amount left over after performing full timestep updates) says that we are 1/10th (0.1) of the way to the next timestep.

Where should I draw my ball? I can't perform an update on the ball because that would ruin my fixed-rate logic.

Do I somehow move the ball in a straight line? If so, how do I know where to move it?

Thanks for your help...


Gabriel(Posted 2007) [#2]
You draw it 1/10th of the way between where it is now and where it was the last time you updated it.


Dreamora(Posted 2007) [#3]
Or mathematically in vectors:
OldPos + Tween*(NewPos-OldPos)
(tween would in your example be 1/10)


SofaKng(Posted 2007) [#4]
So the rendering is always delayed behind the physics/updates?

I was thinking that I would extrapolate a position instead of interpolating. In other words, I thought the physics would update, and then I would draw the object's current position PLUS a tiny bit further due to tween.

Also, wouldn't each object need custom code for tweening? For example, a ballistic object is moving according to a complex (well, not really) formula and I would think that tweening a new position would require re-calculating a "fake" position.

Finally... does this work for network/multiplayer games?


Gabriel(Posted 2007) [#5]
So the rendering is always delayed behind the physics/updates?

No, it just "feels" that way. For the purposes of game timing, it is always assumed that physics is ahead of video.

I was thinking that I would extrapolate a position instead of interpolating. In other words, I thought the physics would update, and then I would draw the object's current position PLUS a tiny bit further due to tween.

I had the same impression after reading that article, but it's just the way the article is written confusing you. You can't extrapolate a new position because that would mean doing another physics update, and that would throw your timing out anyway.

Also, wouldn't each object need custom code for tweening? For example, a ballistic object is moving according to a complex (well, not really) formula and I would think that tweening a new position would require re-calculating a "fake" position.

I've had this discussion with someone on IRC recently, and we eventually had to agree to disagree on this. If you recalculate a "fake" position, you cannot use this method of timing. The person I was in discussion with feels that recalculating a "fake" position ( to account for acceleration in all forms ) is more accurate. Personally I think that it's unnoticeable when you're talking about fractions of fractions of seconds. You're literally talking about 1/600th of a second in your example above.

And you might want to remember that the guy who wrote that article was a senior programmer on Tribes Vengeance. So he knows what he's talking about even if his articles are a little confusing at times.

Finally... does this work for network/multiplayer games?

Should be fine. I render tweened Kick Shot Pool and that works fine in multiplayer. Not that anyone but me ever seems to play it online :P


Who was John Galt?(Posted 2007) [#6]
Straight interpolation looks just fine so long as your timesteps aren't too big. If they are too big, it will look rubbish anyway. Extrapolating would be bad news as you would end up with discontinuities.


Grey Alien(Posted 2007) [#7]
Yeah I wouldn't extrapolate, it's OK to be a fraction of a frame behind, no one will notice.


SofaKng(Posted 2007) [#8]
Thanks for the great replies!

One last question...

Do you store two positions in each object then? (eg. "current" and "previous")

If so, then it makes sense that you draw a straight line from "previous" to "current" and then only travel a percent through the line. (eg. if we are 20% towards our next tick then we only travel 20% on this line)


Gabriel(Posted 2007) [#9]
Yes, all my "entities" have a previous and a current position for use with render tweening.