Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/20/24 01:28
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (kzhao, AndrewAMD, bigsmack, 7th_zorro), 869 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Hermite spline - moving with constant speed #391574
01/13/12 22:29
01/13/12 22:29
Joined: May 2010
Posts: 117
Germany , Dortmund
B
Bone Offline OP
Member
Bone  Offline OP
Member
B

Joined: May 2010
Posts: 117
Germany , Dortmund
Hello,

I use the formula from http://cubic.org/docs/hermite.htm for calculating a spline.

Now I want to move a model along the spline but with constant speed.

The user set the waypoints so i cant place them in the same distance.
This is the problem- if the waypoints have a higher distance between each waypoint, the model moves faster along the spline.


I have the circa length of the curve.
I go through the curve in 100 steps and save the length between each point on the curve.

The range of the curve is between 0.0 and 1.0 .

How can I calculate the right value between 0.0 and 1.0
in relation to the speed?

I tried some things:

Code:
var dist += 1 / curveLength * speed * time_step

spline(ent.x, dist);



Code:
spline(nextpoint.x,dist);

while(vec_dist(ent.x,nextpoint.x) > 0)
{
  c_move(...); // speed * time_step
}

dist += 0.1



and some other ways.

But they dont work.
The speed is not constant and/or the entity dont move
not exactly along the spline.

Google shows me some article about this topic
but there are no real examples, only complicate formulas
that i dont understand.

I hope somebody have a tip for me.

Good evening laugh

Last edited by Bone; 01/14/12 11:54.
Re: Hermite spline - moving with constant speed [Re: Bone] #391614
01/14/12 10:32
01/14/12 10:32
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline
Expert
sivan  Offline
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
hi
something like this is built in A8, called path_spline(). check there the example. I think, together with path_create(), and a simple c_move() script, you can do the same but more easily.


Free world editor for 3D Gamestudio: MapBuilder Editor
Re: Hermite spline - moving with constant speed [Re: sivan] #391618
01/14/12 11:56
01/14/12 11:56
Joined: May 2010
Posts: 117
Germany , Dortmund
B
Bone Offline OP
Member
Bone  Offline OP
Member
B

Joined: May 2010
Posts: 117
Germany , Dortmund
I had some problems with path_spline()
It need a distance parameter to calculate the position on the spline and the distance is not the real distance on the curve.

From manual:
Quote:

The dist parameter corresponds to the distances of straight lines connecting the nodes, and not to the real distance of the curve. Thus, when adding a constant speed to the dist parameter, the real speed along the curve can vary. It is the faster the more the curve deviates from the straight lines between the nodes. If this is undesired, place more nodes to avoid deviations at sharp bends in the path.


Its the same problem, the speed vary.
I dont know how can I solve my problem with path_spline
and c_move.

Do you have another idea?

Re: Hermite spline - moving with constant speed [Re: Bone] #391634
01/14/12 14:25
01/14/12 14:25
Joined: Sep 2007
Posts: 101
Luxembourg
K
krial057 Offline
Member
krial057  Offline
Member
K

Joined: Sep 2007
Posts: 101
Luxembourg
You have to normalize the direction vector and then scale it with the speed. Here is the code part of my algorithm to follow a bezier curve:

Php Code:

vec_set(dir,currentNode->next->pos);
vec_sub(dir,currentNode->pos);
vec_normalize(dir,speed*time_step);
while(distToNext>=speed*time_step)
{
	//Interpolate the rotation(Not needed if you don't care about the rotation, cause the c_move is done in absoulute coordination
	var percentDone=1-(distToNext/wholeDist);
	quat_slerp(&quaternInter,&quaternStart,&quaternEnd,percentDone);
	ang_for_quat(my.pan,&quaternInter);
	c_move(me,nullvector,dir,IGNORE_MODELS);
	distToNext=vec_dist(my.x,currentNode->next->pos);
	wait(1);
} 




regards Alain

Last edited by krial057; 01/14/12 14:27.
Re: Hermite spline - moving with constant speed [Re: krial057] #391768
01/15/12 18:46
01/15/12 18:46
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline
Expert
sivan  Offline
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
you seem to be much better in maths than me... quat_slerp works in Lite-C?


