@Orion- It's not a duplicate question -> you got the basics working :)
What I found: Chaikin is good for some kind of pre-smoothing. You capture the touch points in ccTouchesBegan/Moved. If you have two points use chaiking with weight 4 and level 2 on both points - throw away the original points. Do that for every new captured point, with the last captured (and chaikin smoothed) point.
This removes small differences in the captured points. For example if you move your finger over the iPad. You think it is a really smooth curve, but the captured points have a small jitter - just some pixel difference in (x,y) as it "should" be. Chaikin removes this jitter.
Then use the code I posted here to compute the bezier curve control points over all curve segments. You now have:
- N captured touch points, "smoothed" with chaikin
- N-1 cubic bezier curve segments (= a cubic bezier spline), each with 2 computed control points (2 touch points + 2 control points = 1 cubic bezier curve :)
Now you need to break your spline in equal sized segments. I posted some info how to do that already here somewhere, but as you got that far ... again :)
What you need to split the spline in equal sized segments is the arc length of your curves and of your spline. So you can do that mathematically correct or use an approximation, which is faster and -for games- good enough.
- You know the segment size you want, it is ARC
-> Loop over all curve segments, give ARC as argument
- split the cubic bcurve in NUM_STEP points,
where NUM_STEPS = 2*ccpDistance(p1, p4) -> p1/p4 are captured points
p2/p3 are the control points
- now you have points for every t=1/NUM_STEPS
- loop over these points (they are really near) and
calc ccpDistance() between these points
- save the distance for each step to a second array
-> the sum of this array is the arc length of the curve
(approximated)
- now you know the t and the approximated arc length of the
curve in every t
- now search the arc length array to find where it equals
the ARC you want
- if the curve is shorter, just substract the arc length of
the curve from ARC and go to the next curve, using this as ARC
- if you find a point (usually you won't find equal, but inbetween
two t's - interpolate here) reset ARC to the original
segment size you want
- save the points you find :)
Problems:
- Extrema. But depends on your texture size (line width).
- the last captured point may not be in your segment size ... decide if you want to add it or not (I did: if (remaining_arc_length_before_last_point >= 0.5f * ARC) add_it(); else do_not_add_it(); )