aboutsummaryrefslogtreecommitdiff
path: root/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullLib.cpp
diff options
context:
space:
mode:
authorsschirm <[email protected]>2017-01-06 14:45:46 +0100
committersschirm <[email protected]>2017-01-06 14:45:46 +0100
commitc7a921796332e8fcd51f3e05c1a318a41282e1e2 (patch)
tree770db0c76e954045fe5178a36a7519b26df6942a /PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullLib.cpp
parentPhysX 3.4, APEX 1.4 release candidate update: @21511067-21511214 (diff)
downloadphysx-3.4-c7a921796332e8fcd51f3e05c1a318a41282e1e2.tar.xz
physx-3.4-c7a921796332e8fcd51f3e05c1a318a41282e1e2.zip
PhysX 3.4, APEX 1.4 release candidate update: @21542069
Diffstat (limited to 'PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullLib.cpp')
-rw-r--r--PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullLib.cpp57
1 files changed, 55 insertions, 2 deletions
diff --git a/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullLib.cpp b/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullLib.cpp
index 92ffc888..90e8a66b 100644
--- a/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullLib.cpp
+++ b/PhysX_3.4/Source/PhysXCooking/src/convex/ConvexHullLib.cpp
@@ -23,7 +23,7 @@
// components in life support devices or systems without express written approval of
// NVIDIA Corporation.
//
-// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved.
+// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
@@ -127,12 +127,62 @@ namespace local
}
+
+//////////////////////////////////////////////////////////////////////////
+// shift vertices around origin and normalize point cloud, remove duplicates!
+bool ConvexHullLib::shiftAndcleanupVertices(PxU32 svcount, const PxVec3* svertices, PxU32 stride,
+ PxU32& vcount, PxVec3* vertices, PxVec3& scale, PxVec3& center)
+{
+ mShiftedVerts = reinterpret_cast<PxVec3*> (PX_ALLOC_TEMP(sizeof(PxVec3)*svcount, "PxVec3"));
+ const char* vtx = reinterpret_cast<const char *> (svertices);
+ PxBounds3 bounds;
+ bounds.setEmpty();
+
+ // get the bounding box
+ for (PxU32 i = 0; i < svcount; i++)
+ {
+ const PxVec3& p = *reinterpret_cast<const PxVec3 *> (vtx);
+ vtx += stride;
+
+ bounds.include(p);
+ }
+ mOriginShift = bounds.getCenter();
+ vtx = reinterpret_cast<const char *> (svertices);
+ for (PxU32 i = 0; i < svcount; i++)
+ {
+ const PxVec3& p = *reinterpret_cast<const PxVec3 *> (vtx);
+ vtx += stride;
+
+ mShiftedVerts[i] = p - mOriginShift;
+ }
+ return cleanupVertices(svcount, mShiftedVerts, sizeof(PxVec3), vcount, vertices, scale, center);
+}
+
+//////////////////////////////////////////////////////////////////////////
+// Shift verts/planes in the desc back
+void ConvexHullLib::shiftConvexMeshDesc(PxConvexMeshDesc& desc)
+{
+ PX_ASSERT(mConvexMeshDesc.flags & PxConvexFlag::eSHIFT_VERTICES);
+
+ PxVec3* points = reinterpret_cast<PxVec3*>(const_cast<void*>(desc.points.data));
+ for(PxU32 i = 0; i < desc.points.count; i++)
+ {
+ points[i] = points[i] + mOriginShift;
+ }
+
+ PxHullPolygon* polygons = reinterpret_cast<PxHullPolygon*>(const_cast<void*>(desc.polygons.data));
+ for(PxU32 i = 0; i < desc.polygons.count; i++)
+ {
+ polygons[i].mPlane[3] -= PxVec3(polygons[i].mPlane[0], polygons[i].mPlane[1], polygons[i].mPlane[2]).dot(mOriginShift);
+ }
+}
+
//////////////////////////////////////////////////////////////////////////
// normalize point cloud, remove duplicates!
bool ConvexHullLib::cleanupVertices(PxU32 svcount, const PxVec3* svertices, PxU32 stride,
PxU32& vcount, PxVec3* vertices, PxVec3& scale, PxVec3& center)
{
- if ( svcount == 0 )
+ if (svcount == 0)
return false;
const PxVec3* verticesToClean = svertices;
@@ -296,4 +346,7 @@ ConvexHullLib::~ConvexHullLib()
{
if (mSwappedIndices)
PX_FREE(mSwappedIndices);
+
+ if(mShiftedVerts)
+ PX_FREE(mShiftedVerts);
}