Free world editor for 3D Gamestudio: MapBuilder Editor
Re: Hermite spline - moving with constant speed [Re: sivan] #391868
01/16/12 17:22
01/16/12 17:22
Joined: Sep 2007
Posts: 101
Luxembourg
K
krial057 Offline
Member
krial057  Offline
Member
K

Joined: Sep 2007
Posts: 101
Luxembourg
Yes it works, but you have to write them xD. Here are the quaternion functions i used(written by JibbSmart):
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=284378&page=5
There you have the function quat_nlerp it should work as fine as with an slerp. If you still want to ues an slerp, you can add this function that i created:
Php Code:
function quat_slerp(QUATERNION *q, QUATERNION *u, QUATERNION *v, double t) {
	QUATERNION qa, qb;
	quat_set(&qa, u);
	quat_set(&qb, v);
	double cosHalfTheta=qa.w*qb.w + qa.x*qb.x + qa.y*qb.y + qa.z*qb.z;
	if(abs(cosHalfTheta)>=1.0)
		quat_set(&q,&qa);
	else
	{
		double halfTheta=acos(cosHalfTheta);
		double sinHalfTheta=sqrt(1.0 - cosHalfTheta*cosHalfTheta);
		if (abs(sinHalfTheta) < 0.001)
		{ 
			q.w = (qa.w * 0.5 + qb.w * 0.5);
			q.x = (qa.x * 0.5 + qb.x * 0.5);
			q.y = (qa.y * 0.5 + qb.y * 0.5);
			q.z = (qa.z * 0.5 + qb.z * 0.5);
		}
		else
		{
			double ratioA = sin((1 - t) * halfTheta) / sinHalfTheta;
			double ratioB = sin(t * halfTheta) / sinHalfTheta; 
			//calculate Quaternion.
			q.w = (qa.w * ratioA + qb.w * ratioB);
			q.x = (qa.x * ratioA + qb.x * ratioB);
			q.y = (qa.y * ratioA + qb.y * ratioB);
			q.z = (qa.z * ratioA + qb.z * ratioB);
		}
	}
} 




And this will be the reuslt:
http://www.youtube.com/watch?v=O07tSEez7sc

If rotations are not needed, you can leave out all the quaternion stuff. (first three lines inside the while loop)

regards Alain

Last edited by krial057; 01/16/12 17:30.
Re: Hermite spline - moving with constant speed [Re: krial057] #391902
01/16/12 20:41
01/16/12 20:41
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline
Expert
sivan  Offline
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
thanx a lot!
it is really useful even to make more realistic my grid based pathfinding system!
so I dig into it a bit laugh


Free world editor for 3D Gamestudio: MapBuilder Editor
Re: Hermite spline - moving with constant speed [Re: sivan] #392124
01/19/12 14:47
01/19/12 14:47
Joined: Jan 2007
Posts: 2,247
Deutsch Niedersachsen
Puppeteer Offline
Expert
Puppeteer  Offline
Expert

Joined: Jan 2007
Posts: 2,247
Deutsch Niedersachsen
I use Splines too and what I do is using the first derivation to calculate the spline direction of movement on the spline and move the agent along this normal.

You do not have to do exacly that, but what you definatly need is a method to find the current positon of the agent along the spline. This Method works fine for me and it is really fast too.
Do not iterate over the whole spline every frame!


Formally known as Omega
Avatar randomness by Quadraxas & Blade
http://omegapuppeteer.mybrute.com
Re: Hermite spline - moving with constant speed [Re: sivan] #392191
01/19/12 21:51
01/19/12 21:51
Joined: May 2010
Posts: 117
Germany , Dortmund
B
Bone Offline OP
Member
Bone  Offline OP
Member
B

Joined: May 2010
Posts: 117
Germany , Dortmund
Thank you krial057,

your code works well!

Puppeteer,

that sounds interesting but Its to complicated for me crazy

Last edited by Bone; 01/19/12 21:54.
Re: Hermite spline - moving with constant speed [Re: Bone] #392210
01/20/12 09:51
01/20/12 09:51
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline
Expert
sivan  Offline
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
learn, learn, and learn laugh


Free world editor for 3D Gamestudio: MapBuilder Editor

Moderated by  HeelX, Spirit 

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