Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to handle terrain holes?
#6
(04-09-2024, 11:04 PM)btduser Wrote: This means that at height zero it results in 0 * -1 = -0 which is not <0 as you point out. I changed the logic to instead just assign the height value if there is solid terrain, or a constant -1 if there is a hole, and it seems to behave as expected. Is this a viable solution or are there any negative implications of this I'm not aware of?

Hi,

This will break collision detection in all cases, except when all surrounding neighbors of the hole (as well as the hole itself) have a height of 1. The reason is the terrain's collision geometry is built as quads, whose vertices' heights are read from the height map. So even if a quad if marked as a hole (its first sample having a negative height) we still need the actual height value for its neighbor quads to be correct, that's why we take the absolute value of the heights for building the quads after testing for holes:

Code:
if (h1 < 0) continue; // this would be a hole, skip quad
h1 = math.abs(h1);
h2 = math.abs(h2);
h3 = math.abs(h3);
h4 = math.abs(h4);

Let's say this happens on flat terrain, all samples having a height of 5. This quad's h1 (bottom left) sample is also its bottom left neighbor's top right sample. If h1 is -1 the current quad will be ignored, however the bottom left neighbor will have its top right corner incorrectly slanted down towards 1, yielding incorrect collision geometry around the hole. This is a crude diagram of the problem, "H" would be the current quad which is a hole, and "T" would be its bottom left neighbor which is solid terrain:

Code:
Incorrect:
       5-----5
       |  H  |   
5-----1-----5
|  T  |     
5-----5

Correct:
       5-----5
       |  H  |   
5-----5-----5
|  T  |     
5-----5


kind regards,
Reply


Messages In This Thread
How to handle terrain holes? - by btduser - 04-09-2024, 04:55 PM
RE: How to handle terrain holes? - by josemendez - 04-09-2024, 07:38 PM
RE: How to handle terrain holes? - by btduser - 04-09-2024, 08:34 PM
RE: How to handle terrain holes? - by josemendez - 04-09-2024, 10:35 PM
RE: How to handle terrain holes? - by btduser - 04-09-2024, 11:04 PM
RE: How to handle terrain holes? - by josemendez - 05-09-2024, 07:53 AM
RE: How to handle terrain holes? - by btduser - 05-09-2024, 02:28 PM
RE: How to handle terrain holes? - by josemendez - 06-09-2024, 07:56 AM