Gamestudio Links
Zorro Links
Newest Posts
zorro license, IB connection
by AndrewAMD. 12/06/23 17:16
Newbie Questions
by fairtrader. 12/06/23 11:29
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
5 registered members (AndrewAMD, miwok, TipmyPip, 3run, 1 invisible), 631 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 3 1 2 3
Re: Get the angle of the surface of a normal. [Re: Pappenheimer] #261875
04/20/09 20:23
04/20/09 20:23
Joined: Mar 2003
Posts: 3,010
analysis paralysis
NITRO777 Offline
Expert
NITRO777  Offline
Expert

Joined: Mar 2003
Posts: 3,010
analysis paralysis
Quote:
I mean, a vector of a direction doesn't contain any information of a sort of roll factor. For instance when fixing a sword in a hand via vec_for_vertex you need three points to fix it properly, but a direction has only two points.
If this is true, then vec_to_angle has to _add_ a sort of information to get the angles out of the direction, although it doesn't have this information.


I think I know what you mean, but a direction vector has two point indeed, you are right, but in 3d each one of those two points has an x,y, and z. So there is no lost information.

The definition of a vector in 3d is simply v=q-p where q has (x1,y1,z1) and p also has(x2,y2,z2) so v= (x1-x2,y1-y2,z1-z2). So q and p are only two different points in space, you are correct, but each of those 2 point have 3 coordinates.

Re: Get the angle of the surface of a normal. [Re: DJBMASTER] #261898
04/20/09 22:33
04/20/09 22:33
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Originally Posted By: DJBMASTER
from a direction vector you can use "directional cosines" to retrieve the angles to the x, y and z axis. These should somehow represent roll,tilt and pan angles i believe.

Pappenheimer, when you talk about the sword concept, you are talking about points. Points are absolute, vectors are relative.


Although, it sounds like absolute, I don't mean it absolute.

I don't think from the maths, I'm thinking from the geometry, its more an imagination, but I can express it this way, too:

To keep the angles of a sword properly without jerkins within the hand you need two vectors, let's call them 'space vectors'.
(This is what the three points of a triangle give: at least two directions/vectors.)

This means, a single 'space' vector like that of the direction can't have enough information to keep an object's angles under control.

Last edited by Pappenheimer; 04/20/09 22:35.
Re: Get the angle of the surface of a normal. [Re: Pappenheimer] #261914
04/21/09 01:00
04/21/09 01:00
Joined: Sep 2003
Posts: 928
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 928
Yes, for object orientation a vector is not enough.

A vector has more information than an angle, the vector has length but an angle has not. On the other hand, an angle has roll which the vector does not have. Only a normal vector which has length 1, is equivalent to an pan and tilt angle (no roll).

Here is the idea for giving an object the same orientation as the surface, first give it the same angle as the normal, then roll it in pan direction, and then put it upright by -90 tilt:

vec_to_angle(my.pan,hit.nx);
my.roll = pan_angle;
ang_rotate(my.pan,vector(0,-90,0));



Re: Get the angle of the surface of a normal. [Re: Spirit] #261936
04/21/09 07:57
04/21/09 07:57
Joined: Jul 2000
Posts: 27,967
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,967
Frankfurt
Yes, this should work for all slopes. But when you want to adapt an object to a floor or wall that can be vertical, or even upside down, you need to define how you want to rotate the object. Normally the pan angle will change dependent on the slope. For instance, when you switch from the floor to the ceiling, the pan angle has to change by 180 degrees when you want the object to face the same direction as before.

You can correct the pan angle with a second rotation:

vec_to_angle(my.pan,hit.nx); // adapt object to floor slope
my.roll = 0;
ang_rotate(my.pan,vector(0,-90,0)); // make it upright
ang_rotate(my.pan,vector(pan_angle-my.pan,0,0)); // adjust the pan angle

Hope this helps to find the final solution.

