|
|
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
OP
Expert
|
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
Expert
|
Expert
Joined: Mar 2003
Posts: 3,010
analysis paralysis
|
Hi EvilSOB, 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?
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
Serious User
|
Serious User
Joined: Jan 2007
Posts: 1,619
Germany
|
|
|
|
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
Expert
|
Expert
Joined: Mar 2003
Posts: 3,010
analysis paralysis
|
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. 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: EvilSOB]
#261771
04/20/09 04:11
04/20/09 04:11
|
Joined: Jul 2008
Posts: 553 Singapore
delinkx
User
|
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.
|
|
|
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
OP
Expert
|
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
Senior Expert
|
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
Serious User
|
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.
|
|
|
|