mirror of
https://github.com/bulletphysics/bullet3
synced 2025-01-10 17:30:12 +00:00
Make getShapeType() a non virtual function.
Add localGetSupportVertexNonVirtual, localGetSupportVertexWithoutMarginNonVirtual, getAabbNonVirtual and getMarginNonVirtual methods to convex shape classes
This commit is contained in:
parent
41b6eaa87f
commit
2b71784c86
@ -25,12 +25,13 @@ subject to the following restrictions:
|
||||
/// to facilitate type checking
|
||||
enum BroadphaseNativeTypes
|
||||
{
|
||||
// polyhedral convex shapes
|
||||
// polyhedral convex shapes
|
||||
BOX_SHAPE_PROXYTYPE,
|
||||
TRIANGLE_SHAPE_PROXYTYPE,
|
||||
TETRAHEDRAL_SHAPE_PROXYTYPE,
|
||||
CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE,
|
||||
CONVEX_HULL_SHAPE_PROXYTYPE,
|
||||
CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE,
|
||||
//implicit convex shapes
|
||||
IMPLICIT_CONVEX_SHAPES_START_HERE,
|
||||
SPHERE_SHAPE_PROXYTYPE,
|
||||
@ -64,7 +65,10 @@ CONCAVE_SHAPES_END_HERE,
|
||||
|
||||
SOFTBODY_SHAPE_PROXYTYPE,
|
||||
|
||||
INVALID_SHAPE_PROXYTYPE,
|
||||
|
||||
MAX_BROADPHASE_COLLISION_TYPES
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -45,8 +45,6 @@ public:
|
||||
}
|
||||
|
||||
|
||||
virtual int getShapeType() const { return BOX_SHAPE_PROXYTYPE;}
|
||||
|
||||
virtual btVector3 localGetSupportingVertex(const btVector3& vec) const
|
||||
{
|
||||
btVector3 halfExtents = getHalfExtentsWithoutMargin();
|
||||
@ -82,8 +80,10 @@ public:
|
||||
}
|
||||
|
||||
|
||||
btBoxShape( const btVector3& boxHalfExtents)
|
||||
btBoxShape( const btVector3& boxHalfExtents)
|
||||
: btPolyhedralConvexShape()
|
||||
{
|
||||
m_shapeType = BOX_SHAPE_PROXYTYPE;
|
||||
btVector3 margin(getMargin(),getMargin(),getMargin());
|
||||
m_implicitShapeDimensions = (boxHalfExtents * m_localScaling) - margin;
|
||||
};
|
||||
|
@ -26,6 +26,7 @@ m_bvh(0),
|
||||
m_useQuantizedAabbCompression(useQuantizedAabbCompression),
|
||||
m_ownsBvh(false)
|
||||
{
|
||||
m_shapeType = TRIANGLE_MESH_SHAPE_PROXYTYPE;
|
||||
//construct bvh from meshInterface
|
||||
#ifndef DISABLE_BVH
|
||||
|
||||
@ -57,6 +58,7 @@ m_bvh(0),
|
||||
m_useQuantizedAabbCompression(useQuantizedAabbCompression),
|
||||
m_ownsBvh(false)
|
||||
{
|
||||
m_shapeType = TRIANGLE_MESH_SHAPE_PROXYTYPE;
|
||||
//construct bvh from meshInterface
|
||||
#ifndef DISABLE_BVH
|
||||
|
||||
|
@ -37,7 +37,7 @@ public:
|
||||
|
||||
BT_DECLARE_ALIGNED_ALLOCATOR();
|
||||
|
||||
btBvhTriangleMeshShape() :btTriangleMeshShape(0),m_bvh(0),m_ownsBvh(false) {};
|
||||
btBvhTriangleMeshShape() : btTriangleMeshShape(0),m_bvh(0),m_ownsBvh(false) {m_shapeType = TRIANGLE_MESH_SHAPE_PROXYTYPE;};
|
||||
btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression, bool buildBvh = true);
|
||||
|
||||
///optionally pass in a larger bvh aabb, used for quantization. This allows for deformations within this aabb
|
||||
@ -50,10 +50,7 @@ public:
|
||||
return m_ownsBvh;
|
||||
}
|
||||
|
||||
virtual int getShapeType() const
|
||||
{
|
||||
return TRIANGLE_MESH_SHAPE_PROXYTYPE;
|
||||
}
|
||||
|
||||
|
||||
void performRaycast (btTriangleCallback* callback, const btVector3& raySource, const btVector3& rayTarget);
|
||||
void performConvexcast (btTriangleCallback* callback, const btVector3& boxSource, const btVector3& boxTarget, const btVector3& boxMin, const btVector3& boxMax);
|
||||
|
@ -19,7 +19,7 @@ subject to the following restrictions:
|
||||
#include "BulletCollision/CollisionShapes/btCollisionMargin.h"
|
||||
#include "LinearMath/btQuaternion.h"
|
||||
|
||||
btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height)
|
||||
btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height) : btConvexInternalShape ()
|
||||
{
|
||||
m_upAxis = 1;
|
||||
m_implicitShapeDimensions.setValue(radius,0.5f*height,radius);
|
||||
|
@ -30,7 +30,7 @@ protected:
|
||||
|
||||
protected:
|
||||
///only used for btCapsuleShapeZ and btCapsuleShapeX subclasses.
|
||||
btCapsuleShape() {};
|
||||
btCapsuleShape() : btConvexInternalShape() {m_shapeType = CAPSULE_SHAPE_PROXYTYPE;};
|
||||
|
||||
public:
|
||||
btCapsuleShape(btScalar radius,btScalar height);
|
||||
@ -43,8 +43,6 @@ public:
|
||||
|
||||
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
|
||||
|
||||
virtual int getShapeType() const { return CAPSULE_SHAPE_PROXYTYPE; }
|
||||
|
||||
virtual void getAabb (const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const
|
||||
{
|
||||
btVector3 halfExtents(getRadius(),getRadius(),getRadius());
|
||||
|
@ -25,14 +25,16 @@ subject to the following restrictions:
|
||||
///The btCollisionShape class provides an interface for collision shapes that can be shared among btCollisionObjects.
|
||||
class btCollisionShape
|
||||
{
|
||||
|
||||
protected:
|
||||
int m_shapeType;
|
||||
void* m_userPointer;
|
||||
|
||||
public:
|
||||
|
||||
btCollisionShape() : m_userPointer(0)
|
||||
btCollisionShape() : m_shapeType (INVALID_SHAPE_PROXYTYPE), m_userPointer(0)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~btCollisionShape()
|
||||
{
|
||||
}
|
||||
@ -76,7 +78,7 @@ public:
|
||||
return btBroadphaseProxy::isInfinite(getShapeType());
|
||||
}
|
||||
|
||||
virtual int getShapeType() const=0;
|
||||
|
||||
virtual void setLocalScaling(const btVector3& scaling) =0;
|
||||
virtual const btVector3& getLocalScaling() const =0;
|
||||
virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const = 0;
|
||||
@ -87,13 +89,13 @@ public:
|
||||
#endif //__SPU__
|
||||
|
||||
|
||||
|
||||
int getShapeType() const { return m_shapeType; }
|
||||
virtual void setMargin(btScalar margin) = 0;
|
||||
virtual btScalar getMargin() const = 0;
|
||||
|
||||
|
||||
///optional user data pointer
|
||||
void setUserPointer(void* userPtr)
|
||||
void setUserPointer(void* userPtr)
|
||||
{
|
||||
m_userPointer = userPtr;
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ subject to the following restrictions:
|
||||
#include "BulletCollision/BroadphaseCollision/btDbvt.h"
|
||||
|
||||
btCompoundShape::btCompoundShape()
|
||||
:m_localAabbMin(btScalar(1e30),btScalar(1e30),btScalar(1e30)),
|
||||
: m_localAabbMin(btScalar(1e30),btScalar(1e30),btScalar(1e30)),
|
||||
m_localAabbMax(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30)),
|
||||
m_collisionMargin(btScalar(0.)),
|
||||
m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)),
|
||||
|
@ -121,8 +121,6 @@ public:
|
||||
|
||||
virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const;
|
||||
|
||||
virtual int getShapeType() const { return COMPOUND_SHAPE_PROXYTYPE;}
|
||||
|
||||
virtual void setMargin(btScalar margin)
|
||||
{
|
||||
m_collisionMargin = margin;
|
||||
|
@ -18,10 +18,11 @@ subject to the following restrictions:
|
||||
|
||||
|
||||
|
||||
btConeShape::btConeShape (btScalar radius,btScalar height):
|
||||
btConeShape::btConeShape (btScalar radius,btScalar height): btConvexInternalShape (),
|
||||
m_radius (radius),
|
||||
m_height(height)
|
||||
{
|
||||
m_shapeType = CONE_SHAPE_PROXYTYPE;
|
||||
setConeUpIndex(1);
|
||||
btVector3 halfExtents;
|
||||
m_sinAngle = (m_radius / btSqrt(m_radius * m_radius + m_height * m_height));
|
||||
|
@ -69,9 +69,6 @@ public:
|
||||
}
|
||||
|
||||
|
||||
|
||||
virtual int getShapeType() const { return CONE_SHAPE_PROXYTYPE; }
|
||||
|
||||
virtual const char* getName()const
|
||||
{
|
||||
return "Cone";
|
||||
|
@ -19,8 +19,9 @@ subject to the following restrictions:
|
||||
|
||||
|
||||
|
||||
btConvexHullShape ::btConvexHullShape (const btScalar* points,int numPoints,int stride)
|
||||
btConvexHullShape ::btConvexHullShape (const btScalar* points,int numPoints,int stride) : btPolyhedralConvexShape ()
|
||||
{
|
||||
m_shapeType = CONVEX_HULL_SHAPE_PROXYTYPE;
|
||||
m_points.resize(numPoints);
|
||||
|
||||
unsigned char* pointsBaseAddress = (unsigned char*)points;
|
||||
|
@ -57,7 +57,6 @@ public:
|
||||
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
|
||||
|
||||
|
||||
virtual int getShapeType()const { return CONVEX_HULL_SHAPE_PROXYTYPE; }
|
||||
|
||||
//debugging
|
||||
virtual const char* getName()const {return "Convex";}
|
||||
|
@ -18,7 +18,7 @@ subject to the following restrictions:
|
||||
|
||||
|
||||
btConvexInternalShape::btConvexInternalShape()
|
||||
: m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)),
|
||||
: btConvexShape (), m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)),
|
||||
m_collisionMargin(CONVEX_DISTANCE_MARGIN)
|
||||
{
|
||||
}
|
||||
|
@ -19,9 +19,11 @@ class btConvexInternalShape : public btConvexShape
|
||||
|
||||
btScalar m_padding;
|
||||
|
||||
btConvexInternalShape();
|
||||
|
||||
public:
|
||||
|
||||
btConvexInternalShape();
|
||||
|
||||
|
||||
virtual ~btConvexInternalShape()
|
||||
{
|
||||
|
173
src/BulletCollision/CollisionShapes/btConvexPointCloudShape.cpp
Normal file
173
src/BulletCollision/CollisionShapes/btConvexPointCloudShape.cpp
Normal file
@ -0,0 +1,173 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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 "btConvexPointCloudShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btCollisionMargin.h"
|
||||
|
||||
#include "LinearMath/btQuaternion.h"
|
||||
|
||||
btConvexPointCloudShape::btConvexPointCloudShape (btVector3* points,int numPoints) : btPolyhedralConvexShape ()
|
||||
{
|
||||
m_shapeType = CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE;
|
||||
m_points = points;
|
||||
m_numPoints = numPoints;
|
||||
|
||||
recalcLocalAabb();
|
||||
}
|
||||
|
||||
void btConvexPointCloudShape::setPoints (btVector3* points, int numPoints)
|
||||
{
|
||||
m_points = points;
|
||||
m_numPoints = numPoints;
|
||||
|
||||
recalcLocalAabb();
|
||||
}
|
||||
|
||||
|
||||
void btConvexPointCloudShape::setLocalScaling(const btVector3& scaling)
|
||||
{
|
||||
m_localScaling = scaling;
|
||||
recalcLocalAabb();
|
||||
}
|
||||
|
||||
btVector3 btConvexPointCloudShape::localGetSupportingVertexWithoutMargin(const btVector3& vec0)const
|
||||
{
|
||||
btVector3 supVec(btScalar(0.),btScalar(0.),btScalar(0.));
|
||||
btScalar newDot,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;
|
||||
}
|
||||
|
||||
|
||||
for (int i=0;i<m_numPoints;i++)
|
||||
{
|
||||
btPoint3 vtx = m_points[i] * m_localScaling;
|
||||
|
||||
newDot = vec.dot(vtx);
|
||||
if (newDot > maxDot)
|
||||
{
|
||||
maxDot = newDot;
|
||||
supVec = vtx;
|
||||
}
|
||||
}
|
||||
return supVec;
|
||||
}
|
||||
|
||||
void btConvexPointCloudShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
|
||||
{
|
||||
btScalar newDot;
|
||||
//use 'w' component of supportVerticesOut?
|
||||
{
|
||||
for (int i=0;i<numVectors;i++)
|
||||
{
|
||||
supportVerticesOut[i][3] = btScalar(-1e30);
|
||||
}
|
||||
}
|
||||
for (int i=0;i<m_numPoints;i++)
|
||||
{
|
||||
btPoint3 vtx = m_points[i] * m_localScaling;
|
||||
|
||||
for (int j=0;j<numVectors;j++)
|
||||
{
|
||||
const btVector3& vec = vectors[j];
|
||||
|
||||
newDot = vec.dot(vtx);
|
||||
if (newDot > supportVerticesOut[j][3])
|
||||
{
|
||||
//WARNING: don't swap next lines, the w component would get overwritten!
|
||||
supportVerticesOut[j] = vtx;
|
||||
supportVerticesOut[j][3] = newDot;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
btVector3 btConvexPointCloudShape::localGetSupportingVertex(const btVector3& vec)const
|
||||
{
|
||||
btVector3 supVertex = localGetSupportingVertexWithoutMargin(vec);
|
||||
|
||||
if ( getMargin()!=btScalar(0.) )
|
||||
{
|
||||
btVector3 vecnorm = vec;
|
||||
if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON))
|
||||
{
|
||||
vecnorm.setValue(btScalar(-1.),btScalar(-1.),btScalar(-1.));
|
||||
}
|
||||
vecnorm.normalize();
|
||||
supVertex+= getMargin() * vecnorm;
|
||||
}
|
||||
return supVertex;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//currently just for debugging (drawing), perhaps future support for algebraic continuous collision detection
|
||||
//Please note that you can debug-draw btConvexHullShape with the Raytracer Demo
|
||||
int btConvexPointCloudShape::getNumVertices() const
|
||||
{
|
||||
return m_numPoints;
|
||||
}
|
||||
|
||||
int btConvexPointCloudShape::getNumEdges() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void btConvexPointCloudShape::getEdge(int i,btPoint3& pa,btPoint3& pb) const
|
||||
{
|
||||
btAssert (0);
|
||||
}
|
||||
|
||||
void btConvexPointCloudShape::getVertex(int i,btPoint3& vtx) const
|
||||
{
|
||||
vtx = m_points[i]*m_localScaling;
|
||||
}
|
||||
|
||||
int btConvexPointCloudShape::getNumPlanes() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void btConvexPointCloudShape::getPlane(btVector3& ,btPoint3& ,int ) const
|
||||
{
|
||||
|
||||
btAssert(0);
|
||||
}
|
||||
|
||||
//not yet
|
||||
bool btConvexPointCloudShape::isInside(const btPoint3& ,btScalar ) const
|
||||
{
|
||||
assert(0);
|
||||
return false;
|
||||
}
|
||||
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef BT_CONVEX_POINT_CLOUD_SHAPE_H
|
||||
#define BT_CONVEX_POINT_CLOUD_SHAPE_H
|
||||
|
||||
#include "btPolyhedralConvexShape.h"
|
||||
#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
|
||||
///The btConvexPointCloudShape implements an implicit convex hull of an array of vertices.
|
||||
ATTRIBUTE_ALIGNED16(class) btConvexPointCloudShape : public btPolyhedralConvexShape
|
||||
{
|
||||
btVector3* m_points;
|
||||
int m_numPoints;
|
||||
public:
|
||||
BT_DECLARE_ALIGNED_ALLOCATOR();
|
||||
|
||||
btConvexPointCloudShape(btVector3* points,int numPoints);
|
||||
|
||||
void setPoints (btVector3* points, int numPoints);
|
||||
|
||||
btPoint3* getPoints()
|
||||
{
|
||||
return m_points;
|
||||
}
|
||||
|
||||
const btPoint3* getPoints() const
|
||||
{
|
||||
return m_points;
|
||||
}
|
||||
|
||||
int getNumPoints() const
|
||||
{
|
||||
return m_numPoints;
|
||||
}
|
||||
|
||||
virtual btVector3 localGetSupportingVertex(const btVector3& vec)const;
|
||||
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
|
||||
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
|
||||
|
||||
|
||||
//debugging
|
||||
virtual const char* getName()const {return "ConvexPointCloud";}
|
||||
|
||||
virtual int getNumVertices() const;
|
||||
virtual int getNumEdges() const;
|
||||
virtual void getEdge(int i,btPoint3& pa,btPoint3& pb) const;
|
||||
virtual void getVertex(int i,btPoint3& vtx) const;
|
||||
virtual int getNumPlanes() const;
|
||||
virtual void getPlane(btVector3& planeNormal,btPoint3& planeSupport,int i ) const;
|
||||
virtual bool isInside(const btPoint3& pt,btScalar tolerance) const;
|
||||
|
||||
///in case we receive negative scaling
|
||||
virtual void setLocalScaling(const btVector3& scaling);
|
||||
};
|
||||
|
||||
|
||||
#endif //BT_CONVEX_POINT_CLOUD_SHAPE_H
|
||||
|
@ -14,5 +14,534 @@ subject to the following restrictions:
|
||||
*/
|
||||
|
||||
#include "btConvexShape.h"
|
||||
#include "btConvexInternalShape.h"
|
||||
#include "btTriangleShape.h"
|
||||
#include "btSphereShape.h"
|
||||
#include "btCylinderShape.h"
|
||||
#include "btCapsuleShape.h"
|
||||
#include "btConvexHullShape.h"
|
||||
#include "btConvexPointCloudShape.h"
|
||||
|
||||
static btVector3 convexHullSupport (const btVector3& localDir, const btVector3* points, int numPoints)
|
||||
{
|
||||
btVector3 supVec(btScalar(0.),btScalar(0.),btScalar(0.));
|
||||
btScalar newDot,maxDot = btScalar(-1e30);
|
||||
|
||||
btVector3 vec0(localDir.getX(),localDir.getY(),localDir.getZ());
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
for (int i=0;i<numPoints;i++)
|
||||
{
|
||||
btPoint3 vtx = points[i];// * m_localScaling;
|
||||
|
||||
newDot = vec.dot(vtx);
|
||||
if (newDot > maxDot)
|
||||
{
|
||||
maxDot = newDot;
|
||||
supVec = vtx;
|
||||
}
|
||||
}
|
||||
return btVector3(supVec.getX(),supVec.getY(),supVec.getZ());
|
||||
}
|
||||
|
||||
btVector3 btConvexShape::localGetSupportVertexWithoutMarginNonVirtual (const btVector3& localDir) const
|
||||
{
|
||||
switch (m_shapeType)
|
||||
{
|
||||
case SPHERE_SHAPE_PROXYTYPE:
|
||||
{
|
||||
return btVector3(0,0,0);
|
||||
}
|
||||
break;
|
||||
case BOX_SHAPE_PROXYTYPE:
|
||||
{
|
||||
btConvexInternalShape* convexShape = (btConvexInternalShape*)this;
|
||||
const btVector3& halfExtents = convexShape->getImplicitShapeDimensions();
|
||||
|
||||
return btVector3(localDir.getX() < 0.0f ? -halfExtents.x() : halfExtents.x(),
|
||||
localDir.getY() < 0.0f ? -halfExtents.y() : halfExtents.y(),
|
||||
localDir.getZ() < 0.0f ? -halfExtents.z() : halfExtents.z());
|
||||
}
|
||||
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());
|
||||
}
|
||||
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());
|
||||
} 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());
|
||||
}
|
||||
}
|
||||
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());
|
||||
}
|
||||
break;
|
||||
case CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE:
|
||||
{
|
||||
btConvexPointCloudShape* convexPointCloudShape = (btConvexPointCloudShape*)this;
|
||||
btVector3* points = convexPointCloudShape->getPoints ();
|
||||
int numPoints = convexPointCloudShape->getNumPoints ();
|
||||
return convexHullSupport (localDir, points, numPoints);
|
||||
}
|
||||
case CONVEX_HULL_SHAPE_PROXYTYPE:
|
||||
{
|
||||
btConvexHullShape* convexHullShape = (btConvexHullShape*)this;
|
||||
btPoint3* points = convexHullShape->getPoints ();
|
||||
int numPoints = convexHullShape->getNumPoints ();
|
||||
return convexHullSupport (localDir, points, numPoints);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
#ifndef __SPU__
|
||||
return this->localGetSupportingVertexWithoutMargin (localDir);
|
||||
#else
|
||||
btAssert (0);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
// should never reach here
|
||||
btAssert (0);
|
||||
return btPoint3 (btScalar(0.0f), btScalar(0.0f), btScalar(0.0f));
|
||||
}
|
||||
|
||||
btVector3 btConvexShape::localGetSupportVertexNonVirtual (const btVector3& localDir) const
|
||||
{
|
||||
btVector3 localDirNorm = localDir;
|
||||
if (localDirNorm .length2() < (SIMD_EPSILON*SIMD_EPSILON))
|
||||
{
|
||||
localDirNorm.setValue(btScalar(-1.),btScalar(-1.),btScalar(-1.));
|
||||
}
|
||||
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(),
|
||||
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;
|
||||
btPoint3* 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 btPoint3 (btScalar(0.0f), btScalar(0.0f), btScalar(0.0f));
|
||||
}
|
||||
|
||||
/* TODO: This should be bumped up to btCollisionShape () */
|
||||
btScalar btConvexShape::getMarginNonVirtual () const
|
||||
{
|
||||
switch (m_shapeType)
|
||||
{
|
||||
case SPHERE_SHAPE_PROXYTYPE:
|
||||
{
|
||||
btSphereShape* sphereShape = (btSphereShape*)this;
|
||||
return sphereShape->getRadius ();
|
||||
}
|
||||
break;
|
||||
case BOX_SHAPE_PROXYTYPE:
|
||||
{
|
||||
btConvexInternalShape* convexShape = (btConvexInternalShape*)this;
|
||||
return convexShape->getMarginNV ();
|
||||
}
|
||||
break;
|
||||
case TRIANGLE_SHAPE_PROXYTYPE:
|
||||
{
|
||||
btTriangleShape* triangleShape = (btTriangleShape*)this;
|
||||
return triangleShape->getMarginNV ();
|
||||
}
|
||||
break;
|
||||
case CYLINDER_SHAPE_PROXYTYPE:
|
||||
{
|
||||
btCylinderShape* cylShape = (btCylinderShape*)this;
|
||||
return cylShape->getMarginNV();
|
||||
}
|
||||
break;
|
||||
case CAPSULE_SHAPE_PROXYTYPE:
|
||||
{
|
||||
btCapsuleShape* capsuleShape = (btCapsuleShape*)this;
|
||||
return capsuleShape->getMarginNV();
|
||||
}
|
||||
break;
|
||||
case CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE:
|
||||
/* fall through */
|
||||
case CONVEX_HULL_SHAPE_PROXYTYPE:
|
||||
{
|
||||
btPolyhedralConvexShape* convexHullShape = (btPolyhedralConvexShape*)this;
|
||||
return convexHullShape->getMarginNV();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
#ifndef __SPU__
|
||||
return this->getMargin ();
|
||||
#else
|
||||
btAssert (0);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
// should never reach here
|
||||
btAssert (0);
|
||||
return btScalar(0.0f);
|
||||
}
|
||||
|
||||
void btConvexShape::getAabbNonVirtual (const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const
|
||||
{
|
||||
switch (m_shapeType)
|
||||
{
|
||||
case SPHERE_SHAPE_PROXYTYPE:
|
||||
{
|
||||
btSphereShape* sphereShape = (btSphereShape*)this;
|
||||
float radius = sphereShape->getImplicitShapeDimensions().getX();// * convexShape->getLocalScaling().getX();
|
||||
float margin = radius + sphereShape->getMarginNonVirtual();
|
||||
const btVector3& center = t.getOrigin();
|
||||
btVector3 extent(margin,margin,margin);
|
||||
aabbMin = center - extent;
|
||||
aabbMax = center + extent;
|
||||
}
|
||||
break;
|
||||
case CYLINDER_SHAPE_PROXYTYPE:
|
||||
/* fall through */
|
||||
case BOX_SHAPE_PROXYTYPE:
|
||||
{
|
||||
btConvexInternalShape* convexShape = (btConvexInternalShape*)this;
|
||||
float margin=convexShape->getMarginNonVirtual();
|
||||
btVector3 halfExtents = convexShape->getImplicitShapeDimensions();
|
||||
halfExtents += btVector3(margin,margin,margin);
|
||||
btMatrix3x3 abs_b = t.getBasis().absolute();
|
||||
btPoint3 center = t.getOrigin();
|
||||
btVector3 extent = btVector3(abs_b[0].dot(halfExtents),abs_b[1].dot(halfExtents),abs_b[2].dot(halfExtents));
|
||||
|
||||
aabbMin = center - extent;
|
||||
aabbMax = center + extent;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case TRIANGLE_SHAPE_PROXYTYPE:
|
||||
{
|
||||
btTriangleShape* triangleShape = (btTriangleShape*)this;
|
||||
btScalar margin = triangleShape->getMarginNonVirtual();
|
||||
for (int i=0;i<3;i++)
|
||||
{
|
||||
btVector3 vec(btScalar(0.),btScalar(0.),btScalar(0.));
|
||||
vec[i] = btScalar(1.);
|
||||
|
||||
btVector3 sv = localGetSupportVertexWithoutMarginNonVirtual(vec*t.getBasis());
|
||||
|
||||
btVector3 tmp = t(sv);
|
||||
aabbMax[i] = tmp[i]+margin;
|
||||
vec[i] = btScalar(-1.);
|
||||
tmp = t(localGetSupportVertexWithoutMarginNonVirtual(vec*t.getBasis()));
|
||||
aabbMin[i] = tmp[i]-margin;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CAPSULE_SHAPE_PROXYTYPE:
|
||||
{
|
||||
btCapsuleShape* capsuleShape = (btCapsuleShape*)this;
|
||||
btVector3 halfExtents(capsuleShape->getRadius(),capsuleShape->getRadius(),capsuleShape->getRadius());
|
||||
int m_upAxis = capsuleShape->getUpAxis();
|
||||
halfExtents[m_upAxis] = capsuleShape->getRadius() + capsuleShape->getHalfHeight();
|
||||
halfExtents += btVector3(capsuleShape->getMarginNonVirtual(),capsuleShape->getMarginNonVirtual(),capsuleShape->getMarginNonVirtual());
|
||||
btMatrix3x3 abs_b = t.getBasis().absolute();
|
||||
btPoint3 center = t.getOrigin();
|
||||
btVector3 extent = btVector3(abs_b[0].dot(halfExtents),abs_b[1].dot(halfExtents),abs_b[2].dot(halfExtents));
|
||||
aabbMin = center - extent;
|
||||
aabbMax = center + extent;
|
||||
}
|
||||
break;
|
||||
case CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE:
|
||||
case CONVEX_HULL_SHAPE_PROXYTYPE:
|
||||
{
|
||||
btPolyhedralConvexShape* convexHullShape = (btPolyhedralConvexShape*)this;
|
||||
btScalar margin = convexHullShape->getMarginNonVirtual();
|
||||
convexHullShape->getNonvirtualAabb (t, aabbMin, aabbMax, margin);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
#ifndef __SPU__
|
||||
this->getAabb (t, aabbMin, aabbMax);
|
||||
#else
|
||||
btAssert (0);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
// should never reach here
|
||||
btAssert (0);
|
||||
}
|
@ -38,6 +38,10 @@ public:
|
||||
|
||||
BT_DECLARE_ALIGNED_ALLOCATOR();
|
||||
|
||||
btConvexShape ()
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~btConvexShape()
|
||||
{
|
||||
|
||||
@ -52,6 +56,10 @@ public:
|
||||
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const= 0;
|
||||
#endif //#ifndef __SPU__
|
||||
|
||||
btVector3 localGetSupportVertexWithoutMarginNonVirtual (const btVector3& vec) const;
|
||||
btVector3 localGetSupportVertexNonVirtual (const btVector3& vec) const;
|
||||
btScalar getMarginNonVirtual () const;
|
||||
void getAabbNonVirtual (const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const;
|
||||
|
||||
///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;
|
||||
|
@ -20,8 +20,9 @@ subject to the following restrictions:
|
||||
|
||||
|
||||
btConvexTriangleMeshShape ::btConvexTriangleMeshShape (btStridingMeshInterface* meshInterface, bool calcAabb)
|
||||
:m_stridingMesh(meshInterface)
|
||||
: btPolyhedralConvexShape(), m_stridingMesh(meshInterface)
|
||||
{
|
||||
m_shapeType = CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE;
|
||||
if ( calcAabb )
|
||||
recalcLocalAabb();
|
||||
}
|
||||
|
@ -1,63 +1,61 @@
|
||||
#ifndef CONVEX_TRIANGLEMESH_SHAPE_H
|
||||
#define CONVEX_TRIANGLEMESH_SHAPE_H
|
||||
|
||||
|
||||
#include "btPolyhedralConvexShape.h"
|
||||
#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
|
||||
|
||||
|
||||
/// The btConvexTriangleMeshShape is a convex hull of a triangle mesh, but the performance is not as good as btConvexHullShape.
|
||||
/// A small benefit of this class is that it uses the btStridingMeshInterface, so you can avoid the duplication of the triangle mesh data. Nevertheless, most users should use the much better performing btConvexHullShape instead.
|
||||
class btConvexTriangleMeshShape : public btPolyhedralConvexShape
|
||||
{
|
||||
|
||||
class btStridingMeshInterface* m_stridingMesh;
|
||||
|
||||
public:
|
||||
btConvexTriangleMeshShape(btStridingMeshInterface* meshInterface, bool calcAabb = true);
|
||||
|
||||
class btStridingMeshInterface* getMeshInterface()
|
||||
{
|
||||
return m_stridingMesh;
|
||||
}
|
||||
const class btStridingMeshInterface* getMeshInterface() const
|
||||
{
|
||||
return m_stridingMesh;
|
||||
}
|
||||
|
||||
virtual btVector3 localGetSupportingVertex(const btVector3& vec)const;
|
||||
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
|
||||
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
|
||||
|
||||
virtual int getShapeType()const { return CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE; }
|
||||
|
||||
//debugging
|
||||
virtual const char* getName()const {return "ConvexTrimesh";}
|
||||
|
||||
virtual int getNumVertices() const;
|
||||
virtual int getNumEdges() const;
|
||||
virtual void getEdge(int i,btPoint3& pa,btPoint3& pb) const;
|
||||
virtual void getVertex(int i,btPoint3& vtx) const;
|
||||
virtual int getNumPlanes() const;
|
||||
virtual void getPlane(btVector3& planeNormal,btPoint3& planeSupport,int i ) const;
|
||||
virtual bool isInside(const btPoint3& pt,btScalar tolerance) const;
|
||||
|
||||
|
||||
virtual void setLocalScaling(const btVector3& scaling);
|
||||
virtual const btVector3& getLocalScaling() const;
|
||||
|
||||
///computes the exact moment of inertia and the transform from the coordinate system defined by the principal axes of the moment of inertia
|
||||
///and the center of mass to the current coordinate system. A mass of 1 is assumed, for other masses just multiply the computed "inertia"
|
||||
///by the mass. The resulting transform "principal" has to be applied inversely to the mesh in order for the local coordinate system of the
|
||||
///shape to be centered at the center of mass and to coincide with the principal axes. This also necessitates a correction of the world transform
|
||||
///of the collision object by the principal transform. This method also computes the volume of the convex mesh.
|
||||
void calculatePrincipalAxisTransform(btTransform& principal, btVector3& inertia, btScalar& volume) const;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //CONVEX_TRIANGLEMESH_SHAPE_H
|
||||
|
||||
|
||||
|
||||
#ifndef CONVEX_TRIANGLEMESH_SHAPE_H
|
||||
#define CONVEX_TRIANGLEMESH_SHAPE_H
|
||||
|
||||
|
||||
#include "btPolyhedralConvexShape.h"
|
||||
#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
|
||||
|
||||
|
||||
/// The btConvexTriangleMeshShape is a convex hull of a triangle mesh, but the performance is not as good as btConvexHullShape.
|
||||
/// A small benefit of this class is that it uses the btStridingMeshInterface, so you can avoid the duplication of the triangle mesh data. Nevertheless, most users should use the much better performing btConvexHullShape instead.
|
||||
class btConvexTriangleMeshShape : public btPolyhedralConvexShape
|
||||
{
|
||||
|
||||
class btStridingMeshInterface* m_stridingMesh;
|
||||
|
||||
public:
|
||||
btConvexTriangleMeshShape(btStridingMeshInterface* meshInterface, bool calcAabb = true);
|
||||
|
||||
class btStridingMeshInterface* getMeshInterface()
|
||||
{
|
||||
return m_stridingMesh;
|
||||
}
|
||||
const class btStridingMeshInterface* getMeshInterface() const
|
||||
{
|
||||
return m_stridingMesh;
|
||||
}
|
||||
|
||||
virtual btVector3 localGetSupportingVertex(const btVector3& vec)const;
|
||||
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
|
||||
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
|
||||
|
||||
//debugging
|
||||
virtual const char* getName()const {return "ConvexTrimesh";}
|
||||
|
||||
virtual int getNumVertices() const;
|
||||
virtual int getNumEdges() const;
|
||||
virtual void getEdge(int i,btPoint3& pa,btPoint3& pb) const;
|
||||
virtual void getVertex(int i,btPoint3& vtx) const;
|
||||
virtual int getNumPlanes() const;
|
||||
virtual void getPlane(btVector3& planeNormal,btPoint3& planeSupport,int i ) const;
|
||||
virtual bool isInside(const btPoint3& pt,btScalar tolerance) const;
|
||||
|
||||
|
||||
virtual void setLocalScaling(const btVector3& scaling);
|
||||
virtual const btVector3& getLocalScaling() const;
|
||||
|
||||
///computes the exact moment of inertia and the transform from the coordinate system defined by the principal axes of the moment of inertia
|
||||
///and the center of mass to the current coordinate system. A mass of 1 is assumed, for other masses just multiply the computed "inertia"
|
||||
///by the mass. The resulting transform "principal" has to be applied inversely to the mesh in order for the local coordinate system of the
|
||||
///shape to be centered at the center of mass and to coincide with the principal axes. This also necessitates a correction of the world transform
|
||||
///of the collision object by the principal transform. This method also computes the volume of the convex mesh.
|
||||
void calculatePrincipalAxisTransform(btTransform& principal, btVector3& inertia, btScalar& volume) const;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //CONVEX_TRIANGLEMESH_SHAPE_H
|
||||
|
||||
|
||||
|
||||
|
@ -19,6 +19,7 @@ btCylinderShape::btCylinderShape (const btVector3& halfExtents)
|
||||
:btBoxShape(halfExtents),
|
||||
m_upAxis(1)
|
||||
{
|
||||
m_shapeType = CYLINDER_SHAPE_PROXYTYPE;
|
||||
recalcLocalAabb();
|
||||
}
|
||||
|
||||
|
@ -62,11 +62,7 @@ public:
|
||||
//use box inertia
|
||||
// virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const;
|
||||
|
||||
virtual int getShapeType() const
|
||||
{
|
||||
return CYLINDER_SHAPE_PROXYTYPE;
|
||||
}
|
||||
|
||||
|
||||
int getUpAxis() const
|
||||
{
|
||||
return m_upAxis;
|
||||
|
@ -19,8 +19,9 @@ subject to the following restrictions:
|
||||
#include "btCollisionShape.h"
|
||||
|
||||
|
||||
btEmptyShape::btEmptyShape()
|
||||
btEmptyShape::btEmptyShape() : btConcaveShape ()
|
||||
{
|
||||
m_shapeType = EMPTY_SHAPE_PROXYTYPE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -51,9 +51,6 @@ public:
|
||||
|
||||
virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const;
|
||||
|
||||
virtual int getShapeType() const { return EMPTY_SHAPE_PROXYTYPE;}
|
||||
|
||||
|
||||
virtual const char* getName()const
|
||||
{
|
||||
return "Empty";
|
||||
|
@ -19,7 +19,7 @@ subject to the following restrictions:
|
||||
|
||||
|
||||
btHeightfieldTerrainShape::btHeightfieldTerrainShape(int heightStickWidth, int heightStickLength,void* heightfieldData,btScalar maxHeight,int upAxis,bool useFloatData,bool flipQuadEdges)
|
||||
: m_heightStickWidth(heightStickWidth),
|
||||
: btConcaveShape (), m_heightStickWidth(heightStickWidth),
|
||||
m_heightStickLength(heightStickLength),
|
||||
m_maxHeight(maxHeight),
|
||||
m_width((btScalar)heightStickWidth-1),
|
||||
@ -31,7 +31,7 @@ m_useDiamondSubdivision(false),
|
||||
m_upAxis(upAxis),
|
||||
m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.))
|
||||
{
|
||||
|
||||
m_shapeType = TERRAIN_SHAPE_PROXYTYPE;
|
||||
|
||||
btScalar quantizationMargin = 1.f;
|
||||
|
||||
|
@ -68,10 +68,6 @@ public:
|
||||
|
||||
void setUseDiamondSubdivision(bool useDiamondSubdivision=true) { m_useDiamondSubdivision = useDiamondSubdivision;}
|
||||
|
||||
virtual int getShapeType() const
|
||||
{
|
||||
return TERRAIN_SHAPE_PROXYTYPE;
|
||||
}
|
||||
|
||||
virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
|
||||
|
||||
|
@ -17,9 +17,11 @@ subject to the following restrictions:
|
||||
|
||||
|
||||
btMinkowskiSumShape::btMinkowskiSumShape(const btConvexShape* shapeA,const btConvexShape* shapeB)
|
||||
:m_shapeA(shapeA),
|
||||
: btConvexInternalShape (),
|
||||
m_shapeA(shapeA),
|
||||
m_shapeB(shapeB)
|
||||
{
|
||||
m_shapeType = MINKOWSKI_DIFFERENCE_SHAPE_PROXYTYPE;
|
||||
m_transA.setIdentity();
|
||||
m_transB.setIdentity();
|
||||
}
|
||||
|
@ -46,8 +46,6 @@ public:
|
||||
const btTransform& GetTransformB()const { return m_transB;}
|
||||
|
||||
|
||||
virtual int getShapeType() const { return MINKOWSKI_SUM_SHAPE_PROXYTYPE; }
|
||||
|
||||
virtual btScalar getMargin() const;
|
||||
|
||||
const btConvexShape* getShapeA() const { return m_shapeA;}
|
||||
|
@ -18,8 +18,9 @@ subject to the following restrictions:
|
||||
#include "LinearMath/btQuaternion.h"
|
||||
|
||||
btMultiSphereShape::btMultiSphereShape (const btVector3& inertiaHalfExtents,const btVector3* positions,const btScalar* radi,int numSpheres)
|
||||
:m_inertiaHalfExtents(inertiaHalfExtents)
|
||||
:btConvexInternalShape (), m_inertiaHalfExtents(inertiaHalfExtents)
|
||||
{
|
||||
m_shapeType = MULTI_SPHERE_SHAPE_PROXYTYPE;
|
||||
btScalar startMargin = btScalar(1e30);
|
||||
|
||||
m_numSpheres = numSpheres;
|
||||
|
@ -62,7 +62,6 @@ public:
|
||||
return m_radi[index];
|
||||
}
|
||||
|
||||
virtual int getShapeType() const { return MULTI_SPHERE_SHAPE_PROXYTYPE; }
|
||||
|
||||
virtual const char* getName()const
|
||||
{
|
||||
|
@ -16,7 +16,8 @@ subject to the following restrictions:
|
||||
#include "BulletCollision/CollisionShapes/btPolyhedralConvexShape.h"
|
||||
|
||||
btPolyhedralConvexShape::btPolyhedralConvexShape()
|
||||
:m_localAabbMin(1,1,1),
|
||||
:btConvexInternalShape(),
|
||||
m_localAabbMin(1,1,1),
|
||||
m_localAabbMax(-1,-1,-1),
|
||||
m_isLocalAabbValid(false),
|
||||
m_optionalHull(0)
|
||||
|
@ -31,9 +31,10 @@ protected:
|
||||
btVector3 m_localAabbMax;
|
||||
bool m_isLocalAabbValid;
|
||||
|
||||
btPolyhedralConvexShape();
|
||||
public:
|
||||
|
||||
btPolyhedralConvexShape();
|
||||
|
||||
|
||||
//brute force implementations
|
||||
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
|
||||
|
@ -16,10 +16,9 @@ subject to the following restrictions:
|
||||
#include "btScaledBvhTriangleMeshShape.h"
|
||||
|
||||
btScaledBvhTriangleMeshShape::btScaledBvhTriangleMeshShape(btBvhTriangleMeshShape* childShape,btVector3 localScaling)
|
||||
:m_bvhTriMeshShape(childShape),
|
||||
m_localScaling(localScaling)
|
||||
:m_localScaling(localScaling),m_bvhTriMeshShape(childShape)
|
||||
{
|
||||
|
||||
m_shapeType = SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE;
|
||||
}
|
||||
|
||||
btScaledBvhTriangleMeshShape::~btScaledBvhTriangleMeshShape()
|
||||
|
@ -36,11 +36,6 @@ public:
|
||||
|
||||
virtual ~btScaledBvhTriangleMeshShape();
|
||||
|
||||
virtual int getShapeType() const
|
||||
{
|
||||
//use un-used 'FAST_CONCAVE_MESH_PROXYTYPE' for now, later add SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE to btBroadphaseProxy.h
|
||||
return SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE;
|
||||
}
|
||||
|
||||
virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
|
||||
virtual void setLocalScaling(const btVector3& scaling);
|
||||
|
@ -19,9 +19,11 @@ subject to the following restrictions:
|
||||
#include "LinearMath/btQuaternion.h"
|
||||
|
||||
|
||||
btSphereShape ::btSphereShape (btScalar radius)
|
||||
btSphereShape ::btSphereShape (btScalar radius) : btConvexInternalShape ()
|
||||
{
|
||||
m_shapeType = SPHERE_SHAPE_PROXYTYPE;
|
||||
m_implicitShapeDimensions.setX(radius);
|
||||
m_collisionMargin = radius;
|
||||
}
|
||||
|
||||
btVector3 btSphereShape::localGetSupportingVertexWithoutMargin(const btVector3& vec)const
|
||||
|
@ -40,7 +40,6 @@ public:
|
||||
|
||||
virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
|
||||
|
||||
virtual int getShapeType() const { return SPHERE_SHAPE_PROXYTYPE; }
|
||||
|
||||
btScalar getRadius() const { return m_implicitShapeDimensions.getX() * m_localScaling.getX();}
|
||||
|
||||
|
@ -19,10 +19,11 @@ subject to the following restrictions:
|
||||
|
||||
|
||||
btStaticPlaneShape::btStaticPlaneShape(const btVector3& planeNormal,btScalar planeConstant)
|
||||
:m_planeNormal(planeNormal.normalized()),
|
||||
: btConcaveShape (), m_planeNormal(planeNormal.normalized()),
|
||||
m_planeConstant(planeConstant),
|
||||
m_localScaling(btScalar(0.),btScalar(0.),btScalar(0.))
|
||||
{
|
||||
m_shapeType = STATIC_PLANE_PROXYTYPE;
|
||||
// btAssert( btFuzzyZero(m_planeNormal.length() - btScalar(1.)) );
|
||||
}
|
||||
|
||||
|
@ -36,11 +36,6 @@ public:
|
||||
virtual ~btStaticPlaneShape();
|
||||
|
||||
|
||||
virtual int getShapeType() const
|
||||
{
|
||||
return STATIC_PLANE_PROXYTYPE;
|
||||
}
|
||||
|
||||
virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
|
||||
|
||||
virtual void processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const;
|
||||
|
@ -16,35 +16,40 @@ subject to the following restrictions:
|
||||
#include "btTetrahedronShape.h"
|
||||
#include "LinearMath/btMatrix3x3.h"
|
||||
|
||||
btBU_Simplex1to4::btBU_Simplex1to4()
|
||||
:m_numVertices(0)
|
||||
btBU_Simplex1to4::btBU_Simplex1to4() : btPolyhedralConvexShape (),
|
||||
m_numVertices(0)
|
||||
{
|
||||
m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE;
|
||||
}
|
||||
|
||||
btBU_Simplex1to4::btBU_Simplex1to4(const btPoint3& pt0)
|
||||
:m_numVertices(0)
|
||||
btBU_Simplex1to4::btBU_Simplex1to4(const btPoint3& pt0) : btPolyhedralConvexShape (),
|
||||
m_numVertices(0)
|
||||
{
|
||||
m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE;
|
||||
addVertex(pt0);
|
||||
}
|
||||
|
||||
btBU_Simplex1to4::btBU_Simplex1to4(const btPoint3& pt0,const btPoint3& pt1)
|
||||
:m_numVertices(0)
|
||||
btBU_Simplex1to4::btBU_Simplex1to4(const btPoint3& pt0,const btPoint3& pt1) : btPolyhedralConvexShape (),
|
||||
m_numVertices(0)
|
||||
{
|
||||
m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE;
|
||||
addVertex(pt0);
|
||||
addVertex(pt1);
|
||||
}
|
||||
|
||||
btBU_Simplex1to4::btBU_Simplex1to4(const btPoint3& pt0,const btPoint3& pt1,const btPoint3& pt2)
|
||||
:m_numVertices(0)
|
||||
btBU_Simplex1to4::btBU_Simplex1to4(const btPoint3& pt0,const btPoint3& pt1,const btPoint3& pt2) : btPolyhedralConvexShape (),
|
||||
m_numVertices(0)
|
||||
{
|
||||
m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE;
|
||||
addVertex(pt0);
|
||||
addVertex(pt1);
|
||||
addVertex(pt2);
|
||||
}
|
||||
|
||||
btBU_Simplex1to4::btBU_Simplex1to4(const btPoint3& pt0,const btPoint3& pt1,const btPoint3& pt2,const btPoint3& pt3)
|
||||
:m_numVertices(0)
|
||||
btBU_Simplex1to4::btBU_Simplex1to4(const btPoint3& pt0,const btPoint3& pt1,const btPoint3& pt2,const btPoint3& pt3) : btPolyhedralConvexShape (),
|
||||
m_numVertices(0)
|
||||
{
|
||||
m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE;
|
||||
addVertex(pt0);
|
||||
addVertex(pt1);
|
||||
addVertex(pt2);
|
||||
|
@ -44,7 +44,6 @@ public:
|
||||
}
|
||||
|
||||
|
||||
virtual int getShapeType() const{ return TETRAHEDRAL_SHAPE_PROXYTYPE; }
|
||||
|
||||
void addVertex(const btPoint3& pt);
|
||||
|
||||
|
@ -22,8 +22,9 @@ subject to the following restrictions:
|
||||
|
||||
|
||||
btTriangleMeshShape::btTriangleMeshShape(btStridingMeshInterface* meshInterface)
|
||||
: m_meshInterface(meshInterface)
|
||||
: btConcaveShape (), m_meshInterface(meshInterface)
|
||||
{
|
||||
m_shapeType = TRIANGLE_MESH_SHAPE_PROXYTYPE;
|
||||
if(meshInterface->hasPremadeAabb())
|
||||
{
|
||||
meshInterface->getPremadeAabb(&m_localAabbMin, &m_localAabbMax);
|
||||
|
@ -40,10 +40,6 @@ public:
|
||||
{
|
||||
vert = m_vertices1[index];
|
||||
}
|
||||
virtual int getShapeType() const
|
||||
{
|
||||
return TRIANGLE_SHAPE_PROXYTYPE;
|
||||
}
|
||||
|
||||
virtual int getNumEdges() const
|
||||
{
|
||||
@ -83,8 +79,9 @@ public:
|
||||
|
||||
|
||||
|
||||
btTriangleShape(const btVector3& p0,const btVector3& p1,const btVector3& p2)
|
||||
btTriangleShape(const btVector3& p0,const btVector3& p1,const btVector3& p2) : btPolyhedralConvexShape ()
|
||||
{
|
||||
m_shapeType = TRIANGLE_SHAPE_PROXYTYPE;
|
||||
m_vertices1[0] = p0;
|
||||
m_vertices1[1] = p1;
|
||||
m_vertices1[2] = p2;
|
||||
|
@ -16,9 +16,10 @@ subject to the following restrictions:
|
||||
#include "btUniformScalingShape.h"
|
||||
|
||||
btUniformScalingShape::btUniformScalingShape( btConvexShape* convexChildShape,btScalar uniformScalingFactor):
|
||||
m_childConvexShape(convexChildShape),
|
||||
btConvexShape (), m_childConvexShape(convexChildShape),
|
||||
m_uniformScalingFactor(uniformScalingFactor)
|
||||
{
|
||||
m_shapeType = UNIFORM_SCALING_SHAPE_PROXYTYPE;
|
||||
}
|
||||
|
||||
btUniformScalingShape::~btUniformScalingShape()
|
||||
|
@ -61,7 +61,6 @@ class btUniformScalingShape : public btConvexShape
|
||||
return "UniformScalingShape";
|
||||
}
|
||||
|
||||
virtual int getShapeType() const { return UNIFORM_SCALING_SHAPE_PROXYTYPE; }
|
||||
|
||||
|
||||
///////////////////////////
|
||||
|
@ -72,9 +72,9 @@ struct MinkowskiDiff
|
||||
void EnableMargin(bool enable)
|
||||
{
|
||||
if(enable)
|
||||
Ls=&btConvexShape::localGetSupportingVertex;
|
||||
Ls=&btConvexShape::localGetSupportVertexNonVirtual;
|
||||
else
|
||||
Ls=&btConvexShape::localGetSupportingVertexWithoutMargin;
|
||||
Ls=&btConvexShape::localGetSupportVertexWithoutMarginNonVirtual;
|
||||
}
|
||||
inline btVector3 Support0(const btVector3& d) const
|
||||
{
|
||||
|
@ -17,7 +17,15 @@ subject to the following restrictions:
|
||||
|
||||
#include "BulletCollision/CollisionShapes/btConvexShape.h"
|
||||
#include "btGjkEpaPenetrationDepthSolver.h"
|
||||
|
||||
#ifndef __SPU__
|
||||
//#define USE_ORIGINAL_GJK 1
|
||||
#endif
|
||||
|
||||
#ifdef USE_ORIGINAL_GJK
|
||||
#include "BulletCollision/NarrowPhaseCollision/btGjkEpa.h"
|
||||
#endif
|
||||
|
||||
#include "BulletCollision/NarrowPhaseCollision/btGjkEpa2.h"
|
||||
|
||||
bool btGjkEpaPenetrationDepthSolver::calcPenDepth( btSimplexSolverInterface& simplexSolver,
|
||||
|
@ -23,6 +23,7 @@ subject to the following restrictions:
|
||||
#ifdef __SPU__
|
||||
#include <spu_printf.h>
|
||||
#define printf spu_printf
|
||||
//#define DEBUG_SPU_COLLISION_DETECTION 1
|
||||
#endif //__SPU__
|
||||
#endif
|
||||
|
||||
@ -58,16 +59,22 @@ void btGjkPairDetector::getClosestPoints(const ClosestPointInput& input,Result&
|
||||
localTransA.getOrigin() -= positionOffset;
|
||||
localTransB.getOrigin() -= positionOffset;
|
||||
|
||||
btScalar marginA = m_minkowskiA->getMargin();
|
||||
btScalar marginB = m_minkowskiB->getMargin();
|
||||
btScalar marginA = m_minkowskiA->getMarginNonVirtual();
|
||||
btScalar marginB = m_minkowskiB->getMarginNonVirtual();
|
||||
|
||||
gNumGjkChecks++;
|
||||
|
||||
#ifdef DEBUG_SPU_COLLISION_DETECTION
|
||||
spu_printf("inside gjk\n");
|
||||
#endif
|
||||
//for CCD we don't use margins
|
||||
if (m_ignoreMargin)
|
||||
{
|
||||
marginA = btScalar(0.);
|
||||
marginB = btScalar(0.);
|
||||
#ifdef DEBUG_SPU_COLLISION_DETECTION
|
||||
spu_printf("ignoring margin\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
m_curIter = 0;
|
||||
@ -98,11 +105,15 @@ void btGjkPairDetector::getClosestPoints(const ClosestPointInput& input,Result&
|
||||
btVector3 seperatingAxisInA = (-m_cachedSeparatingAxis)* input.m_transformA.getBasis();
|
||||
btVector3 seperatingAxisInB = m_cachedSeparatingAxis* input.m_transformB.getBasis();
|
||||
|
||||
btVector3 pInA = m_minkowskiA->localGetSupportingVertexWithoutMargin(seperatingAxisInA);
|
||||
btVector3 qInB = m_minkowskiB->localGetSupportingVertexWithoutMargin(seperatingAxisInB);
|
||||
btVector3 pInA = m_minkowskiA->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInA);
|
||||
btVector3 qInB = m_minkowskiB->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInB);
|
||||
btPoint3 pWorld = localTransA(pInA);
|
||||
btPoint3 qWorld = localTransB(qInB);
|
||||
|
||||
|
||||
#ifdef DEBUG_SPU_COLLISION_DETECTION
|
||||
spu_printf("got local supporting vertices\n");
|
||||
#endif
|
||||
|
||||
btVector3 w = pWorld - qWorld;
|
||||
delta = m_cachedSeparatingAxis.dot(w);
|
||||
|
||||
@ -133,9 +144,15 @@ void btGjkPairDetector::getClosestPoints(const ClosestPointInput& input,Result&
|
||||
checkSimplex = true;
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_SPU_COLLISION_DETECTION
|
||||
spu_printf("addVertex 1\n");
|
||||
#endif
|
||||
//add current vertex to simplex
|
||||
m_simplexSolver->addVertex(w, pWorld, qWorld);
|
||||
|
||||
#ifdef DEBUG_SPU_COLLISION_DETECTION
|
||||
spu_printf("addVertex 2\n");
|
||||
#endif
|
||||
//calculate the closest point to the origin (update vector v)
|
||||
if (!m_simplexSolver->closest(m_cachedSeparatingAxis))
|
||||
{
|
||||
@ -167,7 +184,7 @@ void btGjkPairDetector::getClosestPoints(const ClosestPointInput& input,Result&
|
||||
//degeneracy, this is typically due to invalid/uninitialized worldtransforms for a btCollisionObject
|
||||
if (m_curIter++ > gGjkMaxIter)
|
||||
{
|
||||
#if defined(DEBUG) || defined (_DEBUG)
|
||||
#if defined(DEBUG) || defined (_DEBUG) || defined (DEBUG_SPU_COLLISION_DETECTION)
|
||||
|
||||
printf("btGjkPairDetector maxIter exceeded:%i\n",m_curIter);
|
||||
printf("sepAxis=(%f,%f,%f), squaredDistance = %f, shapeTypeA=%i,shapeTypeB=%i\n",
|
||||
@ -290,10 +307,17 @@ void btGjkPairDetector::getClosestPoints(const ClosestPointInput& input,Result&
|
||||
#endif //__CELLOS_LV2__
|
||||
|
||||
|
||||
#ifdef DEBUG_SPU_COLLISION_DETECTION
|
||||
spu_printf("output 1\n");
|
||||
#endif
|
||||
output.addContactPoint(
|
||||
normalInB,
|
||||
pointOnB+positionOffset,
|
||||
distance);
|
||||
|
||||
#ifdef DEBUG_SPU_COLLISION_DETECTION
|
||||
spu_printf("output 2\n");
|
||||
#endif
|
||||
//printf("gjk add:%f",distance);
|
||||
}
|
||||
|
||||
|
@ -19,9 +19,6 @@ subject to the following restrictions:
|
||||
#include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h"
|
||||
#include "BulletCollision/CollisionShapes/btConvexShape.h"
|
||||
|
||||
|
||||
|
||||
|
||||
#define NUM_UNITSPHERE_POINTS 42
|
||||
static btVector3 sPenetrationDirections[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2] =
|
||||
{
|
||||
@ -117,7 +114,9 @@ bool btMinkowskiPenetrationDepthSolver::calcPenDepth(btSimplexSolverInterface& s
|
||||
btVector3 seperatingAxisInA,seperatingAxisInB;
|
||||
btVector3 pInA,qInB,pWorld,qWorld,w;
|
||||
|
||||
#ifndef __SPU__
|
||||
#define USE_BATCHED_SUPPORT 1
|
||||
#endif
|
||||
#ifdef USE_BATCHED_SUPPORT
|
||||
|
||||
btVector3 supportVerticesABatch[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2];
|
||||
@ -200,6 +199,7 @@ bool btMinkowskiPenetrationDepthSolver::calcPenDepth(btSimplexSolverInterface& s
|
||||
|
||||
int numSampleDirections = NUM_UNITSPHERE_POINTS;
|
||||
|
||||
#ifndef __SPU__
|
||||
{
|
||||
int numPDA = convexA->getNumPreferredPenetrationDirections();
|
||||
if (numPDA)
|
||||
@ -229,14 +229,15 @@ bool btMinkowskiPenetrationDepthSolver::calcPenDepth(btSimplexSolverInterface& s
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // __SPU__
|
||||
|
||||
for (int i=0;i<numSampleDirections;i++)
|
||||
{
|
||||
const btVector3& norm = sPenetrationDirections[i];
|
||||
seperatingAxisInA = (-norm)* transA.getBasis();
|
||||
seperatingAxisInB = norm* transB.getBasis();
|
||||
pInA = convexA->localGetSupportingVertexWithoutMargin(seperatingAxisInA);
|
||||
qInB = convexB->localGetSupportingVertexWithoutMargin(seperatingAxisInB);
|
||||
pInA = convexA->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInA);
|
||||
qInB = convexB->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInB);
|
||||
pWorld = transA(pInA);
|
||||
qWorld = transB(qInB);
|
||||
w = qWorld - pWorld;
|
||||
@ -254,13 +255,13 @@ bool btMinkowskiPenetrationDepthSolver::calcPenDepth(btSimplexSolverInterface& s
|
||||
|
||||
//add the margins
|
||||
|
||||
minA += minNorm*convexA->getMargin();
|
||||
minB -= minNorm*convexB->getMargin();
|
||||
minA += minNorm*convexA->getMarginNonVirtual();
|
||||
minB -= minNorm*convexB->getMarginNonVirtual();
|
||||
//no penetration
|
||||
if (minProj < btScalar(0.))
|
||||
return false;
|
||||
|
||||
minProj += (convexA->getMargin() + convexB->getMargin());
|
||||
minProj += (convexA->getMarginNonVirtual() + convexB->getMarginNonVirtual());
|
||||
|
||||
|
||||
|
||||
|
@ -30,7 +30,6 @@ public:
|
||||
btVector3& v, btPoint3& pa, btPoint3& pb,
|
||||
class btIDebugDraw* debugDraw,btStackAlloc* stackAlloc
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
#endif //MINKOWSKI_PENETRATION_DEPTH_SOLVER_H
|
||||
|
Loading…
Reference in New Issue
Block a user