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 1 of 3 1 2 3
Get the angle of the surface of a normal. #261535
04/18/09 11:29
04/18/09 11:29
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Ive tried in the engine forum but cant get an answer from anyone thats helpful.

But it may be I just have a mental block...

Is there any way to use the normal returned from c_trace, (either "normal" or "hit.nx,ny,nz")
to extract the angle of the surface it is referring to?

Reason ::
Im trying to get an entity to adjust its tilt and roll to match the surface it is above (on its own z-axis).
There have been several code snippets Ive gone through in the AUM's and other user supplied,
but they all go spastic when they go on the "ceiling". (normal.z goes negative)



"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] #261612
04/18/09 20:38
04/18/09 20:38
Joined: Mar 2003
Posts: 3,010
analysis paralysis
NITRO777 Offline
Expert
NITRO777  Offline
Expert

Joined: Mar 2003
Posts: 3,010
analysis paralysis
Hi EvilSOB,
Quote:
Get the angle of the surface of a normal.


I am very sure that the developers and other people will have a better answer than me, but my suggestion is that you take the dot product of the normal and the vector of the trace. Then get the arc Cosine of the result.This would give an angular relationship between the normal and your moveable entity?

Maybe something like this?


Code:
angle = acos(vec_dot(normalVector,traceVector)/(vec_length(normalVector)*vec_length(traceVector))); 


This is straight out of the manual description for vec_dot, it is based on the formula:

A dot B = magnitude of A * magnitude of B * cosine of angle

if you rearrange the formula you get:

cosine of angle = A dot B / (magnitude of A * magnitude of B)

and then to get the actual angle you just use the acos function of the engine.

Last edited by TriNitroToluene; 04/18/09 20:39.
Re: Get the angle of the surface of a normal. [Re: NITRO777] #261699
04/19/09 15:07
04/19/09 15:07
Joined: Jan 2007
Posts: 1,619
Germany
Scorpion Offline
Serious User
Scorpion  Offline
Serious User

Joined: Jan 2007
Posts: 1,619
Germany
vec_to_angle^^

Re: Get the angle of the surface of a normal. [Re: Scorpion] #261760
04/19/09 22:42
04/19/09 22:42
Joined: Mar 2003
Posts: 3,010
analysis paralysis
NITRO777 Offline
Expert
NITRO777  Offline
Expert

Joined: Mar 2003
Posts: 3,010
analysis paralysis
Quote:
vec_to_angle
Ok then, maybe a developer can answer what the underlying algorithm is for vec_to_angle? I want to know because the manual does not have it written. frown

I have a feeling that these will not help the original post but its difficult to see what the problem is without seeing his code in it's entirety.

Last edited by TriNitroToluene; 04/19/09 22:42.
Re: Get the angle of the surface of a normal. [Re: NITRO777] #261764
04/20/09 01:02
04/20/09 01:02
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
The Kinji Tutorials exlained this very well. It must be a good explaination in the AUMs or in a beginner workshop, too, but I don't remember where I'd seen it.

Re: Get the angle of the surface of a normal. [Re: EvilSOB] #261771
04/20/09 04:11
04/20/09 04:11
Joined: Jul 2008
Posts: 553
Singapore
delinkx Offline
User
delinkx  Offline
User

Joined: Jul 2008
Posts: 553
Singapore
as TriNitroToluene said, i just clarify it with a diagram.



as shown in the diagram P1 is the point on the surface and NORMAL is the normal vector to that point. ME is the entity from which u want to calculate the trace.

Ø is the angle between the vector from P1 to entity and NORMAL vector from P1, which is calculated by a dot product between the 2 vectors and do a cos inverse on the result.

usint this angle u can adjust ur entity.


A7 commercial Team / VC++ 2008 Pro
homepage | twitter | facebook
Re: Get the angle of the surface of a normal. [Re: delinkx] #261803
04/20/09 10:07
04/20/09 10:07
Joined: Jul 2000
Posts: 27,967
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,967
Frankfurt
If you want to keep the player's pan angle, and only adjust its tilt and roll values to the floor slope, you can just use a projection of the x and y components of the floor normal relative to the player angle:

vec_rotateback(hit.nx,vector(my.pan,0,0));
my.tilt = -asin(hit.nx);
my.roll = -asin(hit.ny);

This approach works as long as the surface is not too steep.


Re: Get the angle of the surface of a normal. [Re: jcl] #261814
04/20/09 11:27
04/20/09 11:27
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Thanx all for your answers to date. I will, in time, get back to you all regarding your suggestions.

JCL : I have tried code similar to this with no joy. (I will try this again shortly though)
But the problem Im getting IS when it get too steep, cause I need to go "right over".
What is happening when the "steepness" is so high? (I have detected this is as NZ goes negative)
As soon as NZ hits negative, both NX and NY jump by 90 or 180 degrees in some pattern I cant
decipher. Is the whole normal being rotated or flipped by 180 or something?

Can you suggest any code/concepts I can try to correct this "steepness" issue?


"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] #261864
04/20/09 19:22
04/20/09 19:22
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Just a thought, maybe, a dumb one:

When transforming an angle to a direction as it happens in a vec_for_angle instruction, isn't there one information lost? 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.

Or, is this completely off?

Probably, the vec_to_angle instruction adds a sort of 'dummy' information which works as long its all in the positive nz area, but it fails when nz gets negative. Means, we need an instruction with a different dummy information for nz = -.

Last edited by Pappenheimer; 04/20/09 19:41. Reason: Another thought
Re: Get the angle of the surface of a normal. [Re: Pappenheimer] #261867
04/20/09 19:42
04/20/09 19:42
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
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.

Last edited by DJBMASTER; 04/20/09 19:45.
Page 1 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