Re: Get the angle of the surface of a normal. [Re: jcl] #262022
04/21/09 15:55
04/21/09 15:55
Joined: Mar 2003
Posts: 3,010
analysis paralysis
NITRO777 Offline
Expert
NITRO777  Offline
Expert

Joined: Mar 2003
Posts: 3,010
analysis paralysis
hey jcl and spirit you guys are darn smart smile I am still scratching my head over this. grin

Re: Get the angle of the surface of a normal. [Re: NITRO777] #262127
04/22/09 03:19
04/22/09 03:19
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Replys to suggestions attempting to clear my mental constipation.

TNT :: I cant see a way to implement your suggestion, as I need both tilt and roll,
but your suggestion only gives me a single angle, and I cant see how to apply it.

Scorpion :: Ive been down the vec_to_angle road with no joy. It performs an un-decypherable
transformation when the normal.z goes negative.

delinkx :: you suggestion sounds promising, (btw the pic is broken cause youve got http///:)
But can you give an example using the vec_dot function. I fail to understand it at all.
I cant seem to mentally map the single angle of the result to tilt and roll requirements.

DJBMASTER :: Can you clarify of give axamples of your "directional cosines"? I dont know how
the normal.x,y,z relate to one onother in order to translate into pan/tilt/roll.

Spirit :: Sorry, your idea spasms as soon as there is any roll retrieved from the surface.

JCL :: Still no go. It goes spastic when it hits a verticle wall.

Anyone :: Is it just me, but whenever I use vec_to_angle, the returned Roll value seems to be
random between compiles.
Ive never tried to use its roll for anything, but I would like to know why.
(JCL, this is another request for an explanitory algorithm for vec_to_angle, if possible.)

Now here is the test code Im using. For everyones perusal.
Just in case Im doing something stupid elsewhere in the function.
Code:
action player_action()
{
	var pan_angle=0;
	wait(1);	c_setminmax(my);	Player = my;	
	VECTOR tmpV;
	while(1)
	{	//move or rotate me
		if(key_e)	c_move(my,vector( 15*time_step,0,0),nullvector,GLIDE);
		if(key_q)	c_move(my,vector(-15*time_step,0,0),nullvector,GLIDE);
		if(key_cul)	pan_angle += time_step;
		if(key_cur)	pan_angle -= time_step;
		//
		//look at ground below me.
		vec_set(tmpV, vector(0,0,-999));
		vec_rotate(tmpV, my.pan);
		vec_add(tmpV, my.x);
		c_trace(my.x, tmpV, IGNORE_ME | USE_BOX | IGNORE_PASSABLE);
		if(trace_hit)	// Hit SOMETHING - expecting "track" surface
		{
			///// PROBLEM AREA START /////

			
			// adjust MY angle to match surface using NORMAL

			//JCL's latest suggested code.
			vec_to_angle(my.pan,hit.nx); // adapt object to floor slope
			my.roll = 0;
			ang_rotate(my.pan,vector(0,-90,0)); // make it upright
			ang_rotate(my.pan,vector(pan_angle-my.pan,0,0)); // adjust the pan angle


//			// My initial code, loops right over but doesnt allow for pan at all
//			if(normal.z>=0)	{  my.tilt = -asin(normal.x);  		my.roll = -asin(normal.y); 	}
//			else		{  my.tilt = 180-asin(-normal.x);	my.roll = -asin(normal.y);	}


			///// PROBLEM AREA END ///////
			//adjust my height to be 20 quants above the surface
			if((my.skill1=vec_dist(my.x, target.x)) != 20)	c_move(my, vector(0,0,20-my.skill1), nullvector, GLIDE);	
		}
		wait(1);
	}
}
 




Last edited by EvilSOB; 04/22/09 03:46.

"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Get the angle of the surface of a normal. [Re: EvilSOB] #262146
04/22/09 06:24
04/22/09 06:24
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Miracle of Miracles! I got it!
I think?!?


Thanks to ALL for their input. It appears that something someone said (or multiple someones)
crystallised in my brain and enabled me to see the error of my ways.

Just changing the order of my angle-adjust with my height-adjust seems to have resolved the issue!
It forces me to do an extra c-trace, but thats probably whats fixing it.

If anyone has an explanation as to WHY this makes a difference, Im all ears.
Also, further testing by others and their feedback would be much appreciated.
(Yes, I know the angle changes arent smooth but I know how to solve that)

And I dont know about my fudge if(normal.z<0) my.tilt=180-my.tilt;
It came from an educated guess, and it does the job, but it seems ugly.
I feel there should be an ang_rotate or something to cover this transform but I cant find anything
that gives me usable results.

Thanks again to everyone.

Code:
action player_action()
{
	VECTOR tmpV;	var HeightLock = 30;
	wait(1);		c_setminmax(my);	Player = my;	
	while(1)
	{	//move or rotate me
		if(key_cuu)	c_move(my,vector( 15*time_step,0,0),nullvector,GLIDE|IGNORE_PASSABLE);
		if(key_cud)	c_move(my,vector(-15*time_step,0,0),nullvector,GLIDE|IGNORE_PASSABLE);
		if(key_cul)	my.pan += time_step;
		if(key_cur)	my.pan -= time_step;
		//
		//look at ground below me.
		vec_set(tmpV, vector(0,0,-999));		vec_rotate(tmpV, my.pan);
		c_trace(my.x, vec_add(tmpV, my.x), IGNORE_ME | USE_BOX | IGNORE_PASSABLE);
		if(trace_hit)	// Hit SOMETHING - expecting "track" surface
		{	//adjust my height to be HeightLock quants above the surface
			if(vec_dist(my.x, target.x) != HeightLock)
			{	c_move(my, vector(0,0,HeightLock-vec_dist(my.x, target.x)), nullvector, GLIDE);	
				//get new target
				vec_set(tmpV, vector(0,0,-HeightLock*2));		vec_rotate(tmpV, my.pan);
				c_trace(my.x, vec_add(tmpV, my.x), IGNORE_ME | USE_BOX | IGNORE_PASSABLE);
			}
		}
		if(trace_hit)	// Hit SOMETHING - expecting "track" surface
		{	// adjust MY angle to match surface using NORMAL
			vec_rotateback(normal, vector(my.pan,0,0));
			vec_set(my.pan,vector(my.pan,asin(-normal.x),asin(-normal.y)));
			if(normal.z<0)	{	my.tilt = 180 - my.tilt;	}
		}
		wait(1);
	}
}




"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Get the angle of the surface of a normal. [Re: EvilSOB] #262353
04/23/09 09:11
04/23/09 09:11
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Grrrr. My fudge turns out to be next to useless.

My testbed was obscuring the fact that both the pan angle changes direction
and the roll is a bit screwy on the ceiling.

Im still open for advice. As code/pseudocode by preference, as I dont seem to
be able to grasp decriptions given in words on vector issues. Sorry laugh


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Get the angle of the surface of a normal. [Re: EvilSOB] #262360
04/23/09 10:15
04/23/09 10:15
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Can you post a video to show the effect?
BTW, what are you trying to achieve, something like Mario Galaxy or a spider, that runs on any surface?

Re: Get the angle of the surface of a normal. [Re: Pappenheimer] #262363
04/23/09 10:44
04/23/09 10:44
Joined: Apr 2009
Posts: 298
Southern Oceans
KiwiBoy Offline
Member
KiwiBoy  Offline
Member

Joined: Apr 2009
Posts: 298
Southern Oceans
Maybe a solution is to keep normal parameters as far as possible but flip the model upside down, then trace can stay downwards but push the model up against an obstacle?

Page 2 of 3 1 2 3

Moderated by  old_bill, Tobias 

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