added some brute-force way to shrink convex polyhedra (to compensate collision margin)
made Extra/EPA compile again, updated Pierre's testbed to compile out-of-the-box
This commit is contained in:
@@ -16,6 +16,7 @@ subject to the following restrictions:
|
||||
#include "BspConverter.h"
|
||||
#include "BspLoader.h"
|
||||
#include "LinearMath/btVector3.h"
|
||||
#include "LinearMath/btGeometryUtil.h"
|
||||
|
||||
void BspConverter::convertBsp(BspLoader& bspLoader,float scaling)
|
||||
{
|
||||
@@ -83,10 +84,8 @@ void BspConverter::convertBsp(BspLoader& bspLoader,float scaling)
|
||||
{
|
||||
|
||||
std::vector<btVector3> vertices;
|
||||
|
||||
getVerticesFromPlaneEquations(planeEquations,vertices);
|
||||
printf("getVerticesFromPlaneEquations returned %i\n",(int)vertices.size());
|
||||
|
||||
btGeometryUtil::getVerticesFromPlaneEquations(planeEquations,vertices);
|
||||
|
||||
bool isEntity = false;
|
||||
btVector3 entityTarget(0.f,0.f,0.f);
|
||||
addConvexVerticesCollider(vertices,isEntity,entityTarget);
|
||||
@@ -160,7 +159,7 @@ void BspConverter::convertBsp(BspLoader& bspLoader,float scaling)
|
||||
{
|
||||
|
||||
std::vector<btVector3> vertices;
|
||||
getVerticesFromPlaneEquations(planeEquations,vertices);
|
||||
btGeometryUtil::getVerticesFromPlaneEquations(planeEquations,vertices);
|
||||
|
||||
bool isEntity=true;
|
||||
addConvexVerticesCollider(vertices,isEntity,targetLocation);
|
||||
@@ -196,78 +195,3 @@ void BspConverter::convertBsp(BspLoader& bspLoader,float scaling)
|
||||
|
||||
|
||||
|
||||
void BspConverter::getVerticesFromPlaneEquations(const std::vector<btVector3>& planeEquations , std::vector<btVector3>& verticesOut )
|
||||
{
|
||||
const int numbrushes = planeEquations.size();
|
||||
// brute force:
|
||||
for (int i=0;i<numbrushes;i++)
|
||||
{
|
||||
const btVector3& N1 = planeEquations[i];
|
||||
|
||||
|
||||
for (int j=i+1;j<numbrushes;j++)
|
||||
{
|
||||
const btVector3& N2 = planeEquations[j];
|
||||
|
||||
for (int k=j+1;k<numbrushes;k++)
|
||||
{
|
||||
|
||||
const btVector3& N3 = planeEquations[k];
|
||||
|
||||
btVector3 n2n3; n2n3 = N2.cross(N3);
|
||||
btVector3 n3n1; n3n1 = N3.cross(N1);
|
||||
btVector3 n1n2; n1n2 = N1.cross(N2);
|
||||
|
||||
if ( ( n2n3.length2() > 0.0001f ) &&
|
||||
( n3n1.length2() > 0.0001f ) &&
|
||||
( n1n2.length2() > 0.0001f ) )
|
||||
{
|
||||
//point P out of 3 plane equations:
|
||||
|
||||
// d1 ( N2 * N3 ) + d2 ( N3 * N1 ) + d3 ( N1 * N2 )
|
||||
//P = -------------------------------------------------------------------------
|
||||
// N1 . ( N2 * N3 )
|
||||
|
||||
|
||||
float quotient = (N1.dot(n2n3));
|
||||
if (btFabs(quotient) > 0.000001f)
|
||||
{
|
||||
quotient = -1.f / quotient;
|
||||
n2n3 *= N1[3];
|
||||
n3n1 *= N2[3];
|
||||
n1n2 *= N3[3];
|
||||
btVector3 potentialVertex = n2n3;
|
||||
potentialVertex += n3n1;
|
||||
potentialVertex += n1n2;
|
||||
potentialVertex *= quotient;
|
||||
|
||||
//check if inside, and replace supportingVertexOut if needed
|
||||
if (isInside(planeEquations,potentialVertex,0.1f))
|
||||
{
|
||||
verticesOut.push_back(potentialVertex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool BspConverter::isInside(const std::vector<btVector3>& planeEquations, const btVector3& point, float margin)
|
||||
{
|
||||
int numbrushes = planeEquations.size();
|
||||
for (int i=0;i<numbrushes;i++)
|
||||
{
|
||||
const btVector3& N1 = planeEquations[i];
|
||||
float dist = float(N1.dot(point))+float(N1[3])-margin;
|
||||
if (dist>0.f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user