Hi, just showing a different approach to the curve (called "catmull rom" actually but looks identical to yours). The function takes 4 parameters which are 4 vertices that form the curve. You want to draw the curve between points 2 and 3 while the end points 1 and 4 "lead the curve". If end point 1 equal to 2 or point 4 to 3, those simply show going straight to that direction.
These functions are capable of doing that in 1,2 and 3 dimensions. (You get the idea though even if wanted to add 4th dimension
)
[pascal]type
TVector2f = record x,y: single; end;
TVector3f = record x,y,z: single; end;
PVector2f = ^TVector2f;
PVector3f = ^TVector3f;
function CatmullCalc(const p0,p1,p2,p3,t: single): single;
begin
result:=0.5*( 2*p1+(p2-p0)*t +
(2*p0-5*p1+4*p2-p3)*t*t +
(3*p1-p0-3*p2+p3)*t*t*t );
end;
function Catmull2f(const a,b,c,d: PVector2f; const delta: single): TVector2f;
begin
result.x:=CatmullCalc(a.x, b.x, c.x, d.x, delta);
result.y:=CatmullCalc(a.y, b.y, c.y, d.y, delta);
end;
procedure Catmull3f(res: PVector3f; const a,b,c,d: PVector3f; const delta: single);
begin
res^.x:=CatmullCalc(a.x, b.x, c.x, d.x, delta);
res^.y:=CatmullCalc(a.y, b.y, c.y, d.y, delta);
res^.z:=CatmullCalc(a.z, b.z, c.z, d.z, delta);
end;[/pascal]
Feel free to bring out a more optimal solution, i'm already passing vector pointers x_X
Bookmarks