diff options
| author | Sheikh Dawood <[email protected]> | 2018-08-13 13:37:04 -0500 |
|---|---|---|
| committer | Sheikh Dawood <[email protected]> | 2018-08-13 13:37:04 -0500 |
| commit | 3f9977d72f8a481e76b6ad643a3d312a8cf9b551 (patch) | |
| tree | 8dfa563cf2a06498b56b055af133bd066f1f349c /PhysX_3.4/Source/GeomUtils/src/hf | |
| parent | PhysX 3.4, APEX 1.4 patch release @24214033 (diff) | |
| download | physx-3.4-3f9977d72f8a481e76b6ad643a3d312a8cf9b551.tar.xz physx-3.4-3f9977d72f8a481e76b6ad643a3d312a8cf9b551.zip | |
PhysX 3.4, APEX 1.4 patch release @24698370
Diffstat (limited to 'PhysX_3.4/Source/GeomUtils/src/hf')
| -rw-r--r-- | PhysX_3.4/Source/GeomUtils/src/hf/GuHeightField.h | 7 | ||||
| -rw-r--r-- | PhysX_3.4/Source/GeomUtils/src/hf/GuHeightFieldUtil.h | 25 |
2 files changed, 22 insertions, 10 deletions
diff --git a/PhysX_3.4/Source/GeomUtils/src/hf/GuHeightField.h b/PhysX_3.4/Source/GeomUtils/src/hf/GuHeightField.h index 7a86d7db..64487852 100644 --- a/PhysX_3.4/Source/GeomUtils/src/hf/GuHeightField.h +++ b/PhysX_3.4/Source/GeomUtils/src/hf/GuHeightField.h @@ -102,7 +102,12 @@ public: PX_PHYSX_COMMON_API virtual PxVec3 getTriangleNormal(PxTriangleID triangleIndex) const { return getTriangleNormalInternal(triangleIndex); - } + } + PX_PHYSX_COMMON_API virtual const PxHeightFieldSample& getSample(PxU32 row, PxU32 column) const + { + const PxU32 cell = row * getNbColumnsFast() + column; + return getSample(cell); + } /** \brief Returns the number of times the heightfield data has been modified diff --git a/PhysX_3.4/Source/GeomUtils/src/hf/GuHeightFieldUtil.h b/PhysX_3.4/Source/GeomUtils/src/hf/GuHeightFieldUtil.h index d6560559..537864e8 100644 --- a/PhysX_3.4/Source/GeomUtils/src/hf/GuHeightFieldUtil.h +++ b/PhysX_3.4/Source/GeomUtils/src/hf/GuHeightFieldUtil.h @@ -683,16 +683,20 @@ namespace Gu // we need to extend the field for the inflated radius, we will now operate even with negative u|v // map p0 from (x, z, y) to (u0, v0, h0) - PxF32 u0 = PxMin(PxMax(p0.x * mOneOverRowScale, 1e-7f - expandu), nbUcells + expandu); // multiplication rescales the u,v grid steps to 1 - PxF32 v0 = PxMin(PxMax(p0.z * mOneOverColumnScale, 1e-7f - expandv), nbVcells + expandv); + // we need to use the unclamped values, otherwise we change the direction of the traversal + const PxF32 uu0 = p0.x * mOneOverRowScale; + PxF32 u0 = PxMin(PxMax(uu0, 1e-7f - expandu), nbUcells + expandu); // multiplication rescales the u,v grid steps to 1 + const PxF32 uv0 = p0.z * mOneOverColumnScale; + PxF32 v0 = PxMin(PxMax(uv0, 1e-7f - expandv), nbVcells + expandv); const PxReal h0 = p0.y; // we don't scale y // map p1 from (x, z, y) to (u1, v1, h1) - PxF32 u1 = PxMin(PxMax(p1.x * mOneOverRowScale, 1e-7f - expandu), nbUcells + expandu); - PxF32 v1 = PxMin(PxMax(p1.z * mOneOverColumnScale, 1e-7f - expandv), nbVcells + expandv); + // we need to use the unclamped values, otherwise we change the direction of the traversal + const PxF32 uu1 = p1.x * mOneOverRowScale; + const PxF32 uv1 = p1.z * mOneOverColumnScale; const PxReal h1 = p1.y; // we don't scale y - PxF32 du = u1 - u0, dv = v1 - v0; // recompute du, dv from adjusted uvs + PxF32 du = uu1 - uu0, dv = uv1 - uv0; // recompute du, dv from adjusted uvs const PxReal dh = h1 - h0; // grid u&v step is always either 1 or -1, we precompute as both integers and floats to avoid conversions @@ -731,10 +735,13 @@ namespace Gu const PxReal vhit0 = dv > 0.0f ? ceilUp(v0) : floorDown(v0); // tu, tv can be > 1 but since the loop is structured as do {} while(tMin < tEnd) we still visit the first cell - PxF32 last_tu = 0.0f, last_tv = 0.0f; - PxReal tu = (uhit0 - u0) / du; - PxReal tv = (vhit0 - v0) / dv; - PX_ASSERT(tu >= 0.0f && tv >= 0.0f); + PxF32 last_tu = 0.0f, last_tv = 0.0f; + PxReal tu = (uhit0 - uu0) / du; + PxReal tv = (vhit0 - uv0) / dv; + if(tu < 0.0f) // negative value may happen, as we may have started out of the AABB (since we did enlarge it) + tu = PxAbs(clampEps / du); + if(tv < 0.0f) // negative value may happen, as we may have started out of the AABB (since we did enlarge it) + tv = PxAbs(clampEps / dv); // compute step_tu and step_tv; t steps per grid cell in u and v direction const PxReal step_tu = 1.0f / PxAbs(du), step_tv = 1.0f / PxAbs(dv); |