Ramble: Curves Roadblock

I've been pounding my head against the wall over these Bézier curves for the past couple days. For a change of pace, I'm going to pound my head against this blog instead, and hope that something useful falls out.

The overall challenge is to preserve the apparent position of an object (i.e. the character) along the curve while dragging one of the handles.

Currently, the character's position is defined between 0.0 and 1.0, representing how far along the entire curve he is (0.5 being halfway around; for a closed curve, 0.0 and 1.0 are at the same location).

The character should seem to stick to a point on the curve, moving as that point moves. This means that the character's actual position along the curve needs to be adjusted to compensate for the change in overall curve length.

Without such adjustment, the character will seem to slide along the curve, even if the curve is being modified somewhere else (because the curve's overall length will change).

One possible solution would be to modify how the character defines its position. If it were defined as the position 0.0 to 1.0 along an individual segment, then modifying other segments would not affect the character's position. More, modifying the segment that the character is on would cause the character to move along with the segment as it's stretched/squashed. Problems solved.

(Even better than defining 0.0 to 1.0 along a segment, would be to define 0.0 to L, the length of the segment. This will make it easier to have the character seem to move at a constant speed.)

This somewhat complicates the way the character's true position is defined, because it will have to remember which segment it is on, and find out what the next segment is when it walks off of the current one. This can be accomplished by having each segment remember the previous and next segments in the chair (i.e. linked list of segments).

This entails a substantial rearranging of how the curve system is currently defined. Much of the power and responsibility of th Curve class will be shifted off to other classes, especially Segment.

Previous post: Bézier Curve Test Next post: Picking apart Rubygems and Rake