2

Can somebody walk me through how this madness works: http://www.youtube.com/watch?v=KL8QLLmUvbg

Specifically I'm interested in equally distributing a given number of squares along a path. I'm also wondering if this would work with multiple line segments-- this is one curved segment and I need a solution to distribute objects across one big line with multiple curves in it.

Basically I'm trying to make a tail that realistically follows a character.

Thanks

4

3 回答 3

7

First a Bezier spline is a curve parametrized by t. However t is not arc-length along the curve. So the procedure is this.

  1. Calculate the length of the bezier curve.
  2. Find the t values that divide the curve into N equal length segments.

However these two steps are tricky.

The first has a closed form solution only for quadratic Beziers. (You can find the solution here ) Otherwise you use a subdivide and approximate approach, or a numerical integration approach (and in some sense these are equivalent - I'd go the numerical integration approach as this has better provable behavior at the cost of slightly trickier implementation, but you may or may not care about that.)

The second is basically a guess a t value, and improve approach (using the same style of calculation at each step as step 1). I'd implement this using a secant style search, as I suspect the derivatives required to use a Newton's method search would be too expensive to calculate.

Once you've got the positions of the objects, you need to use the curve tangent and cotangent to create a local reference frame for the object. This allows the objects to sit nicely in the path of the curve, rather than all having the same orientation. Note that this only works nicely in 2D - in 3D you can still get some weird behavior with object orientation.

于 2012-08-16T05:19:05.213 回答
0

You can start by looking into how a bezier curve is calculated. Wikipedia has some nice animations with the explanation and this link has some as3 code.

but if you're trying to create a tail, there are simpler ways of doing that, like using following behaviour or a physics library

于 2012-08-16T04:56:29.427 回答
0

I ended up creating a following behavior system like Daniel recommended for simplicities sake. But to elaborate on Michael's awesome answer I stumbled onto this tutorial which details the the spline technique.

http://gamedev.tutsplus.com/tutorials/implementation/create-a-glowing-flowing-lava-river-using-bezier-curves-and-shaders/

于 2012-10-10T16:04:32.220 回答