You are totally off, like motorherp expected.
But first lets see if I got your source right:
1. pathLengths is a float array you fill with hundreds of precomputed length values on the spline.
2. your t isn't kept between 0..1 but is rather a float casted to an int to be used as index into said pathLengths array (wait: you use it as index into the splineSegments array...).
3. at the same time that t is used for a0 and a1.
4. t0 and t1 are filled with the precomputed coordinates (not lengths).
5. you got the most inefficient a0/t0/a1/t1 lookup code I ever saw

Okay, let's see:
(1) seems to be okay.
(2) not keeping t inside 0..1 is okay, as long as the rest of your code takes this into account.
But now the bulls#%& starts

Because later you don't look up the pathLengths but splineSegments (t0= / t1= )!
(3) a0=i respectively a1=i is just wrong: It should be
'a0' and 'a1' are the two closest tabulated values of arc length
but in your case a0 and a1 become t-values instead of pathLengths[t]-values... (since i is nothing more than a "rounded" t in your case).
(4) Similar t0 and t1 are wrong. Those you fill with the precomputed POSITIONS (?) close to t, while they should be the t that was used to create those table-values.
(5) Why don't you exploit the fact that your t is not kept in the range of 0..1? Because here it would ease things a lot: just cast t to an int and use that as index into your tables (with a range check for safety). No for-loop needed at all.
Let's compare your code
float tX = t0.x + ((a - a0) / (a1 - a0)) * (t1.x - t0.x);
float tY = t0.y + ((a - a0) / (a1 - a0)) * (t1.y - t0.y);
with the tutorial's formula
t = t0 + ((a - a0) / (a1 - a0)) * (t1 - t0)
Why do you come up with a 2D vector? The formula is about time and distance, not positions in 2D space.
So essentially it boils down to:
- t0 and t1 have to be float, not Vec2D
- tX and tY are wrong, you just need one single float result_t.
- a0 and a1 have to be values out of your pathLengths table.
- t0 and t1 have to be the t that was used to compute the pathLengths
- since your t is not kept in the range of 0..1 your result_t won't be neither. You have to take that into account when using that value later.
Phew.
EDIT: I first thought you didn't start your pathLength array at 0-distance when in fact you do. Nevertheless that doesn't change anything overall.
«
Last Edit: November 21, 2011, 11:55:49 AM by Hornet600S »
"When the Amiga came out, everyone at Apple was scared as hell."
(Jean-Louis Gassée - Head of Macintosh development at Apple)