From 3cb80ad1a3036e4ce8e2e92bca7c6a869c7c8d58 Mon Sep 17 00:00:00 2001 From: erwin coumans Date: Tue, 16 Apr 2013 17:13:38 -0700 Subject: [PATCH] more bt->b3* --- btgui/GwenOpenGLTest/Apple/premake4.lua | 4 +- btgui/GwenOpenGLTest/premake4.lua | 4 +- btgui/OpenGLWindow/premake4.lua | 4 +- demo/gpudemo/premake4.lua | 4 +- .../host/b3ConvexHullContact.cpp | 2 +- .../gpu_narrowphase/host/b3ConvexUtility.cpp | 12 +- .../gpu_narrowphase/host/b3OptimizedBvh.cpp | 2 +- .../gpu_narrowphase/host/b3QuantizedBvh.cpp | 2 +- .../gpu_rigidbody/host/b3GpuNarrowPhase.cpp | 2 +- .../host/b3GpuRigidBodyPipeline.cpp | 2 +- .../{btAabbUtil2.h => b3AabbUtil.h} | 0 ...lComputer.cpp => b3ConvexHullComputer.cpp} | 4 +- ...xHullComputer.h => b3ConvexHullComputer.h} | 4 +- ...{btGeometryUtil.cpp => b3GeometryUtil.cpp} | 10 +- .../{btGeometryUtil.h => b3GeometryUtil.h} | 4 +- ...onvexHull.h => b3GrahamScan2dConvexHull.h} | 0 src/BulletGeometry/btConvexHull.cpp | 1167 ----------------- src/BulletGeometry/btConvexHull.h | 241 ---- src/BulletGeometry/btPolarDecomposition.cpp | 99 -- src/BulletGeometry/btPolarDecomposition.h | 73 -- 20 files changed, 30 insertions(+), 1610 deletions(-) rename src/BulletGeometry/{btAabbUtil2.h => b3AabbUtil.h} (100%) rename src/BulletGeometry/{btConvexHullComputer.cpp => b3ConvexHullComputer.cpp} (99%) rename src/BulletGeometry/{btConvexHullComputer.h => b3ConvexHullComputer.h} (98%) rename src/BulletGeometry/{btGeometryUtil.cpp => b3GeometryUtil.cpp} (94%) rename src/BulletGeometry/{btGeometryUtil.h => b3GeometryUtil.h} (95%) rename src/BulletGeometry/{btGrahamScan2dConvexHull.h => b3GrahamScan2dConvexHull.h} (100%) delete mode 100644 src/BulletGeometry/btConvexHull.cpp delete mode 100644 src/BulletGeometry/btConvexHull.h delete mode 100644 src/BulletGeometry/btPolarDecomposition.cpp delete mode 100644 src/BulletGeometry/btPolarDecomposition.h diff --git a/btgui/GwenOpenGLTest/Apple/premake4.lua b/btgui/GwenOpenGLTest/Apple/premake4.lua index 62cacb75b..ea6081c49 100644 --- a/btgui/GwenOpenGLTest/Apple/premake4.lua +++ b/btgui/GwenOpenGLTest/Apple/premake4.lua @@ -37,8 +37,8 @@ "../../../OpenGLTrueTypeFont/fontstash.h", "../../../OpenGLTrueTypeFont/opengl_fontstashcallbacks.cpp", "../../../OpenGLTrueTypeFont/opengl_fontstashcallbacks.h", - "../../../../bullet2/LinearMath/btConvexHullComputer.cpp", - "../../../../bullet2/LinearMath/btConvexHullComputer.h", + "../../../../bullet2/LinearMath/b3ConvexHullComputer.cpp", + "../../../../bullet2/LinearMath/b3ConvexHullComputer.h", "../../../../bullet2/LinearMath/btSerializer.cpp", "../../../../bullet2/LinearMath/btSerializer.h", "../../../../bullet2/LinearMath/b3AlignedAllocator.cpp", diff --git a/btgui/GwenOpenGLTest/premake4.lua b/btgui/GwenOpenGLTest/premake4.lua index dfaefd378..011073183 100644 --- a/btgui/GwenOpenGLTest/premake4.lua +++ b/btgui/GwenOpenGLTest/premake4.lua @@ -37,8 +37,8 @@ "../OpenGLTrueTypeFont/fontstash.h", "../OpenGLTrueTypeFont/opengl_fontstashcallbacks.cpp", "../OpenGLTrueTypeFont/opengl_fontstashcallbacks.h", - "../../src/BulletGeometry/btConvexHullComputer.cpp", - "../../src/BulletGeometry/btConvexHullComputer.h", + "../../src/BulletGeometry/b3ConvexHullComputer.cpp", + "../../src/BulletGeometry/b3ConvexHullComputer.h", "../../src/BulletCommon/b3AlignedAllocator.cpp", "../../src/BulletCommon/b3Quickprof.cpp", "../../src/BulletCommon/b3Quickprof.h", diff --git a/btgui/OpenGLWindow/premake4.lua b/btgui/OpenGLWindow/premake4.lua index 97bb3dc72..405da77db 100644 --- a/btgui/OpenGLWindow/premake4.lua +++ b/btgui/OpenGLWindow/premake4.lua @@ -41,8 +41,8 @@ "../OpenGLTrueTypeFont/fontstash.h", "../OpenGLTrueTypeFont/opengl_fontstashcallbacks.cpp", "../OpenGLTrueTypeFont/opengl_fontstashcallbacks.h", - "../../src/BulletGeometry/btConvexHullComputer.cpp", - "../../src/BulletGeometry/btConvexHullComputer.h", + "../../src/BulletGeometry/b3ConvexHullComputer.cpp", + "../../src/BulletGeometry/b3ConvexHullComputer.h", "../../src/BulletCommon/b3AlignedAllocator.cpp", "../../src/BulletCommon/b3Quickprof.cpp", "../../src/BulletCommon/b3Quickprof.h" diff --git a/demo/gpudemo/premake4.lua b/demo/gpudemo/premake4.lua index d2aad4e8f..491f0461d 100644 --- a/demo/gpudemo/premake4.lua +++ b/demo/gpudemo/premake4.lua @@ -45,8 +45,8 @@ function createProject(vendor) "../../src/BulletCommon/b3AlignedAllocator.h", "../../src/BulletCommon/b3Quickprof.cpp", "../../src/BulletCommon/b3Quickprof.h", - "../../src/BulletGeometry/btConvexHullComputer.cpp", - "../../src/BulletGeometry/btConvexHullComputer.h", + "../../src/BulletGeometry/b3ConvexHullComputer.cpp", + "../../src/BulletGeometry/b3ConvexHullComputer.h", "../../btgui/OpenGLWindow/GLInstancingRenderer.cpp", "../../btgui/OpenGLWindow/GLInstancingRenderer.h", diff --git a/opencl/gpu_narrowphase/host/b3ConvexHullContact.cpp b/opencl/gpu_narrowphase/host/b3ConvexHullContact.cpp index a80399497..69e2de270 100644 --- a/opencl/gpu_narrowphase/host/b3ConvexHullContact.cpp +++ b/opencl/gpu_narrowphase/host/b3ConvexHullContact.cpp @@ -38,7 +38,7 @@ typedef b3AlignedObjectArray btVertexArray; #include "../kernels/bvhTraversal.h" #include "../kernels/primitiveContacts.h" -#include "BulletGeometry/btAabbUtil2.h" +#include "BulletGeometry/b3AabbUtil.h" #define dot3F4 btDot diff --git a/opencl/gpu_narrowphase/host/b3ConvexUtility.cpp b/opencl/gpu_narrowphase/host/b3ConvexUtility.cpp index 510dd7667..248724901 100644 --- a/opencl/gpu_narrowphase/host/b3ConvexUtility.cpp +++ b/opencl/gpu_narrowphase/host/b3ConvexUtility.cpp @@ -15,8 +15,8 @@ subject to the following restrictions: #include "b3ConvexUtility.h" -#include "BulletGeometry/btConvexHullComputer.h" -#include "BulletGeometry/btGrahamScan2dConvexHull.h" +#include "BulletGeometry/b3ConvexHullComputer.h" +#include "BulletGeometry/b3GrahamScan2dConvexHull.h" #include "BulletCommon/b3Quaternion.h" #include "BulletCommon/b3HashMap.h" @@ -33,13 +33,13 @@ bool b3ConvexUtility::initializePolyhedralFeatures(const b3Vector3* orgVertices, - btConvexHullComputer conv; + b3ConvexHullComputer conv; conv.compute(&orgVertices[0].getX(), sizeof(b3Vector3),numPoints,0.f,0.f); b3AlignedObjectArray faceNormals; int numFaces = conv.faces.size(); faceNormals.resize(numFaces); - btConvexHullComputer* convexUtil = &conv; + b3ConvexHullComputer* convexUtil = &conv; b3AlignedObjectArray tmpFaces; @@ -57,8 +57,8 @@ bool b3ConvexUtility::initializePolyhedralFeatures(const b3Vector3* orgVertices, { int face = convexUtil->faces[i]; //printf("face=%d\n",face); - const btConvexHullComputer::Edge* firstEdge = &convexUtil->edges[face]; - const btConvexHullComputer::Edge* edge = firstEdge; + const b3ConvexHullComputer::Edge* firstEdge = &convexUtil->edges[face]; + const b3ConvexHullComputer::Edge* edge = firstEdge; b3Vector3 edges[3]; int numEdges = 0; diff --git a/opencl/gpu_narrowphase/host/b3OptimizedBvh.cpp b/opencl/gpu_narrowphase/host/b3OptimizedBvh.cpp index a220a3425..c7536d20d 100644 --- a/opencl/gpu_narrowphase/host/b3OptimizedBvh.cpp +++ b/opencl/gpu_narrowphase/host/b3OptimizedBvh.cpp @@ -16,7 +16,7 @@ subject to the following restrictions: #include "b3OptimizedBvh.h" #include "b3StridingMeshInterface.h" -#include "BulletGeometry/btAabbUtil2.h" +#include "BulletGeometry/b3AabbUtil.h" b3OptimizedBvh::b3OptimizedBvh() diff --git a/opencl/gpu_narrowphase/host/b3QuantizedBvh.cpp b/opencl/gpu_narrowphase/host/b3QuantizedBvh.cpp index c5a99f664..ba278e317 100644 --- a/opencl/gpu_narrowphase/host/b3QuantizedBvh.cpp +++ b/opencl/gpu_narrowphase/host/b3QuantizedBvh.cpp @@ -15,7 +15,7 @@ subject to the following restrictions: #include "b3QuantizedBvh.h" -#include "BulletGeometry/btAabbUtil2.h" +#include "BulletGeometry/b3AabbUtil.h" #define RAYAABB2 diff --git a/opencl/gpu_rigidbody/host/b3GpuNarrowPhase.cpp b/opencl/gpu_rigidbody/host/b3GpuNarrowPhase.cpp index ce12c2915..028a06646 100644 --- a/opencl/gpu_rigidbody/host/b3GpuNarrowPhase.cpp +++ b/opencl/gpu_rigidbody/host/b3GpuNarrowPhase.cpp @@ -9,7 +9,7 @@ #include "b3Config.h" #include "../../gpu_narrowphase/host/b3OptimizedBvh.h" #include "../../gpu_narrowphase/host/b3TriangleIndexVertexArray.h" -#include "BulletGeometry/btAabbUtil2.h" +#include "BulletGeometry/b3AabbUtil.h" struct btGpuNarrowPhaseInternalData { diff --git a/opencl/gpu_rigidbody/host/b3GpuRigidBodyPipeline.cpp b/opencl/gpu_rigidbody/host/b3GpuRigidBodyPipeline.cpp index 0a434bbdf..0a83e3fd5 100644 --- a/opencl/gpu_rigidbody/host/b3GpuRigidBodyPipeline.cpp +++ b/opencl/gpu_rigidbody/host/b3GpuRigidBodyPipeline.cpp @@ -5,7 +5,7 @@ #include "../../basic_initialize/b3OpenCLUtils.h" #include "b3GpuNarrowPhase.h" -#include "BulletGeometry/btAabbUtil2.h" +#include "BulletGeometry/b3AabbUtil.h" #include "../../gpu_broadphase/host/b3SapAabb.h" #include "../../gpu_broadphase/host/b3GpuSapBroadphase.h" #include "parallel_primitives/host/btLauncherCL.h" diff --git a/src/BulletGeometry/btAabbUtil2.h b/src/BulletGeometry/b3AabbUtil.h similarity index 100% rename from src/BulletGeometry/btAabbUtil2.h rename to src/BulletGeometry/b3AabbUtil.h diff --git a/src/BulletGeometry/btConvexHullComputer.cpp b/src/BulletGeometry/b3ConvexHullComputer.cpp similarity index 99% rename from src/BulletGeometry/btConvexHullComputer.cpp rename to src/BulletGeometry/b3ConvexHullComputer.cpp index 14103d701..734c27dfe 100644 --- a/src/BulletGeometry/btConvexHullComputer.cpp +++ b/src/BulletGeometry/b3ConvexHullComputer.cpp @@ -14,7 +14,7 @@ subject to the following restrictions: #include -#include "btConvexHullComputer.h" +#include "b3ConvexHullComputer.h" #include "BulletCommon/b3AlignedObjectArray.h" #include "BulletCommon/b3MinMax.h" #include "BulletCommon/b3Vector3.h" @@ -2638,7 +2638,7 @@ static int getVertexCopy(btConvexHullInternal::Vertex* vertex, b3AlignedObjectAr return index; } -b3Scalar btConvexHullComputer::compute(const void* coords, bool doubleCoords, int stride, int count, b3Scalar shrink, b3Scalar shrinkClamp) +b3Scalar b3ConvexHullComputer::compute(const void* coords, bool doubleCoords, int stride, int count, b3Scalar shrink, b3Scalar shrinkClamp) { if (count <= 0) { diff --git a/src/BulletGeometry/btConvexHullComputer.h b/src/BulletGeometry/b3ConvexHullComputer.h similarity index 98% rename from src/BulletGeometry/btConvexHullComputer.h rename to src/BulletGeometry/b3ConvexHullComputer.h index 63bc5405c..1b64c4006 100644 --- a/src/BulletGeometry/btConvexHullComputer.h +++ b/src/BulletGeometry/b3ConvexHullComputer.h @@ -21,7 +21,7 @@ subject to the following restrictions: /// Convex hull implementation based on Preparata and Hong /// See http://code.google.com/p/bullet/issues/detail?id=275 /// Ole Kniemeyer, MAXON Computer GmbH -class btConvexHullComputer +class b3ConvexHullComputer { private: b3Scalar compute(const void* coords, bool doubleCoords, int stride, int count, b3Scalar shrink, b3Scalar shrinkClamp); @@ -35,7 +35,7 @@ class btConvexHullComputer int reverse; int targetVertex; - friend class btConvexHullComputer; + friend class b3ConvexHullComputer; public: int getSourceVertex() const diff --git a/src/BulletGeometry/btGeometryUtil.cpp b/src/BulletGeometry/b3GeometryUtil.cpp similarity index 94% rename from src/BulletGeometry/btGeometryUtil.cpp rename to src/BulletGeometry/b3GeometryUtil.cpp index 93f15148c..a9d93ffbe 100644 --- a/src/BulletGeometry/btGeometryUtil.cpp +++ b/src/BulletGeometry/b3GeometryUtil.cpp @@ -14,7 +14,7 @@ subject to the following restrictions: -#include "btGeometryUtil.h" +#include "b3GeometryUtil.h" /* @@ -30,7 +30,7 @@ extern "C" } -bool btGeometryUtil::isPointInsidePlanes(const b3AlignedObjectArray& planeEquations, const b3Vector3& point, b3Scalar margin) +bool b3GeometryUtil::isPointInsidePlanes(const b3AlignedObjectArray& planeEquations, const b3Vector3& point, b3Scalar margin) { int numbrushes = planeEquations.size(); for (int i=0;i& } -bool btGeometryUtil::areVerticesBehindPlane(const b3Vector3& planeNormal, const b3AlignedObjectArray& vertices, b3Scalar margin) +bool b3GeometryUtil::areVerticesBehindPlane(const b3Vector3& planeNormal, const b3AlignedObjectArray& vertices, b3Scalar margin) { int numvertices = vertices.size(); for (int i=0;i& vertices, b3AlignedObjectArray& planeEquationsOut ) +void b3GeometryUtil::getPlaneEquationsFromVertices(b3AlignedObjectArray& vertices, b3AlignedObjectArray& planeEquationsOut ) { const int numvertices = vertices.size(); // brute force: @@ -126,7 +126,7 @@ void btGeometryUtil::getPlaneEquationsFromVertices(b3AlignedObjectArray& planeEquations , b3AlignedObjectArray& verticesOut ) +void b3GeometryUtil::getVerticesFromPlaneEquations(const b3AlignedObjectArray& planeEquations , b3AlignedObjectArray& verticesOut ) { const int numbrushes = planeEquations.size(); // brute force: diff --git a/src/BulletGeometry/btGeometryUtil.h b/src/BulletGeometry/b3GeometryUtil.h similarity index 95% rename from src/BulletGeometry/btGeometryUtil.h rename to src/BulletGeometry/b3GeometryUtil.h index 6a0298370..921accc87 100644 --- a/src/BulletGeometry/btGeometryUtil.h +++ b/src/BulletGeometry/b3GeometryUtil.h @@ -19,8 +19,8 @@ subject to the following restrictions: #include "BulletCommon/b3Vector3.h" #include "BulletCommon/b3AlignedObjectArray.h" -///The btGeometryUtil helper class provides a few methods to convert between plane equations and vertices. -class btGeometryUtil +///The b3GeometryUtil helper class provides a few methods to convert between plane equations and vertices. +class b3GeometryUtil { public: diff --git a/src/BulletGeometry/btGrahamScan2dConvexHull.h b/src/BulletGeometry/b3GrahamScan2dConvexHull.h similarity index 100% rename from src/BulletGeometry/btGrahamScan2dConvexHull.h rename to src/BulletGeometry/b3GrahamScan2dConvexHull.h diff --git a/src/BulletGeometry/btConvexHull.cpp b/src/BulletGeometry/btConvexHull.cpp deleted file mode 100644 index 8786af3f1..000000000 --- a/src/BulletGeometry/btConvexHull.cpp +++ /dev/null @@ -1,1167 +0,0 @@ -/* -Stan Melax Convex Hull Computation -Copyright (c) 2003-2006 Stan Melax http://www.melax.com/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - -#include - -#include "btConvexHull.h" -#include "BulletCommon/b3AlignedObjectArray.h" -#include "BulletCommon/b3MinMax.h" -#include "BulletCommon/b3Vector3.h" - - - - - -//---------------------------------- - -class int3 -{ -public: - int x,y,z; - int3(){}; - int3(int _x,int _y, int _z){x=_x;y=_y;z=_z;} - const int& operator[](int i) const {return (&x)[i];} - int& operator[](int i) {return (&x)[i];} -}; - - -//------- btPlane ---------- - - -inline btPlane PlaneFlip(const btPlane &plane){return btPlane(-plane.normal,-plane.dist);} -inline int operator==( const btPlane &a, const btPlane &b ) { return (a.normal==b.normal && a.dist==b.dist); } -inline int coplanar( const btPlane &a, const btPlane &b ) { return (a==b || a==PlaneFlip(b)); } - - -//--------- Utility Functions ------ - -b3Vector3 PlaneLineIntersection(const btPlane &plane, const b3Vector3 &p0, const b3Vector3 &p1); -b3Vector3 PlaneProject(const btPlane &plane, const b3Vector3 &point); - -b3Vector3 ThreePlaneIntersection(const btPlane &p0,const btPlane &p1, const btPlane &p2); -b3Vector3 ThreePlaneIntersection(const btPlane &p0,const btPlane &p1, const btPlane &p2) -{ - b3Vector3 N1 = p0.normal; - b3Vector3 N2 = p1.normal; - b3Vector3 N3 = p2.normal; - - b3Vector3 n2n3; n2n3 = N2.cross(N3); - b3Vector3 n3n1; n3n1 = N3.cross(N1); - b3Vector3 n1n2; n1n2 = N1.cross(N2); - - b3Scalar quotient = (N1.dot(n2n3)); - - btAssert(btFabs(quotient) > b3Scalar(0.000001)); - - quotient = b3Scalar(-1.) / quotient; - n2n3 *= p0.dist; - n3n1 *= p1.dist; - n1n2 *= p2.dist; - b3Vector3 potentialVertex = n2n3; - potentialVertex += n3n1; - potentialVertex += n1n2; - potentialVertex *= quotient; - - b3Vector3 result(potentialVertex.getX(),potentialVertex.getY(),potentialVertex.getZ()); - return result; - -} - -b3Scalar DistanceBetweenLines(const b3Vector3 &ustart, const b3Vector3 &udir, const b3Vector3 &vstart, const b3Vector3 &vdir, b3Vector3 *upoint=NULL, b3Vector3 *vpoint=NULL); -b3Vector3 TriNormal(const b3Vector3 &v0, const b3Vector3 &v1, const b3Vector3 &v2); -b3Vector3 NormalOf(const b3Vector3 *vert, const int n); - - -b3Vector3 PlaneLineIntersection(const btPlane &plane, const b3Vector3 &p0, const b3Vector3 &p1) -{ - // returns the point where the line p0-p1 intersects the plane n&d - static b3Vector3 dif; - dif = p1-p0; - b3Scalar dn= btDot(plane.normal,dif); - b3Scalar t = -(plane.dist+btDot(plane.normal,p0) )/dn; - return p0 + (dif*t); -} - -b3Vector3 PlaneProject(const btPlane &plane, const b3Vector3 &point) -{ - return point - plane.normal * (btDot(point,plane.normal)+plane.dist); -} - -b3Vector3 TriNormal(const b3Vector3 &v0, const b3Vector3 &v1, const b3Vector3 &v2) -{ - // return the normal of the triangle - // inscribed by v0, v1, and v2 - b3Vector3 cp=btCross(v1-v0,v2-v1); - b3Scalar m=cp.length(); - if(m==0) return b3Vector3(1,0,0); - return cp*(b3Scalar(1.0)/m); -} - - -b3Scalar DistanceBetweenLines(const b3Vector3 &ustart, const b3Vector3 &udir, const b3Vector3 &vstart, const b3Vector3 &vdir, b3Vector3 *upoint, b3Vector3 *vpoint) -{ - static b3Vector3 cp; - cp = btCross(udir,vdir).normalized(); - - b3Scalar distu = -btDot(cp,ustart); - b3Scalar distv = -btDot(cp,vstart); - b3Scalar dist = (b3Scalar)fabs(distu-distv); - if(upoint) - { - btPlane plane; - plane.normal = btCross(vdir,cp).normalized(); - plane.dist = -btDot(plane.normal,vstart); - *upoint = PlaneLineIntersection(plane,ustart,ustart+udir); - } - if(vpoint) - { - btPlane plane; - plane.normal = btCross(udir,cp).normalized(); - plane.dist = -btDot(plane.normal,ustart); - *vpoint = PlaneLineIntersection(plane,vstart,vstart+vdir); - } - return dist; -} - - - - - - - -#define COPLANAR (0) -#define UNDER (1) -#define OVER (2) -#define SPLIT (OVER|UNDER) -#define PAPERWIDTH (b3Scalar(0.001)) - -b3Scalar planetestepsilon = PAPERWIDTH; - - - -typedef ConvexH::HalfEdge HalfEdge; - -ConvexH::ConvexH(int vertices_size,int edges_size,int facets_size) -{ - vertices.resize(vertices_size); - edges.resize(edges_size); - facets.resize(facets_size); -} - - -int PlaneTest(const btPlane &p, const b3Vector3 &v); -int PlaneTest(const btPlane &p, const b3Vector3 &v) { - b3Scalar a = btDot(v,p.normal)+p.dist; - int flag = (a>planetestepsilon)?OVER:((a<-planetestepsilon)?UNDER:COPLANAR); - return flag; -} - -int SplitTest(ConvexH &convex,const btPlane &plane); -int SplitTest(ConvexH &convex,const btPlane &plane) { - int flag=0; - for(int i=0;i -int maxdirfiltered(const T *p,int count,const T &dir,b3AlignedObjectArray &allow) -{ - btAssert(count); - int m=-1; - for(int i=0;ibtDot(p[m],dir)) - m=i; - } - btAssert(m!=-1); - return m; -} - -b3Vector3 orth(const b3Vector3 &v); -b3Vector3 orth(const b3Vector3 &v) -{ - b3Vector3 a=btCross(v,b3Vector3(0,0,1)); - b3Vector3 b=btCross(v,b3Vector3(0,1,0)); - if (a.length() > b.length()) - { - return a.normalized(); - } else { - return b.normalized(); - } -} - - -template -int maxdirsterid(const T *p,int count,const T &dir,b3AlignedObjectArray &allow) -{ - int m=-1; - while(m==-1) - { - m = maxdirfiltered(p,count,dir,allow); - if(allow[m]==3) return m; - T u = orth(dir); - T v = btCross(u,dir); - int ma=-1; - for(b3Scalar x = b3Scalar(0.0) ; x<= b3Scalar(360.0) ; x+= b3Scalar(45.0)) - { - b3Scalar s = btSin(SIMD_RADS_PER_DEG*(x)); - b3Scalar c = btCos(SIMD_RADS_PER_DEG*(x)); - int mb = maxdirfiltered(p,count,dir+(u*s+v*c)*b3Scalar(0.025),allow); - if(ma==m && mb==m) - { - allow[m]=3; - return m; - } - if(ma!=-1 && ma!=mb) // Yuck - this is really ugly - { - int mc = ma; - for(b3Scalar xx = x-b3Scalar(40.0) ; xx <= x ; xx+= b3Scalar(5.0)) - { - b3Scalar s = btSin(SIMD_RADS_PER_DEG*(xx)); - b3Scalar c = btCos(SIMD_RADS_PER_DEG*(xx)); - int md = maxdirfiltered(p,count,dir+(u*s+v*c)*b3Scalar(0.025),allow); - if(mc==m && md==m) - { - allow[m]=3; - return m; - } - mc=md; - } - } - ma=mb; - } - allow[m]=0; - m=-1; - } - btAssert(0); - return m; -} - - - - -int operator ==(const int3 &a,const int3 &b); -int operator ==(const int3 &a,const int3 &b) -{ - for(int i=0;i<3;i++) - { - if(a[i]!=b[i]) return 0; - } - return 1; -} - - -int above(b3Vector3* vertices,const int3& t, const b3Vector3 &p, b3Scalar epsilon); -int above(b3Vector3* vertices,const int3& t, const b3Vector3 &p, b3Scalar epsilon) -{ - b3Vector3 n=TriNormal(vertices[t[0]],vertices[t[1]],vertices[t[2]]); - return (btDot(n,p-vertices[t[0]]) > epsilon); // EPSILON??? -} -int hasedge(const int3 &t, int a,int b); -int hasedge(const int3 &t, int a,int b) -{ - for(int i=0;i<3;i++) - { - int i1= (i+1)%3; - if(t[i]==a && t[i1]==b) return 1; - } - return 0; -} -int hasvert(const int3 &t, int v); -int hasvert(const int3 &t, int v) -{ - return (t[0]==v || t[1]==v || t[2]==v) ; -} -int shareedge(const int3 &a,const int3 &b); -int shareedge(const int3 &a,const int3 &b) -{ - int i; - for(i=0;i<3;i++) - { - int i1= (i+1)%3; - if(hasedge(a,b[i1],b[i])) return 1; - } - return 0; -} - -class btHullTriangle; - - - -class btHullTriangle : public int3 -{ -public: - int3 n; - int id; - int vmax; - b3Scalar rise; - btHullTriangle(int a,int b,int c):int3(a,b,c),n(-1,-1,-1) - { - vmax=-1; - rise = b3Scalar(0.0); - } - ~btHullTriangle() - { - } - int &neib(int a,int b); -}; - - -int &btHullTriangle::neib(int a,int b) -{ - static int er=-1; - int i; - for(i=0;i<3;i++) - { - int i1=(i+1)%3; - int i2=(i+2)%3; - if((*this)[i]==a && (*this)[i1]==b) return n[i2]; - if((*this)[i]==b && (*this)[i1]==a) return n[i2]; - } - btAssert(0); - return er; -} -void HullLibrary::b2bfix(btHullTriangle* s,btHullTriangle*t) -{ - int i; - for(i=0;i<3;i++) - { - int i1=(i+1)%3; - int i2=(i+2)%3; - int a = (*s)[i1]; - int b = (*s)[i2]; - btAssert(m_tris[s->neib(a,b)]->neib(b,a) == s->id); - btAssert(m_tris[t->neib(a,b)]->neib(b,a) == t->id); - m_tris[s->neib(a,b)]->neib(b,a) = t->neib(b,a); - m_tris[t->neib(b,a)]->neib(a,b) = s->neib(a,b); - } -} - -void HullLibrary::removeb2b(btHullTriangle* s,btHullTriangle*t) -{ - b2bfix(s,t); - deAllocateTriangle(s); - - deAllocateTriangle(t); -} - -void HullLibrary::checkit(btHullTriangle *t) -{ - (void)t; - - int i; - btAssert(m_tris[t->id]==t); - for(i=0;i<3;i++) - { - int i1=(i+1)%3; - int i2=(i+2)%3; - int a = (*t)[i1]; - int b = (*t)[i2]; - - // release compile fix - (void)i1; - (void)i2; - (void)a; - (void)b; - - btAssert(a!=b); - btAssert( m_tris[t->n[i]]->neib(b,a) == t->id); - } -} - -btHullTriangle* HullLibrary::allocateTriangle(int a,int b,int c) -{ - void* mem = btAlignedAlloc(sizeof(btHullTriangle),16); - btHullTriangle* tr = new (mem)btHullTriangle(a,b,c); - tr->id = m_tris.size(); - m_tris.push_back(tr); - - return tr; -} - -void HullLibrary::deAllocateTriangle(btHullTriangle* tri) -{ - btAssert(m_tris[tri->id]==tri); - m_tris[tri->id]=NULL; - tri->~btHullTriangle(); - btAlignedFree(tri); -} - - -void HullLibrary::extrude(btHullTriangle *t0,int v) -{ - int3 t= *t0; - int n = m_tris.size(); - btHullTriangle* ta = allocateTriangle(v,t[1],t[2]); - ta->n = int3(t0->n[0],n+1,n+2); - m_tris[t0->n[0]]->neib(t[1],t[2]) = n+0; - btHullTriangle* tb = allocateTriangle(v,t[2],t[0]); - tb->n = int3(t0->n[1],n+2,n+0); - m_tris[t0->n[1]]->neib(t[2],t[0]) = n+1; - btHullTriangle* tc = allocateTriangle(v,t[0],t[1]); - tc->n = int3(t0->n[2],n+0,n+1); - m_tris[t0->n[2]]->neib(t[0],t[1]) = n+2; - checkit(ta); - checkit(tb); - checkit(tc); - if(hasvert(*m_tris[ta->n[0]],v)) removeb2b(ta,m_tris[ta->n[0]]); - if(hasvert(*m_tris[tb->n[0]],v)) removeb2b(tb,m_tris[tb->n[0]]); - if(hasvert(*m_tris[tc->n[0]],v)) removeb2b(tc,m_tris[tc->n[0]]); - deAllocateTriangle(t0); - -} - -btHullTriangle* HullLibrary::extrudable(b3Scalar epsilon) -{ - int i; - btHullTriangle *t=NULL; - for(i=0;iriserise)) - { - t = m_tris[i]; - } - } - return (t->rise >epsilon)?t:NULL ; -} - - - - -int4 HullLibrary::FindSimplex(b3Vector3 *verts,int verts_count,b3AlignedObjectArray &allow) -{ - b3Vector3 basis[3]; - basis[0] = b3Vector3( b3Scalar(0.01), b3Scalar(0.02), b3Scalar(1.0) ); - int p0 = maxdirsterid(verts,verts_count, basis[0],allow); - int p1 = maxdirsterid(verts,verts_count,-basis[0],allow); - basis[0] = verts[p0]-verts[p1]; - if(p0==p1 || basis[0]==b3Vector3(0,0,0)) - return int4(-1,-1,-1,-1); - basis[1] = btCross(b3Vector3( b3Scalar(1),b3Scalar(0.02), b3Scalar(0)),basis[0]); - basis[2] = btCross(b3Vector3(b3Scalar(-0.02), b3Scalar(1), b3Scalar(0)),basis[0]); - if (basis[1].length() > basis[2].length()) - { - basis[1].normalize(); - } else { - basis[1] = basis[2]; - basis[1].normalize (); - } - int p2 = maxdirsterid(verts,verts_count,basis[1],allow); - if(p2 == p0 || p2 == p1) - { - p2 = maxdirsterid(verts,verts_count,-basis[1],allow); - } - if(p2 == p0 || p2 == p1) - return int4(-1,-1,-1,-1); - basis[1] = verts[p2] - verts[p0]; - basis[2] = btCross(basis[1],basis[0]).normalized(); - int p3 = maxdirsterid(verts,verts_count,basis[2],allow); - if(p3==p0||p3==p1||p3==p2) p3 = maxdirsterid(verts,verts_count,-basis[2],allow); - if(p3==p0||p3==p1||p3==p2) - return int4(-1,-1,-1,-1); - btAssert(!(p0==p1||p0==p2||p0==p3||p1==p2||p1==p3||p2==p3)); - if(btDot(verts[p3]-verts[p0],btCross(verts[p1]-verts[p0],verts[p2]-verts[p0])) <0) {btSwap(p2,p3);} - return int4(p0,p1,p2,p3); -} - -int HullLibrary::calchullgen(b3Vector3 *verts,int verts_count, int vlimit) -{ - if(verts_count <4) return 0; - if(vlimit==0) vlimit=1000000000; - int j; - b3Vector3 bmin(*verts),bmax(*verts); - b3AlignedObjectArray isextreme; - isextreme.reserve(verts_count); - b3AlignedObjectArray allow; - allow.reserve(verts_count); - - for(j=0;jn=int3(2,3,1); - btHullTriangle *t1 = allocateTriangle(p[3],p[2],p[0]); t1->n=int3(3,2,0); - btHullTriangle *t2 = allocateTriangle(p[0],p[1],p[3]); t2->n=int3(0,1,3); - btHullTriangle *t3 = allocateTriangle(p[1],p[0],p[2]); t3->n=int3(1,0,2); - isextreme[p[0]]=isextreme[p[1]]=isextreme[p[2]]=isextreme[p[3]]=1; - checkit(t0);checkit(t1);checkit(t2);checkit(t3); - - for(j=0;jvmax<0); - b3Vector3 n=TriNormal(verts[(*t)[0]],verts[(*t)[1]],verts[(*t)[2]]); - t->vmax = maxdirsterid(verts,verts_count,n,allow); - t->rise = btDot(n,verts[t->vmax]-verts[(*t)[0]]); - } - btHullTriangle *te; - vlimit-=4; - while(vlimit >0 && ((te=extrudable(epsilon)) != 0)) - { - //int3 ti=*te; - int v=te->vmax; - btAssert(v != -1); - btAssert(!isextreme[v]); // wtf we've already done this vertex - isextreme[v]=1; - //if(v==p0 || v==p1 || v==p2 || v==p3) continue; // done these already - j=m_tris.size(); - while(j--) { - if(!m_tris[j]) continue; - int3 t=*m_tris[j]; - if(above(verts,t,verts[v],b3Scalar(0.01)*epsilon)) - { - extrude(m_tris[j],v); - } - } - // now check for those degenerate cases where we have a flipped triangle or a really skinny triangle - j=m_tris.size(); - while(j--) - { - if(!m_tris[j]) continue; - if(!hasvert(*m_tris[j],v)) break; - int3 nt=*m_tris[j]; - if(above(verts,nt,center,b3Scalar(0.01)*epsilon) || btCross(verts[nt[1]]-verts[nt[0]],verts[nt[2]]-verts[nt[1]]).length()< epsilon*epsilon*b3Scalar(0.1) ) - { - btHullTriangle *nb = m_tris[m_tris[j]->n[0]]; - btAssert(nb);btAssert(!hasvert(*nb,v));btAssert(nb->idvmax>=0) break; - b3Vector3 n=TriNormal(verts[(*t)[0]],verts[(*t)[1]],verts[(*t)[2]]); - t->vmax = maxdirsterid(verts,verts_count,n,allow); - if(isextreme[t->vmax]) - { - t->vmax=-1; // already done that vertex - algorithm needs to be able to terminate. - } - else - { - t->rise = btDot(n,verts[t->vmax]-verts[(*t)[0]]); - } - } - vlimit --; - } - return 1; -} - -int HullLibrary::calchull(b3Vector3 *verts,int verts_count, TUIntArray& tris_out, int &tris_count,int vlimit) -{ - int rc=calchullgen(verts,verts_count, vlimit) ; - if(!rc) return 0; - b3AlignedObjectArray ts; - int i; - - for(i=0;i(ts[i]); - } - m_tris.resize(0); - - return 1; -} - - - - - -bool HullLibrary::ComputeHull(unsigned int vcount,const b3Vector3 *vertices,PHullResult &result,unsigned int vlimit) -{ - - int tris_count; - int ret = calchull( (b3Vector3 *) vertices, (int) vcount, result.m_Indices, tris_count, static_cast(vlimit) ); - if(!ret) return false; - result.mIndexCount = (unsigned int) (tris_count*3); - result.mFaceCount = (unsigned int) tris_count; - result.mVertices = (b3Vector3*) vertices; - result.mVcount = (unsigned int) vcount; - return true; - -} - - -void ReleaseHull(PHullResult &result); -void ReleaseHull(PHullResult &result) -{ - if ( result.m_Indices.size() ) - { - result.m_Indices.clear(); - } - - result.mVcount = 0; - result.mIndexCount = 0; - result.mVertices = 0; -} - - -//********************************************************************* -//********************************************************************* -//******** HullLib header -//********************************************************************* -//********************************************************************* - -//********************************************************************* -//********************************************************************* -//******** HullLib implementation -//********************************************************************* -//********************************************************************* - -HullError HullLibrary::CreateConvexHull(const HullDesc &desc, // describes the input request - HullResult &result) // contains the resulst -{ - HullError ret = QE_FAIL; - - - PHullResult hr; - - unsigned int vcount = desc.mVcount; - if ( vcount < 8 ) vcount = 8; - - b3AlignedObjectArray vertexSource; - vertexSource.resize(static_cast(vcount)); - - b3Vector3 scale; - - unsigned int ovcount; - - bool ok = CleanupVertices(desc.mVcount,desc.mVertices, desc.mVertexStride, ovcount, &vertexSource[0], desc.mNormalEpsilon, scale ); // normalize point cloud, remove duplicates! - - if ( ok ) - { - - -// if ( 1 ) // scale vertices back to their original size. - { - for (unsigned int i=0; i(i)]; - v[0]*=scale[0]; - v[1]*=scale[1]; - v[2]*=scale[2]; - } - } - - ok = ComputeHull(ovcount,&vertexSource[0],hr,desc.mMaxVertices); - - if ( ok ) - { - - // re-index triangle mesh so it refers to only used vertices, rebuild a new vertex table. - b3AlignedObjectArray vertexScratch; - vertexScratch.resize(static_cast(hr.mVcount)); - - BringOutYourDead(hr.mVertices,hr.mVcount, &vertexScratch[0], ovcount, &hr.m_Indices[0], hr.mIndexCount ); - - ret = QE_OK; - - if ( desc.HasHullFlag(QF_TRIANGLES) ) // if he wants the results as triangle! - { - result.mPolygons = false; - result.mNumOutputVertices = ovcount; - result.m_OutputVertices.resize(static_cast(ovcount)); - result.mNumFaces = hr.mFaceCount; - result.mNumIndices = hr.mIndexCount; - - result.m_Indices.resize(static_cast(hr.mIndexCount)); - - memcpy(&result.m_OutputVertices[0], &vertexScratch[0], sizeof(b3Vector3)*ovcount ); - - if ( desc.HasHullFlag(QF_REVERSE_ORDER) ) - { - - const unsigned int *source = &hr.m_Indices[0]; - unsigned int *dest = &result.m_Indices[0]; - - for (unsigned int i=0; i(ovcount)); - result.mNumFaces = hr.mFaceCount; - result.mNumIndices = hr.mIndexCount+hr.mFaceCount; - result.m_Indices.resize(static_cast(result.mNumIndices)); - memcpy(&result.m_OutputVertices[0], &vertexScratch[0], sizeof(b3Vector3)*ovcount ); - -// if ( 1 ) - { - const unsigned int *source = &hr.m_Indices[0]; - unsigned int *dest = &result.m_Indices[0]; - for (unsigned int i=0; i bmax[j] ) bmax[j] = p[j]; - } - } - } - - b3Scalar dx = bmax[0] - bmin[0]; - b3Scalar dy = bmax[1] - bmin[1]; - b3Scalar dz = bmax[2] - bmin[2]; - - b3Vector3 center; - - center[0] = dx*b3Scalar(0.5) + bmin[0]; - center[1] = dy*b3Scalar(0.5) + bmin[1]; - center[2] = dz*b3Scalar(0.5) + bmin[2]; - - if ( dx < EPSILON || dy < EPSILON || dz < EPSILON || svcount < 3 ) - { - - b3Scalar len = FLT_MAX; - - if ( dx > EPSILON && dx < len ) len = dx; - if ( dy > EPSILON && dy < len ) len = dy; - if ( dz > EPSILON && dz < len ) len = dz; - - if ( len == FLT_MAX ) - { - dx = dy = dz = b3Scalar(0.01); // one centimeter - } - else - { - if ( dx < EPSILON ) dx = len * b3Scalar(0.05); // 1/5th the shortest non-zero edge. - if ( dy < EPSILON ) dy = len * b3Scalar(0.05); - if ( dz < EPSILON ) dz = len * b3Scalar(0.05); - } - - b3Scalar x1 = center[0] - dx; - b3Scalar x2 = center[0] + dx; - - b3Scalar y1 = center[1] - dy; - b3Scalar y2 = center[1] + dy; - - b3Scalar z1 = center[2] - dz; - b3Scalar z2 = center[2] + dz; - - addPoint(vcount,vertices,x1,y1,z1); - addPoint(vcount,vertices,x2,y1,z1); - addPoint(vcount,vertices,x2,y2,z1); - addPoint(vcount,vertices,x1,y2,z1); - addPoint(vcount,vertices,x1,y1,z2); - addPoint(vcount,vertices,x2,y1,z2); - addPoint(vcount,vertices,x2,y2,z2); - addPoint(vcount,vertices,x1,y2,z2); - - return true; // return cube - - - } - else - { - if ( scale ) - { - scale[0] = dx; - scale[1] = dy; - scale[2] = dz; - - recip[0] = 1 / dx; - recip[1] = 1 / dy; - recip[2] = 1 / dz; - - center[0]*=recip[0]; - center[1]*=recip[1]; - center[2]*=recip[2]; - - } - - } - - - - vtx = (const char *) svertices; - - for (unsigned int i=0; igetX(); - b3Scalar py = p->getY(); - b3Scalar pz = p->getZ(); - - if ( scale ) - { - px = px*recip[0]; // normalize - py = py*recip[1]; // normalize - pz = pz*recip[2]; // normalize - } - -// if ( 1 ) - { - unsigned int j; - - for (j=0; j dist2 ) - { - v[0] = px; - v[1] = py; - v[2] = pz; - - } - - break; - } - } - - if ( j == vcount ) - { - b3Vector3& dest = vertices[vcount]; - dest[0] = px; - dest[1] = py; - dest[2] = pz; - vcount++; - } - m_vertexIndexMapping.push_back(j); - } - } - - // ok..now make sure we didn't prune so many vertices it is now invalid. -// if ( 1 ) - { - b3Scalar bmin[3] = { FLT_MAX, FLT_MAX, FLT_MAX }; - b3Scalar bmax[3] = { -FLT_MAX, -FLT_MAX, -FLT_MAX }; - - for (unsigned int i=0; i bmax[j] ) bmax[j] = p[j]; - } - } - - b3Scalar dx = bmax[0] - bmin[0]; - b3Scalar dy = bmax[1] - bmin[1]; - b3Scalar dz = bmax[2] - bmin[2]; - - if ( dx < EPSILON || dy < EPSILON || dz < EPSILON || vcount < 3) - { - b3Scalar cx = dx*b3Scalar(0.5) + bmin[0]; - b3Scalar cy = dy*b3Scalar(0.5) + bmin[1]; - b3Scalar cz = dz*b3Scalar(0.5) + bmin[2]; - - b3Scalar len = FLT_MAX; - - if ( dx >= EPSILON && dx < len ) len = dx; - if ( dy >= EPSILON && dy < len ) len = dy; - if ( dz >= EPSILON && dz < len ) len = dz; - - if ( len == FLT_MAX ) - { - dx = dy = dz = b3Scalar(0.01); // one centimeter - } - else - { - if ( dx < EPSILON ) dx = len * b3Scalar(0.05); // 1/5th the shortest non-zero edge. - if ( dy < EPSILON ) dy = len * b3Scalar(0.05); - if ( dz < EPSILON ) dz = len * b3Scalar(0.05); - } - - b3Scalar x1 = cx - dx; - b3Scalar x2 = cx + dx; - - b3Scalar y1 = cy - dy; - b3Scalar y2 = cy + dy; - - b3Scalar z1 = cz - dz; - b3Scalar z2 = cz + dz; - - vcount = 0; // add box - - addPoint(vcount,vertices,x1,y1,z1); - addPoint(vcount,vertices,x2,y1,z1); - addPoint(vcount,vertices,x2,y2,z1); - addPoint(vcount,vertices,x1,y2,z1); - addPoint(vcount,vertices,x1,y1,z2); - addPoint(vcount,vertices,x2,y1,z2); - addPoint(vcount,vertices,x2,y2,z2); - addPoint(vcount,vertices,x1,y2,z2); - - return true; - } - } - - return true; -} - -void HullLibrary::BringOutYourDead(const b3Vector3* verts,unsigned int vcount, b3Vector3* overts,unsigned int &ocount,unsigned int *indices,unsigned indexcount) -{ - b3AlignedObjectArraytmpIndices; - tmpIndices.resize(m_vertexIndexMapping.size()); - int i; - - for (i=0;i(vcount)); - memset(&usedIndices[0],0,sizeof(unsigned int)*vcount); - - ocount = 0; - - for (i=0; i= 0 && v < vcount ); - - if ( usedIndices[static_cast(v)] ) // if already remapped - { - indices[i] = usedIndices[static_cast(v)]-1; // index to new array - } - else - { - - indices[i] = ocount; // new index mapping - - overts[ocount][0] = verts[v][0]; // copy old vert to new vert array - overts[ocount][1] = verts[v][1]; - overts[ocount][2] = verts[v][2]; - - for (int k=0;k=0 && ocount <= vcount ); - - usedIndices[static_cast(v)] = ocount; // assign new index remapping - - - } - } - - -} diff --git a/src/BulletGeometry/btConvexHull.h b/src/BulletGeometry/btConvexHull.h deleted file mode 100644 index a0a31cc68..000000000 --- a/src/BulletGeometry/btConvexHull.h +++ /dev/null @@ -1,241 +0,0 @@ - -/* -Stan Melax Convex Hull Computation -Copyright (c) 2008 Stan Melax http://www.melax.com/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - -///includes modifications/improvements by John Ratcliff, see BringOutYourDead below. - -#ifndef BT_CD_HULL_H -#define BT_CD_HULL_H - -#include "BulletCommon/b3Vector3.h" -#include "BulletCommon/b3AlignedObjectArray.h" - -typedef b3AlignedObjectArray TUIntArray; - -class HullResult -{ -public: - HullResult(void) - { - mPolygons = true; - mNumOutputVertices = 0; - mNumFaces = 0; - mNumIndices = 0; - } - bool mPolygons; // true if indices represents polygons, false indices are triangles - unsigned int mNumOutputVertices; // number of vertices in the output hull - b3AlignedObjectArray m_OutputVertices; // array of vertices - unsigned int mNumFaces; // the number of faces produced - unsigned int mNumIndices; // the total number of indices - b3AlignedObjectArray m_Indices; // pointer to indices. - -// If triangles, then indices are array indexes into the vertex list. -// If polygons, indices are in the form (number of points in face) (p1, p2, p3, ..) etc.. -}; - -enum HullFlag -{ - QF_TRIANGLES = (1<<0), // report results as triangles, not polygons. - QF_REVERSE_ORDER = (1<<1), // reverse order of the triangle indices. - QF_DEFAULT = QF_TRIANGLES -}; - - -class HullDesc -{ -public: - HullDesc(void) - { - mFlags = QF_DEFAULT; - mVcount = 0; - mVertices = 0; - mVertexStride = sizeof(b3Vector3); - mNormalEpsilon = 0.001f; - mMaxVertices = 4096; // maximum number of points to be considered for a convex hull. - mMaxFaces = 4096; - }; - - HullDesc(HullFlag flag, - unsigned int vcount, - const b3Vector3 *vertices, - unsigned int stride = sizeof(b3Vector3)) - { - mFlags = flag; - mVcount = vcount; - mVertices = vertices; - mVertexStride = stride; - mNormalEpsilon = b3Scalar(0.001); - mMaxVertices = 4096; - } - - bool HasHullFlag(HullFlag flag) const - { - if ( mFlags & flag ) return true; - return false; - } - - void SetHullFlag(HullFlag flag) - { - mFlags|=flag; - } - - void ClearHullFlag(HullFlag flag) - { - mFlags&=~flag; - } - - unsigned int mFlags; // flags to use when generating the convex hull. - unsigned int mVcount; // number of vertices in the input point cloud - const b3Vector3 *mVertices; // the array of vertices. - unsigned int mVertexStride; // the stride of each vertex, in bytes. - b3Scalar mNormalEpsilon; // the epsilon for removing duplicates. This is a normalized value, if normalized bit is on. - unsigned int mMaxVertices; // maximum number of vertices to be considered for the hull! - unsigned int mMaxFaces; -}; - -enum HullError -{ - QE_OK, // success! - QE_FAIL // failed. -}; - -class btPlane -{ - public: - b3Vector3 normal; - b3Scalar dist; // distance below origin - the D from plane equasion Ax+By+Cz+D=0 - btPlane(const b3Vector3 &n,b3Scalar d):normal(n),dist(d){} - btPlane():normal(),dist(0){} - -}; - - - -class ConvexH -{ - public: - class HalfEdge - { - public: - short ea; // the other half of the edge (index into edges list) - unsigned char v; // the vertex at the start of this edge (index into vertices list) - unsigned char p; // the facet on which this edge lies (index into facets list) - HalfEdge(){} - HalfEdge(short _ea,unsigned char _v, unsigned char _p):ea(_ea),v(_v),p(_p){} - }; - ConvexH() - { - } - ~ConvexH() - { - } - b3AlignedObjectArray vertices; - b3AlignedObjectArray edges; - b3AlignedObjectArray facets; - ConvexH(int vertices_size,int edges_size,int facets_size); -}; - - -class int4 -{ -public: - int x,y,z,w; - int4(){}; - int4(int _x,int _y, int _z,int _w){x=_x;y=_y;z=_z;w=_w;} - const int& operator[](int i) const {return (&x)[i];} - int& operator[](int i) {return (&x)[i];} -}; - -class PHullResult -{ -public: - - PHullResult(void) - { - mVcount = 0; - mIndexCount = 0; - mFaceCount = 0; - mVertices = 0; - } - - unsigned int mVcount; - unsigned int mIndexCount; - unsigned int mFaceCount; - b3Vector3* mVertices; - TUIntArray m_Indices; -}; - - - -///The HullLibrary class can create a convex hull from a collection of vertices, using the ComputeHull method. -///The btShapeHull class uses this HullLibrary to create a approximate convex mesh given a general (non-polyhedral) convex shape. -class HullLibrary -{ - - b3AlignedObjectArray m_tris; - -public: - - b3AlignedObjectArray m_vertexIndexMapping; - - - HullError CreateConvexHull(const HullDesc& desc, // describes the input request - HullResult& result); // contains the resulst - HullError ReleaseResult(HullResult &result); // release memory allocated for this result, we are done with it. - -private: - - bool ComputeHull(unsigned int vcount,const b3Vector3 *vertices,PHullResult &result,unsigned int vlimit); - - class btHullTriangle* allocateTriangle(int a,int b,int c); - void deAllocateTriangle(btHullTriangle*); - void b2bfix(btHullTriangle* s,btHullTriangle*t); - - void removeb2b(btHullTriangle* s,btHullTriangle*t); - - void checkit(btHullTriangle *t); - - btHullTriangle* extrudable(b3Scalar epsilon); - - int calchull(b3Vector3 *verts,int verts_count, TUIntArray& tris_out, int &tris_count,int vlimit); - - int calchullgen(b3Vector3 *verts,int verts_count, int vlimit); - - int4 FindSimplex(b3Vector3 *verts,int verts_count,b3AlignedObjectArray &allow); - - class ConvexH* ConvexHCrop(ConvexH& convex,const btPlane& slice); - - void extrude(class btHullTriangle* t0,int v); - - ConvexH* test_cube(); - - //BringOutYourDead (John Ratcliff): When you create a convex hull you hand it a large input set of vertices forming a 'point cloud'. - //After the hull is generated it give you back a set of polygon faces which index the *original* point cloud. - //The thing is, often times, there are many 'dead vertices' in the point cloud that are on longer referenced by the hull. - //The routine 'BringOutYourDead' find only the referenced vertices, copies them to an new buffer, and re-indexes the hull so that it is a minimal representation. - void BringOutYourDead(const b3Vector3* verts,unsigned int vcount, b3Vector3* overts,unsigned int &ocount,unsigned int* indices,unsigned indexcount); - - bool CleanupVertices(unsigned int svcount, - const b3Vector3* svertices, - unsigned int stride, - unsigned int &vcount, // output number of vertices - b3Vector3* vertices, // location to store the results. - b3Scalar normalepsilon, - b3Vector3& scale); -}; - - -#endif //BT_CD_HULL_H - diff --git a/src/BulletGeometry/btPolarDecomposition.cpp b/src/BulletGeometry/btPolarDecomposition.cpp deleted file mode 100644 index eb0613d7b..000000000 --- a/src/BulletGeometry/btPolarDecomposition.cpp +++ /dev/null @@ -1,99 +0,0 @@ -#include "btPolarDecomposition.h" -#include "BulletCommon/b3MinMax.h" - -namespace -{ - b3Scalar abs_column_sum(const b3Matrix3x3& a, int i) - { - return btFabs(a[0][i]) + btFabs(a[1][i]) + btFabs(a[2][i]); - } - - b3Scalar abs_row_sum(const b3Matrix3x3& a, int i) - { - return btFabs(a[i][0]) + btFabs(a[i][1]) + btFabs(a[i][2]); - } - - b3Scalar p1_norm(const b3Matrix3x3& a) - { - const b3Scalar sum0 = abs_column_sum(a,0); - const b3Scalar sum1 = abs_column_sum(a,1); - const b3Scalar sum2 = abs_column_sum(a,2); - return btMax(btMax(sum0, sum1), sum2); - } - - b3Scalar pinf_norm(const b3Matrix3x3& a) - { - const b3Scalar sum0 = abs_row_sum(a,0); - const b3Scalar sum1 = abs_row_sum(a,1); - const b3Scalar sum2 = abs_row_sum(a,2); - return btMax(btMax(sum0, sum1), sum2); - } -} - -const b3Scalar btPolarDecomposition::DEFAULT_TOLERANCE = b3Scalar(0.0001); -const unsigned int btPolarDecomposition::DEFAULT_MAX_ITERATIONS = 16; - -btPolarDecomposition::btPolarDecomposition(b3Scalar tolerance, unsigned int maxIterations) -: m_tolerance(tolerance) -, m_maxIterations(maxIterations) -{ -} - -unsigned int btPolarDecomposition::decompose(const b3Matrix3x3& a, b3Matrix3x3& u, b3Matrix3x3& h) const -{ - // Use the 'u' and 'h' matrices for intermediate calculations - u = a; - h = a.inverse(); - - for (unsigned int i = 0; i < m_maxIterations; ++i) - { - const b3Scalar h_1 = p1_norm(h); - const b3Scalar h_inf = pinf_norm(h); - const b3Scalar u_1 = p1_norm(u); - const b3Scalar u_inf = pinf_norm(u); - - const b3Scalar h_norm = h_1 * h_inf; - const b3Scalar u_norm = u_1 * u_inf; - - // The matrix is effectively singular so we cannot invert it - if (btFuzzyZero(h_norm) || btFuzzyZero(u_norm)) - break; - - const b3Scalar gamma = btPow(h_norm / u_norm, 0.25f); - const b3Scalar inv_gamma = 1.0 / gamma; - - // Determine the delta to 'u' - const b3Matrix3x3 delta = (u * (gamma - 2.0) + h.transpose() * inv_gamma) * 0.5; - - // Update the matrices - u += delta; - h = u.inverse(); - - // Check for convergence - if (p1_norm(delta) <= m_tolerance * u_1) - { - h = u.transpose() * a; - h = (h + h.transpose()) * 0.5; - return i; - } - } - - // The algorithm has failed to converge to the specified tolerance, but we - // want to make sure that the matrices returned are in the right form. - h = u.transpose() * a; - h = (h + h.transpose()) * 0.5; - - return m_maxIterations; -} - -unsigned int btPolarDecomposition::maxIterations() const -{ - return m_maxIterations; -} - -unsigned int polarDecompose(const b3Matrix3x3& a, b3Matrix3x3& u, b3Matrix3x3& h) -{ - static btPolarDecomposition polar; - return polar.decompose(a, u, h); -} - diff --git a/src/BulletGeometry/btPolarDecomposition.h b/src/BulletGeometry/btPolarDecomposition.h deleted file mode 100644 index 8a8bf9a30..000000000 --- a/src/BulletGeometry/btPolarDecomposition.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef POLARDECOMPOSITION_H -#define POLARDECOMPOSITION_H - -#include "BulletCommon/b3Matrix3x3.h" - -/** - * This class is used to compute the polar decomposition of a matrix. In - * general, the polar decomposition factorizes a matrix, A, into two parts: a - * unitary matrix (U) and a positive, semi-definite Hermitian matrix (H). - * However, in this particular implementation the original matrix, A, is - * required to be a square 3x3 matrix with real elements. This means that U will - * be an orthogonal matrix and H with be a positive-definite, symmetric matrix. - */ -class btPolarDecomposition -{ - public: - static const b3Scalar DEFAULT_TOLERANCE; - static const unsigned int DEFAULT_MAX_ITERATIONS; - - /** - * Creates an instance with optional parameters. - * - * @param tolerance - the tolerance used to determine convergence of the - * algorithm - * @param maxIterations - the maximum number of iterations used to achieve - * convergence - */ - btPolarDecomposition(b3Scalar tolerance = DEFAULT_TOLERANCE, - unsigned int maxIterations = DEFAULT_MAX_ITERATIONS); - - /** - * Decomposes a matrix into orthogonal and symmetric, positive-definite - * parts. If the number of iterations returned by this function is equal to - * the maximum number of iterations, the algorithm has failed to converge. - * - * @param a - the original matrix - * @param u - the resulting orthogonal matrix - * @param h - the resulting symmetric matrix - * - * @return the number of iterations performed by the algorithm. - */ - unsigned int decompose(const b3Matrix3x3& a, b3Matrix3x3& u, b3Matrix3x3& h) const; - - /** - * Returns the maximum number of iterations that this algorithm will perform - * to achieve convergence. - * - * @return maximum number of iterations - */ - unsigned int maxIterations() const; - - private: - b3Scalar m_tolerance; - unsigned int m_maxIterations; -}; - -/** - * This functions decomposes the matrix 'a' into two parts: an orthogonal matrix - * 'u' and a symmetric, positive-definite matrix 'h'. If the number of - * iterations returned by this function is equal to - * btPolarDecomposition::DEFAULT_MAX_ITERATIONS, the algorithm has failed to - * converge. - * - * @param a - the original matrix - * @param u - the resulting orthogonal matrix - * @param h - the resulting symmetric matrix - * - * @return the number of iterations performed by the algorithm. - */ -unsigned int polarDecompose(const b3Matrix3x3& a, b3Matrix3x3& u, b3Matrix3x3& h); - -#endif // POLARDECOMPOSITION_H -