Jump to content
  • Advertisement
  • entries
    743
  • comments
    1924
  • views
    583797

Curves

Sign in to follow this  
Aardvajk

432 views

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.
Sign in to follow this  


5 Comments


Recommended Comments

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 :)

Share this comment


Link to comment
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.

Share this comment


Link to comment
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..)

Share this comment


Link to comment
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.

Share this comment


Link to comment
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?

Share this comment


Link to comment

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
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!