moved files around
This commit is contained in:
58
Bullet/CollisionShapes/BoxShape.cpp
Normal file
58
Bullet/CollisionShapes/BoxShape.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
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 "BoxShape.h"
|
||||
|
||||
SimdVector3 BoxShape::GetHalfExtents() const
|
||||
{
|
||||
return m_boxHalfExtents1 * m_localScaling;
|
||||
}
|
||||
//{
|
||||
|
||||
|
||||
void BoxShape::GetAabb(const SimdTransform& t,SimdVector3& aabbMin,SimdVector3& aabbMax) const
|
||||
{
|
||||
SimdVector3 halfExtents = GetHalfExtents();
|
||||
|
||||
SimdMatrix3x3 abs_b = t.getBasis().absolute();
|
||||
SimdPoint3 center = t.getOrigin();
|
||||
SimdVector3 extent = SimdVector3(abs_b[0].dot(halfExtents),
|
||||
abs_b[1].dot(halfExtents),
|
||||
abs_b[2].dot(halfExtents));
|
||||
extent += SimdVector3(GetMargin(),GetMargin(),GetMargin());
|
||||
|
||||
aabbMin = center - extent;
|
||||
aabbMax = center + extent;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void BoxShape::CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia)
|
||||
{
|
||||
//float margin = 0.f;
|
||||
SimdVector3 halfExtents = GetHalfExtents();
|
||||
|
||||
SimdScalar lx=2.f*(halfExtents.x());
|
||||
SimdScalar ly=2.f*(halfExtents.y());
|
||||
SimdScalar lz=2.f*(halfExtents.z());
|
||||
|
||||
inertia[0] = mass/(12.0f) * (ly*ly + lz*lz);
|
||||
inertia[1] = mass/(12.0f) * (lx*lx + lz*lz);
|
||||
inertia[2] = mass/(12.0f) * (lx*lx + ly*ly);
|
||||
|
||||
|
||||
}
|
||||
|
||||
279
Bullet/CollisionShapes/BoxShape.h
Normal file
279
Bullet/CollisionShapes/BoxShape.h
Normal file
@@ -0,0 +1,279 @@
|
||||
/*
|
||||
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 OBB_BOX_MINKOWSKI_H
|
||||
#define OBB_BOX_MINKOWSKI_H
|
||||
|
||||
#include "PolyhedralConvexShape.h"
|
||||
#include "CollisionShapes/CollisionMargin.h"
|
||||
#include "BroadphaseCollision/BroadphaseProxy.h"
|
||||
#include "SimdPoint3.h"
|
||||
#include "SimdMinMax.h"
|
||||
|
||||
///BoxShape implements both a feature based (vertex/edge/plane) and implicit (getSupportingVertex) Box
|
||||
class BoxShape: public PolyhedralConvexShape
|
||||
{
|
||||
|
||||
SimdVector3 m_boxHalfExtents1;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
virtual ~BoxShape()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SimdVector3 GetHalfExtents() const;
|
||||
//{ return m_boxHalfExtents1 * m_localScaling;}
|
||||
//const SimdVector3& GetHalfExtents() const{ return m_boxHalfExtents1;}
|
||||
|
||||
|
||||
|
||||
virtual int GetShapeType() const { return BOX_SHAPE_PROXYTYPE;}
|
||||
|
||||
virtual SimdVector3 LocalGetSupportingVertex(const SimdVector3& vec) const
|
||||
{
|
||||
|
||||
SimdVector3 halfExtents = GetHalfExtents();
|
||||
SimdVector3 margin(GetMargin(),GetMargin(),GetMargin());
|
||||
halfExtents -= margin;
|
||||
|
||||
SimdVector3 supVertex;
|
||||
supVertex = SimdPoint3(vec.x() < SimdScalar(0.0f) ? -halfExtents.x() : halfExtents.x(),
|
||||
vec.y() < SimdScalar(0.0f) ? -halfExtents.y() : halfExtents.y(),
|
||||
vec.z() < SimdScalar(0.0f) ? -halfExtents.z() : halfExtents.z());
|
||||
|
||||
if ( GetMargin()!=0.f )
|
||||
{
|
||||
SimdVector3 vecnorm = vec;
|
||||
if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON))
|
||||
{
|
||||
vecnorm.setValue(-1.f,-1.f,-1.f);
|
||||
}
|
||||
vecnorm.normalize();
|
||||
supVertex+= GetMargin() * vecnorm;
|
||||
}
|
||||
return supVertex;
|
||||
}
|
||||
|
||||
virtual inline SimdVector3 LocalGetSupportingVertexWithoutMargin(const SimdVector3& vec)const
|
||||
{
|
||||
SimdVector3 halfExtents = GetHalfExtents();
|
||||
SimdVector3 margin(GetMargin(),GetMargin(),GetMargin());
|
||||
halfExtents -= margin;
|
||||
|
||||
return SimdVector3(vec.x() < SimdScalar(0.0f) ? -halfExtents.x() : halfExtents.x(),
|
||||
vec.y() < SimdScalar(0.0f) ? -halfExtents.y() : halfExtents.y(),
|
||||
vec.z() < SimdScalar(0.0f) ? -halfExtents.z() : halfExtents.z());
|
||||
}
|
||||
|
||||
virtual void BatchedUnitVectorGetSupportingVertexWithoutMargin(const SimdVector3* vectors,SimdVector3* supportVerticesOut,int numVectors) const
|
||||
{
|
||||
SimdVector3 halfExtents = GetHalfExtents();
|
||||
SimdVector3 margin(GetMargin(),GetMargin(),GetMargin());
|
||||
halfExtents -= margin;
|
||||
|
||||
|
||||
for (int i=0;i<numVectors;i++)
|
||||
{
|
||||
const SimdVector3& vec = vectors[i];
|
||||
supportVerticesOut[i].setValue(vec.x() < SimdScalar(0.0f) ? -halfExtents.x() : halfExtents.x(),
|
||||
vec.y() < SimdScalar(0.0f) ? -halfExtents.y() : halfExtents.y(),
|
||||
vec.z() < SimdScalar(0.0f) ? -halfExtents.z() : halfExtents.z());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
BoxShape( const SimdVector3& boxHalfExtents) : m_boxHalfExtents1(boxHalfExtents){};
|
||||
|
||||
virtual void GetAabb(const SimdTransform& t,SimdVector3& aabbMin,SimdVector3& aabbMax) const;
|
||||
|
||||
|
||||
|
||||
virtual void CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia);
|
||||
|
||||
virtual void GetPlane(SimdVector3& planeNormal,SimdPoint3& planeSupport,int i ) const
|
||||
{
|
||||
//this plane might not be aligned...
|
||||
SimdVector4 plane ;
|
||||
GetPlaneEquation(plane,i);
|
||||
planeNormal = SimdVector3(plane.getX(),plane.getY(),plane.getZ());
|
||||
planeSupport = LocalGetSupportingVertex(-planeNormal);
|
||||
}
|
||||
|
||||
|
||||
virtual int GetNumPlanes() const
|
||||
{
|
||||
return 6;
|
||||
}
|
||||
|
||||
virtual int GetNumVertices() const
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
|
||||
virtual int GetNumEdges() const
|
||||
{
|
||||
return 12;
|
||||
}
|
||||
|
||||
|
||||
virtual void GetVertex(int i,SimdVector3& vtx) const
|
||||
{
|
||||
SimdVector3 halfExtents = GetHalfExtents();
|
||||
|
||||
vtx = SimdVector3(
|
||||
halfExtents.x() * (1-(i&1)) - halfExtents.x() * (i&1),
|
||||
halfExtents.y() * (1-((i&2)>>1)) - halfExtents.y() * ((i&2)>>1),
|
||||
halfExtents.z() * (1-((i&4)>>2)) - halfExtents.z() * ((i&4)>>2));
|
||||
}
|
||||
|
||||
|
||||
virtual void GetPlaneEquation(SimdVector4& plane,int i) const
|
||||
{
|
||||
SimdVector3 halfExtents = GetHalfExtents();
|
||||
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
plane.setValue(1.f,0.f,0.f);
|
||||
plane[3] = -halfExtents.x();
|
||||
break;
|
||||
case 1:
|
||||
plane.setValue(-1.f,0.f,0.f);
|
||||
plane[3] = -halfExtents.x();
|
||||
break;
|
||||
case 2:
|
||||
plane.setValue(0.f,1.f,0.f);
|
||||
plane[3] = -halfExtents.y();
|
||||
break;
|
||||
case 3:
|
||||
plane.setValue(0.f,-1.f,0.f);
|
||||
plane[3] = -halfExtents.y();
|
||||
break;
|
||||
case 4:
|
||||
plane.setValue(0.f,0.f,1.f);
|
||||
plane[3] = -halfExtents.z();
|
||||
break;
|
||||
case 5:
|
||||
plane.setValue(0.f,0.f,-1.f);
|
||||
plane[3] = -halfExtents.z();
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
virtual void GetEdge(int i,SimdPoint3& pa,SimdPoint3& pb) const
|
||||
//virtual void GetEdge(int i,Edge& edge) const
|
||||
{
|
||||
int edgeVert0 = 0;
|
||||
int edgeVert1 = 0;
|
||||
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
edgeVert0 = 0;
|
||||
edgeVert1 = 1;
|
||||
break;
|
||||
case 1:
|
||||
edgeVert0 = 0;
|
||||
edgeVert1 = 2;
|
||||
break;
|
||||
case 2:
|
||||
edgeVert0 = 1;
|
||||
edgeVert1 = 3;
|
||||
|
||||
break;
|
||||
case 3:
|
||||
edgeVert0 = 2;
|
||||
edgeVert1 = 3;
|
||||
break;
|
||||
case 4:
|
||||
edgeVert0 = 0;
|
||||
edgeVert1 = 4;
|
||||
break;
|
||||
case 5:
|
||||
edgeVert0 = 1;
|
||||
edgeVert1 = 5;
|
||||
|
||||
break;
|
||||
case 6:
|
||||
edgeVert0 = 2;
|
||||
edgeVert1 = 6;
|
||||
break;
|
||||
case 7:
|
||||
edgeVert0 = 3;
|
||||
edgeVert1 = 7;
|
||||
break;
|
||||
case 8:
|
||||
edgeVert0 = 4;
|
||||
edgeVert1 = 5;
|
||||
break;
|
||||
case 9:
|
||||
edgeVert0 = 4;
|
||||
edgeVert1 = 6;
|
||||
break;
|
||||
case 10:
|
||||
edgeVert0 = 5;
|
||||
edgeVert1 = 7;
|
||||
break;
|
||||
case 11:
|
||||
edgeVert0 = 6;
|
||||
edgeVert1 = 7;
|
||||
break;
|
||||
default:
|
||||
ASSERT(0);
|
||||
|
||||
}
|
||||
|
||||
GetVertex(edgeVert0,pa );
|
||||
GetVertex(edgeVert1,pb );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
virtual bool IsInside(const SimdPoint3& pt,SimdScalar tolerance) const
|
||||
{
|
||||
SimdVector3 halfExtents = GetHalfExtents();
|
||||
|
||||
//SimdScalar minDist = 2*tolerance;
|
||||
|
||||
bool result = (pt.x() <= (halfExtents.x()+tolerance)) &&
|
||||
(pt.x() >= (-halfExtents.x()-tolerance)) &&
|
||||
(pt.y() <= (halfExtents.y()+tolerance)) &&
|
||||
(pt.y() >= (-halfExtents.y()-tolerance)) &&
|
||||
(pt.z() <= (halfExtents.z()+tolerance)) &&
|
||||
(pt.z() >= (-halfExtents.z()-tolerance));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//debugging
|
||||
virtual char* GetName()const
|
||||
{
|
||||
return "Box";
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif //OBB_BOX_MINKOWSKI_H
|
||||
138
Bullet/CollisionShapes/BvhTriangleMeshShape.cpp
Normal file
138
Bullet/CollisionShapes/BvhTriangleMeshShape.cpp
Normal file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
//#define DISABLE_BVH
|
||||
|
||||
|
||||
#include "CollisionShapes/BvhTriangleMeshShape.h"
|
||||
#include "CollisionShapes/OptimizedBvh.h"
|
||||
|
||||
///Bvh Concave triangle mesh is a static-triangle mesh shape with Bounding Volume Hierarchy optimization.
|
||||
///Uses an interface to access the triangles to allow for sharing graphics/physics triangles.
|
||||
BvhTriangleMeshShape::BvhTriangleMeshShape(StridingMeshInterface* meshInterface)
|
||||
:TriangleMeshShape(meshInterface)
|
||||
{
|
||||
//construct bvh from meshInterface
|
||||
#ifndef DISABLE_BVH
|
||||
|
||||
m_bvh = new OptimizedBvh();
|
||||
m_bvh->Build(meshInterface);
|
||||
|
||||
#endif //DISABLE_BVH
|
||||
|
||||
}
|
||||
|
||||
BvhTriangleMeshShape::~BvhTriangleMeshShape()
|
||||
{
|
||||
delete m_bvh;
|
||||
}
|
||||
|
||||
//perform bvh tree traversal and report overlapping triangles to 'callback'
|
||||
void BvhTriangleMeshShape::ProcessAllTriangles(TriangleCallback* callback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const
|
||||
{
|
||||
|
||||
#ifdef DISABLE_BVH
|
||||
//brute force traverse all triangles
|
||||
TriangleMeshShape::ProcessAllTriangles(callback,aabbMin,aabbMax);
|
||||
#else
|
||||
|
||||
//first get all the nodes
|
||||
|
||||
|
||||
struct MyNodeOverlapCallback : public NodeOverlapCallback
|
||||
{
|
||||
StridingMeshInterface* m_meshInterface;
|
||||
TriangleCallback* m_callback;
|
||||
SimdVector3 m_triangle[3];
|
||||
|
||||
|
||||
MyNodeOverlapCallback(TriangleCallback* callback,StridingMeshInterface* meshInterface)
|
||||
:m_meshInterface(meshInterface),
|
||||
m_callback(callback)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void ProcessNode(const OptimizedBvhNode* node)
|
||||
{
|
||||
const unsigned char *vertexbase;
|
||||
int numverts;
|
||||
PHY_ScalarType type;
|
||||
int stride;
|
||||
const unsigned char *indexbase;
|
||||
int indexstride;
|
||||
int numfaces;
|
||||
PHY_ScalarType indicestype;
|
||||
|
||||
|
||||
m_meshInterface->getLockedReadOnlyVertexIndexBase(
|
||||
&vertexbase,
|
||||
numverts,
|
||||
type,
|
||||
stride,
|
||||
&indexbase,
|
||||
indexstride,
|
||||
numfaces,
|
||||
indicestype,
|
||||
node->m_subPart);
|
||||
|
||||
int* gfxbase = (int*)(indexbase+node->m_triangleIndex*indexstride);
|
||||
|
||||
const SimdVector3& meshScaling = m_meshInterface->getScaling();
|
||||
for (int j=2;j>=0;j--)
|
||||
{
|
||||
|
||||
int graphicsindex = gfxbase[j];
|
||||
#ifdef DEBUG_TRIANGLE_MESH
|
||||
printf("%d ,",graphicsindex);
|
||||
#endif //DEBUG_TRIANGLE_MESH
|
||||
float* graphicsbase = (float*)(vertexbase+graphicsindex*stride);
|
||||
|
||||
m_triangle[j] = SimdVector3(
|
||||
graphicsbase[0]*meshScaling.getX(),
|
||||
graphicsbase[1]*meshScaling.getY(),
|
||||
graphicsbase[2]*meshScaling.getZ());
|
||||
#ifdef DEBUG_TRIANGLE_MESH
|
||||
printf("triangle vertices:%f,%f,%f\n",triangle[j].x(),triangle[j].y(),triangle[j].z());
|
||||
#endif //DEBUG_TRIANGLE_MESH
|
||||
}
|
||||
|
||||
m_callback->ProcessTriangle(m_triangle,node->m_subPart,node->m_triangleIndex);
|
||||
m_meshInterface->unLockReadOnlyVertexBase(node->m_subPart);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
MyNodeOverlapCallback myNodeCallback(callback,m_meshInterface);
|
||||
|
||||
m_bvh->ReportAabbOverlappingNodex(&myNodeCallback,aabbMin,aabbMax);
|
||||
|
||||
|
||||
#endif//DISABLE_BVH
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void BvhTriangleMeshShape::setLocalScaling(const SimdVector3& scaling)
|
||||
{
|
||||
if ((getLocalScaling() -scaling).length2() > SIMD_EPSILON)
|
||||
{
|
||||
TriangleMeshShape::setLocalScaling(scaling);
|
||||
delete m_bvh;
|
||||
m_bvh = new OptimizedBvh();
|
||||
m_bvh->Build(m_meshInterface);
|
||||
//rebuild the bvh...
|
||||
}
|
||||
}
|
||||
58
Bullet/CollisionShapes/BvhTriangleMeshShape.h
Normal file
58
Bullet/CollisionShapes/BvhTriangleMeshShape.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
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 BVH_TRIANGLE_MESH_SHAPE_H
|
||||
#define BVH_TRIANGLE_MESH_SHAPE_H
|
||||
|
||||
#include "CollisionShapes/TriangleMeshShape.h"
|
||||
#include "CollisionShapes/OptimizedBvh.h"
|
||||
|
||||
///Bvh Concave triangle mesh is a static-triangle mesh shape with Bounding Volume Hierarchy optimization.
|
||||
///Uses an interface to access the triangles to allow for sharing graphics/physics triangles.
|
||||
class BvhTriangleMeshShape : public TriangleMeshShape
|
||||
{
|
||||
|
||||
OptimizedBvh* m_bvh;
|
||||
|
||||
|
||||
public:
|
||||
BvhTriangleMeshShape(StridingMeshInterface* meshInterface);
|
||||
|
||||
virtual ~BvhTriangleMeshShape();
|
||||
|
||||
|
||||
/*
|
||||
virtual int GetShapeType() const
|
||||
{
|
||||
return TRIANGLE_MESH_SHAPE_PROXYTYPE;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
virtual void ProcessAllTriangles(TriangleCallback* callback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const;
|
||||
|
||||
|
||||
//debugging
|
||||
virtual char* GetName()const {return "BVHTRIANGLEMESH";}
|
||||
|
||||
|
||||
virtual void setLocalScaling(const SimdVector3& scaling);
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif //BVH_TRIANGLE_MESH_SHAPE_H
|
||||
26
Bullet/CollisionShapes/CollisionMargin.h
Normal file
26
Bullet/CollisionShapes/CollisionMargin.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
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 COLLISION_MARGIN_H
|
||||
#define COLLISION_MARGIN_H
|
||||
|
||||
//used by Gjk and some other algorithms
|
||||
|
||||
#define CONVEX_DISTANCE_MARGIN 0.04f// 0.1f//;//0.01f
|
||||
|
||||
|
||||
|
||||
#endif //COLLISION_MARGIN_H
|
||||
|
||||
75
Bullet/CollisionShapes/CollisionShape.cpp
Normal file
75
Bullet/CollisionShapes/CollisionShape.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
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 "CollisionShapes/CollisionShape.h"
|
||||
|
||||
void CollisionShape::GetBoundingSphere(SimdVector3& center,SimdScalar& radius) const
|
||||
{
|
||||
SimdTransform tr;
|
||||
tr.setIdentity();
|
||||
SimdVector3 aabbMin,aabbMax;
|
||||
|
||||
GetAabb(tr,aabbMin,aabbMax);
|
||||
|
||||
radius = (aabbMax-aabbMin).length()*0.5f;
|
||||
center = (aabbMin+aabbMax)*0.5f;
|
||||
}
|
||||
|
||||
float CollisionShape::GetAngularMotionDisc() const
|
||||
{
|
||||
SimdVector3 center;
|
||||
float disc;
|
||||
GetBoundingSphere(center,disc);
|
||||
disc += (center).length();
|
||||
return disc;
|
||||
}
|
||||
|
||||
void CollisionShape::CalculateTemporalAabb(const SimdTransform& curTrans,const SimdVector3& linvel,const SimdVector3& angvel,SimdScalar timeStep, SimdVector3& temporalAabbMin,SimdVector3& temporalAabbMax)
|
||||
{
|
||||
//start with static aabb
|
||||
GetAabb(curTrans,temporalAabbMin,temporalAabbMax);
|
||||
|
||||
float temporalAabbMaxx = temporalAabbMax.getX();
|
||||
float temporalAabbMaxy = temporalAabbMax.getY();
|
||||
float temporalAabbMaxz = temporalAabbMax.getZ();
|
||||
float temporalAabbMinx = temporalAabbMin.getX();
|
||||
float temporalAabbMiny = temporalAabbMin.getY();
|
||||
float temporalAabbMinz = temporalAabbMin.getZ();
|
||||
|
||||
// add linear motion
|
||||
SimdVector3 linMotion = linvel*timeStep;
|
||||
//todo: simd would have a vector max/min operation, instead of per-element access
|
||||
if (linMotion.x() > 0.f)
|
||||
temporalAabbMaxx += linMotion.x();
|
||||
else
|
||||
temporalAabbMinx += linMotion.x();
|
||||
if (linMotion.y() > 0.f)
|
||||
temporalAabbMaxy += linMotion.y();
|
||||
else
|
||||
temporalAabbMiny += linMotion.y();
|
||||
if (linMotion.z() > 0.f)
|
||||
temporalAabbMaxz += linMotion.z();
|
||||
else
|
||||
temporalAabbMinz += linMotion.z();
|
||||
|
||||
//add conservative angular motion
|
||||
SimdScalar angularMotion = angvel.length() * GetAngularMotionDisc() * timeStep;
|
||||
SimdVector3 angularMotion3d(angularMotion,angularMotion,angularMotion);
|
||||
temporalAabbMin = SimdVector3(temporalAabbMinx,temporalAabbMiny,temporalAabbMinz);
|
||||
temporalAabbMax = SimdVector3(temporalAabbMaxx,temporalAabbMaxy,temporalAabbMaxz);
|
||||
|
||||
temporalAabbMin -= angularMotion3d;
|
||||
temporalAabbMax += angularMotion3d;
|
||||
}
|
||||
84
Bullet/CollisionShapes/CollisionShape.h
Normal file
84
Bullet/CollisionShapes/CollisionShape.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
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 COLLISION_SHAPE_H
|
||||
#define COLLISION_SHAPE_H
|
||||
|
||||
#include "SimdTransform.h"
|
||||
#include "SimdVector3.h"
|
||||
#include <SimdMatrix3x3.h>
|
||||
#include "SimdPoint3.h"
|
||||
#include "BroadphaseCollision/BroadphaseProxy.h" //for the shape types
|
||||
|
||||
///CollisionShape provides generic interface for collidable objects
|
||||
class CollisionShape
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
CollisionShape()
|
||||
:m_tempDebug(0)
|
||||
{
|
||||
}
|
||||
virtual ~CollisionShape()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void GetAabb(const SimdTransform& t,SimdVector3& aabbMin,SimdVector3& aabbMax) const =0;
|
||||
|
||||
virtual void GetBoundingSphere(SimdVector3& center,SimdScalar& radius) const;
|
||||
|
||||
virtual float GetAngularMotionDisc() const;
|
||||
|
||||
virtual int GetShapeType() const=0;
|
||||
|
||||
///CalculateTemporalAabb calculates the enclosing aabb for the moving object over interval [0..timeStep)
|
||||
///result is conservative
|
||||
void CalculateTemporalAabb(const SimdTransform& curTrans,const SimdVector3& linvel,const SimdVector3& angvel,SimdScalar timeStep, SimdVector3& temporalAabbMin,SimdVector3& temporalAabbMax);
|
||||
|
||||
bool IsPolyhedral() const
|
||||
{
|
||||
return (GetShapeType() < IMPLICIT_CONVEX_SHAPES_START_HERE);
|
||||
}
|
||||
|
||||
bool IsConvex() const
|
||||
{
|
||||
return (GetShapeType() < CONCAVE_SHAPES_START_HERE);
|
||||
}
|
||||
bool IsConcave() const
|
||||
{
|
||||
return (GetShapeType() > CONCAVE_SHAPES_START_HERE);
|
||||
}
|
||||
|
||||
|
||||
virtual void setLocalScaling(const SimdVector3& scaling) =0;
|
||||
virtual const SimdVector3& getLocalScaling() const =0;
|
||||
|
||||
virtual void CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia) = 0;
|
||||
|
||||
//debugging support
|
||||
virtual char* GetName()const =0 ;
|
||||
const char* GetExtraDebugInfo() const { return m_tempDebug;}
|
||||
void SetExtraDebugInfo(const char* extraDebugInfo) { m_tempDebug = extraDebugInfo;}
|
||||
const char * m_tempDebug;
|
||||
//endif debugging support
|
||||
|
||||
virtual void SetMargin(float margin) = 0;
|
||||
virtual float GetMargin() const = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif //COLLISION_SHAPE_H
|
||||
|
||||
100
Bullet/CollisionShapes/ConeShape.cpp
Normal file
100
Bullet/CollisionShapes/ConeShape.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
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 "ConeShape.h"
|
||||
#include "SimdPoint3.h"
|
||||
|
||||
#ifdef WIN32
|
||||
static int coneindices[3] = {1,2,0};
|
||||
#else
|
||||
static int coneindices[3] = {2,1,0};
|
||||
#endif
|
||||
|
||||
ConeShape::ConeShape (SimdScalar radius,SimdScalar height):
|
||||
m_radius (radius),
|
||||
m_height(height)
|
||||
{
|
||||
SimdVector3 halfExtents;
|
||||
m_sinAngle = (m_radius / sqrt(m_radius * m_radius + m_height * m_height));
|
||||
}
|
||||
|
||||
|
||||
SimdVector3 ConeShape::ConeLocalSupport(const SimdVector3& v) const
|
||||
{
|
||||
|
||||
float halfHeight = m_height * 0.5f;
|
||||
|
||||
if (v[coneindices[1]] > v.length() * m_sinAngle)
|
||||
{
|
||||
SimdVector3 tmp;
|
||||
|
||||
tmp[coneindices[0]] = 0.f;
|
||||
tmp[coneindices[1]] = halfHeight;
|
||||
tmp[coneindices[2]] = 0.f;
|
||||
return tmp;
|
||||
}
|
||||
else {
|
||||
SimdScalar s = SimdSqrt(v[coneindices[0]] * v[coneindices[0]] + v[coneindices[2]] * v[coneindices[2]]);
|
||||
if (s > SIMD_EPSILON) {
|
||||
SimdScalar d = m_radius / s;
|
||||
SimdVector3 tmp;
|
||||
tmp[coneindices[0]] = v[coneindices[0]] * d;
|
||||
tmp[coneindices[1]] = -halfHeight;
|
||||
tmp[coneindices[2]] = v[coneindices[2]] * d;
|
||||
return tmp;
|
||||
}
|
||||
else {
|
||||
SimdVector3 tmp;
|
||||
tmp[coneindices[0]] = 0.f;
|
||||
tmp[coneindices[1]] = -halfHeight;
|
||||
tmp[coneindices[2]] = 0.f;
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SimdVector3 ConeShape::LocalGetSupportingVertexWithoutMargin(const SimdVector3& vec) const
|
||||
{
|
||||
return ConeLocalSupport(vec);
|
||||
}
|
||||
|
||||
void ConeShape::BatchedUnitVectorGetSupportingVertexWithoutMargin(const SimdVector3* vectors,SimdVector3* supportVerticesOut,int numVectors) const
|
||||
{
|
||||
for (int i=0;i<numVectors;i++)
|
||||
{
|
||||
const SimdVector3& vec = vectors[i];
|
||||
supportVerticesOut[i] = ConeLocalSupport(vec);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SimdVector3 ConeShape::LocalGetSupportingVertex(const SimdVector3& vec) const
|
||||
{
|
||||
SimdVector3 supVertex = ConeLocalSupport(vec);
|
||||
if ( GetMargin()!=0.f )
|
||||
{
|
||||
SimdVector3 vecnorm = vec;
|
||||
if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON))
|
||||
{
|
||||
vecnorm.setValue(-1.f,-1.f,-1.f);
|
||||
}
|
||||
vecnorm.normalize();
|
||||
supVertex+= GetMargin() * vecnorm;
|
||||
}
|
||||
return supVertex;
|
||||
}
|
||||
|
||||
|
||||
83
Bullet/CollisionShapes/ConeShape.h
Normal file
83
Bullet/CollisionShapes/ConeShape.h
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
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 CONE_MINKOWSKI_H
|
||||
#define CONE_MINKOWSKI_H
|
||||
|
||||
#include "ConvexShape.h"
|
||||
#include "BroadphaseCollision/BroadphaseProxy.h" // for the types
|
||||
|
||||
/// implements cone shape interface
|
||||
class ConeShape : public ConvexShape
|
||||
|
||||
{
|
||||
|
||||
float m_sinAngle;
|
||||
float m_radius;
|
||||
float m_height;
|
||||
|
||||
SimdVector3 ConeLocalSupport(const SimdVector3& v) const;
|
||||
|
||||
|
||||
public:
|
||||
ConeShape (SimdScalar radius,SimdScalar height);
|
||||
|
||||
virtual SimdVector3 LocalGetSupportingVertex(const SimdVector3& vec) const;
|
||||
virtual SimdVector3 LocalGetSupportingVertexWithoutMargin(const SimdVector3& vec) const;
|
||||
virtual void BatchedUnitVectorGetSupportingVertexWithoutMargin(const SimdVector3* vectors,SimdVector3* supportVerticesOut,int numVectors) const;
|
||||
|
||||
float GetRadius() const { return m_radius;}
|
||||
float GetHeight() const { return m_height;}
|
||||
|
||||
|
||||
virtual void CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia)
|
||||
{
|
||||
SimdTransform identity;
|
||||
identity.setIdentity();
|
||||
SimdVector3 aabbMin,aabbMax;
|
||||
GetAabb(identity,aabbMin,aabbMax);
|
||||
|
||||
SimdVector3 halfExtents = (aabbMax-aabbMin)*0.5f;
|
||||
|
||||
float margin = GetMargin();
|
||||
|
||||
SimdScalar lx=2.f*(halfExtents.x()+margin);
|
||||
SimdScalar ly=2.f*(halfExtents.y()+margin);
|
||||
SimdScalar lz=2.f*(halfExtents.z()+margin);
|
||||
const SimdScalar x2 = lx*lx;
|
||||
const SimdScalar y2 = ly*ly;
|
||||
const SimdScalar z2 = lz*lz;
|
||||
const SimdScalar scaledmass = mass * 0.08333333f;
|
||||
|
||||
inertia = scaledmass * (SimdVector3(y2+z2,x2+z2,x2+y2));
|
||||
|
||||
// inertia.x() = scaledmass * (y2+z2);
|
||||
// inertia.y() = scaledmass * (x2+z2);
|
||||
// inertia.z() = scaledmass * (x2+y2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
virtual int GetShapeType() const { return CONE_SHAPE_PROXYTYPE; }
|
||||
|
||||
virtual char* GetName()const
|
||||
{
|
||||
return "Cone";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif //CONE_MINKOWSKI_H
|
||||
|
||||
160
Bullet/CollisionShapes/ConvexHullShape.cpp
Normal file
160
Bullet/CollisionShapes/ConvexHullShape.cpp
Normal file
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
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 "ConvexHullShape.h"
|
||||
#include "CollisionShapes/CollisionMargin.h"
|
||||
|
||||
#include "SimdQuaternion.h"
|
||||
|
||||
|
||||
ConvexHullShape ::ConvexHullShape (SimdPoint3* points,int numPoints)
|
||||
{
|
||||
m_points.resize(numPoints);
|
||||
for (int i=0;i<numPoints;i++)
|
||||
m_points[i] = points[i];
|
||||
}
|
||||
|
||||
SimdVector3 ConvexHullShape::LocalGetSupportingVertexWithoutMargin(const SimdVector3& vec0)const
|
||||
{
|
||||
SimdVector3 supVec(0.f,0.f,0.f);
|
||||
SimdScalar newDot,maxDot = -1e30f;
|
||||
|
||||
SimdVector3 vec = vec0;
|
||||
SimdScalar lenSqr = vec.length2();
|
||||
if (lenSqr < 0.0001f)
|
||||
{
|
||||
vec.setValue(1,0,0);
|
||||
} else
|
||||
{
|
||||
float rlen = 1.f / SimdSqrt(lenSqr );
|
||||
vec *= rlen;
|
||||
}
|
||||
|
||||
|
||||
for (size_t i=0;i<m_points.size();i++)
|
||||
{
|
||||
SimdPoint3 vtx = m_points[i] * m_localScaling;
|
||||
|
||||
newDot = vec.dot(vtx);
|
||||
if (newDot > maxDot)
|
||||
{
|
||||
maxDot = newDot;
|
||||
supVec = vtx;
|
||||
}
|
||||
}
|
||||
return supVec;
|
||||
}
|
||||
|
||||
void ConvexHullShape::BatchedUnitVectorGetSupportingVertexWithoutMargin(const SimdVector3* vectors,SimdVector3* supportVerticesOut,int numVectors) const
|
||||
{
|
||||
SimdScalar newDot;
|
||||
//use 'w' component of supportVerticesOut?
|
||||
{
|
||||
for (int i=0;i<numVectors;i++)
|
||||
{
|
||||
supportVerticesOut[i][3] = -1e30f;
|
||||
}
|
||||
}
|
||||
for (size_t i=0;i<m_points.size();i++)
|
||||
{
|
||||
SimdPoint3 vtx = m_points[i] * m_localScaling;
|
||||
|
||||
for (int j=0;j<numVectors;j++)
|
||||
{
|
||||
const SimdVector3& 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
SimdVector3 ConvexHullShape::LocalGetSupportingVertex(const SimdVector3& vec)const
|
||||
{
|
||||
SimdVector3 supVertex = LocalGetSupportingVertexWithoutMargin(vec);
|
||||
|
||||
if ( GetMargin()!=0.f )
|
||||
{
|
||||
SimdVector3 vecnorm = vec;
|
||||
if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON))
|
||||
{
|
||||
vecnorm.setValue(-1.f,-1.f,-1.f);
|
||||
}
|
||||
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 ConvexHullShape with the Raytracer Demo
|
||||
int ConvexHullShape::GetNumVertices() const
|
||||
{
|
||||
return m_points.size();
|
||||
}
|
||||
|
||||
int ConvexHullShape::GetNumEdges() const
|
||||
{
|
||||
return m_points.size()*m_points.size();
|
||||
}
|
||||
|
||||
void ConvexHullShape::GetEdge(int i,SimdPoint3& pa,SimdPoint3& pb) const
|
||||
{
|
||||
|
||||
int index0 = i%m_points.size();
|
||||
int index1 = i/m_points.size();
|
||||
pa = m_points[index0]*m_localScaling;
|
||||
pb = m_points[index1]*m_localScaling;
|
||||
}
|
||||
|
||||
void ConvexHullShape::GetVertex(int i,SimdPoint3& vtx) const
|
||||
{
|
||||
vtx = m_points[i]*m_localScaling;
|
||||
}
|
||||
|
||||
int ConvexHullShape::GetNumPlanes() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ConvexHullShape::GetPlane(SimdVector3& planeNormal,SimdPoint3& planeSupport,int i ) const
|
||||
{
|
||||
assert(0);
|
||||
}
|
||||
|
||||
//not yet
|
||||
bool ConvexHullShape::IsInside(const SimdPoint3& pt,SimdScalar tolerance) const
|
||||
{
|
||||
assert(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
64
Bullet/CollisionShapes/ConvexHullShape.h
Normal file
64
Bullet/CollisionShapes/ConvexHullShape.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
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 CONVEX_HULL_SHAPE_H
|
||||
#define CONVEX_HULL_SHAPE_H
|
||||
|
||||
#include "PolyhedralConvexShape.h"
|
||||
#include "BroadphaseCollision/BroadphaseProxy.h" // for the types
|
||||
|
||||
#include <vector>
|
||||
|
||||
///ConvexHullShape implements an implicit (getSupportingVertex) Convex Hull of a Point Cloud (vertices)
|
||||
///No connectivity is needed. LocalGetSupportingVertex iterates linearly though all vertices.
|
||||
///on modern hardware, due to cache coherency this isn't that bad. Complex algorithms tend to trash the cash.
|
||||
///(memory is much slower then the cpu)
|
||||
class ConvexHullShape : public PolyhedralConvexShape
|
||||
{
|
||||
std::vector<SimdPoint3> m_points;
|
||||
|
||||
public:
|
||||
ConvexHullShape(SimdPoint3* points,int numPoints);
|
||||
|
||||
void AddPoint(const SimdPoint3& point)
|
||||
{
|
||||
m_points.push_back(point);
|
||||
}
|
||||
virtual SimdVector3 LocalGetSupportingVertex(const SimdVector3& vec)const;
|
||||
virtual SimdVector3 LocalGetSupportingVertexWithoutMargin(const SimdVector3& vec)const;
|
||||
virtual void BatchedUnitVectorGetSupportingVertexWithoutMargin(const SimdVector3* vectors,SimdVector3* supportVerticesOut,int numVectors) const;
|
||||
|
||||
|
||||
virtual int GetShapeType()const { return CONVEX_HULL_SHAPE_PROXYTYPE; }
|
||||
|
||||
//debugging
|
||||
virtual char* GetName()const {return "Convex";}
|
||||
|
||||
|
||||
virtual int GetNumVertices() const;
|
||||
virtual int GetNumEdges() const;
|
||||
virtual void GetEdge(int i,SimdPoint3& pa,SimdPoint3& pb) const;
|
||||
virtual void GetVertex(int i,SimdPoint3& vtx) const;
|
||||
virtual int GetNumPlanes() const;
|
||||
virtual void GetPlane(SimdVector3& planeNormal,SimdPoint3& planeSupport,int i ) const;
|
||||
virtual bool IsInside(const SimdPoint3& pt,SimdScalar tolerance) const;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //CONVEX_HULL_SHAPE_H
|
||||
|
||||
74
Bullet/CollisionShapes/ConvexShape.cpp
Normal file
74
Bullet/CollisionShapes/ConvexShape.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
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 "ConvexShape.h"
|
||||
|
||||
ConvexShape::~ConvexShape()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ConvexShape::ConvexShape()
|
||||
:m_collisionMargin(CONVEX_DISTANCE_MARGIN),
|
||||
m_localScaling(1.f,1.f,1.f)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void ConvexShape::setLocalScaling(const SimdVector3& scaling)
|
||||
{
|
||||
m_localScaling = scaling;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ConvexShape::GetAabbSlow(const SimdTransform& trans,SimdVector3&minAabb,SimdVector3&maxAabb) const
|
||||
{
|
||||
|
||||
SimdScalar margin = GetMargin();
|
||||
for (int i=0;i<3;i++)
|
||||
{
|
||||
SimdVector3 vec(0.f,0.f,0.f);
|
||||
vec[i] = 1.f;
|
||||
|
||||
SimdVector3 sv = LocalGetSupportingVertex(vec*trans.getBasis());
|
||||
|
||||
SimdVector3 tmp = trans(sv);
|
||||
maxAabb[i] = tmp[i]+margin;
|
||||
vec[i] = -1.f;
|
||||
tmp = trans(LocalGetSupportingVertex(vec*trans.getBasis()));
|
||||
minAabb[i] = tmp[i]-margin;
|
||||
}
|
||||
};
|
||||
|
||||
SimdVector3 ConvexShape::LocalGetSupportingVertex(const SimdVector3& vec)const
|
||||
{
|
||||
SimdVector3 supVertex = LocalGetSupportingVertexWithoutMargin(vec);
|
||||
|
||||
if ( GetMargin()!=0.f )
|
||||
{
|
||||
SimdVector3 vecnorm = vec;
|
||||
if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON))
|
||||
{
|
||||
vecnorm.setValue(-1.f,-1.f,-1.f);
|
||||
}
|
||||
vecnorm.normalize();
|
||||
supVertex+= GetMargin() * vecnorm;
|
||||
}
|
||||
return supVertex;
|
||||
|
||||
}
|
||||
|
||||
|
||||
85
Bullet/CollisionShapes/ConvexShape.h
Normal file
85
Bullet/CollisionShapes/ConvexShape.h
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
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 CONVEX_SHAPE_INTERFACE1
|
||||
#define CONVEX_SHAPE_INTERFACE1
|
||||
|
||||
#include "CollisionShape.h"
|
||||
|
||||
#include "SimdVector3.h"
|
||||
#include "SimdTransform.h"
|
||||
#include "SimdMatrix3x3.h"
|
||||
#include <vector>
|
||||
#include "CollisionShapes/CollisionMargin.h"
|
||||
|
||||
//todo: get rid of this ConvexCastResult thing!
|
||||
struct ConvexCastResult;
|
||||
|
||||
|
||||
/// ConvexShape is an abstract shape interface.
|
||||
/// The explicit part provides plane-equations, the implicit part provides GetClosestPoint interface.
|
||||
/// used in combination with GJK or ConvexCast
|
||||
class ConvexShape : public CollisionShape
|
||||
{
|
||||
public:
|
||||
ConvexShape();
|
||||
|
||||
virtual ~ConvexShape();
|
||||
|
||||
virtual SimdVector3 LocalGetSupportingVertex(const SimdVector3& vec)const;
|
||||
virtual SimdVector3 LocalGetSupportingVertexWithoutMargin(const SimdVector3& vec) const= 0;
|
||||
|
||||
//notice that the vectors should be unit length
|
||||
virtual void BatchedUnitVectorGetSupportingVertexWithoutMargin(const SimdVector3* vectors,SimdVector3* supportVerticesOut,int numVectors) const= 0;
|
||||
|
||||
// testing for hullnode code
|
||||
|
||||
///GetAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
|
||||
void GetAabb(const SimdTransform& t,SimdVector3& aabbMin,SimdVector3& aabbMax) const
|
||||
{
|
||||
GetAabbSlow(t,aabbMin,aabbMax);
|
||||
}
|
||||
|
||||
|
||||
|
||||
virtual void GetAabbSlow(const SimdTransform& t,SimdVector3& aabbMin,SimdVector3& aabbMax) const;
|
||||
|
||||
|
||||
virtual void setLocalScaling(const SimdVector3& scaling);
|
||||
virtual const SimdVector3& getLocalScaling() const
|
||||
{
|
||||
return m_localScaling;
|
||||
}
|
||||
|
||||
|
||||
virtual void SetMargin(float margin)
|
||||
{
|
||||
m_collisionMargin = margin;
|
||||
}
|
||||
virtual float GetMargin() const
|
||||
{
|
||||
return m_collisionMargin;
|
||||
}
|
||||
private:
|
||||
SimdScalar m_collisionMargin;
|
||||
//local scaling. collisionMargin is not scaled !
|
||||
protected:
|
||||
SimdVector3 m_localScaling;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //CONVEX_SHAPE_INTERFACE1
|
||||
196
Bullet/CollisionShapes/CylinderShape.cpp
Normal file
196
Bullet/CollisionShapes/CylinderShape.cpp
Normal file
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
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 "CylinderShape.h"
|
||||
#include "SimdPoint3.h"
|
||||
|
||||
CylinderShape::CylinderShape (const SimdVector3& halfExtents)
|
||||
:BoxShape(halfExtents)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
CylinderShapeX::CylinderShapeX (const SimdVector3& halfExtents)
|
||||
:CylinderShape(halfExtents)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CylinderShapeZ::CylinderShapeZ (const SimdVector3& halfExtents)
|
||||
:CylinderShape(halfExtents)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline SimdVector3 CylinderLocalSupportX(const SimdVector3& halfExtents,const SimdVector3& v)
|
||||
{
|
||||
const int cylinderUpAxis = 0;
|
||||
const int XX = 1;
|
||||
const int YY = 0;
|
||||
const int ZZ = 2;
|
||||
|
||||
//mapping depends on how cylinder local orientation is
|
||||
// extents of the cylinder is: X,Y is for radius, and Z for height
|
||||
|
||||
|
||||
float radius = halfExtents[XX];
|
||||
float halfHeight = halfExtents[cylinderUpAxis];
|
||||
|
||||
|
||||
SimdVector3 tmp;
|
||||
SimdScalar d ;
|
||||
|
||||
SimdScalar s = SimdSqrt(v[XX] * v[XX] + v[ZZ] * v[ZZ]);
|
||||
if (s != SimdScalar(0.0))
|
||||
{
|
||||
d = radius / s;
|
||||
tmp[XX] = v[XX] * d;
|
||||
tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
|
||||
tmp[ZZ] = v[ZZ] * d;
|
||||
return tmp;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp[XX] = radius;
|
||||
tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
|
||||
tmp[ZZ] = SimdScalar(0.0);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
inline SimdVector3 CylinderLocalSupportY(const SimdVector3& halfExtents,const SimdVector3& v)
|
||||
{
|
||||
|
||||
const int cylinderUpAxis = 1;
|
||||
const int XX = 0;
|
||||
const int YY = 1;
|
||||
const int ZZ = 2;
|
||||
|
||||
|
||||
float radius = halfExtents[XX];
|
||||
float halfHeight = halfExtents[cylinderUpAxis];
|
||||
|
||||
|
||||
SimdVector3 tmp;
|
||||
SimdScalar d ;
|
||||
|
||||
SimdScalar s = SimdSqrt(v[XX] * v[XX] + v[ZZ] * v[ZZ]);
|
||||
if (s != SimdScalar(0.0))
|
||||
{
|
||||
d = radius / s;
|
||||
tmp[XX] = v[XX] * d;
|
||||
tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
|
||||
tmp[ZZ] = v[ZZ] * d;
|
||||
return tmp;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp[XX] = radius;
|
||||
tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
|
||||
tmp[ZZ] = SimdScalar(0.0);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
inline SimdVector3 CylinderLocalSupportZ(const SimdVector3& halfExtents,const SimdVector3& v)
|
||||
{
|
||||
const int cylinderUpAxis = 2;
|
||||
const int XX = 0;
|
||||
const int YY = 2;
|
||||
const int ZZ = 1;
|
||||
|
||||
//mapping depends on how cylinder local orientation is
|
||||
// extents of the cylinder is: X,Y is for radius, and Z for height
|
||||
|
||||
|
||||
float radius = halfExtents[XX];
|
||||
float halfHeight = halfExtents[cylinderUpAxis];
|
||||
|
||||
|
||||
SimdVector3 tmp;
|
||||
SimdScalar d ;
|
||||
|
||||
SimdScalar s = SimdSqrt(v[XX] * v[XX] + v[ZZ] * v[ZZ]);
|
||||
if (s != SimdScalar(0.0))
|
||||
{
|
||||
d = radius / s;
|
||||
tmp[XX] = v[XX] * d;
|
||||
tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
|
||||
tmp[ZZ] = v[ZZ] * d;
|
||||
return tmp;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp[XX] = radius;
|
||||
tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
|
||||
tmp[ZZ] = SimdScalar(0.0);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
SimdVector3 CylinderShapeX::LocalGetSupportingVertexWithoutMargin(const SimdVector3& vec)const
|
||||
{
|
||||
return CylinderLocalSupportX(GetHalfExtents(),vec);
|
||||
}
|
||||
|
||||
|
||||
SimdVector3 CylinderShapeZ::LocalGetSupportingVertexWithoutMargin(const SimdVector3& vec)const
|
||||
{
|
||||
return CylinderLocalSupportZ(GetHalfExtents(),vec);
|
||||
}
|
||||
SimdVector3 CylinderShape::LocalGetSupportingVertexWithoutMargin(const SimdVector3& vec)const
|
||||
{
|
||||
return CylinderLocalSupportY(GetHalfExtents(),vec);
|
||||
}
|
||||
|
||||
void CylinderShape::BatchedUnitVectorGetSupportingVertexWithoutMargin(const SimdVector3* vectors,SimdVector3* supportVerticesOut,int numVectors) const
|
||||
{
|
||||
for (int i=0;i<numVectors;i++)
|
||||
{
|
||||
supportVerticesOut[i] = CylinderLocalSupportY(GetHalfExtents(),vectors[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void CylinderShapeZ::BatchedUnitVectorGetSupportingVertexWithoutMargin(const SimdVector3* vectors,SimdVector3* supportVerticesOut,int numVectors) const
|
||||
{
|
||||
for (int i=0;i<numVectors;i++)
|
||||
{
|
||||
supportVerticesOut[i] = CylinderLocalSupportZ(GetHalfExtents(),vectors[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void CylinderShapeX::BatchedUnitVectorGetSupportingVertexWithoutMargin(const SimdVector3* vectors,SimdVector3* supportVerticesOut,int numVectors) const
|
||||
{
|
||||
for (int i=0;i<numVectors;i++)
|
||||
{
|
||||
supportVerticesOut[i] = CylinderLocalSupportX(GetHalfExtents(),vectors[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
94
Bullet/CollisionShapes/CylinderShape.h
Normal file
94
Bullet/CollisionShapes/CylinderShape.h
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
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 CYLINDER_MINKOWSKI_H
|
||||
#define CYLINDER_MINKOWSKI_H
|
||||
|
||||
#include "BoxShape.h"
|
||||
#include "BroadphaseCollision/BroadphaseProxy.h" // for the types
|
||||
#include "SimdVector3.h"
|
||||
|
||||
/// implements cylinder shape interface
|
||||
class CylinderShape : public BoxShape
|
||||
|
||||
{
|
||||
|
||||
public:
|
||||
CylinderShape (const SimdVector3& halfExtents);
|
||||
|
||||
///GetAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
|
||||
void GetAabb(const SimdTransform& t,SimdVector3& aabbMin,SimdVector3& aabbMax) const
|
||||
{
|
||||
GetAabbSlow(t,aabbMin,aabbMax);
|
||||
}
|
||||
|
||||
virtual SimdVector3 LocalGetSupportingVertexWithoutMargin(const SimdVector3& vec)const;
|
||||
|
||||
virtual void BatchedUnitVectorGetSupportingVertexWithoutMargin(const SimdVector3* vectors,SimdVector3* supportVerticesOut,int numVectors) const;
|
||||
|
||||
virtual SimdVector3 LocalGetSupportingVertex(const SimdVector3& vec) const
|
||||
{
|
||||
|
||||
SimdVector3 supVertex;
|
||||
supVertex = LocalGetSupportingVertexWithoutMargin(vec);
|
||||
|
||||
if ( GetMargin()!=0.f )
|
||||
{
|
||||
SimdVector3 vecnorm = vec;
|
||||
if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON))
|
||||
{
|
||||
vecnorm.setValue(-1.f,-1.f,-1.f);
|
||||
}
|
||||
vecnorm.normalize();
|
||||
supVertex+= GetMargin() * vecnorm;
|
||||
}
|
||||
return supVertex;
|
||||
}
|
||||
|
||||
|
||||
//use box inertia
|
||||
// virtual void CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia);
|
||||
|
||||
virtual int GetShapeType() const
|
||||
{
|
||||
return CYLINDER_SHAPE_PROXYTYPE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
class CylinderShapeX : public CylinderShape
|
||||
{
|
||||
public:
|
||||
CylinderShapeX (const SimdVector3& halfExtents);
|
||||
|
||||
virtual SimdVector3 LocalGetSupportingVertexWithoutMargin(const SimdVector3& vec)const;
|
||||
virtual void BatchedUnitVectorGetSupportingVertexWithoutMargin(const SimdVector3* vectors,SimdVector3* supportVerticesOut,int numVectors) const;
|
||||
};
|
||||
|
||||
class CylinderShapeZ : public CylinderShape
|
||||
{
|
||||
public:
|
||||
CylinderShapeZ (const SimdVector3& halfExtents);
|
||||
|
||||
virtual SimdVector3 LocalGetSupportingVertexWithoutMargin(const SimdVector3& vec)const;
|
||||
virtual void BatchedUnitVectorGetSupportingVertexWithoutMargin(const SimdVector3* vectors,SimdVector3* supportVerticesOut,int numVectors) const;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //CYLINDER_MINKOWSKI_H
|
||||
|
||||
49
Bullet/CollisionShapes/EmptyShape.cpp
Normal file
49
Bullet/CollisionShapes/EmptyShape.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
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 "EmptyShape.h"
|
||||
|
||||
|
||||
#include "CollisionShape.h"
|
||||
|
||||
|
||||
EmptyShape::EmptyShape()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
EmptyShape::~EmptyShape()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///GetAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
|
||||
void EmptyShape::GetAabb(const SimdTransform& t,SimdVector3& aabbMin,SimdVector3& aabbMax) const
|
||||
{
|
||||
SimdVector3 margin(GetMargin(),GetMargin(),GetMargin());
|
||||
|
||||
aabbMin = t.getOrigin() - margin;
|
||||
|
||||
aabbMax = t.getOrigin() + margin;
|
||||
|
||||
}
|
||||
|
||||
void EmptyShape::CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia)
|
||||
{
|
||||
assert(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
79
Bullet/CollisionShapes/EmptyShape.h
Normal file
79
Bullet/CollisionShapes/EmptyShape.h
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
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 EMPTY_SHAPE_H
|
||||
#define EMPTY_SHAPE_H
|
||||
|
||||
#include "CollisionShape.h"
|
||||
|
||||
#include "SimdVector3.h"
|
||||
#include "SimdTransform.h"
|
||||
#include "SimdMatrix3x3.h"
|
||||
#include <vector>
|
||||
#include "CollisionShapes/CollisionMargin.h"
|
||||
|
||||
|
||||
|
||||
|
||||
/// EmptyShape is a collision shape without actual collision detection. It can be replaced by another shape during runtime
|
||||
class EmptyShape : public CollisionShape
|
||||
{
|
||||
public:
|
||||
EmptyShape();
|
||||
|
||||
virtual ~EmptyShape();
|
||||
|
||||
|
||||
///GetAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
|
||||
void GetAabb(const SimdTransform& t,SimdVector3& aabbMin,SimdVector3& aabbMax) const;
|
||||
|
||||
|
||||
virtual void setLocalScaling(const SimdVector3& scaling)
|
||||
{
|
||||
m_localScaling = scaling;
|
||||
}
|
||||
virtual const SimdVector3& getLocalScaling() const
|
||||
{
|
||||
return m_localScaling;
|
||||
}
|
||||
|
||||
virtual void CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia);
|
||||
|
||||
virtual int GetShapeType() const { return EMPTY_SHAPE_PROXYTYPE;}
|
||||
|
||||
virtual void SetMargin(float margin)
|
||||
{
|
||||
m_collisionMargin = margin;
|
||||
}
|
||||
virtual float GetMargin() const
|
||||
{
|
||||
return m_collisionMargin;
|
||||
}
|
||||
virtual char* GetName()const
|
||||
{
|
||||
return "Empty";
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
SimdScalar m_collisionMargin;
|
||||
protected:
|
||||
SimdVector3 m_localScaling;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //EMPTY_SHAPE_H
|
||||
56
Bullet/CollisionShapes/MinkowskiSumShape.cpp
Normal file
56
Bullet/CollisionShapes/MinkowskiSumShape.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
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 "MinkowskiSumShape.h"
|
||||
|
||||
|
||||
MinkowskiSumShape::MinkowskiSumShape(ConvexShape* shapeA,ConvexShape* shapeB)
|
||||
:m_shapeA(shapeA),
|
||||
m_shapeB(shapeB)
|
||||
{
|
||||
m_transA.setIdentity();
|
||||
m_transB.setIdentity();
|
||||
}
|
||||
|
||||
SimdVector3 MinkowskiSumShape::LocalGetSupportingVertexWithoutMargin(const SimdVector3& vec)const
|
||||
{
|
||||
SimdVector3 supVertexA = m_transA(m_shapeA->LocalGetSupportingVertexWithoutMargin(vec*m_transA.getBasis()));
|
||||
SimdVector3 supVertexB = m_transB(m_shapeB->LocalGetSupportingVertexWithoutMargin(vec*m_transB.getBasis()));
|
||||
return supVertexA + supVertexB;
|
||||
}
|
||||
|
||||
void MinkowskiSumShape::BatchedUnitVectorGetSupportingVertexWithoutMargin(const SimdVector3* vectors,SimdVector3* supportVerticesOut,int numVectors) const
|
||||
{
|
||||
//todo: could make recursive use of batching. probably this shape is not used frequently.
|
||||
for (int i=0;i<numVectors;i++)
|
||||
{
|
||||
supportVerticesOut[i] = LocalGetSupportingVertexWithoutMargin(vectors[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
float MinkowskiSumShape::GetMargin() const
|
||||
{
|
||||
return m_shapeA->GetMargin() + m_shapeB->GetMargin();
|
||||
}
|
||||
|
||||
|
||||
void MinkowskiSumShape::CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia)
|
||||
{
|
||||
assert(0);
|
||||
inertia.setValue(0,0,0);
|
||||
}
|
||||
62
Bullet/CollisionShapes/MinkowskiSumShape.h
Normal file
62
Bullet/CollisionShapes/MinkowskiSumShape.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
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 MINKOWSKI_SUM_SHAPE_H
|
||||
#define MINKOWSKI_SUM_SHAPE_H
|
||||
|
||||
#include "ConvexShape.h"
|
||||
#include "BroadphaseCollision/BroadphaseProxy.h" // for the types
|
||||
|
||||
/// MinkowskiSumShape represents implicit (getSupportingVertex) based minkowski sum of two convex implicit shapes.
|
||||
class MinkowskiSumShape : public ConvexShape
|
||||
{
|
||||
|
||||
SimdTransform m_transA;
|
||||
SimdTransform m_transB;
|
||||
ConvexShape* m_shapeA;
|
||||
ConvexShape* m_shapeB;
|
||||
|
||||
public:
|
||||
|
||||
MinkowskiSumShape(ConvexShape* shapeA,ConvexShape* shapeB);
|
||||
|
||||
virtual SimdVector3 LocalGetSupportingVertexWithoutMargin(const SimdVector3& vec)const;
|
||||
|
||||
virtual void BatchedUnitVectorGetSupportingVertexWithoutMargin(const SimdVector3* vectors,SimdVector3* supportVerticesOut,int numVectors) const;
|
||||
|
||||
|
||||
virtual void CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia);
|
||||
|
||||
void SetTransformA(const SimdTransform& transA) { m_transA = transA;}
|
||||
void SetTransformB(const SimdTransform& transB) { m_transB = transB;}
|
||||
|
||||
const SimdTransform& GetTransformA()const { return m_transA;}
|
||||
const SimdTransform& GetTransformB()const { return m_transB;}
|
||||
|
||||
|
||||
virtual int GetShapeType() const { return MINKOWSKI_SUM_SHAPE_PROXYTYPE; }
|
||||
|
||||
virtual float GetMargin() const;
|
||||
|
||||
const ConvexShape* GetShapeA() const { return m_shapeA;}
|
||||
const ConvexShape* GetShapeB() const { return m_shapeB;}
|
||||
|
||||
virtual char* GetName()const
|
||||
{
|
||||
return "MinkowskiSum";
|
||||
}
|
||||
};
|
||||
|
||||
#endif //MINKOWSKI_SUM_SHAPE_H
|
||||
148
Bullet/CollisionShapes/MultiSphereShape.cpp
Normal file
148
Bullet/CollisionShapes/MultiSphereShape.cpp
Normal file
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
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 "MultiSphereShape.h"
|
||||
#include "CollisionShapes/CollisionMargin.h"
|
||||
#include "SimdQuaternion.h"
|
||||
|
||||
MultiSphereShape::MultiSphereShape (const SimdVector3& inertiaHalfExtents,const SimdVector3* positions,const SimdScalar* radi,int numSpheres)
|
||||
:m_inertiaHalfExtents(inertiaHalfExtents)
|
||||
{
|
||||
m_minRadius = 1e30f;
|
||||
|
||||
m_numSpheres = numSpheres;
|
||||
for (int i=0;i<m_numSpheres;i++)
|
||||
{
|
||||
m_localPositions[i] = positions[i];
|
||||
m_radi[i] = radi[i];
|
||||
if (radi[i] < m_minRadius)
|
||||
m_minRadius = radi[i];
|
||||
}
|
||||
SetMargin(m_minRadius);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
SimdVector3 MultiSphereShape::LocalGetSupportingVertexWithoutMargin(const SimdVector3& vec0)const
|
||||
{
|
||||
int i;
|
||||
SimdVector3 supVec(0,0,0);
|
||||
|
||||
SimdScalar maxDot(-1e30f);
|
||||
|
||||
|
||||
SimdVector3 vec = vec0;
|
||||
SimdScalar lenSqr = vec.length2();
|
||||
if (lenSqr < 0.0001f)
|
||||
{
|
||||
vec.setValue(1,0,0);
|
||||
} else
|
||||
{
|
||||
float rlen = 1.f / SimdSqrt(lenSqr );
|
||||
vec *= rlen;
|
||||
}
|
||||
|
||||
SimdVector3 vtx;
|
||||
SimdScalar newDot;
|
||||
|
||||
const SimdVector3* pos = &m_localPositions[0];
|
||||
const SimdScalar* rad = &m_radi[0];
|
||||
|
||||
for (i=0;i<m_numSpheres;i++)
|
||||
{
|
||||
vtx = (*pos) +vec*((*rad)-m_minRadius);
|
||||
pos++;
|
||||
rad++;
|
||||
newDot = vec.dot(vtx);
|
||||
if (newDot > maxDot)
|
||||
{
|
||||
maxDot = newDot;
|
||||
supVec = vtx;
|
||||
}
|
||||
}
|
||||
|
||||
return supVec;
|
||||
|
||||
}
|
||||
|
||||
void MultiSphereShape::BatchedUnitVectorGetSupportingVertexWithoutMargin(const SimdVector3* vectors,SimdVector3* supportVerticesOut,int numVectors) const
|
||||
{
|
||||
|
||||
for (int j=0;j<numVectors;j++)
|
||||
{
|
||||
SimdScalar maxDot(-1e30f);
|
||||
|
||||
const SimdVector3& vec = vectors[j];
|
||||
|
||||
SimdVector3 vtx;
|
||||
SimdScalar newDot;
|
||||
|
||||
const SimdVector3* pos = &m_localPositions[0];
|
||||
const SimdScalar* rad = &m_radi[0];
|
||||
|
||||
for (int i=0;i<m_numSpheres;i++)
|
||||
{
|
||||
vtx = (*pos) +vec*((*rad)-m_minRadius);
|
||||
pos++;
|
||||
rad++;
|
||||
newDot = vec.dot(vtx);
|
||||
if (newDot > maxDot)
|
||||
{
|
||||
maxDot = newDot;
|
||||
supportVerticesOut[j] = vtx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void MultiSphereShape::CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia)
|
||||
{
|
||||
//as an approximation, take the inertia of the box that bounds the spheres
|
||||
|
||||
SimdTransform ident;
|
||||
ident.setIdentity();
|
||||
// SimdVector3 aabbMin,aabbMax;
|
||||
|
||||
// GetAabb(ident,aabbMin,aabbMax);
|
||||
|
||||
SimdVector3 halfExtents = m_inertiaHalfExtents;//(aabbMax - aabbMin)* 0.5f;
|
||||
|
||||
float margin = CONVEX_DISTANCE_MARGIN;
|
||||
|
||||
SimdScalar lx=2.f*(halfExtents[0]+margin);
|
||||
SimdScalar ly=2.f*(halfExtents[1]+margin);
|
||||
SimdScalar lz=2.f*(halfExtents[2]+margin);
|
||||
const SimdScalar x2 = lx*lx;
|
||||
const SimdScalar y2 = ly*ly;
|
||||
const SimdScalar z2 = lz*lz;
|
||||
const SimdScalar scaledmass = mass * 0.08333333f;
|
||||
|
||||
inertia[0] = scaledmass * (y2+z2);
|
||||
inertia[1] = scaledmass * (x2+z2);
|
||||
inertia[2] = scaledmass * (x2+y2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
62
Bullet/CollisionShapes/MultiSphereShape.h
Normal file
62
Bullet/CollisionShapes/MultiSphereShape.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
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 MULTI_SPHERE_MINKOWSKI_H
|
||||
#define MULTI_SPHERE_MINKOWSKI_H
|
||||
|
||||
#include "ConvexShape.h"
|
||||
#include "BroadphaseCollision/BroadphaseProxy.h" // for the types
|
||||
|
||||
#define MAX_NUM_SPHERES 5
|
||||
|
||||
///MultiSphereShape represents implicit convex hull of a collection of spheres (using getSupportingVertex)
|
||||
class MultiSphereShape : public ConvexShape
|
||||
|
||||
{
|
||||
|
||||
SimdVector3 m_localPositions[MAX_NUM_SPHERES];
|
||||
SimdScalar m_radi[MAX_NUM_SPHERES];
|
||||
SimdVector3 m_inertiaHalfExtents;
|
||||
|
||||
int m_numSpheres;
|
||||
float m_minRadius;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public:
|
||||
MultiSphereShape (const SimdVector3& inertiaHalfExtents,const SimdVector3* positions,const SimdScalar* radi,int numSpheres);
|
||||
|
||||
///CollisionShape Interface
|
||||
virtual void CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia);
|
||||
|
||||
/// ConvexShape Interface
|
||||
virtual SimdVector3 LocalGetSupportingVertexWithoutMargin(const SimdVector3& vec)const;
|
||||
|
||||
virtual void BatchedUnitVectorGetSupportingVertexWithoutMargin(const SimdVector3* vectors,SimdVector3* supportVerticesOut,int numVectors) const;
|
||||
|
||||
|
||||
virtual int GetShapeType() const { return MULTI_SPHERE_SHAPE_PROXYTYPE; }
|
||||
|
||||
virtual char* GetName()const
|
||||
{
|
||||
return "MultiSphere";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //MULTI_SPHERE_MINKOWSKI_H
|
||||
276
Bullet/CollisionShapes/OptimizedBvh.cpp
Normal file
276
Bullet/CollisionShapes/OptimizedBvh.cpp
Normal file
@@ -0,0 +1,276 @@
|
||||
/*
|
||||
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 "OptimizedBvh.h"
|
||||
#include "StridingMeshInterface.h"
|
||||
#include "AabbUtil2.h"
|
||||
|
||||
|
||||
|
||||
void OptimizedBvh::Build(StridingMeshInterface* triangles)
|
||||
{
|
||||
//int countTriangles = 0;
|
||||
|
||||
|
||||
|
||||
// NodeArray triangleNodes;
|
||||
|
||||
struct NodeTriangleCallback : public InternalTriangleIndexCallback
|
||||
{
|
||||
NodeArray& m_triangleNodes;
|
||||
|
||||
NodeTriangleCallback(NodeArray& triangleNodes)
|
||||
:m_triangleNodes(triangleNodes)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
virtual void InternalProcessTriangleIndex(SimdVector3* triangle,int partId,int triangleIndex)
|
||||
{
|
||||
|
||||
OptimizedBvhNode node;
|
||||
node.m_aabbMin = SimdVector3(1e30f,1e30f,1e30f);
|
||||
node.m_aabbMax = SimdVector3(-1e30f,-1e30f,-1e30f);
|
||||
node.m_aabbMin.setMin(triangle[0]);
|
||||
node.m_aabbMax.setMax(triangle[0]);
|
||||
node.m_aabbMin.setMin(triangle[1]);
|
||||
node.m_aabbMax.setMax(triangle[1]);
|
||||
node.m_aabbMin.setMin(triangle[2]);
|
||||
node.m_aabbMax.setMax(triangle[2]);
|
||||
|
||||
node.m_escapeIndex = -1;
|
||||
node.m_leftChild = 0;
|
||||
node.m_rightChild = 0;
|
||||
|
||||
|
||||
//for child nodes
|
||||
node.m_subPart = partId;
|
||||
node.m_triangleIndex = triangleIndex;
|
||||
|
||||
|
||||
m_triangleNodes.push_back(node);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
NodeTriangleCallback callback(m_leafNodes);
|
||||
|
||||
SimdVector3 aabbMin(-1e30f,-1e30f,-1e30f);
|
||||
SimdVector3 aabbMax(1e30f,1e30f,1e30f);
|
||||
|
||||
triangles->InternalProcessAllTriangles(&callback,aabbMin,aabbMax);
|
||||
|
||||
//now we have an array of leafnodes in m_leafNodes
|
||||
|
||||
m_contiguousNodes = new OptimizedBvhNode[2*m_leafNodes.size()];
|
||||
m_curNodeIndex = 0;
|
||||
|
||||
m_rootNode1 = BuildTree(m_leafNodes,0,m_leafNodes.size());
|
||||
|
||||
|
||||
///create the leafnodes first
|
||||
// OptimizedBvhNode* leafNodes = new OptimizedBvhNode;
|
||||
}
|
||||
|
||||
|
||||
OptimizedBvhNode* OptimizedBvh::BuildTree (NodeArray& leafNodes,int startIndex,int endIndex)
|
||||
{
|
||||
OptimizedBvhNode* internalNode;
|
||||
|
||||
int splitAxis, splitIndex, i;
|
||||
int numIndices =endIndex-startIndex;
|
||||
int curIndex = m_curNodeIndex;
|
||||
|
||||
assert(numIndices>0);
|
||||
|
||||
if (numIndices==1)
|
||||
{
|
||||
return new (&m_contiguousNodes[m_curNodeIndex++]) OptimizedBvhNode(leafNodes[startIndex]);
|
||||
}
|
||||
//calculate Best Splitting Axis and where to split it. Sort the incoming 'leafNodes' array within range 'startIndex/endIndex'.
|
||||
|
||||
splitAxis = CalcSplittingAxis(leafNodes,startIndex,endIndex);
|
||||
|
||||
splitIndex = SortAndCalcSplittingIndex(leafNodes,startIndex,endIndex,splitAxis);
|
||||
|
||||
internalNode = &m_contiguousNodes[m_curNodeIndex++];
|
||||
|
||||
internalNode->m_aabbMax.setValue(-1e30f,-1e30f,-1e30f);
|
||||
internalNode->m_aabbMin.setValue(1e30f,1e30f,1e30f);
|
||||
|
||||
for (i=startIndex;i<endIndex;i++)
|
||||
{
|
||||
internalNode->m_aabbMax.setMax(leafNodes[i].m_aabbMax);
|
||||
internalNode->m_aabbMin.setMin(leafNodes[i].m_aabbMin);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//internalNode->m_escapeIndex;
|
||||
internalNode->m_leftChild = BuildTree(leafNodes,startIndex,splitIndex);
|
||||
internalNode->m_rightChild = BuildTree(leafNodes,splitIndex,endIndex);
|
||||
|
||||
internalNode->m_escapeIndex = m_curNodeIndex - curIndex;
|
||||
return internalNode;
|
||||
}
|
||||
|
||||
int OptimizedBvh::SortAndCalcSplittingIndex(NodeArray& leafNodes,int startIndex,int endIndex,int splitAxis)
|
||||
{
|
||||
int i;
|
||||
int splitIndex =startIndex;
|
||||
int numIndices = endIndex - startIndex;
|
||||
float splitValue;
|
||||
|
||||
SimdVector3 means(0.f,0.f,0.f);
|
||||
for (i=startIndex;i<endIndex;i++)
|
||||
{
|
||||
SimdVector3 center = 0.5f*(leafNodes[i].m_aabbMax+leafNodes[i].m_aabbMin);
|
||||
means+=center;
|
||||
}
|
||||
means *= (1.f/(float)numIndices);
|
||||
|
||||
splitValue = means[splitAxis];
|
||||
|
||||
//sort leafNodes so all values larger then splitValue comes first, and smaller values start from 'splitIndex'.
|
||||
for (i=startIndex;i<endIndex;i++)
|
||||
{
|
||||
SimdVector3 center = 0.5f*(leafNodes[i].m_aabbMax+leafNodes[i].m_aabbMin);
|
||||
if (center[splitAxis] > splitValue)
|
||||
{
|
||||
//swap
|
||||
OptimizedBvhNode tmp = leafNodes[i];
|
||||
leafNodes[i] = leafNodes[splitIndex];
|
||||
leafNodes[splitIndex] = tmp;
|
||||
splitIndex++;
|
||||
}
|
||||
}
|
||||
if ((splitIndex==startIndex) || (splitIndex == (endIndex-1)))
|
||||
{
|
||||
splitIndex = startIndex+ (numIndices>>1);
|
||||
}
|
||||
return splitIndex;
|
||||
}
|
||||
|
||||
|
||||
int OptimizedBvh::CalcSplittingAxis(NodeArray& leafNodes,int startIndex,int endIndex)
|
||||
{
|
||||
int i;
|
||||
|
||||
SimdVector3 means(0.f,0.f,0.f);
|
||||
SimdVector3 variance(0.f,0.f,0.f);
|
||||
int numIndices = endIndex-startIndex;
|
||||
|
||||
for (i=startIndex;i<endIndex;i++)
|
||||
{
|
||||
SimdVector3 center = 0.5f*(leafNodes[i].m_aabbMax+leafNodes[i].m_aabbMin);
|
||||
means+=center;
|
||||
}
|
||||
means *= (1.f/(float)numIndices);
|
||||
|
||||
for (i=startIndex;i<endIndex;i++)
|
||||
{
|
||||
SimdVector3 center = 0.5f*(leafNodes[i].m_aabbMax+leafNodes[i].m_aabbMin);
|
||||
SimdVector3 diff2 = center-means;
|
||||
diff2 = diff2 * diff2;
|
||||
variance += diff2;
|
||||
}
|
||||
variance *= (1.f/ ((float)numIndices-1) );
|
||||
|
||||
return variance.maxAxis();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void OptimizedBvh::ReportAabbOverlappingNodex(NodeOverlapCallback* nodeCallback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const
|
||||
{
|
||||
if (aabbMin.length() > 1000.f)
|
||||
{
|
||||
for (size_t i=0;i<m_leafNodes.size();i++)
|
||||
{
|
||||
const OptimizedBvhNode& node = m_leafNodes[i];
|
||||
nodeCallback->ProcessNode(&node);
|
||||
}
|
||||
} else
|
||||
{
|
||||
//WalkTree(m_rootNode1,nodeCallback,aabbMin,aabbMax);
|
||||
WalkStacklessTree(m_rootNode1,nodeCallback,aabbMin,aabbMax);
|
||||
}
|
||||
}
|
||||
|
||||
void OptimizedBvh::WalkTree(OptimizedBvhNode* rootNode,NodeOverlapCallback* nodeCallback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const
|
||||
{
|
||||
bool isLeafNode, aabbOverlap = TestAabbAgainstAabb2(aabbMin,aabbMax,rootNode->m_aabbMin,rootNode->m_aabbMax);
|
||||
if (aabbOverlap)
|
||||
{
|
||||
isLeafNode = (!rootNode->m_leftChild && !rootNode->m_rightChild);
|
||||
if (isLeafNode)
|
||||
{
|
||||
nodeCallback->ProcessNode(rootNode);
|
||||
} else
|
||||
{
|
||||
WalkTree(rootNode->m_leftChild,nodeCallback,aabbMin,aabbMax);
|
||||
WalkTree(rootNode->m_rightChild,nodeCallback,aabbMin,aabbMax);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int maxIterations = 0;
|
||||
|
||||
void OptimizedBvh::WalkStacklessTree(OptimizedBvhNode* rootNode,NodeOverlapCallback* nodeCallback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const
|
||||
{
|
||||
int escapeIndex, curIndex = 0;
|
||||
int walkIterations = 0;
|
||||
bool aabbOverlap, isLeafNode;
|
||||
|
||||
while (curIndex < m_curNodeIndex)
|
||||
{
|
||||
//catch bugs in tree data
|
||||
assert (walkIterations < m_curNodeIndex);
|
||||
|
||||
walkIterations++;
|
||||
aabbOverlap = TestAabbAgainstAabb2(aabbMin,aabbMax,rootNode->m_aabbMin,rootNode->m_aabbMax);
|
||||
isLeafNode = (!rootNode->m_leftChild && !rootNode->m_rightChild);
|
||||
|
||||
if (isLeafNode && aabbOverlap)
|
||||
{
|
||||
nodeCallback->ProcessNode(rootNode);
|
||||
}
|
||||
|
||||
if (aabbOverlap || isLeafNode)
|
||||
{
|
||||
rootNode++;
|
||||
curIndex++;
|
||||
} else
|
||||
{
|
||||
escapeIndex = rootNode->m_escapeIndex;
|
||||
rootNode += escapeIndex;
|
||||
curIndex += escapeIndex;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (maxIterations < walkIterations)
|
||||
maxIterations = walkIterations;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void OptimizedBvh::ReportSphereOverlappingNodex(NodeOverlapCallback* nodeCallback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
100
Bullet/CollisionShapes/OptimizedBvh.h
Normal file
100
Bullet/CollisionShapes/OptimizedBvh.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
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 OPTIMIZED_BVH_H
|
||||
#define OPTIMIZED_BVH_H
|
||||
#include "SimdVector3.h"
|
||||
#include <vector>
|
||||
|
||||
class StridingMeshInterface;
|
||||
|
||||
/// OptimizedBvhNode contains both internal and leaf node information.
|
||||
/// It hasn't been optimized yet for storage. Some obvious optimizations are:
|
||||
/// Removal of the pointers (can already be done, they are not used for traversal)
|
||||
/// and storing aabbmin/max as quantized integers.
|
||||
/// 'subpart' doesn't need an integer either. It allows to re-use graphics triangle
|
||||
/// meshes stored in a non-uniform way (like batches/subparts of triangle-fans
|
||||
struct OptimizedBvhNode
|
||||
{
|
||||
|
||||
SimdVector3 m_aabbMin;
|
||||
SimdVector3 m_aabbMax;
|
||||
|
||||
//these 2 pointers are obsolete, the stackless traversal just uses the escape index
|
||||
OptimizedBvhNode* m_leftChild;
|
||||
OptimizedBvhNode* m_rightChild;
|
||||
|
||||
int m_escapeIndex;
|
||||
|
||||
//for child nodes
|
||||
int m_subPart;
|
||||
int m_triangleIndex;
|
||||
|
||||
};
|
||||
|
||||
class NodeOverlapCallback
|
||||
{
|
||||
public:
|
||||
virtual ~NodeOverlapCallback() {};
|
||||
|
||||
virtual void ProcessNode(const OptimizedBvhNode* node) = 0;
|
||||
};
|
||||
|
||||
typedef std::vector<OptimizedBvhNode> NodeArray;
|
||||
|
||||
|
||||
///OptimizedBvh store an AABB tree that can be quickly traversed on CPU (and SPU,GPU in future)
|
||||
class OptimizedBvh
|
||||
{
|
||||
OptimizedBvhNode* m_rootNode1;
|
||||
|
||||
OptimizedBvhNode* m_contiguousNodes;
|
||||
int m_curNodeIndex;
|
||||
|
||||
int m_numNodes;
|
||||
|
||||
NodeArray m_leafNodes;
|
||||
|
||||
public:
|
||||
OptimizedBvh() :m_rootNode1(0), m_numNodes(0) { }
|
||||
virtual ~OptimizedBvh() {};
|
||||
|
||||
void Build(StridingMeshInterface* triangles);
|
||||
|
||||
OptimizedBvhNode* BuildTree (NodeArray& leafNodes,int startIndex,int endIndex);
|
||||
|
||||
int CalcSplittingAxis(NodeArray& leafNodes,int startIndex,int endIndex);
|
||||
|
||||
int SortAndCalcSplittingIndex(NodeArray& leafNodes,int startIndex,int endIndex,int splitAxis);
|
||||
|
||||
void WalkTree(OptimizedBvhNode* rootNode,NodeOverlapCallback* nodeCallback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const;
|
||||
|
||||
void WalkStacklessTree(OptimizedBvhNode* rootNode,NodeOverlapCallback* nodeCallback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const;
|
||||
|
||||
|
||||
//OptimizedBvhNode* GetRootNode() { return m_rootNode1;}
|
||||
|
||||
int GetNumNodes() { return m_numNodes;}
|
||||
|
||||
void ReportAabbOverlappingNodex(NodeOverlapCallback* nodeCallback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const;
|
||||
|
||||
void ReportSphereOverlappingNodex(NodeOverlapCallback* nodeCallback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //OPTIMIZED_BVH_H
|
||||
|
||||
113
Bullet/CollisionShapes/PolyhedralConvexShape.cpp
Normal file
113
Bullet/CollisionShapes/PolyhedralConvexShape.cpp
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
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 <CollisionShapes/PolyhedralConvexShape.h>
|
||||
|
||||
PolyhedralConvexShape::PolyhedralConvexShape()
|
||||
:m_optionalHull(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
SimdVector3 PolyhedralConvexShape::LocalGetSupportingVertexWithoutMargin(const SimdVector3& vec0)const
|
||||
{
|
||||
int i;
|
||||
SimdVector3 supVec(0,0,0);
|
||||
|
||||
SimdScalar maxDot(-1e30f);
|
||||
|
||||
SimdVector3 vec = vec0;
|
||||
SimdScalar lenSqr = vec.length2();
|
||||
if (lenSqr < 0.0001f)
|
||||
{
|
||||
vec.setValue(1,0,0);
|
||||
} else
|
||||
{
|
||||
float rlen = 1.f / SimdSqrt(lenSqr );
|
||||
vec *= rlen;
|
||||
}
|
||||
|
||||
SimdVector3 vtx;
|
||||
SimdScalar newDot;
|
||||
|
||||
for (i=0;i<GetNumVertices();i++)
|
||||
{
|
||||
GetVertex(i,vtx);
|
||||
newDot = vec.dot(vtx);
|
||||
if (newDot > maxDot)
|
||||
{
|
||||
maxDot = newDot;
|
||||
supVec = vtx;
|
||||
}
|
||||
}
|
||||
|
||||
return supVec;
|
||||
|
||||
}
|
||||
|
||||
void PolyhedralConvexShape::BatchedUnitVectorGetSupportingVertexWithoutMargin(const SimdVector3* vectors,SimdVector3* supportVerticesOut,int numVectors) const
|
||||
{
|
||||
int i;
|
||||
|
||||
SimdVector3 vtx;
|
||||
SimdScalar newDot;
|
||||
|
||||
for (int j=0;j<numVectors;j++)
|
||||
{
|
||||
SimdScalar maxDot(-1e30f);
|
||||
|
||||
const SimdVector3& vec = vectors[j];
|
||||
|
||||
for (i=0;i<GetNumVertices();i++)
|
||||
{
|
||||
GetVertex(i,vtx);
|
||||
newDot = vec.dot(vtx);
|
||||
if (newDot > maxDot)
|
||||
{
|
||||
maxDot = newDot;
|
||||
supportVerticesOut[i] = vtx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PolyhedralConvexShape::CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia)
|
||||
{
|
||||
//not yet, return box inertia
|
||||
|
||||
float margin = GetMargin();
|
||||
|
||||
SimdTransform ident;
|
||||
ident.setIdentity();
|
||||
SimdVector3 aabbMin,aabbMax;
|
||||
GetAabb(ident,aabbMin,aabbMax);
|
||||
SimdVector3 halfExtents = (aabbMax-aabbMin)*0.5f;
|
||||
|
||||
SimdScalar lx=2.f*(halfExtents.x()+margin);
|
||||
SimdScalar ly=2.f*(halfExtents.y()+margin);
|
||||
SimdScalar lz=2.f*(halfExtents.z()+margin);
|
||||
const SimdScalar x2 = lx*lx;
|
||||
const SimdScalar y2 = ly*ly;
|
||||
const SimdScalar z2 = lz*lz;
|
||||
const SimdScalar scaledmass = mass * 0.08333333f;
|
||||
|
||||
inertia = scaledmass * (SimdVector3(y2+z2,x2+z2,x2+y2));
|
||||
|
||||
}
|
||||
|
||||
55
Bullet/CollisionShapes/PolyhedralConvexShape.h
Normal file
55
Bullet/CollisionShapes/PolyhedralConvexShape.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
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 BU_SHAPE
|
||||
#define BU_SHAPE
|
||||
|
||||
#include <SimdPoint3.h>
|
||||
#include <SimdMatrix3x3.h>
|
||||
#include <CollisionShapes/ConvexShape.h>
|
||||
|
||||
|
||||
///PolyhedralConvexShape is an interface class for feature based (vertex/edge/face) convex shapes.
|
||||
class PolyhedralConvexShape : public ConvexShape
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
PolyhedralConvexShape();
|
||||
|
||||
//brute force implementations
|
||||
virtual SimdVector3 LocalGetSupportingVertexWithoutMargin(const SimdVector3& vec)const;
|
||||
virtual void BatchedUnitVectorGetSupportingVertexWithoutMargin(const SimdVector3* vectors,SimdVector3* supportVerticesOut,int numVectors) const;
|
||||
|
||||
virtual void CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia);
|
||||
|
||||
|
||||
|
||||
virtual int GetNumVertices() const = 0 ;
|
||||
virtual int GetNumEdges() const = 0;
|
||||
virtual void GetEdge(int i,SimdPoint3& pa,SimdPoint3& pb) const = 0;
|
||||
virtual void GetVertex(int i,SimdPoint3& vtx) const = 0;
|
||||
virtual int GetNumPlanes() const = 0;
|
||||
virtual void GetPlane(SimdVector3& planeNormal,SimdPoint3& planeSupport,int i ) const = 0;
|
||||
// virtual int GetIndex(int i) const = 0 ;
|
||||
|
||||
virtual bool IsInside(const SimdPoint3& pt,SimdScalar tolerance) const = 0;
|
||||
|
||||
/// optional Hull is for optional Separating Axis Test Hull collision detection, see Hull.cpp
|
||||
class Hull* m_optionalHull;
|
||||
|
||||
};
|
||||
|
||||
#endif //BU_SHAPE
|
||||
193
Bullet/CollisionShapes/Simplex1to4Shape.cpp
Normal file
193
Bullet/CollisionShapes/Simplex1to4Shape.cpp
Normal file
@@ -0,0 +1,193 @@
|
||||
|
||||
/*
|
||||
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 "Simplex1to4Shape.h"
|
||||
#include "SimdMatrix3x3.h"
|
||||
|
||||
BU_Simplex1to4::BU_Simplex1to4()
|
||||
:m_numVertices(0)
|
||||
{
|
||||
}
|
||||
|
||||
BU_Simplex1to4::BU_Simplex1to4(const SimdPoint3& pt0)
|
||||
:m_numVertices(0)
|
||||
{
|
||||
AddVertex(pt0);
|
||||
}
|
||||
|
||||
BU_Simplex1to4::BU_Simplex1to4(const SimdPoint3& pt0,const SimdPoint3& pt1)
|
||||
:m_numVertices(0)
|
||||
{
|
||||
AddVertex(pt0);
|
||||
AddVertex(pt1);
|
||||
}
|
||||
|
||||
BU_Simplex1to4::BU_Simplex1to4(const SimdPoint3& pt0,const SimdPoint3& pt1,const SimdPoint3& pt2)
|
||||
:m_numVertices(0)
|
||||
{
|
||||
AddVertex(pt0);
|
||||
AddVertex(pt1);
|
||||
AddVertex(pt2);
|
||||
}
|
||||
|
||||
BU_Simplex1to4::BU_Simplex1to4(const SimdPoint3& pt0,const SimdPoint3& pt1,const SimdPoint3& pt2,const SimdPoint3& pt3)
|
||||
:m_numVertices(0)
|
||||
{
|
||||
AddVertex(pt0);
|
||||
AddVertex(pt1);
|
||||
AddVertex(pt2);
|
||||
AddVertex(pt3);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void BU_Simplex1to4::AddVertex(const SimdPoint3& pt)
|
||||
{
|
||||
m_vertices[m_numVertices++] = pt;
|
||||
}
|
||||
|
||||
|
||||
int BU_Simplex1to4::GetNumVertices() const
|
||||
{
|
||||
return m_numVertices;
|
||||
}
|
||||
|
||||
int BU_Simplex1to4::GetNumEdges() const
|
||||
{
|
||||
//euler formula, F-E+V = 2, so E = F+V-2
|
||||
|
||||
switch (m_numVertices)
|
||||
{
|
||||
case 0:
|
||||
return 0;
|
||||
case 1: return 0;
|
||||
case 2: return 1;
|
||||
case 3: return 3;
|
||||
case 4: return 6;
|
||||
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void BU_Simplex1to4::GetEdge(int i,SimdPoint3& pa,SimdPoint3& pb) const
|
||||
{
|
||||
|
||||
switch (m_numVertices)
|
||||
{
|
||||
|
||||
case 2:
|
||||
pa = m_vertices[0];
|
||||
pb = m_vertices[1];
|
||||
break;
|
||||
case 3:
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
pa = m_vertices[0];
|
||||
pb = m_vertices[1];
|
||||
break;
|
||||
case 1:
|
||||
pa = m_vertices[1];
|
||||
pb = m_vertices[2];
|
||||
break;
|
||||
case 2:
|
||||
pa = m_vertices[2];
|
||||
pb = m_vertices[0];
|
||||
break;
|
||||
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
pa = m_vertices[0];
|
||||
pb = m_vertices[1];
|
||||
break;
|
||||
case 1:
|
||||
pa = m_vertices[1];
|
||||
pb = m_vertices[2];
|
||||
break;
|
||||
case 2:
|
||||
pa = m_vertices[2];
|
||||
pb = m_vertices[0];
|
||||
break;
|
||||
case 3:
|
||||
pa = m_vertices[0];
|
||||
pb = m_vertices[3];
|
||||
break;
|
||||
case 4:
|
||||
pa = m_vertices[1];
|
||||
pb = m_vertices[3];
|
||||
break;
|
||||
case 5:
|
||||
pa = m_vertices[2];
|
||||
pb = m_vertices[3];
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void BU_Simplex1to4::GetVertex(int i,SimdPoint3& vtx) const
|
||||
{
|
||||
vtx = m_vertices[i];
|
||||
}
|
||||
|
||||
int BU_Simplex1to4::GetNumPlanes() const
|
||||
{
|
||||
switch (m_numVertices)
|
||||
{
|
||||
case 0:
|
||||
return 0;
|
||||
case 1:
|
||||
return 0;
|
||||
case 2:
|
||||
return 0;
|
||||
case 3:
|
||||
return 2;
|
||||
case 4:
|
||||
return 4;
|
||||
default:
|
||||
{
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void BU_Simplex1to4::GetPlane(SimdVector3& planeNormal,SimdPoint3& planeSupport,int i) const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int BU_Simplex1to4::GetIndex(int i) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool BU_Simplex1to4::IsInside(const SimdPoint3& pt,SimdScalar tolerance) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
75
Bullet/CollisionShapes/Simplex1to4Shape.h
Normal file
75
Bullet/CollisionShapes/Simplex1to4Shape.h
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
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 BU_SIMPLEX_1TO4_SHAPE
|
||||
#define BU_SIMPLEX_1TO4_SHAPE
|
||||
|
||||
|
||||
#include <CollisionShapes/PolyhedralConvexShape.h>
|
||||
#include "BroadphaseCollision/BroadphaseProxy.h"
|
||||
|
||||
|
||||
///BU_Simplex1to4 implements feature based and implicit simplex of up to 4 vertices (tetrahedron, triangle, line, vertex).
|
||||
class BU_Simplex1to4 : public PolyhedralConvexShape
|
||||
{
|
||||
protected:
|
||||
|
||||
int m_numVertices;
|
||||
SimdPoint3 m_vertices[4];
|
||||
|
||||
public:
|
||||
BU_Simplex1to4();
|
||||
|
||||
BU_Simplex1to4(const SimdPoint3& pt0);
|
||||
BU_Simplex1to4(const SimdPoint3& pt0,const SimdPoint3& pt1);
|
||||
BU_Simplex1to4(const SimdPoint3& pt0,const SimdPoint3& pt1,const SimdPoint3& pt2);
|
||||
BU_Simplex1to4(const SimdPoint3& pt0,const SimdPoint3& pt1,const SimdPoint3& pt2,const SimdPoint3& pt3);
|
||||
|
||||
|
||||
void Reset()
|
||||
{
|
||||
m_numVertices = 0;
|
||||
}
|
||||
|
||||
|
||||
virtual int GetShapeType() const{ return TETRAHEDRAL_SHAPE_PROXYTYPE; }
|
||||
|
||||
void AddVertex(const SimdPoint3& pt);
|
||||
|
||||
//PolyhedralConvexShape interface
|
||||
|
||||
virtual int GetNumVertices() const;
|
||||
|
||||
virtual int GetNumEdges() const;
|
||||
|
||||
virtual void GetEdge(int i,SimdPoint3& pa,SimdPoint3& pb) const;
|
||||
|
||||
virtual void GetVertex(int i,SimdPoint3& vtx) const;
|
||||
|
||||
virtual int GetNumPlanes() const;
|
||||
|
||||
virtual void GetPlane(SimdVector3& planeNormal,SimdPoint3& planeSupport,int i) const;
|
||||
|
||||
virtual int GetIndex(int i) const;
|
||||
|
||||
virtual bool IsInside(const SimdPoint3& pt,SimdScalar tolerance) const;
|
||||
|
||||
|
||||
///GetName is for debugging
|
||||
virtual char* GetName()const { return "BU_Simplex1to4";}
|
||||
|
||||
};
|
||||
|
||||
#endif //BU_SIMPLEX_1TO4_SHAPE
|
||||
74
Bullet/CollisionShapes/SphereShape.cpp
Normal file
74
Bullet/CollisionShapes/SphereShape.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
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 "SphereShape.h"
|
||||
#include "CollisionShapes/CollisionMargin.h"
|
||||
|
||||
#include "SimdQuaternion.h"
|
||||
|
||||
|
||||
SphereShape ::SphereShape (SimdScalar radius)
|
||||
: m_radius(radius)
|
||||
{
|
||||
}
|
||||
|
||||
SimdVector3 SphereShape::LocalGetSupportingVertexWithoutMargin(const SimdVector3& vec)const
|
||||
{
|
||||
return SimdVector3(0.f,0.f,0.f);
|
||||
}
|
||||
|
||||
void SphereShape::BatchedUnitVectorGetSupportingVertexWithoutMargin(const SimdVector3* vectors,SimdVector3* supportVerticesOut,int numVectors) const
|
||||
{
|
||||
for (int i=0;i<numVectors;i++)
|
||||
{
|
||||
supportVerticesOut[i].setValue(0.f,0.f,0.f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SimdVector3 SphereShape::LocalGetSupportingVertex(const SimdVector3& vec)const
|
||||
{
|
||||
SimdVector3 supVertex;
|
||||
supVertex = LocalGetSupportingVertexWithoutMargin(vec);
|
||||
|
||||
SimdVector3 vecnorm = vec;
|
||||
if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON))
|
||||
{
|
||||
vecnorm.setValue(-1.f,-1.f,-1.f);
|
||||
}
|
||||
vecnorm.normalize();
|
||||
supVertex+= GetMargin() * vecnorm;
|
||||
return supVertex;
|
||||
}
|
||||
|
||||
|
||||
//broken due to scaling
|
||||
void SphereShape::GetAabb(const SimdTransform& t,SimdVector3& aabbMin,SimdVector3& aabbMax) const
|
||||
{
|
||||
const SimdVector3& center = t.getOrigin();
|
||||
SimdVector3 extent(GetMargin(),GetMargin(),GetMargin());
|
||||
aabbMin = center - extent;
|
||||
aabbMax = center + extent;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SphereShape::CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia)
|
||||
{
|
||||
SimdScalar elem = 0.4f * mass * GetMargin()*GetMargin();
|
||||
inertia[0] = inertia[1] = inertia[2] = elem;
|
||||
|
||||
}
|
||||
|
||||
64
Bullet/CollisionShapes/SphereShape.h
Normal file
64
Bullet/CollisionShapes/SphereShape.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
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 SPHERE_MINKOWSKI_H
|
||||
#define SPHERE_MINKOWSKI_H
|
||||
|
||||
#include "ConvexShape.h"
|
||||
#include "BroadphaseCollision/BroadphaseProxy.h" // for the types
|
||||
|
||||
///SphereShape implements an implicit (getSupportingVertex) Sphere
|
||||
class SphereShape : public ConvexShape
|
||||
|
||||
{
|
||||
SimdScalar m_radius;
|
||||
|
||||
public:
|
||||
SphereShape (SimdScalar radius);
|
||||
|
||||
|
||||
virtual SimdVector3 LocalGetSupportingVertex(const SimdVector3& vec)const;
|
||||
virtual SimdVector3 LocalGetSupportingVertexWithoutMargin(const SimdVector3& vec)const;
|
||||
//notice that the vectors should be unit length
|
||||
virtual void BatchedUnitVectorGetSupportingVertexWithoutMargin(const SimdVector3* vectors,SimdVector3* supportVerticesOut,int numVectors) const;
|
||||
|
||||
|
||||
virtual void CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia);
|
||||
|
||||
virtual void GetAabb(const SimdTransform& t,SimdVector3& aabbMin,SimdVector3& aabbMax) const;
|
||||
|
||||
virtual int GetShapeType() const { return SPHERE_SHAPE_PROXYTYPE; }
|
||||
|
||||
SimdScalar GetRadius() const { return m_radius;}
|
||||
|
||||
//debugging
|
||||
virtual char* GetName()const {return "SPHERE";}
|
||||
|
||||
virtual void SetMargin(float margin)
|
||||
{
|
||||
ConvexShape::SetMargin(margin);
|
||||
}
|
||||
virtual float GetMargin() const
|
||||
{
|
||||
//to improve gjk behaviour, use radius+margin as the full margin, so never get into the penetration case
|
||||
//this means, non-uniform scaling is not supported anymore
|
||||
return m_localScaling[0] * m_radius + ConvexShape::GetMargin();
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //SPHERE_MINKOWSKI_H
|
||||
85
Bullet/CollisionShapes/StridingMeshInterface.cpp
Normal file
85
Bullet/CollisionShapes/StridingMeshInterface.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
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 "StridingMeshInterface.h"
|
||||
|
||||
StridingMeshInterface::~StridingMeshInterface()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void StridingMeshInterface::InternalProcessAllTriangles(InternalTriangleIndexCallback* callback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const
|
||||
{
|
||||
|
||||
SimdVector3 meshScaling = getScaling();
|
||||
|
||||
int numtotalphysicsverts = 0;
|
||||
int part,graphicssubparts = getNumSubParts();
|
||||
for (part=0;part<graphicssubparts ;part++)
|
||||
{
|
||||
const unsigned char * vertexbase;
|
||||
const unsigned char * indexbase;
|
||||
int indexstride;
|
||||
PHY_ScalarType type;
|
||||
PHY_ScalarType gfxindextype;
|
||||
int stride,numverts,numtriangles;
|
||||
getLockedReadOnlyVertexIndexBase(&vertexbase,numverts,type,stride,&indexbase,indexstride,numtriangles,gfxindextype,part);
|
||||
|
||||
numtotalphysicsverts+=numtriangles*3; //upper bound
|
||||
|
||||
|
||||
int gfxindex;
|
||||
SimdVector3 triangle[3];
|
||||
|
||||
for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
|
||||
{
|
||||
|
||||
int graphicsindex=0;
|
||||
|
||||
#ifdef DEBUG_TRIANGLE_MESH
|
||||
printf("triangle indices:\n");
|
||||
#endif //DEBUG_TRIANGLE_MESH
|
||||
ASSERT(gfxindextype == PHY_INTEGER);
|
||||
int* gfxbase = (int*)(indexbase+gfxindex*indexstride);
|
||||
|
||||
for (int j=2;j>=0;j--)
|
||||
{
|
||||
|
||||
graphicsindex = gfxbase[j];
|
||||
#ifdef DEBUG_TRIANGLE_MESH
|
||||
printf("%d ,",graphicsindex);
|
||||
#endif //DEBUG_TRIANGLE_MESH
|
||||
float* graphicsbase = (float*)(vertexbase+graphicsindex*stride);
|
||||
|
||||
triangle[j] = SimdVector3(
|
||||
graphicsbase[0]*meshScaling.getX(),
|
||||
graphicsbase[1]*meshScaling.getY(),
|
||||
graphicsbase[2]*meshScaling.getZ());
|
||||
#ifdef DEBUG_TRIANGLE_MESH
|
||||
printf("triangle vertices:%f,%f,%f\n",triangle[j].x(),triangle[j].y(),triangle[j].z());
|
||||
#endif //DEBUG_TRIANGLE_MESH
|
||||
}
|
||||
|
||||
|
||||
//check aabb in triangle-space, before doing this
|
||||
callback->InternalProcessTriangleIndex(triangle,part,gfxindex);
|
||||
|
||||
}
|
||||
|
||||
unLockReadOnlyVertexBase(part);
|
||||
}
|
||||
}
|
||||
|
||||
87
Bullet/CollisionShapes/StridingMeshInterface.h
Normal file
87
Bullet/CollisionShapes/StridingMeshInterface.h
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
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 STRIDING_MESHINTERFACE_H
|
||||
#define STRIDING_MESHINTERFACE_H
|
||||
|
||||
#include "SimdVector3.h"
|
||||
#include "TriangleCallback.h"
|
||||
|
||||
/// PHY_ScalarType enumerates possible scalar types.
|
||||
/// See the StridingMeshInterface for its use
|
||||
typedef enum PHY_ScalarType {
|
||||
PHY_FLOAT,
|
||||
PHY_DOUBLE,
|
||||
PHY_INTEGER,
|
||||
PHY_SHORT,
|
||||
PHY_FIXEDPOINT88
|
||||
} PHY_ScalarType;
|
||||
|
||||
/// StridingMeshInterface is the interface class for high performance access to triangle meshes
|
||||
/// It allows for sharing graphics and collision meshes. Also it provides locking/unlocking of graphics meshes that are in gpu memory.
|
||||
class StridingMeshInterface
|
||||
{
|
||||
protected:
|
||||
|
||||
SimdVector3 m_scaling;
|
||||
|
||||
public:
|
||||
StridingMeshInterface() :m_scaling(1.f,1.f,1.f)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
virtual ~StridingMeshInterface();
|
||||
|
||||
|
||||
|
||||
void InternalProcessAllTriangles(InternalTriangleIndexCallback* callback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const;
|
||||
|
||||
|
||||
/// get read and write access to a subpart of a triangle mesh
|
||||
/// this subpart has a continuous array of vertices and indices
|
||||
/// in this way the mesh can be handled as chunks of memory with striding
|
||||
/// very similar to OpenGL vertexarray support
|
||||
/// make a call to unLockVertexBase when the read and write access is finished
|
||||
virtual void getLockedVertexIndexBase(unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& stride,unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart=0)=0;
|
||||
|
||||
virtual void getLockedReadOnlyVertexIndexBase(const unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& stride,const unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart=0) const=0;
|
||||
|
||||
/// unLockVertexBase finishes the access to a subpart of the triangle mesh
|
||||
/// make a call to unLockVertexBase when the read and write access (using getLockedVertexIndexBase) is finished
|
||||
virtual void unLockVertexBase(int subpart)=0;
|
||||
|
||||
virtual void unLockReadOnlyVertexBase(int subpart) const=0;
|
||||
|
||||
|
||||
/// getNumSubParts returns the number of seperate subparts
|
||||
/// each subpart has a continuous array of vertices and indices
|
||||
virtual int getNumSubParts() const=0;
|
||||
|
||||
virtual void preallocateVertices(int numverts)=0;
|
||||
virtual void preallocateIndices(int numindices)=0;
|
||||
|
||||
const SimdVector3& getScaling() const {
|
||||
return m_scaling;
|
||||
}
|
||||
void setScaling(const SimdVector3& scaling)
|
||||
{
|
||||
m_scaling = scaling;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif //STRIDING_MESHINTERFACE_H
|
||||
28
Bullet/CollisionShapes/TriangleCallback.cpp
Normal file
28
Bullet/CollisionShapes/TriangleCallback.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
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 "TriangleCallback.h"
|
||||
|
||||
TriangleCallback::~TriangleCallback()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
InternalTriangleIndexCallback::~InternalTriangleIndexCallback()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
40
Bullet/CollisionShapes/TriangleCallback.h
Normal file
40
Bullet/CollisionShapes/TriangleCallback.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
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 TRIANGLE_CALLBACK_H
|
||||
#define TRIANGLE_CALLBACK_H
|
||||
|
||||
#include "SimdVector3.h"
|
||||
|
||||
|
||||
class TriangleCallback
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~TriangleCallback();
|
||||
virtual void ProcessTriangle(SimdVector3* triangle, int partId, int triangleIndex) = 0;
|
||||
};
|
||||
|
||||
class InternalTriangleIndexCallback
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~InternalTriangleIndexCallback();
|
||||
virtual void InternalProcessTriangleIndex(SimdVector3* triangle,int partId,int triangleIndex) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //TRIANGLE_CALLBACK_H
|
||||
53
Bullet/CollisionShapes/TriangleIndexVertexArray.cpp
Normal file
53
Bullet/CollisionShapes/TriangleIndexVertexArray.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
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 "TriangleIndexVertexArray.h"
|
||||
|
||||
TriangleIndexVertexArray::TriangleIndexVertexArray(int numTriangleIndices,int* triangleIndexBase,int triangleIndexStride,int numVertices,float* vertexBase,int vertexStride)
|
||||
:m_numTriangleIndices(numTriangleIndices),
|
||||
m_triangleIndexBase(triangleIndexBase),
|
||||
m_triangleIndexStride(triangleIndexStride),
|
||||
m_numVertices(numVertices),
|
||||
m_vertexBase(vertexBase),
|
||||
m_vertexStride(vertexStride)
|
||||
{
|
||||
}
|
||||
|
||||
void TriangleIndexVertexArray::getLockedVertexIndexBase(unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& vertexStride,unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart)
|
||||
{
|
||||
numverts = m_numVertices;
|
||||
(*vertexbase) = (unsigned char *)m_vertexBase;
|
||||
type = PHY_FLOAT;
|
||||
vertexStride = m_vertexStride;
|
||||
|
||||
numfaces = m_numTriangleIndices;
|
||||
(*indexbase) = (unsigned char *)m_triangleIndexBase;
|
||||
indexstride = m_triangleIndexStride;
|
||||
indicestype = PHY_INTEGER;
|
||||
}
|
||||
|
||||
void TriangleIndexVertexArray::getLockedReadOnlyVertexIndexBase(const unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& vertexStride,const unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart) const
|
||||
{
|
||||
numverts = m_numVertices;
|
||||
(*vertexbase) = (unsigned char *)m_vertexBase;
|
||||
type = PHY_FLOAT;
|
||||
vertexStride = m_vertexStride;
|
||||
|
||||
numfaces = m_numTriangleIndices;
|
||||
(*indexbase) = (unsigned char *)m_triangleIndexBase;
|
||||
indexstride = m_triangleIndexStride;
|
||||
indicestype = PHY_INTEGER;
|
||||
}
|
||||
|
||||
51
Bullet/CollisionShapes/TriangleIndexVertexArray.h
Normal file
51
Bullet/CollisionShapes/TriangleIndexVertexArray.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
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 "StridingMeshInterface.h"
|
||||
|
||||
|
||||
class TriangleIndexVertexArray : public StridingMeshInterface
|
||||
{
|
||||
|
||||
int m_numTriangleIndices;
|
||||
int* m_triangleIndexBase;
|
||||
int m_triangleIndexStride;
|
||||
int m_numVertices;
|
||||
float* m_vertexBase;
|
||||
int m_vertexStride;
|
||||
|
||||
public:
|
||||
|
||||
TriangleIndexVertexArray(int numTriangleIndices,int* triangleIndexBase,int triangleIndexStride,int numVertices,float* vertexBase,int vertexStride);
|
||||
|
||||
virtual void getLockedVertexIndexBase(unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& vertexStride,unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart=0);
|
||||
|
||||
virtual void getLockedReadOnlyVertexIndexBase(const unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& vertexStride,const unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart=0) const;
|
||||
|
||||
/// unLockVertexBase finishes the access to a subpart of the triangle mesh
|
||||
/// make a call to unLockVertexBase when the read and write access (using getLockedVertexIndexBase) is finished
|
||||
virtual void unLockVertexBase(int subpart) {}
|
||||
|
||||
virtual void unLockReadOnlyVertexBase(int subpart) const {}
|
||||
|
||||
/// getNumSubParts returns the number of seperate subparts
|
||||
/// each subpart has a continuous array of vertices and indices
|
||||
virtual int getNumSubParts() const { return 1;}
|
||||
|
||||
virtual void preallocateVertices(int numverts){}
|
||||
virtual void preallocateIndices(int numindices){}
|
||||
|
||||
};
|
||||
|
||||
61
Bullet/CollisionShapes/TriangleMesh.cpp
Normal file
61
Bullet/CollisionShapes/TriangleMesh.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
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 "TriangleMesh.h"
|
||||
#include <assert.h>
|
||||
|
||||
static int myindices[3] = {0,1,2};
|
||||
|
||||
TriangleMesh::TriangleMesh ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TriangleMesh::getLockedVertexIndexBase(unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& stride,unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart)
|
||||
{
|
||||
numverts = 3;
|
||||
*vertexbase = (unsigned char*)&m_triangles[subpart];
|
||||
type = PHY_FLOAT;
|
||||
stride = sizeof(SimdVector3);
|
||||
|
||||
|
||||
numfaces = 1;
|
||||
*indexbase = (unsigned char*) &myindices[0];
|
||||
indicestype = PHY_INTEGER;
|
||||
indexstride = sizeof(int);
|
||||
|
||||
}
|
||||
|
||||
void TriangleMesh::getLockedReadOnlyVertexIndexBase(const unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& stride,const unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart) const
|
||||
{
|
||||
numverts = 3;
|
||||
*vertexbase = (unsigned char*)&m_triangles[subpart];
|
||||
type = PHY_FLOAT;
|
||||
stride = sizeof(SimdVector3);
|
||||
|
||||
|
||||
numfaces = 1;
|
||||
*indexbase = (unsigned char*) &myindices[0];
|
||||
indicestype = PHY_INTEGER;
|
||||
indexstride = sizeof(int);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int TriangleMesh::getNumSubParts() const
|
||||
{
|
||||
return m_triangles.size();
|
||||
}
|
||||
73
Bullet/CollisionShapes/TriangleMesh.h
Normal file
73
Bullet/CollisionShapes/TriangleMesh.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
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 TRIANGLE_MESH_H
|
||||
#define TRIANGLE_MESH_H
|
||||
|
||||
#include "CollisionShapes/StridingMeshInterface.h"
|
||||
#include <vector>
|
||||
#include <SimdVector3.h>
|
||||
|
||||
struct MyTriangle
|
||||
{
|
||||
SimdVector3 m_vert0;
|
||||
SimdVector3 m_vert1;
|
||||
SimdVector3 m_vert2;
|
||||
};
|
||||
|
||||
///TriangleMesh provides storage for a concave triangle mesh. It can be used as data for the TriangleMeshShape.
|
||||
class TriangleMesh : public StridingMeshInterface
|
||||
{
|
||||
std::vector<MyTriangle> m_triangles;
|
||||
|
||||
|
||||
public:
|
||||
TriangleMesh ();
|
||||
|
||||
void AddTriangle(const SimdVector3& vertex0,const SimdVector3& vertex1,const SimdVector3& vertex2)
|
||||
{
|
||||
MyTriangle tri;
|
||||
tri.m_vert0 = vertex0;
|
||||
tri.m_vert1 = vertex1;
|
||||
tri.m_vert2 = vertex2;
|
||||
m_triangles.push_back(tri);
|
||||
}
|
||||
|
||||
|
||||
//StridingMeshInterface interface implementation
|
||||
|
||||
virtual void getLockedVertexIndexBase(unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& stride,unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart=0);
|
||||
|
||||
virtual void getLockedReadOnlyVertexIndexBase(const unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& stride,const unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart=0) const;
|
||||
|
||||
/// unLockVertexBase finishes the access to a subpart of the triangle mesh
|
||||
/// make a call to unLockVertexBase when the read and write access (using getLockedVertexIndexBase) is finished
|
||||
virtual void unLockVertexBase(int subpart) {}
|
||||
|
||||
virtual void unLockReadOnlyVertexBase(int subpart) const {}
|
||||
|
||||
/// getNumSubParts returns the number of seperate subparts
|
||||
/// each subpart has a continuous array of vertices and indices
|
||||
virtual int getNumSubParts() const;
|
||||
|
||||
virtual void preallocateVertices(int numverts){}
|
||||
virtual void preallocateIndices(int numindices){}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif //TRIANGLE_MESH_H
|
||||
|
||||
202
Bullet/CollisionShapes/TriangleMeshShape.cpp
Normal file
202
Bullet/CollisionShapes/TriangleMeshShape.cpp
Normal file
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
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 "TriangleMeshShape.h"
|
||||
#include "SimdVector3.h"
|
||||
#include "SimdQuaternion.h"
|
||||
#include "StridingMeshInterface.h"
|
||||
#include "AabbUtil2.h"
|
||||
#include "CollisionShapes/CollisionMargin.h"
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
TriangleMeshShape::TriangleMeshShape(StridingMeshInterface* meshInterface)
|
||||
: m_meshInterface(meshInterface),
|
||||
m_collisionMargin(CONVEX_DISTANCE_MARGIN)
|
||||
{
|
||||
RecalcLocalAabb();
|
||||
}
|
||||
|
||||
|
||||
TriangleMeshShape::~TriangleMeshShape()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void TriangleMeshShape::GetAabb(const SimdTransform& trans,SimdVector3& aabbMin,SimdVector3& aabbMax) const
|
||||
{
|
||||
|
||||
SimdVector3 localHalfExtents = 0.5f*(m_localAabbMax-m_localAabbMin);
|
||||
SimdVector3 localCenter = 0.5f*(m_localAabbMax+m_localAabbMin);
|
||||
|
||||
SimdMatrix3x3 abs_b = trans.getBasis().absolute();
|
||||
|
||||
SimdPoint3 center = trans(localCenter);
|
||||
|
||||
SimdVector3 extent = SimdVector3(abs_b[0].dot(localHalfExtents),
|
||||
abs_b[1].dot(localHalfExtents),
|
||||
abs_b[2].dot(localHalfExtents));
|
||||
extent += SimdVector3(GetMargin(),GetMargin(),GetMargin());
|
||||
|
||||
aabbMin = center - extent;
|
||||
aabbMax = center + extent;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void TriangleMeshShape::RecalcLocalAabb()
|
||||
{
|
||||
for (int i=0;i<3;i++)
|
||||
{
|
||||
SimdVector3 vec(0.f,0.f,0.f);
|
||||
vec[i] = 1.f;
|
||||
SimdVector3 tmp = LocalGetSupportingVertex(vec);
|
||||
m_localAabbMax[i] = tmp[i]+m_collisionMargin;
|
||||
vec[i] = -1.f;
|
||||
tmp = LocalGetSupportingVertex(vec);
|
||||
m_localAabbMin[i] = tmp[i]-m_collisionMargin;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
class SupportVertexCallback : public TriangleCallback
|
||||
{
|
||||
|
||||
SimdVector3 m_supportVertexLocal;
|
||||
public:
|
||||
|
||||
SimdTransform m_worldTrans;
|
||||
SimdScalar m_maxDot;
|
||||
SimdVector3 m_supportVecLocal;
|
||||
|
||||
SupportVertexCallback(const SimdVector3& supportVecWorld,const SimdTransform& trans)
|
||||
: m_supportVertexLocal(0.f,0.f,0.f), m_worldTrans(trans) ,m_maxDot(-1e30f)
|
||||
|
||||
{
|
||||
m_supportVecLocal = supportVecWorld * m_worldTrans.getBasis();
|
||||
}
|
||||
|
||||
virtual void ProcessTriangle( SimdVector3* triangle,int partId, int triangleIndex)
|
||||
{
|
||||
for (int i=0;i<3;i++)
|
||||
{
|
||||
SimdScalar dot = m_supportVecLocal.dot(triangle[i]);
|
||||
if (dot > m_maxDot)
|
||||
{
|
||||
m_maxDot = dot;
|
||||
m_supportVertexLocal = triangle[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SimdVector3 GetSupportVertexWorldSpace()
|
||||
{
|
||||
return m_worldTrans(m_supportVertexLocal);
|
||||
}
|
||||
|
||||
SimdVector3 GetSupportVertexLocal()
|
||||
{
|
||||
return m_supportVertexLocal;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
void TriangleMeshShape::setLocalScaling(const SimdVector3& scaling)
|
||||
{
|
||||
m_meshInterface->setScaling(scaling);
|
||||
RecalcLocalAabb();
|
||||
}
|
||||
|
||||
const SimdVector3& TriangleMeshShape::getLocalScaling() const
|
||||
{
|
||||
return m_meshInterface->getScaling();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//#define DEBUG_TRIANGLE_MESH
|
||||
|
||||
|
||||
void TriangleMeshShape::ProcessAllTriangles(TriangleCallback* callback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const
|
||||
{
|
||||
|
||||
struct FilteredCallback : public InternalTriangleIndexCallback
|
||||
{
|
||||
TriangleCallback* m_callback;
|
||||
SimdVector3 m_aabbMin;
|
||||
SimdVector3 m_aabbMax;
|
||||
|
||||
FilteredCallback(TriangleCallback* callback,const SimdVector3& aabbMin,const SimdVector3& aabbMax)
|
||||
:m_callback(callback),
|
||||
m_aabbMin(aabbMin),
|
||||
m_aabbMax(aabbMax)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void InternalProcessTriangleIndex(SimdVector3* triangle,int partId,int triangleIndex)
|
||||
{
|
||||
if (TestTriangleAgainstAabb2(&triangle[0],m_aabbMin,m_aabbMax))
|
||||
{
|
||||
//check aabb in triangle-space, before doing this
|
||||
m_callback->ProcessTriangle(triangle,partId,triangleIndex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
FilteredCallback filterCallback(callback,aabbMin,aabbMax);
|
||||
|
||||
m_meshInterface->InternalProcessAllTriangles(&filterCallback,aabbMin,aabbMax);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void TriangleMeshShape::CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia)
|
||||
{
|
||||
//moving concave objects not supported
|
||||
assert(0);
|
||||
inertia.setValue(0.f,0.f,0.f);
|
||||
}
|
||||
|
||||
|
||||
SimdVector3 TriangleMeshShape::LocalGetSupportingVertex(const SimdVector3& vec) const
|
||||
{
|
||||
SimdVector3 supportVertex;
|
||||
|
||||
SimdTransform ident;
|
||||
ident.setIdentity();
|
||||
|
||||
SupportVertexCallback supportCallback(vec,ident);
|
||||
|
||||
SimdVector3 aabbMax(1e30f,1e30f,1e30f);
|
||||
|
||||
ProcessAllTriangles(&supportCallback,-aabbMax,aabbMax);
|
||||
|
||||
supportVertex = supportCallback.GetSupportVertexLocal();
|
||||
|
||||
return supportVertex;
|
||||
}
|
||||
84
Bullet/CollisionShapes/TriangleMeshShape.h
Normal file
84
Bullet/CollisionShapes/TriangleMeshShape.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
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 TRIANGLE_MESH_SHAPE_H
|
||||
#define TRIANGLE_MESH_SHAPE_H
|
||||
|
||||
#include "CollisionShapes/CollisionShape.h"
|
||||
#include "BroadphaseCollision/BroadphaseProxy.h" // for the types
|
||||
|
||||
#include "StridingMeshInterface.h"
|
||||
#include "TriangleCallback.h"
|
||||
|
||||
|
||||
|
||||
///Concave triangle mesh. Uses an interface to access the triangles to allow for sharing graphics/physics triangles.
|
||||
class TriangleMeshShape : public CollisionShape
|
||||
{
|
||||
protected:
|
||||
StridingMeshInterface* m_meshInterface;
|
||||
SimdVector3 m_localAabbMin;
|
||||
SimdVector3 m_localAabbMax;
|
||||
float m_collisionMargin;
|
||||
|
||||
public:
|
||||
TriangleMeshShape(StridingMeshInterface* meshInterface);
|
||||
|
||||
virtual ~TriangleMeshShape();
|
||||
|
||||
|
||||
|
||||
virtual SimdVector3 LocalGetSupportingVertex(const SimdVector3& vec) const;
|
||||
|
||||
virtual SimdVector3 LocalGetSupportingVertexWithoutMargin(const SimdVector3& vec)const
|
||||
{
|
||||
assert(0);
|
||||
return LocalGetSupportingVertex(vec);
|
||||
}
|
||||
|
||||
void RecalcLocalAabb();
|
||||
|
||||
virtual int GetShapeType() const
|
||||
{
|
||||
return TRIANGLE_MESH_SHAPE_PROXYTYPE;
|
||||
}
|
||||
|
||||
virtual void GetAabb(const SimdTransform& t,SimdVector3& aabbMin,SimdVector3& aabbMax) const;
|
||||
|
||||
virtual void ProcessAllTriangles(TriangleCallback* callback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const;
|
||||
|
||||
virtual void CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia);
|
||||
|
||||
virtual void setLocalScaling(const SimdVector3& scaling);
|
||||
virtual const SimdVector3& getLocalScaling() const;
|
||||
|
||||
|
||||
//debugging
|
||||
virtual char* GetName()const {return "TRIANGLEMESH";}
|
||||
|
||||
|
||||
virtual float GetMargin() const {
|
||||
return m_collisionMargin;
|
||||
}
|
||||
virtual void SetMargin(float collisionMargin)
|
||||
{
|
||||
m_collisionMargin = collisionMargin;
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif //TRIANGLE_MESH_SHAPE_H
|
||||
164
Bullet/CollisionShapes/TriangleShape.h
Normal file
164
Bullet/CollisionShapes/TriangleShape.h
Normal file
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
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 OBB_TRIANGLE_MINKOWSKI_H
|
||||
#define OBB_TRIANGLE_MINKOWSKI_H
|
||||
|
||||
#include "ConvexShape.h"
|
||||
#include "CollisionShapes/BoxShape.h"
|
||||
|
||||
class TriangleShape : public PolyhedralConvexShape
|
||||
{
|
||||
|
||||
|
||||
public:
|
||||
|
||||
SimdVector3 m_vertices1[3];
|
||||
|
||||
|
||||
virtual int GetNumVertices() const
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
const SimdVector3& GetVertexPtr(int index) const
|
||||
{
|
||||
return m_vertices1[index];
|
||||
}
|
||||
virtual void GetVertex(int index,SimdVector3& vert) const
|
||||
{
|
||||
vert = m_vertices1[index];
|
||||
}
|
||||
virtual int GetShapeType() const
|
||||
{
|
||||
return TRIANGLE_SHAPE_PROXYTYPE;
|
||||
}
|
||||
|
||||
virtual int GetNumEdges() const
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
virtual void GetEdge(int i,SimdPoint3& pa,SimdPoint3& pb) const
|
||||
{
|
||||
GetVertex(i,pa);
|
||||
GetVertex((i+1)%3,pb);
|
||||
}
|
||||
|
||||
virtual void GetAabb(const SimdTransform& t,SimdVector3& aabbMin,SimdVector3& aabbMax)const
|
||||
{
|
||||
// ASSERT(0);
|
||||
GetAabbSlow(t,aabbMin,aabbMax);
|
||||
}
|
||||
|
||||
SimdVector3 LocalGetSupportingVertexWithoutMargin(const SimdVector3& dir)const
|
||||
{
|
||||
SimdVector3 dots(dir.dot(m_vertices1[0]), dir.dot(m_vertices1[1]), dir.dot(m_vertices1[2]));
|
||||
return m_vertices1[dots.maxAxis()];
|
||||
|
||||
}
|
||||
|
||||
virtual void BatchedUnitVectorGetSupportingVertexWithoutMargin(const SimdVector3* vectors,SimdVector3* supportVerticesOut,int numVectors) const
|
||||
{
|
||||
for (int i=0;i<numVectors;i++)
|
||||
{
|
||||
const SimdVector3& dir = vectors[i];
|
||||
SimdVector3 dots(dir.dot(m_vertices1[0]), dir.dot(m_vertices1[1]), dir.dot(m_vertices1[2]));
|
||||
supportVerticesOut[i] = m_vertices1[dots.maxAxis()];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
TriangleShape(const SimdVector3& p0,const SimdVector3& p1,const SimdVector3& p2)
|
||||
{
|
||||
m_vertices1[0] = p0;
|
||||
m_vertices1[1] = p1;
|
||||
m_vertices1[2] = p2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
virtual void GetPlane(SimdVector3& planeNormal,SimdPoint3& planeSupport,int i) const
|
||||
{
|
||||
GetPlaneEquation(i,planeNormal,planeSupport);
|
||||
}
|
||||
|
||||
virtual int GetNumPlanes() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void CalcNormal(SimdVector3& normal) const
|
||||
{
|
||||
normal = (m_vertices1[1]-m_vertices1[0]).cross(m_vertices1[2]-m_vertices1[0]);
|
||||
normal.normalize();
|
||||
}
|
||||
|
||||
virtual void GetPlaneEquation(int i, SimdVector3& planeNormal,SimdPoint3& planeSupport) const
|
||||
{
|
||||
CalcNormal(planeNormal);
|
||||
planeSupport = m_vertices1[0];
|
||||
}
|
||||
|
||||
virtual void CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia)
|
||||
{
|
||||
ASSERT(0);
|
||||
inertia.setValue(0.f,0.f,0.f);
|
||||
}
|
||||
|
||||
virtual bool IsInside(const SimdPoint3& pt,SimdScalar tolerance) const
|
||||
{
|
||||
SimdVector3 normal;
|
||||
CalcNormal(normal);
|
||||
//distance to plane
|
||||
SimdScalar dist = pt.dot(normal);
|
||||
SimdScalar planeconst = m_vertices1[0].dot(normal);
|
||||
dist -= planeconst;
|
||||
if (dist >= -tolerance && dist <= tolerance)
|
||||
{
|
||||
//inside check on edge-planes
|
||||
int i;
|
||||
for (i=0;i<3;i++)
|
||||
{
|
||||
SimdPoint3 pa,pb;
|
||||
GetEdge(i,pa,pb);
|
||||
SimdVector3 edge = pb-pa;
|
||||
SimdVector3 edgeNormal = edge.cross(normal);
|
||||
edgeNormal.normalize();
|
||||
SimdScalar dist = pt.dot( edgeNormal);
|
||||
SimdScalar edgeConst = pa.dot(edgeNormal);
|
||||
dist -= edgeConst;
|
||||
if (dist < -tolerance)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
//debugging
|
||||
virtual char* GetName()const
|
||||
{
|
||||
return "Triangle";
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif //OBB_TRIANGLE_MINKOWSKI_H
|
||||
|
||||
Reference in New Issue
Block a user