Curves

Published November 16, 2010
Advertisement
Need to start updating here a bit more often really so no screenshots today but I've sort of managed to get smooth tracking along my multisegment curves working in the game.

It appears it is actually quite hard to get constant speed along a bezier but I'm not too worried given the usage I need.

The basic idea is that the curve is stored as a sequence of points, each with an associated control point, the control point of the last point being unused, and storing the pre-computed length of each curve with each point.

The class that looks after this data then returns a point based on the input of a distance along the curve.

First, easy early outs. If distance<=0, return the first point. If distance>=total length, return the last point and signal that we have completed the path.

For the rest, start by copying the required distance to a variable remainder. Then loop through each segment. If the length of the current segment is less than the remainder, deduct the length from the remainder then move to the next segment.

When the segment length is greater than the remainder, we have the segment we need to examine. We can then divide remainder by the segment length to get a value between 0 and 1 along the relevant curve.

Then just call the Bezier function on the current curve to get the position.

I've tested this with a cloud moving around a curvy path and seems to work okay apart from the constant speed issue but a bit of googling suggests this is not simple to solve - sampling along T on a curve does not return equidistant points - but I don't really care.

Making the camera follow a curve is more a UI and interface problem now that the actual maths is proven to work so more a ponder in quiet moments problem than a grapple with numbers issue.
Previous Entry Curves
Next Entry Curves 2
0 likes 5 comments

Comments

Drilian
That's the exact same mechanism I ended up using for Procyon's enemy flight paths, to get constant speed :)

Glad I'm not the only one that backed off of the ideal of pure curves and went with subdivided line segments instead :)
November 16, 2010 12:56 PM
Aardvajk
Glad great minds thinking alike [smile].

You're updating your journal even less than me at the moment. What are you up to? And where the hell is Milkshake? Bought an island off the iPhone sales of Melon Golf and given up gamedev I reckon.
November 16, 2010 01:01 PM
_the_phantom_
Hmmm, I don't have them to hand but I'm pretty sure one of the early Game Programming Gems books had some stuff about following curves in it, including moving at a constant rate..

I'll have to check when I get home (provided its the right side of 11pm when I get home that is..)
November 16, 2010 01:02 PM
Aardvajk
Quote:Original post by phantom
Hmmm, I don't have them to hand but I'm pretty sure one of the early Game Programming Gems books had some stuff about following curves in it, including moving at a constant rate..

I'll have to check when I get home (provided its the right side of 11pm when I get home that is..)


That would be appreciated, cheers Phantom.
November 16, 2010 01:03 PM
Drilian
Quote:Original post by Aardvajk
Glad great minds thinking alike [smile].

You're updating your journal even less than me at the moment. What are you up to? And where the hell is Milkshake? Bought an island off the iPhone sales of Melon Golf and given up gamedev I reckon.


Hah...I guess I should probably update my journal ever again, eh?
November 16, 2010 01:19 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement