aboutsummaryrefslogtreecommitdiff
path: root/PhysX_3.4/Source/GeomUtils
diff options
context:
space:
mode:
Diffstat (limited to 'PhysX_3.4/Source/GeomUtils')
-rw-r--r--PhysX_3.4/Source/GeomUtils/src/GuRaycastTests.cpp4
-rw-r--r--PhysX_3.4/Source/GeomUtils/src/gjk/GuEPA.cpp6
-rw-r--r--PhysX_3.4/Source/GeomUtils/src/gjk/GuEPAFacet.h34
-rw-r--r--PhysX_3.4/Source/GeomUtils/src/hf/GuHeightField.h7
-rw-r--r--PhysX_3.4/Source/GeomUtils/src/hf/GuHeightFieldUtil.h25
-rw-r--r--PhysX_3.4/Source/GeomUtils/src/mesh/GuMidphaseRTree.cpp2
6 files changed, 45 insertions, 33 deletions
diff --git a/PhysX_3.4/Source/GeomUtils/src/GuRaycastTests.cpp b/PhysX_3.4/Source/GeomUtils/src/GuRaycastTests.cpp
index 86b7a8f8..2980bdc1 100644
--- a/PhysX_3.4/Source/GeomUtils/src/GuRaycastTests.cpp
+++ b/PhysX_3.4/Source/GeomUtils/src/GuRaycastTests.cpp
@@ -447,8 +447,8 @@ namespace
}
if(mHitFlags & PxHitFlag::eDISTANCE)
- {
- hit.distance = (hit.position - mLocalRayOrig).dot(mLocalRayDir);
+ {
+ hit.distance = physx::intrinsics::selectMax(0.f, (hit.position - mLocalRayOrig).dot(mLocalRayDir));
hit.flags |= PxHitFlag::eDISTANCE;
}
diff --git a/PhysX_3.4/Source/GeomUtils/src/gjk/GuEPA.cpp b/PhysX_3.4/Source/GeomUtils/src/gjk/GuEPA.cpp
index 5dfef1cd..066fd3ae 100644
--- a/PhysX_3.4/Source/GeomUtils/src/gjk/GuEPA.cpp
+++ b/PhysX_3.4/Source/GeomUtils/src/gjk/GuEPA.cpp
@@ -288,7 +288,8 @@ namespace Gu
{
//ML: facet isn't visible from w (we don't have a reflex edge), this facet will be on the boundary and part of the new polytope so that
//we will push it into our edgeBuffer
- edgeBuffer.Insert(f, index);
+ if(!edgeBuffer.Insert(f, index))
+ return;
}
else
{
@@ -622,7 +623,8 @@ namespace Gu
facet->silhouette(q, aBuf, bBuf, edgeBuffer, facetManager);
- if (edgeBuffer.IsEmpty())
+ //the edge buffer either empty or overflow
+ if (!edgeBuffer.IsValid())
{
calculateContactInformation(aBuf, bBuf, facet, a, b, pa, pb, normal, penDepth, takeCoreShape);
return EPA_DEGENERATE;
diff --git a/PhysX_3.4/Source/GeomUtils/src/gjk/GuEPAFacet.h b/PhysX_3.4/Source/GeomUtils/src/gjk/GuEPAFacet.h
index ae86fd16..1a6ffdb3 100644
--- a/PhysX_3.4/Source/GeomUtils/src/gjk/GuEPAFacet.h
+++ b/PhysX_3.4/Source/GeomUtils/src/gjk/GuEPAFacet.h
@@ -193,25 +193,21 @@ namespace Gu
class EdgeBuffer
{
public:
- EdgeBuffer() : m_Size(0)
+ EdgeBuffer() : m_Size(0), m_OverFlow(false)
{
}
- Edge* Insert(const Edge& edge)
- {
- PX_ASSERT(m_Size < MaxEdges);
- Edge* PX_RESTRICT pEdge = &m_pEdges[m_Size++];
- *pEdge = edge;
- return pEdge;
- }
-
Edge* Insert(Facet* PX_RESTRICT facet, const PxU32 index)
{
- PX_ASSERT(m_Size < MaxEdges);
- Edge* pEdge = &m_pEdges[m_Size++];
- pEdge->m_facet=facet;
- pEdge->m_index=index;
- return pEdge;
+ if (m_Size < MaxEdges)
+ {
+ Edge* pEdge = &m_pEdges[m_Size++];
+ pEdge->m_facet = facet;
+ pEdge->m_index = index;
+ return pEdge;
+ }
+ m_OverFlow = true;
+ return NULL;
}
Edge* Get(const PxU32 index)
@@ -225,18 +221,20 @@ namespace Gu
return m_Size;
}
- bool IsEmpty()
+ bool IsValid()
{
- return m_Size == 0;
+ return m_Size > 0 && !m_OverFlow;
}
void MakeEmpty()
{
m_Size = 0;
+ m_OverFlow = false;
}
- Edge m_pEdges[MaxEdges];
- PxU32 m_Size;
+ Edge m_pEdges[MaxEdges];
+ PxU32 m_Size;
+ bool m_OverFlow;
};
//ML: calculate MTD points for a shape pair
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);
diff --git a/PhysX_3.4/Source/GeomUtils/src/mesh/GuMidphaseRTree.cpp b/PhysX_3.4/Source/GeomUtils/src/mesh/GuMidphaseRTree.cpp
index e1d711a7..8f873379 100644
--- a/PhysX_3.4/Source/GeomUtils/src/mesh/GuMidphaseRTree.cpp
+++ b/PhysX_3.4/Source/GeomUtils/src/mesh/GuMidphaseRTree.cpp
@@ -79,7 +79,7 @@ public:
if(!intersectRayTriangle(mOrigin, mDir, vert0, vert1, vert2, hit.distance, hit.u, hit.v, !mBothSides, mGeomEpsilon))
return false;
- if(hit.distance<-mGeomEpsilon) // test if the ray intersection t is really negative
+ if(hit.distance< 0.0f) // test if the ray intersection t is negative
return false;
return true;