reactphysics3d icon indicating copy to clipboard operation
reactphysics3d copied to clipboard

Heightfield inverted winding order?

Open naluhh opened this issue 5 years ago • 3 comments

Raycasting won't return a collision if you try to recast top-down because of winding order. (using z-up). Raycasting bottom-up worked as expected.

It was confusing to me.

Heightfield created like this: float heightmap = new float[4]; heightmap[0] = 0.0f; heightmap[1] = 0.0f; heightmap[2] = 0.0f; heightmap[3] = 0.0f;

HeightFieldShape(2, 2, 0.f, 0.f, heightmap, reactphysics3d::HeightFieldShape::HeightDataType::HEIGHT_FLOAT_TYPE, 2 /*2 for z up */)

naluhh avatar Feb 11 '20 15:02 naluhh

By default, raycasting on HeightFieldShape and ConcaveMeshShape is only done on the front face of the triangles. Note that the front face is the one as seen from the outside of the mesh when the winding order is counter clock-wise (as seen from outside the of mesh). The outside of the HeightFieldShape is the top side.

If you want to raycast against the back or even the front and back of the triangles, you can use the setRaycastTestType() method on the HeightFieldShape to change that.

I hope this helps.

DanielChappuis avatar Feb 13 '20 09:02 DanielChappuis

This helps, thanks. But according to what you are saying, if I use the default raycastside, it should intersect properly when raycasting top down. I found it to not be the case. (maybe I did something wrong?)

Two other things were a bit confusing to me: -The size of the Heightfield is related to the size of the texture. I would have expected it to be 1 by 1 whatever the texture is. Right now I end up doing a scaling of target_surface_size / pixel_count. -The 0 altitude is located at (min_altitude + max_altitude) * 0.5. I would have expected it to be 0.

naluhh avatar Feb 13 '20 09:02 naluhh

@naluhh Was it your experience that the collisions and raycasting results used opposite culling rules?

HugoPeters1024 avatar Apr 06 '20 15:04 HugoPeters1024