Gamestudio Links
Zorro Links
Newest Posts
zorro 64bit command line support
by jcl. 04/20/24 08:52
StartWeek not working as it should
by jcl. 04/20/24 08:38
Data from CSV not parsed correctly
by jcl. 04/20/24 08:32
Zorro FIX plugin - Experimental
by jcl. 04/20/24 08:30
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (7th_zorro, Aku_Aku, henrybane, flink, 1 invisible), 712 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Catmull spline - How to calculate? #426820
07/30/13 09:08
07/30/13 09:08
Joined: Mar 2006
Posts: 1,993
Karlsruhe
PadMalcom Offline OP
Serious User
PadMalcom  Offline 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:

Code:
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 Offline
Senior Expert
Superku  Offline
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: Superku] #426823
07/30/13 09:47
07/30/13 09:47
Joined: Mar 2006
Posts: 1,993
Karlsruhe
PadMalcom Offline OP
Serious User
PadMalcom  Offline OP
Serious User

Joined: Mar 2006
Posts: 1,993
Karlsruhe
That makes sense, thanks for the explaination! But then one problem remains, as you pointed out. How to get the spline data of the path P0->P1 and P2->P3. One could possibly interpolate between these points and create new paths but that seems to be a weired way. I'll use google for a while to find it out...

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 Offline OP
Serious User
PadMalcom  Offline 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.html

Quote:
To 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:
Code:
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 laugh


Last edited by PadMalcom; 07/30/13 10:03.
Re: Catmull spline - How to calculate? [Re: PadMalcom] #426831
07/30/13 12:21
07/30/13 12:21
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline
Expert
sivan  Offline
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
great! and congratulation for the fast implementation laugh
I think the article I read is in Game Programming Gems 1 and deals with path smoothing.


Free world editor for 3D Gamestudio: MapBuilder Editor

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1