|
Catmull spline - How to calculate?
#426820
07/30/13 09:08
07/30/13 09:08
|
Joined: Mar 2006
Posts: 1,993 Karlsruhe
PadMalcom
OP
Serious User
|
OP
Serious User
Joined: Mar 2006
Posts: 1,993
Karlsruhe
|
Sivan showed me a nice algorithm for a spline called catmull rom spline. It is implemented in DX and easy to use as you can see here: http://www.mvps.org/directx/articles/catmull/The function looks like:
D3DXVec3CatmullRom(D3DXVECTOR3* pOut,
CONST D3DXVECTOR3* pV1,
CONST D3DXVECTOR3* pV2,
CONST D3DXVECTOR3* pV3,
CONST D3DXVECTOR3* pV4,
FLOAT s)
As s, I pass values from 0 to 1 in steps of 0.1 My problem is that when I define a spline, it only goes 2/3 of the entire path as you can see in this image (blue is the path, red is the spline): Any ideas?
Last edited by PadMalcom; 07/30/13 09:08.
|
|
|
Re: Catmull spline - How to calculate?
[Re: PadMalcom]
#426822
07/30/13 09:35
07/30/13 09:35
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
It's not drawing 2/3 of the path but only one third (the change in color, the transition from red to blue seems to be just a property of the draw_line3d function). To allow for continuous splines one has to use boundary conditions, which are in your case the arguments pV1 and pV4 (or P0 and P3 in the graphic). When you now have a chain of let's say 100 nodes you can easily draw spline segments with p_i and p_i+1 while increasing i only by 1 each time. I am not sure how you would draw the end pieces, maybe you pass the same argument for pV1 and pV2 and vice versa.
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: Catmull spline - How to calculate?
[Re: PadMalcom]
#426826
07/30/13 10:02
07/30/13 10:02
|
Joined: Mar 2006
Posts: 1,993 Karlsruhe
PadMalcom
OP
Serious User
|
OP
Serious User
Joined: Mar 2006
Posts: 1,993
Karlsruhe
|
Solved it with the help of this site: http://steve.hollasch.net/cgindex/curves/catmull-rom.htmlTo do more than two points just step through the array of points using the previous point, the current point and the next two points as the four points for the spline. For each of these segments draw a curve for 0<t<1. This curve will be between the current point and the next point. The code to draw the spine is:
var i;
for(i=0; i<3; i++)
{
for(f = 0; f <= 1.0; f += 0.01)
{
draw_line(vec_to_catmull(pos, pt[cycle(i-1,0,4)], pt[cycle(i,0,4)], pt[cycle(i+1,0,4)], pt[cycle(i+2,0,4)], f), COLOR_RED, 100);
}
}
As usual it can be found in the TUST library
Last edited by PadMalcom; 07/30/13 10:03.
|
|
|
|