enable convex separation util, potentially improves performance. set threshold to zero (docs follow)
fix scaling issue with btConvexHullShape use virtual getSupportingVertex on non-SPU platform
This commit is contained in:
@@ -47,7 +47,7 @@ struct btDispatcherInfo
|
|||||||
m_useEpa(true),
|
m_useEpa(true),
|
||||||
m_allowedCcdPenetration(btScalar(0.04)),
|
m_allowedCcdPenetration(btScalar(0.04)),
|
||||||
m_useConvexConservativeDistanceUtil(true),
|
m_useConvexConservativeDistanceUtil(true),
|
||||||
m_convexConservativeDistanceThreshold(0.01f),
|
m_convexConservativeDistanceThreshold(0.0f),
|
||||||
m_stackAllocator(0)
|
m_stackAllocator(0)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -129,22 +129,31 @@ void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btColl
|
|||||||
//TODO: if (dispatchInfo.m_useContinuous)
|
//TODO: if (dispatchInfo.m_useContinuous)
|
||||||
gjkPairDetector.setMinkowskiA(min0);
|
gjkPairDetector.setMinkowskiA(min0);
|
||||||
gjkPairDetector.setMinkowskiB(min1);
|
gjkPairDetector.setMinkowskiB(min1);
|
||||||
input.m_maximumDistanceSquared = 1e30f;//min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactBreakingThreshold();
|
|
||||||
//input.m_maximumDistanceSquared*= input.m_maximumDistanceSquared;
|
#ifdef USE_SEPDISTANCE_UTIL2
|
||||||
|
if (dispatchInfo.m_useConvexConservativeDistanceUtil)
|
||||||
|
{
|
||||||
|
input.m_maximumDistanceSquared = 1e30f;
|
||||||
|
} else
|
||||||
|
#endif //USE_SEPDISTANCE_UTIL2
|
||||||
|
{
|
||||||
|
input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactBreakingThreshold();
|
||||||
|
input.m_maximumDistanceSquared*= input.m_maximumDistanceSquared;
|
||||||
|
}
|
||||||
|
|
||||||
input.m_stackAlloc = dispatchInfo.m_stackAllocator;
|
input.m_stackAlloc = dispatchInfo.m_stackAllocator;
|
||||||
|
|
||||||
// input.m_maximumDistanceSquared = btScalar(1e30);
|
|
||||||
|
|
||||||
input.m_transformA = body0->getWorldTransform();
|
input.m_transformA = body0->getWorldTransform();
|
||||||
input.m_transformB = body1->getWorldTransform();
|
input.m_transformB = body1->getWorldTransform();
|
||||||
|
|
||||||
gjkPairDetector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw);
|
gjkPairDetector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw);
|
||||||
|
|
||||||
|
|
||||||
btScalar sepDist = gjkPairDetector.getCachedSeparatingDistance()+dispatchInfo.m_convexConservativeDistanceThreshold;
|
btScalar sepDist = gjkPairDetector.getCachedSeparatingDistance()+dispatchInfo.m_convexConservativeDistanceThreshold;
|
||||||
|
|
||||||
#ifdef USE_SEPDISTANCE_UTIL2
|
#ifdef USE_SEPDISTANCE_UTIL2
|
||||||
m_sepDistance.initSeparatingDistance(m_gjkPairDetector.getCachedSeparatingAxis(),sepDist,body0->getWorldTransform(),body1->getWorldTransform());
|
if (dispatchInfo.m_useConvexConservativeDistanceUtil)
|
||||||
|
{
|
||||||
|
m_sepDistance.initSeparatingDistance(gjkPairDetector.getCachedSeparatingAxis(),sepDist,body0->getWorldTransform(),body1->getWorldTransform());
|
||||||
|
}
|
||||||
#endif //USE_SEPDISTANCE_UTIL2
|
#endif //USE_SEPDISTANCE_UTIL2
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ subject to the following restrictions:
|
|||||||
|
|
||||||
class btConvexPenetrationDepthSolver;
|
class btConvexPenetrationDepthSolver;
|
||||||
|
|
||||||
//#define USE_SEPDISTANCE_UTIL2 1
|
#define USE_SEPDISTANCE_UTIL2 1
|
||||||
|
|
||||||
///ConvexConvexAlgorithm collision algorithm implements time of impact, convex closest points and penetration depth calculations.
|
///ConvexConvexAlgorithm collision algorithm implements time of impact, convex closest points and penetration depth calculations.
|
||||||
class btConvexConvexAlgorithm : public btCollisionAlgorithm
|
class btConvexConvexAlgorithm : public btCollisionAlgorithm
|
||||||
|
|||||||
@@ -22,14 +22,14 @@ subject to the following restrictions:
|
|||||||
btConvexHullShape ::btConvexHullShape (const btScalar* points,int numPoints,int stride) : btPolyhedralConvexShape ()
|
btConvexHullShape ::btConvexHullShape (const btScalar* points,int numPoints,int stride) : btPolyhedralConvexShape ()
|
||||||
{
|
{
|
||||||
m_shapeType = CONVEX_HULL_SHAPE_PROXYTYPE;
|
m_shapeType = CONVEX_HULL_SHAPE_PROXYTYPE;
|
||||||
m_points.resize(numPoints);
|
m_unscaledPoints.resize(numPoints);
|
||||||
|
|
||||||
unsigned char* pointsBaseAddress = (unsigned char*)points;
|
unsigned char* pointsBaseAddress = (unsigned char*)points;
|
||||||
|
|
||||||
for (int i=0;i<numPoints;i++)
|
for (int i=0;i<numPoints;i++)
|
||||||
{
|
{
|
||||||
btVector3* point = (btVector3*)(pointsBaseAddress + i*stride);
|
btVector3* point = (btVector3*)(pointsBaseAddress + i*stride);
|
||||||
m_points[i] = point[0];
|
m_unscaledPoints[i] = point[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
recalcLocalAabb();
|
recalcLocalAabb();
|
||||||
@@ -46,7 +46,7 @@ void btConvexHullShape::setLocalScaling(const btVector3& scaling)
|
|||||||
|
|
||||||
void btConvexHullShape::addPoint(const btVector3& point)
|
void btConvexHullShape::addPoint(const btVector3& point)
|
||||||
{
|
{
|
||||||
m_points.push_back(point);
|
m_unscaledPoints.push_back(point);
|
||||||
recalcLocalAabb();
|
recalcLocalAabb();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -68,9 +68,9 @@ btVector3 btConvexHullShape::localGetSupportingVertexWithoutMargin(const btVecto
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (int i=0;i<m_points.size();i++)
|
for (int i=0;i<m_unscaledPoints.size();i++)
|
||||||
{
|
{
|
||||||
btVector3 vtx = m_points[i] * m_localScaling;
|
btVector3 vtx = m_unscaledPoints[i] * m_localScaling;
|
||||||
|
|
||||||
newDot = vec.dot(vtx);
|
newDot = vec.dot(vtx);
|
||||||
if (newDot > maxDot)
|
if (newDot > maxDot)
|
||||||
@@ -92,9 +92,9 @@ void btConvexHullShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const
|
|||||||
supportVerticesOut[i][3] = btScalar(-1e30);
|
supportVerticesOut[i][3] = btScalar(-1e30);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i=0;i<m_points.size();i++)
|
for (int i=0;i<m_unscaledPoints.size();i++)
|
||||||
{
|
{
|
||||||
btVector3 vtx = m_points[i] * m_localScaling;
|
btVector3 vtx = getScaledPoint(i);
|
||||||
|
|
||||||
for (int j=0;j<numVectors;j++)
|
for (int j=0;j<numVectors;j++)
|
||||||
{
|
{
|
||||||
@@ -145,26 +145,26 @@ btVector3 btConvexHullShape::localGetSupportingVertex(const btVector3& vec)const
|
|||||||
//Please note that you can debug-draw btConvexHullShape with the Raytracer Demo
|
//Please note that you can debug-draw btConvexHullShape with the Raytracer Demo
|
||||||
int btConvexHullShape::getNumVertices() const
|
int btConvexHullShape::getNumVertices() const
|
||||||
{
|
{
|
||||||
return m_points.size();
|
return m_unscaledPoints.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
int btConvexHullShape::getNumEdges() const
|
int btConvexHullShape::getNumEdges() const
|
||||||
{
|
{
|
||||||
return m_points.size();
|
return m_unscaledPoints.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void btConvexHullShape::getEdge(int i,btVector3& pa,btVector3& pb) const
|
void btConvexHullShape::getEdge(int i,btVector3& pa,btVector3& pb) const
|
||||||
{
|
{
|
||||||
|
|
||||||
int index0 = i%m_points.size();
|
int index0 = i%m_unscaledPoints.size();
|
||||||
int index1 = (i+1)%m_points.size();
|
int index1 = (i+1)%m_unscaledPoints.size();
|
||||||
pa = m_points[index0]*m_localScaling;
|
pa = getScaledPoint(index0);
|
||||||
pb = m_points[index1]*m_localScaling;
|
pb = getScaledPoint(index1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void btConvexHullShape::getVertex(int i,btVector3& vtx) const
|
void btConvexHullShape::getVertex(int i,btVector3& vtx) const
|
||||||
{
|
{
|
||||||
vtx = m_points[i]*m_localScaling;
|
vtx = getScaledPoint(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
int btConvexHullShape::getNumPlanes() const
|
int btConvexHullShape::getNumPlanes() const
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ subject to the following restrictions:
|
|||||||
///Bullet provides a general and fast collision detector for convex shapes based on GJK and EPA using localGetSupportingVertex.
|
///Bullet provides a general and fast collision detector for convex shapes based on GJK and EPA using localGetSupportingVertex.
|
||||||
ATTRIBUTE_ALIGNED16(class) btConvexHullShape : public btPolyhedralConvexShape
|
ATTRIBUTE_ALIGNED16(class) btConvexHullShape : public btPolyhedralConvexShape
|
||||||
{
|
{
|
||||||
btAlignedObjectArray<btVector3> m_points;
|
btAlignedObjectArray<btVector3> m_unscaledPoints;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BT_DECLARE_ALIGNED_ALLOCATOR();
|
BT_DECLARE_ALIGNED_ALLOCATOR();
|
||||||
@@ -37,19 +37,24 @@ public:
|
|||||||
|
|
||||||
void addPoint(const btVector3& point);
|
void addPoint(const btVector3& point);
|
||||||
|
|
||||||
btVector3* getPoints()
|
btVector3* getUnscaledPoints()
|
||||||
{
|
{
|
||||||
return &m_points[0];
|
return &m_unscaledPoints[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
const btVector3* getPoints() const
|
const btVector3* getUnscaledPoints() const
|
||||||
{
|
{
|
||||||
return &m_points[0];
|
return &m_unscaledPoints[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
int getNumPoints() const
|
SIMD_FORCE_INLINE btVector3 getScaledPoint(int i) const
|
||||||
{
|
{
|
||||||
return m_points.size();
|
return m_unscaledPoints[i] * m_localScaling;
|
||||||
|
}
|
||||||
|
|
||||||
|
SIMD_FORCE_INLINE int getNumPoints() const
|
||||||
|
{
|
||||||
|
return m_unscaledPoints.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual btVector3 localGetSupportingVertex(const btVector3& vec)const;
|
virtual btVector3 localGetSupportingVertex(const btVector3& vec)const;
|
||||||
|
|||||||
@@ -17,8 +17,9 @@ subject to the following restrictions:
|
|||||||
#include "btConvexInternalShape.h"
|
#include "btConvexInternalShape.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
btConvexInternalShape::btConvexInternalShape()
|
btConvexInternalShape::btConvexInternalShape()
|
||||||
: btConvexShape (), m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)),
|
: m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)),
|
||||||
m_collisionMargin(CONVEX_DISTANCE_MARGIN)
|
m_collisionMargin(CONVEX_DISTANCE_MARGIN)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -51,6 +52,7 @@ void btConvexInternalShape::getAabbSlow(const btTransform& trans,btVector3&minAa
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
btVector3 btConvexInternalShape::localGetSupportingVertex(const btVector3& vec)const
|
btVector3 btConvexInternalShape::localGetSupportingVertex(const btVector3& vec)const
|
||||||
{
|
{
|
||||||
#ifndef __SPU__
|
#ifndef __SPU__
|
||||||
@@ -70,6 +72,7 @@ btVector3 btConvexInternalShape::localGetSupportingVertex(const btVector3& vec)c
|
|||||||
return supVertex;
|
return supVertex;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
btAssert(0);
|
||||||
return btVector3(0,0,0);
|
return btVector3(0,0,0);
|
||||||
#endif //__SPU__
|
#endif //__SPU__
|
||||||
|
|
||||||
|
|||||||
@@ -30,14 +30,7 @@ public:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual btVector3 localGetSupportingVertex(const btVector3& vec)const;
|
virtual btVector3 localGetSupportingVertex(const btVector3& vec)const;
|
||||||
#ifndef __SPU__
|
|
||||||
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec) const= 0;
|
|
||||||
|
|
||||||
//notice that the vectors should be unit length
|
|
||||||
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const= 0;
|
|
||||||
#endif //#ifndef __SPU__
|
|
||||||
|
|
||||||
const btVector3& getImplicitShapeDimensions() const
|
const btVector3& getImplicitShapeDimensions() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ btVector3 btConvexPointCloudShape::localGetSupportingVertexWithoutMargin(const b
|
|||||||
|
|
||||||
for (int i=0;i<m_numPoints;i++)
|
for (int i=0;i<m_numPoints;i++)
|
||||||
{
|
{
|
||||||
btVector3 vtx = m_points[i] * m_localScaling;
|
btVector3 vtx = getScaledPoint(i);
|
||||||
|
|
||||||
newDot = vec.dot(vtx);
|
newDot = vec.dot(vtx);
|
||||||
if (newDot > maxDot)
|
if (newDot > maxDot)
|
||||||
@@ -67,7 +67,7 @@ void btConvexPointCloudShape::batchedUnitVectorGetSupportingVertexWithoutMargin(
|
|||||||
}
|
}
|
||||||
for (int i=0;i<m_numPoints;i++)
|
for (int i=0;i<m_numPoints;i++)
|
||||||
{
|
{
|
||||||
btVector3 vtx = m_points[i] * m_localScaling;
|
btVector3 vtx = getScaledPoint(i);
|
||||||
|
|
||||||
for (int j=0;j<numVectors;j++)
|
for (int j=0;j<numVectors;j++)
|
||||||
{
|
{
|
||||||
@@ -133,7 +133,7 @@ void btConvexPointCloudShape::getEdge(int i,btVector3& pa,btVector3& pb) const
|
|||||||
|
|
||||||
void btConvexPointCloudShape::getVertex(int i,btVector3& vtx) const
|
void btConvexPointCloudShape::getVertex(int i,btVector3& vtx) const
|
||||||
{
|
{
|
||||||
vtx = m_points[i]*m_localScaling;
|
vtx = m_unscaledPoints[i]*m_localScaling;
|
||||||
}
|
}
|
||||||
|
|
||||||
int btConvexPointCloudShape::getNumPlanes() const
|
int btConvexPointCloudShape::getNumPlanes() const
|
||||||
|
|||||||
@@ -23,15 +23,17 @@ subject to the following restrictions:
|
|||||||
///The btConvexPointCloudShape implements an implicit convex hull of an array of vertices.
|
///The btConvexPointCloudShape implements an implicit convex hull of an array of vertices.
|
||||||
ATTRIBUTE_ALIGNED16(class) btConvexPointCloudShape : public btPolyhedralConvexShape
|
ATTRIBUTE_ALIGNED16(class) btConvexPointCloudShape : public btPolyhedralConvexShape
|
||||||
{
|
{
|
||||||
btVector3* m_points;
|
btVector3* m_unscaledPoints;
|
||||||
int m_numPoints;
|
int m_numPoints;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BT_DECLARE_ALIGNED_ALLOCATOR();
|
BT_DECLARE_ALIGNED_ALLOCATOR();
|
||||||
|
|
||||||
btConvexPointCloudShape(btVector3* points,int numPoints, bool computeAabb = true)
|
btConvexPointCloudShape(btVector3* points,int numPoints, const btVector3& localScaling,bool computeAabb = true)
|
||||||
{
|
{
|
||||||
|
m_localScaling = localScaling;
|
||||||
m_shapeType = CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE;
|
m_shapeType = CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE;
|
||||||
m_points = points;
|
m_unscaledPoints = points;
|
||||||
m_numPoints = numPoints;
|
m_numPoints = numPoints;
|
||||||
|
|
||||||
if (computeAabb)
|
if (computeAabb)
|
||||||
@@ -40,28 +42,33 @@ public:
|
|||||||
|
|
||||||
void setPoints (btVector3* points, int numPoints, bool computeAabb = true)
|
void setPoints (btVector3* points, int numPoints, bool computeAabb = true)
|
||||||
{
|
{
|
||||||
m_points = points;
|
m_unscaledPoints = points;
|
||||||
m_numPoints = numPoints;
|
m_numPoints = numPoints;
|
||||||
|
|
||||||
if (computeAabb)
|
if (computeAabb)
|
||||||
recalcLocalAabb();
|
recalcLocalAabb();
|
||||||
}
|
}
|
||||||
|
|
||||||
btVector3* getPoints()
|
SIMD_FORCE_INLINE btVector3* getUnscaledPoints()
|
||||||
{
|
{
|
||||||
return m_points;
|
return m_unscaledPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
const btVector3* getPoints() const
|
SIMD_FORCE_INLINE const btVector3* getUnscaledPoints() const
|
||||||
{
|
{
|
||||||
return m_points;
|
return m_unscaledPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getNumPoints() const
|
SIMD_FORCE_INLINE int getNumPoints() const
|
||||||
{
|
{
|
||||||
return m_numPoints;
|
return m_numPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SIMD_FORCE_INLINE btVector3 getScaledPoint( int index) const
|
||||||
|
{
|
||||||
|
return m_unscaledPoints[index] * m_localScaling;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef __SPU__
|
#ifndef __SPU__
|
||||||
virtual btVector3 localGetSupportingVertex(const btVector3& vec)const;
|
virtual btVector3 localGetSupportingVertex(const btVector3& vec)const;
|
||||||
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
|
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ subject to the following restrictions:
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "btConvexShape.h"
|
#include "btConvexShape.h"
|
||||||
#include "btConvexInternalShape.h"
|
|
||||||
#include "btTriangleShape.h"
|
#include "btTriangleShape.h"
|
||||||
#include "btSphereShape.h"
|
#include "btSphereShape.h"
|
||||||
#include "btCylinderShape.h"
|
#include "btCylinderShape.h"
|
||||||
@@ -22,7 +21,18 @@ subject to the following restrictions:
|
|||||||
#include "btConvexHullShape.h"
|
#include "btConvexHullShape.h"
|
||||||
#include "btConvexPointCloudShape.h"
|
#include "btConvexPointCloudShape.h"
|
||||||
|
|
||||||
static btVector3 convexHullSupport (const btVector3& localDir, const btVector3* points, int numPoints)
|
btConvexShape::btConvexShape ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
btConvexShape::~btConvexShape()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static btVector3 convexHullSupport (const btVector3& localDir, const btVector3* points, int numPoints, const btVector3& localScaling)
|
||||||
{
|
{
|
||||||
btVector3 supVec(btScalar(0.),btScalar(0.),btScalar(0.));
|
btVector3 supVec(btScalar(0.),btScalar(0.),btScalar(0.));
|
||||||
btScalar newDot,maxDot = btScalar(-1e30);
|
btScalar newDot,maxDot = btScalar(-1e30);
|
||||||
@@ -41,7 +51,7 @@ static btVector3 convexHullSupport (const btVector3& localDir, const btVector3*
|
|||||||
|
|
||||||
for (int i=0;i<numPoints;i++)
|
for (int i=0;i<numPoints;i++)
|
||||||
{
|
{
|
||||||
btVector3 vtx = points[i];// * m_localScaling;
|
btVector3 vtx = points[i] * localScaling;
|
||||||
|
|
||||||
newDot = vec.dot(vtx);
|
newDot = vec.dot(vtx);
|
||||||
if (newDot > maxDot)
|
if (newDot > maxDot)
|
||||||
@@ -64,7 +74,7 @@ btVector3 btConvexShape::localGetSupportVertexWithoutMarginNonVirtual (const btV
|
|||||||
break;
|
break;
|
||||||
case BOX_SHAPE_PROXYTYPE:
|
case BOX_SHAPE_PROXYTYPE:
|
||||||
{
|
{
|
||||||
btConvexInternalShape* convexShape = (btConvexInternalShape*)this;
|
btBoxShape* convexShape = (btBoxShape*)this;
|
||||||
const btVector3& halfExtents = convexShape->getImplicitShapeDimensions();
|
const btVector3& halfExtents = convexShape->getImplicitShapeDimensions();
|
||||||
|
|
||||||
return btVector3(btFsels(localDir.x(), halfExtents.x(), -halfExtents.x()),
|
return btVector3(btFsels(localDir.x(), halfExtents.x(), -halfExtents.x()),
|
||||||
@@ -203,16 +213,16 @@ btVector3 btConvexShape::localGetSupportVertexWithoutMarginNonVirtual (const btV
|
|||||||
case CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE:
|
case CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE:
|
||||||
{
|
{
|
||||||
btConvexPointCloudShape* convexPointCloudShape = (btConvexPointCloudShape*)this;
|
btConvexPointCloudShape* convexPointCloudShape = (btConvexPointCloudShape*)this;
|
||||||
btVector3* points = convexPointCloudShape->getPoints ();
|
btVector3* points = convexPointCloudShape->getUnscaledPoints ();
|
||||||
int numPoints = convexPointCloudShape->getNumPoints ();
|
int numPoints = convexPointCloudShape->getNumPoints ();
|
||||||
return convexHullSupport (localDir, points, numPoints);
|
return convexHullSupport (localDir, points, numPoints,convexPointCloudShape->getLocalScalingNV());
|
||||||
}
|
}
|
||||||
case CONVEX_HULL_SHAPE_PROXYTYPE:
|
case CONVEX_HULL_SHAPE_PROXYTYPE:
|
||||||
{
|
{
|
||||||
btConvexHullShape* convexHullShape = (btConvexHullShape*)this;
|
btConvexHullShape* convexHullShape = (btConvexHullShape*)this;
|
||||||
btVector3* points = convexHullShape->getPoints ();
|
btVector3* points = convexHullShape->getUnscaledPoints();
|
||||||
int numPoints = convexHullShape->getNumPoints ();
|
int numPoints = convexHullShape->getNumPoints ();
|
||||||
return convexHullSupport (localDir, points, numPoints);
|
return convexHullSupport (localDir, points, numPoints,convexHullShape->getLocalScalingNV());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -237,174 +247,8 @@ btVector3 btConvexShape::localGetSupportVertexNonVirtual (const btVector3& local
|
|||||||
localDirNorm.setValue(btScalar(-1.),btScalar(-1.),btScalar(-1.));
|
localDirNorm.setValue(btScalar(-1.),btScalar(-1.),btScalar(-1.));
|
||||||
}
|
}
|
||||||
localDirNorm.normalize ();
|
localDirNorm.normalize ();
|
||||||
switch (m_shapeType)
|
|
||||||
{
|
|
||||||
case SPHERE_SHAPE_PROXYTYPE:
|
|
||||||
{
|
|
||||||
return btVector3(0,0,0) + getMarginNonVirtual() * localDirNorm;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case BOX_SHAPE_PROXYTYPE:
|
|
||||||
{
|
|
||||||
btConvexInternalShape* convexShape = (btConvexInternalShape*)this;
|
|
||||||
const btVector3& halfExtents = convexShape->getImplicitShapeDimensions();
|
|
||||||
|
|
||||||
return btVector3(localDir.getX() < 0.0f ? -halfExtents.x() : halfExtents.x(),
|
return localGetSupportVertexWithoutMarginNonVirtual(localDirNorm)+ getMarginNonVirtual() * localDirNorm;
|
||||||
localDir.getY() < 0.0f ? -halfExtents.y() : halfExtents.y(),
|
|
||||||
localDir.getZ() < 0.0f ? -halfExtents.z() : halfExtents.z()) + getMarginNonVirtual() * localDirNorm;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case TRIANGLE_SHAPE_PROXYTYPE:
|
|
||||||
{
|
|
||||||
btTriangleShape* triangleShape = (btTriangleShape*)this;
|
|
||||||
btVector3 dir(localDir.getX(),localDir.getY(),localDir.getZ());
|
|
||||||
btVector3* vertices = &triangleShape->m_vertices1[0];
|
|
||||||
btVector3 dots(dir.dot(vertices[0]), dir.dot(vertices[1]), dir.dot(vertices[2]));
|
|
||||||
btVector3 sup = vertices[dots.maxAxis()];
|
|
||||||
return btVector3(sup.getX(),sup.getY(),sup.getZ()) + getMarginNonVirtual() * localDirNorm;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case CYLINDER_SHAPE_PROXYTYPE:
|
|
||||||
{
|
|
||||||
btCylinderShape* cylShape = (btCylinderShape*)this;
|
|
||||||
//mapping of halfextents/dimension onto radius/height depends on how cylinder local orientation is (upAxis)
|
|
||||||
|
|
||||||
btVector3 halfExtents = cylShape->getImplicitShapeDimensions();
|
|
||||||
btVector3 v(localDir.getX(),localDir.getY(),localDir.getZ());
|
|
||||||
int cylinderUpAxis = cylShape->getUpAxis();
|
|
||||||
int XX(1),YY(0),ZZ(2);
|
|
||||||
|
|
||||||
switch (cylinderUpAxis)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
{
|
|
||||||
XX = 1;
|
|
||||||
YY = 0;
|
|
||||||
ZZ = 2;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
XX = 0;
|
|
||||||
YY = 1;
|
|
||||||
ZZ = 2;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
{
|
|
||||||
XX = 0;
|
|
||||||
YY = 2;
|
|
||||||
ZZ = 1;
|
|
||||||
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
btAssert(0);
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
|
|
||||||
btScalar radius = halfExtents[XX];
|
|
||||||
btScalar halfHeight = halfExtents[cylinderUpAxis];
|
|
||||||
|
|
||||||
btVector3 tmp;
|
|
||||||
btScalar d ;
|
|
||||||
|
|
||||||
btScalar s = btSqrt(v[XX] * v[XX] + v[ZZ] * v[ZZ]);
|
|
||||||
if (s != btScalar(0.0))
|
|
||||||
{
|
|
||||||
d = radius / s;
|
|
||||||
tmp[XX] = v[XX] * d;
|
|
||||||
tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
|
|
||||||
tmp[ZZ] = v[ZZ] * d;
|
|
||||||
return btVector3(tmp.getX(),tmp.getY(),tmp.getZ()) + getMarginNonVirtual() * localDirNorm;
|
|
||||||
} else {
|
|
||||||
tmp[XX] = radius;
|
|
||||||
tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
|
|
||||||
tmp[ZZ] = btScalar(0.0);
|
|
||||||
return btVector3(tmp.getX(),tmp.getY(),tmp.getZ()) + getMarginNonVirtual() * localDirNorm;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case CAPSULE_SHAPE_PROXYTYPE:
|
|
||||||
{
|
|
||||||
btVector3 vec0(localDir.getX(),localDir.getY(),localDir.getZ());
|
|
||||||
|
|
||||||
btCapsuleShape* capsuleShape = (btCapsuleShape*)this;
|
|
||||||
btVector3 halfExtents = capsuleShape->getImplicitShapeDimensions();
|
|
||||||
btScalar halfHeight = capsuleShape->getHalfHeight();
|
|
||||||
int capsuleUpAxis = capsuleShape->getUpAxis();
|
|
||||||
|
|
||||||
btScalar radius = capsuleShape->getRadius();
|
|
||||||
btVector3 supVec(0,0,0);
|
|
||||||
|
|
||||||
btScalar maxDot(btScalar(-1e30));
|
|
||||||
|
|
||||||
btVector3 vec = vec0;
|
|
||||||
btScalar lenSqr = vec.length2();
|
|
||||||
if (lenSqr < btScalar(0.0001))
|
|
||||||
{
|
|
||||||
vec.setValue(1,0,0);
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
btScalar rlen = btScalar(1.) / btSqrt(lenSqr );
|
|
||||||
vec *= rlen;
|
|
||||||
}
|
|
||||||
btVector3 vtx;
|
|
||||||
btScalar newDot;
|
|
||||||
{
|
|
||||||
btVector3 pos(0,0,0);
|
|
||||||
pos[capsuleUpAxis] = halfHeight;
|
|
||||||
|
|
||||||
vtx = pos +vec*(radius);
|
|
||||||
newDot = vec.dot(vtx);
|
|
||||||
if (newDot > maxDot)
|
|
||||||
{
|
|
||||||
maxDot = newDot;
|
|
||||||
supVec = vtx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
btVector3 pos(0,0,0);
|
|
||||||
pos[capsuleUpAxis] = -halfHeight;
|
|
||||||
|
|
||||||
vtx = pos +vec*(radius);
|
|
||||||
newDot = vec.dot(vtx);
|
|
||||||
if (newDot > maxDot)
|
|
||||||
{
|
|
||||||
maxDot = newDot;
|
|
||||||
supVec = vtx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return btVector3(supVec.getX(),supVec.getY(),supVec.getZ()) + getMarginNonVirtual() * localDirNorm;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE:
|
|
||||||
{
|
|
||||||
btConvexPointCloudShape* convexPointCloudShape = (btConvexPointCloudShape*)this;
|
|
||||||
btVector3* points = convexPointCloudShape->getPoints ();
|
|
||||||
int numPoints = convexPointCloudShape->getNumPoints ();
|
|
||||||
return convexHullSupport (localDir, points, numPoints) + getMarginNonVirtual() * localDirNorm;
|
|
||||||
}
|
|
||||||
case CONVEX_HULL_SHAPE_PROXYTYPE:
|
|
||||||
{
|
|
||||||
btConvexHullShape* convexHullShape = (btConvexHullShape*)this;
|
|
||||||
btVector3* points = convexHullShape->getPoints ();
|
|
||||||
int numPoints = convexHullShape->getNumPoints ();
|
|
||||||
return convexHullSupport (localDir, points, numPoints) + getMarginNonVirtual() * localDirNorm;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
#ifndef __SPU__
|
|
||||||
return this->localGetSupportingVertex (localDir);
|
|
||||||
#else
|
|
||||||
btAssert (0);
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// should never reach here
|
|
||||||
btAssert (0);
|
|
||||||
return btVector3 (btScalar(0.0f), btScalar(0.0f), btScalar(0.0f));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: This should be bumped up to btCollisionShape () */
|
/* TODO: This should be bumped up to btCollisionShape () */
|
||||||
@@ -420,7 +264,7 @@ btScalar btConvexShape::getMarginNonVirtual () const
|
|||||||
break;
|
break;
|
||||||
case BOX_SHAPE_PROXYTYPE:
|
case BOX_SHAPE_PROXYTYPE:
|
||||||
{
|
{
|
||||||
btConvexInternalShape* convexShape = (btConvexInternalShape*)this;
|
btBoxShape* convexShape = (btBoxShape*)this;
|
||||||
return convexShape->getMarginNV ();
|
return convexShape->getMarginNV ();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -483,7 +327,7 @@ void btConvexShape::getAabbNonVirtual (const btTransform& t, btVector3& aabbMin,
|
|||||||
/* fall through */
|
/* fall through */
|
||||||
case BOX_SHAPE_PROXYTYPE:
|
case BOX_SHAPE_PROXYTYPE:
|
||||||
{
|
{
|
||||||
btConvexInternalShape* convexShape = (btConvexInternalShape*)this;
|
btBoxShape* convexShape = (btBoxShape*)this;
|
||||||
float margin=convexShape->getMarginNonVirtual();
|
float margin=convexShape->getMarginNonVirtual();
|
||||||
btVector3 halfExtents = convexShape->getImplicitShapeDimensions();
|
btVector3 halfExtents = convexShape->getImplicitShapeDimensions();
|
||||||
halfExtents += btVector3(margin,margin,margin);
|
halfExtents += btVector3(margin,margin,margin);
|
||||||
|
|||||||
@@ -36,22 +36,15 @@ public:
|
|||||||
|
|
||||||
BT_DECLARE_ALIGNED_ALLOCATOR();
|
BT_DECLARE_ALIGNED_ALLOCATOR();
|
||||||
|
|
||||||
btConvexShape ()
|
btConvexShape ();
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~btConvexShape()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
virtual ~btConvexShape();
|
||||||
|
|
||||||
virtual btVector3 localGetSupportingVertex(const btVector3& vec)const = 0;
|
virtual btVector3 localGetSupportingVertex(const btVector3& vec)const = 0;
|
||||||
|
|
||||||
|
////////
|
||||||
#ifndef __SPU__
|
#ifndef __SPU__
|
||||||
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec) const=0;
|
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec) const=0;
|
||||||
|
|
||||||
//notice that the vectors should be unit length
|
|
||||||
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const= 0;
|
|
||||||
#endif //#ifndef __SPU__
|
#endif //#ifndef __SPU__
|
||||||
|
|
||||||
btVector3 localGetSupportVertexWithoutMarginNonVirtual (const btVector3& vec) const;
|
btVector3 localGetSupportVertexWithoutMarginNonVirtual (const btVector3& vec) const;
|
||||||
@@ -59,6 +52,10 @@ public:
|
|||||||
btScalar getMarginNonVirtual () const;
|
btScalar getMarginNonVirtual () const;
|
||||||
void getAabbNonVirtual (const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const;
|
void getAabbNonVirtual (const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const;
|
||||||
|
|
||||||
|
|
||||||
|
//notice that the vectors should be unit length
|
||||||
|
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const= 0;
|
||||||
|
|
||||||
///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
|
///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
|
||||||
void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const =0;
|
void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const =0;
|
||||||
|
|
||||||
@@ -75,6 +72,9 @@ public:
|
|||||||
|
|
||||||
virtual void getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const=0;
|
virtual void getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const=0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -64,17 +64,21 @@ void btGjkPairDetector::getClosestPoints(const ClosestPointInput& input,Result&
|
|||||||
localTransA.getOrigin() -= positionOffset;
|
localTransA.getOrigin() -= positionOffset;
|
||||||
localTransB.getOrigin() -= positionOffset;
|
localTransB.getOrigin() -= positionOffset;
|
||||||
|
|
||||||
|
#ifdef __SPU__
|
||||||
btScalar marginA = m_minkowskiA->getMarginNonVirtual();
|
btScalar marginA = m_minkowskiA->getMarginNonVirtual();
|
||||||
btScalar marginB = m_minkowskiB->getMarginNonVirtual();
|
btScalar marginB = m_minkowskiB->getMarginNonVirtual();
|
||||||
|
#else
|
||||||
|
btScalar marginA = m_minkowskiA->getMargin();
|
||||||
|
btScalar marginB = m_minkowskiB->getMargin();
|
||||||
#ifdef TEST_NON_VIRTUAL
|
#ifdef TEST_NON_VIRTUAL
|
||||||
btScalar marginAv = m_minkowskiA->getMargin();
|
btScalar marginAv = m_minkowskiA->getMarginNonVirtual();
|
||||||
btScalar marginBv = m_minkowskiB->getMargin();
|
btScalar marginBv = m_minkowskiB->getMarginNonVirtual();
|
||||||
|
|
||||||
btAssert(marginA == marginAv);
|
btAssert(marginA == marginAv);
|
||||||
btAssert(marginB == marginBv);
|
btAssert(marginB == marginBv);
|
||||||
#endif //TEST_NON_VIRTUAL
|
#endif //TEST_NON_VIRTUAL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
gNumGjkChecks++;
|
gNumGjkChecks++;
|
||||||
|
|
||||||
@@ -119,16 +123,19 @@ void btGjkPairDetector::getClosestPoints(const ClosestPointInput& input,Result&
|
|||||||
btVector3 seperatingAxisInA = (-m_cachedSeparatingAxis)* input.m_transformA.getBasis();
|
btVector3 seperatingAxisInA = (-m_cachedSeparatingAxis)* input.m_transformA.getBasis();
|
||||||
btVector3 seperatingAxisInB = m_cachedSeparatingAxis* input.m_transformB.getBasis();
|
btVector3 seperatingAxisInB = m_cachedSeparatingAxis* input.m_transformB.getBasis();
|
||||||
|
|
||||||
|
#ifdef __SPU__
|
||||||
|
btVector3 pInA = m_minkowskiA->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInA);
|
||||||
|
btVector3 qInB = m_minkowskiB->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInB);
|
||||||
|
#else
|
||||||
|
btVector3 pInA = m_minkowskiA->localGetSupportingVertexWithoutMargin(seperatingAxisInA);
|
||||||
|
btVector3 qInB = m_minkowskiB->localGetSupportingVertexWithoutMargin(seperatingAxisInB);
|
||||||
#ifdef TEST_NON_VIRTUAL
|
#ifdef TEST_NON_VIRTUAL
|
||||||
btVector3 pInAv = m_minkowskiA->localGetSupportingVertexWithoutMargin(seperatingAxisInA);
|
btVector3 pInAv = m_minkowskiA->localGetSupportingVertexWithoutMargin(seperatingAxisInA);
|
||||||
btVector3 qInBv = m_minkowskiB->localGetSupportingVertexWithoutMargin(seperatingAxisInB);
|
btVector3 qInBv = m_minkowskiB->localGetSupportingVertexWithoutMargin(seperatingAxisInB);
|
||||||
#endif
|
|
||||||
btVector3 pInA = m_minkowskiA->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInA);
|
|
||||||
btVector3 qInB = m_minkowskiB->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInB);
|
|
||||||
#ifdef TEST_NON_VIRTUAL
|
|
||||||
btAssert((pInAv-pInA).length() < 0.0001);
|
btAssert((pInAv-pInA).length() < 0.0001);
|
||||||
btAssert((qInBv-qInB).length() < 0.0001);
|
btAssert((qInBv-qInB).length() < 0.0001);
|
||||||
#endif //
|
#endif //
|
||||||
|
#endif //__SPU__
|
||||||
|
|
||||||
btVector3 pWorld = localTransA(pInA);
|
btVector3 pWorld = localTransA(pInA);
|
||||||
btVector3 qWorld = localTransB(qInB);
|
btVector3 qWorld = localTransB(qInB);
|
||||||
|
|||||||
Reference in New Issue
Block a user