fix convex-plane for > 4 vertices
improve compound demo
This commit is contained in:
@@ -495,6 +495,98 @@ static const char* primitiveContactsKernelsCL= \
|
||||
" \n"
|
||||
"\n"
|
||||
"\n"
|
||||
"int extractManifoldSequential(const float4* p, int nPoints, float4 nearNormal, int4* contactIdx)\n"
|
||||
"{\n"
|
||||
" if( nPoints == 0 )\n"
|
||||
" return 0;\n"
|
||||
" \n"
|
||||
" if (nPoints <=4)\n"
|
||||
" return nPoints;\n"
|
||||
" \n"
|
||||
" \n"
|
||||
" if (nPoints >64)\n"
|
||||
" nPoints = 64;\n"
|
||||
" \n"
|
||||
" float4 center = make_float4(0.f);\n"
|
||||
" {\n"
|
||||
" \n"
|
||||
" for (int i=0;i<nPoints;i++)\n"
|
||||
" center += p[i];\n"
|
||||
" center /= (float)nPoints;\n"
|
||||
" }\n"
|
||||
" \n"
|
||||
" \n"
|
||||
" \n"
|
||||
" // sample 4 directions\n"
|
||||
" \n"
|
||||
" float4 aVector = p[0] - center;\n"
|
||||
" float4 u = cross3( nearNormal, aVector );\n"
|
||||
" float4 v = cross3( nearNormal, u );\n"
|
||||
" u = normalize3( u );\n"
|
||||
" v = normalize3( v );\n"
|
||||
" \n"
|
||||
" \n"
|
||||
" //keep point with deepest penetration\n"
|
||||
" float minW= FLT_MAX;\n"
|
||||
" \n"
|
||||
" int minIndex=-1;\n"
|
||||
" \n"
|
||||
" float4 maxDots;\n"
|
||||
" maxDots.x = FLT_MIN;\n"
|
||||
" maxDots.y = FLT_MIN;\n"
|
||||
" maxDots.z = FLT_MIN;\n"
|
||||
" maxDots.w = FLT_MIN;\n"
|
||||
" \n"
|
||||
" // idx, distance\n"
|
||||
" for(int ie = 0; ie<nPoints; ie++ )\n"
|
||||
" {\n"
|
||||
" if (p[ie].w<minW)\n"
|
||||
" {\n"
|
||||
" minW = p[ie].w;\n"
|
||||
" minIndex=ie;\n"
|
||||
" }\n"
|
||||
" float f;\n"
|
||||
" float4 r = p[ie]-center;\n"
|
||||
" f = dot3F4( u, r );\n"
|
||||
" if (f<maxDots.x)\n"
|
||||
" {\n"
|
||||
" maxDots.x = f;\n"
|
||||
" contactIdx[0].x = ie;\n"
|
||||
" }\n"
|
||||
" \n"
|
||||
" f = dot3F4( -u, r );\n"
|
||||
" if (f<maxDots.y)\n"
|
||||
" {\n"
|
||||
" maxDots.y = f;\n"
|
||||
" contactIdx[0].y = ie;\n"
|
||||
" }\n"
|
||||
" \n"
|
||||
" \n"
|
||||
" f = dot3F4( v, r );\n"
|
||||
" if (f<maxDots.z)\n"
|
||||
" {\n"
|
||||
" maxDots.z = f;\n"
|
||||
" contactIdx[0].z = ie;\n"
|
||||
" }\n"
|
||||
" \n"
|
||||
" f = dot3F4( -v, r );\n"
|
||||
" if (f<maxDots.w)\n"
|
||||
" {\n"
|
||||
" maxDots.w = f;\n"
|
||||
" contactIdx[0].w = ie;\n"
|
||||
" }\n"
|
||||
" \n"
|
||||
" }\n"
|
||||
" \n"
|
||||
" if (contactIdx[0].x != minIndex && contactIdx[0].y != minIndex && contactIdx[0].z != minIndex && contactIdx[0].w != minIndex)\n"
|
||||
" {\n"
|
||||
" //replace the first contact with minimum (todo: replace contact with least penetration)\n"
|
||||
" contactIdx[0].x = minIndex;\n"
|
||||
" }\n"
|
||||
" \n"
|
||||
" return 4;\n"
|
||||
" \n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"#define MAX_PLANE_CONVEX_POINTS 64\n"
|
||||
"\n"
|
||||
@@ -595,10 +687,10 @@ static const char* primitiveContactsKernelsCL= \
|
||||
" }\n"
|
||||
"\n"
|
||||
" int numReducedPoints = numPoints;\n"
|
||||
" //if (numPoints>4)\n"
|
||||
" //{\n"
|
||||
"// numReducedPoints = extractManifoldSequentialGlobal( contactPoints, numPoints, planeNormalInConvex, &contactIdx);\n"
|
||||
" //}\n"
|
||||
" if (numPoints>4)\n"
|
||||
" {\n"
|
||||
" numReducedPoints = extractManifoldSequential( contactPoints, numPoints, planeNormalInConvex, &contactIdx);\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" if (numReducedPoints>0)\n"
|
||||
" {\n"
|
||||
|
||||
Reference in New Issue
Block a user