Sign in to follow this  
NateDog

Need help with Cubic Spline Dead Reckoning

Recommended Posts

I'm trying to implement the algorithm outlined in this gamedev article (http://www.gamedev.net/reference/articles/article914.asp) for Cubic Spline dead reckoning and I'm definitely hitting some snags. I've setup my 4 ship coordinates (and for simplicity/testing I'm assuming a second interval between old ship location and new ship location): c1 = last ship location c2 = last ship location plus 1 second (velocity applied to c1) c3 = new ship location minus 1 second (negative velocity applied to c4) c4 = new ship location Now according to the article I should use the following formulas? A = c4x - 3*c3x + 3*c2x - c1x B = 3*c4x - 6*c2x + 3*c1x C = 3*c2x - 3*c4x D = c4x E = c4y - 3*c3y + 3*c2y - c1y F = 3*c4y - 6*c2y + 3*c1y G = 3*c2y - 3*c4y H = c4y And then in my frame loop where t=fps/time (i.e. t goes from 0 to 1 in even increments based on the frame rate): x = A * t^3 + B * t^2 + C * t + D; y = E * t^3 + F * t^2 + G * t + H; When I print out my x,y in the frame loop, shouldn't I be seeing a nice smooth path that mimics the drawing in the article? I see in the comments that the article author mixed up coords 3 and 4 and so I tried altering that too, but still the path just isn't smooth at all. Also, this article doesn't show me how to set my bearing in each frame. Anyone know of a good source for code examples that get into the real nitty gritty on this? I searched google and amazon but not finding this cubic spline based dead reckoning ... only linear which I already have in place but am wanting to improve on. Or, can anyone spot the problem for me? Anyone looking for a quick small paypal payment and a huge boost of karma for helping me write out the actual functions including setting the bearing on the ship as it travels along the spline? :)

Share this post


Link to post
Share on other sites
Cubic splines are not that useful for dead reckoning, because they are not constant-velocity. For hairpin turns, they will actually make the entity speed up in world space.

That being said, just calculate a cubic (Hermite) spline value, and it should be smooth. However, the most important part is to manage your time steps correctly. If you're predicting out into the future, and the future samples then suddenly arrive and change your prediction, then there will be a discontinuity in the interpolation.

This is why most systems just do something like linear interpolation between the last two samples, time-delayed backwards by one interval between updates. If you want something fancier, try the Entity Position Interpolation Code sample.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this