Archived

This topic is now archived and is closed to further replies.

djwarder

Terrain Slope ...

Recommended Posts

Hi again At the moment, on my current project, I''m reading in the world mesh, generating face normals and measuring their angle to a up vector (0,1,0) and testing to see if the slope is over 60 degrees then''s it not walkable, else it can be part of the NavMesh. BUT, the code doesn''t work. The normals seem ok, the angle code is solid, and then convertion from RAD to DEG is fine, so what''s wrong??? Any ideas? Has anyone got any code that could help, please?? Cheers y''all Dan

Share this post


Link to post
Share on other sites
If it doesn''t work, than something *must* be wrong, even if it *seems* ok... Without any code, our guesses are as good as yours. If you post your code, maybe we''ll spot something that you overlooked. In any case, goodluck solving the bug..

Michael K.,
Co-designer and Graphics Programmer of "The Keepers"



We come in peace... surrender or die!

Share this post


Link to post
Share on other sites
You are testing to see if the y component of the surface normal vector is < cos(60'') (=0.5) right?

If so:
Are your normals correct? Are they normalized? Can you do a lighting test on them and show the results?

-Michael

Share this post


Link to post
Share on other sites
Hi again

Basically, I''m working out a face normal vector from the 3 vertices of the triangle face, then creating a vector pointing vertical (0,1,0), then comparing the two by normalising both vectors, finding the dot product of the two and using arccos on the result, i.e (psuedocode)


vector3d normal = {...};
vector3d up = {0.00, 1.00, 0.00};

NormaliseVector(&normal);
NormaliseVector(&up);

double angle = arccos(DotProduct(&normal, &up));

if(angle > 60.00)
{
// Not Walkable ...
}
else
{
// Walkable ...}

Any thoughts??

Share this post


Link to post
Share on other sites
Not much information there... The pseudo code is fine, although it can be optimized a bit. But ultimately, it's not the pseudocode that's not working. No offense, but you are giving us very little information, and asking us to help you. All we can do with the information you've given us is to make wild guesses, which are unlikely to help you much. For example, "the code doesn't work" is not very informative. What exactly is the behavior you're getting? Also, your *actual* code can be handy.. help us help you - give us more info.

[sidenote]
A couple of optimizations:
1. You do not need to take the arccosine of the angle (which is expensive) - you can compare the cosines directly (the cosine of 60 dgrees is excactly 0.5).
2. Since you're comparing with the vector (0,1,0), you don't even need to take the dot product - your normalized normal's y coordinate equals the cosine of the angle.

conclusion: do "if (normalize(normal).y > 0.5) {not walkable} ...".
[/sidenote]

Michael K.,
Co-designer and Graphics Programmer of "The Keepers"



We come in peace... surrender or die!

[edited by - technobot on November 15, 2003 10:03:38 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by djwarder
would a snippet of code or the whole .cpp help??

Just the parts where you calculate the normals and the angle, and where you do your check.


Btw, a small correction - since the cosine gets smaller when the angle gets larger, my pseudo code should have been "if (normalize(normal).y < 0.5) {not walkable} ...". Also, if you don''t need the normalized normal for anything else (e.g. for lighting), you can divide only the y component by the length, rather than normalizing the whole normal.

Michael K.,
Co-designer and Graphics Programmer of "The Keepers"



We come in peace... surrender or die!

Share this post


Link to post
Share on other sites