First stage in refactoring Bullet: moved Bullet Collision and Dynamics and LinearMath into src folder, and all files in Collision Detection and Dynamics have bt prefix.
Made all buildsystems to work again (jam, msvc, cmake)
This commit is contained in:
58
src/BulletCollision/CollisionShapes/btBoxShape.cpp
Normal file
58
src/BulletCollision/CollisionShapes/btBoxShape.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 "btBoxShape.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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
263
src/BulletCollision/CollisionShapes/btBoxShape.h
Normal file
263
src/BulletCollision/CollisionShapes/btBoxShape.h
Normal file
@@ -0,0 +1,263 @@
|
||||
/*
|
||||
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 "btPolyhedralConvexShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btCollisionMargin.h"
|
||||
#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
|
||||
#include "LinearMath/SimdPoint3.h"
|
||||
#include "LinearMath/SimdMinMax.h"
|
||||
|
||||
///BoxShape implements both a feature based (vertex/edge/plane) and implicit (getSupportingVertex) Box
|
||||
class BoxShape: public PolyhedralConvexShape
|
||||
{
|
||||
|
||||
SimdVector3 m_boxHalfExtents1;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
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 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());
|
||||
|
||||
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
src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp
Normal file
138
src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.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 "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btOptimizedBvh.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
src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h
Normal file
58
src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.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 "BulletCollision/CollisionShapes/btTriangleMeshShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btOptimizedBvh.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
src/BulletCollision/CollisionShapes/btCollisionMargin.h
Normal file
26
src/BulletCollision/CollisionShapes/btCollisionMargin.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
src/BulletCollision/CollisionShapes/btCollisionShape.cpp
Normal file
75
src/BulletCollision/CollisionShapes/btCollisionShape.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 "BulletCollision/CollisionShapes/btCollisionShape.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;
|
||||
}
|
||||
85
src/BulletCollision/CollisionShapes/btCollisionShape.h
Normal file
85
src/BulletCollision/CollisionShapes/btCollisionShape.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 COLLISION_SHAPE_H
|
||||
#define COLLISION_SHAPE_H
|
||||
|
||||
#include "LinearMath/SimdTransform.h"
|
||||
#include "LinearMath/SimdVector3.h"
|
||||
#include <LinearMath/SimdMatrix3x3.h>
|
||||
#include "LinearMath/SimdPoint3.h"
|
||||
#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.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);
|
||||
|
||||
inline bool IsPolyhedral() const
|
||||
{
|
||||
return BroadphaseProxy::IsPolyhedral(GetShapeType());
|
||||
}
|
||||
|
||||
inline bool IsConvex() const
|
||||
{
|
||||
return BroadphaseProxy::IsConvex(GetShapeType());
|
||||
}
|
||||
inline bool IsConcave() const
|
||||
{
|
||||
return BroadphaseProxy::IsConcave(GetShapeType());
|
||||
}
|
||||
inline bool IsCompound() const
|
||||
{
|
||||
return BroadphaseProxy::IsCompound(GetShapeType());
|
||||
}
|
||||
|
||||
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
src/BulletCollision/CollisionShapes/btCompoundShape.cpp
Normal file
100
src/BulletCollision/CollisionShapes/btCompoundShape.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 "btCompoundShape.h"
|
||||
|
||||
|
||||
#include "btCollisionShape.h"
|
||||
|
||||
|
||||
CompoundShape::CompoundShape()
|
||||
:m_localAabbMin(1e30f,1e30f,1e30f),
|
||||
m_localAabbMax(-1e30f,-1e30f,-1e30f),
|
||||
m_aabbTree(0),
|
||||
m_collisionMargin(0.f),
|
||||
m_localScaling(1.f,1.f,1.f)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CompoundShape::~CompoundShape()
|
||||
{
|
||||
}
|
||||
|
||||
void CompoundShape::AddChildShape(const SimdTransform& localTransform,CollisionShape* shape)
|
||||
{
|
||||
m_childTransforms.push_back(localTransform);
|
||||
m_childShapes.push_back(shape);
|
||||
|
||||
//extend the local aabbMin/aabbMax
|
||||
SimdVector3 localAabbMin,localAabbMax;
|
||||
shape->GetAabb(localTransform,localAabbMin,localAabbMax);
|
||||
for (int i=0;i<3;i++)
|
||||
{
|
||||
if (m_localAabbMin[i] > localAabbMin[i])
|
||||
{
|
||||
m_localAabbMin[i] = localAabbMin[i];
|
||||
}
|
||||
if (m_localAabbMax[i] < localAabbMax[i])
|
||||
{
|
||||
m_localAabbMax[i] = localAabbMax[i];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
///GetAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
|
||||
void CompoundShape::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 CompoundShape::CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia)
|
||||
{
|
||||
//approximation: take the inertia from the aabb for now
|
||||
SimdTransform ident;
|
||||
ident.setIdentity();
|
||||
SimdVector3 aabbMin,aabbMax;
|
||||
GetAabb(ident,aabbMin,aabbMax);
|
||||
|
||||
SimdVector3 halfExtents = (aabbMax-aabbMin)*0.5f;
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
117
src/BulletCollision/CollisionShapes/btCompoundShape.h
Normal file
117
src/BulletCollision/CollisionShapes/btCompoundShape.h
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
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 COMPOUND_SHAPE_H
|
||||
#define COMPOUND_SHAPE_H
|
||||
|
||||
#include "btCollisionShape.h"
|
||||
|
||||
#include "LinearMath/SimdVector3.h"
|
||||
#include "LinearMath/SimdTransform.h"
|
||||
#include "LinearMath/SimdMatrix3x3.h"
|
||||
#include <vector>
|
||||
#include "BulletCollision/CollisionShapes/btCollisionMargin.h"
|
||||
|
||||
class OptimizedBvh;
|
||||
|
||||
/// CompoundShape allows to store multiple other CollisionShapes
|
||||
/// This allows for concave collision objects. This is more general then the Static Concave TriangleMeshShape.
|
||||
class CompoundShape : public CollisionShape
|
||||
{
|
||||
std::vector<SimdTransform> m_childTransforms;
|
||||
std::vector<CollisionShape*> m_childShapes;
|
||||
SimdVector3 m_localAabbMin;
|
||||
SimdVector3 m_localAabbMax;
|
||||
|
||||
OptimizedBvh* m_aabbTree;
|
||||
|
||||
public:
|
||||
CompoundShape();
|
||||
|
||||
virtual ~CompoundShape();
|
||||
|
||||
void AddChildShape(const SimdTransform& localTransform,CollisionShape* shape);
|
||||
|
||||
int GetNumChildShapes() const
|
||||
{
|
||||
return m_childShapes.size();
|
||||
}
|
||||
|
||||
CollisionShape* GetChildShape(int index)
|
||||
{
|
||||
return m_childShapes[index];
|
||||
}
|
||||
const CollisionShape* GetChildShape(int index) const
|
||||
{
|
||||
return m_childShapes[index];
|
||||
}
|
||||
|
||||
SimdTransform GetChildTransform(int index)
|
||||
{
|
||||
return m_childTransforms[index];
|
||||
}
|
||||
const SimdTransform GetChildTransform(int index) const
|
||||
{
|
||||
return m_childTransforms[index];
|
||||
}
|
||||
|
||||
///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 COMPOUND_SHAPE_PROXYTYPE;}
|
||||
|
||||
virtual void SetMargin(float margin)
|
||||
{
|
||||
m_collisionMargin = margin;
|
||||
}
|
||||
virtual float GetMargin() const
|
||||
{
|
||||
return m_collisionMargin;
|
||||
}
|
||||
virtual char* GetName()const
|
||||
{
|
||||
return "Compound";
|
||||
}
|
||||
|
||||
//this is optional, but should make collision queries faster, by culling non-overlapping nodes
|
||||
void CreateAabbTreeFromChildren();
|
||||
|
||||
const OptimizedBvh* GetAabbTree() const
|
||||
{
|
||||
return m_aabbTree;
|
||||
}
|
||||
|
||||
private:
|
||||
SimdScalar m_collisionMargin;
|
||||
protected:
|
||||
SimdVector3 m_localScaling;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //COMPOUND_SHAPE_H
|
||||
28
src/BulletCollision/CollisionShapes/btConcaveShape.cpp
Normal file
28
src/BulletCollision/CollisionShapes/btConcaveShape.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 "btConcaveShape.h"
|
||||
|
||||
ConcaveShape::ConcaveShape() : m_collisionMargin(0.f)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ConcaveShape::~ConcaveShape()
|
||||
{
|
||||
|
||||
}
|
||||
51
src/BulletCollision/CollisionShapes/btConcaveShape.h
Normal file
51
src/BulletCollision/CollisionShapes/btConcaveShape.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.
|
||||
*/
|
||||
|
||||
#ifndef CONCAVE_SHAPE_H
|
||||
#define CONCAVE_SHAPE_H
|
||||
|
||||
#include "BulletCollision/CollisionShapes/btCollisionShape.h"
|
||||
#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
|
||||
|
||||
#include "btTriangleCallback.h"
|
||||
|
||||
|
||||
///Concave shape proves an interface concave shapes that can produce triangles that overlapping a given AABB.
|
||||
///Static triangle mesh, infinite plane, height field/landscapes are example that implement this interface.
|
||||
class ConcaveShape : public CollisionShape
|
||||
{
|
||||
protected:
|
||||
float m_collisionMargin;
|
||||
|
||||
public:
|
||||
ConcaveShape();
|
||||
|
||||
virtual ~ConcaveShape();
|
||||
|
||||
virtual void ProcessAllTriangles(TriangleCallback* callback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const = 0;
|
||||
|
||||
virtual float GetMargin() const {
|
||||
return m_collisionMargin;
|
||||
}
|
||||
virtual void SetMargin(float collisionMargin)
|
||||
{
|
||||
m_collisionMargin = collisionMargin;
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif //CONCAVE_SHAPE_H
|
||||
100
src/BulletCollision/CollisionShapes/btConeShape.cpp
Normal file
100
src/BulletCollision/CollisionShapes/btConeShape.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 "btConeShape.h"
|
||||
#include "LinearMath/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
src/BulletCollision/CollisionShapes/btConeShape.h
Normal file
83
src/BulletCollision/CollisionShapes/btConeShape.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 "btConvexShape.h"
|
||||
#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.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
|
||||
|
||||
165
src/BulletCollision/CollisionShapes/btConvexHullShape.cpp
Normal file
165
src/BulletCollision/CollisionShapes/btConvexHullShape.cpp
Normal file
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
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 "btConvexHullShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btCollisionMargin.h"
|
||||
|
||||
#include "LinearMath/SimdQuaternion.h"
|
||||
|
||||
|
||||
ConvexHullShape ::ConvexHullShape (SimdPoint3* points,int numPoints,int stride)
|
||||
{
|
||||
m_points.resize(numPoints);
|
||||
unsigned char* pointsBaseAddress = (unsigned char*)points;
|
||||
|
||||
for (int i=0;i<numPoints;i++)
|
||||
{
|
||||
SimdPoint3* point = (SimdPoint3*)(pointsBaseAddress + i*stride);
|
||||
m_points[i] = point[0];
|
||||
}
|
||||
}
|
||||
|
||||
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
src/BulletCollision/CollisionShapes/btConvexHullShape.h
Normal file
64
src/BulletCollision/CollisionShapes/btConvexHullShape.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 "btPolyhedralConvexShape.h"
|
||||
#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.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, int stride=sizeof(SimdPoint3));
|
||||
|
||||
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
|
||||
|
||||
69
src/BulletCollision/CollisionShapes/btConvexShape.cpp
Normal file
69
src/BulletCollision/CollisionShapes/btConvexShape.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
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 "btConvexShape.h"
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
83
src/BulletCollision/CollisionShapes/btConvexShape.h
Normal file
83
src/BulletCollision/CollisionShapes/btConvexShape.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 CONVEX_SHAPE_INTERFACE1
|
||||
#define CONVEX_SHAPE_INTERFACE1
|
||||
|
||||
#include "btCollisionShape.h"
|
||||
|
||||
#include "LinearMath/SimdVector3.h"
|
||||
#include "LinearMath/SimdTransform.h"
|
||||
#include "LinearMath/SimdMatrix3x3.h"
|
||||
#include <vector>
|
||||
#include "BulletCollision/CollisionShapes/btCollisionMargin.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 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
|
||||
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
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 "btConvexTriangleMeshShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btCollisionMargin.h"
|
||||
|
||||
#include "LinearMath/SimdQuaternion.h"
|
||||
#include "BulletCollision/CollisionShapes/btStridingMeshInterface.h"
|
||||
|
||||
|
||||
ConvexTriangleMeshShape ::ConvexTriangleMeshShape (StridingMeshInterface* meshInterface)
|
||||
:m_stridingMesh(meshInterface)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
///It's not nice to have all this virtual function overhead, so perhaps we can also gather the points once
|
||||
///but then we are duplicating
|
||||
class LocalSupportVertexCallback: public InternalTriangleIndexCallback
|
||||
{
|
||||
|
||||
SimdVector3 m_supportVertexLocal;
|
||||
public:
|
||||
|
||||
SimdScalar m_maxDot;
|
||||
SimdVector3 m_supportVecLocal;
|
||||
|
||||
LocalSupportVertexCallback(const SimdVector3& supportVecLocal)
|
||||
: m_supportVertexLocal(0.f,0.f,0.f),
|
||||
m_maxDot(-1e30f),
|
||||
m_supportVecLocal(supportVecLocal)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void InternalProcessTriangleIndex(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 GetSupportVertexLocal()
|
||||
{
|
||||
return m_supportVertexLocal;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
SimdVector3 ConvexTriangleMeshShape::LocalGetSupportingVertexWithoutMargin(const SimdVector3& vec0)const
|
||||
{
|
||||
SimdVector3 supVec(0.f,0.f,0.f);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
LocalSupportVertexCallback supportCallback(vec);
|
||||
SimdVector3 aabbMax(1e30f,1e30f,1e30f);
|
||||
m_stridingMesh->InternalProcessAllTriangles(&supportCallback,-aabbMax,aabbMax);
|
||||
supVec = supportCallback.GetSupportVertexLocal();
|
||||
|
||||
return supVec;
|
||||
}
|
||||
|
||||
void ConvexTriangleMeshShape::BatchedUnitVectorGetSupportingVertexWithoutMargin(const SimdVector3* vectors,SimdVector3* supportVerticesOut,int numVectors) const
|
||||
{
|
||||
//use 'w' component of supportVerticesOut?
|
||||
{
|
||||
for (int i=0;i<numVectors;i++)
|
||||
{
|
||||
supportVerticesOut[i][3] = -1e30f;
|
||||
}
|
||||
}
|
||||
|
||||
//todo: could do the batch inside the callback!
|
||||
|
||||
|
||||
for (int j=0;j<numVectors;j++)
|
||||
{
|
||||
const SimdVector3& vec = vectors[j];
|
||||
LocalSupportVertexCallback supportCallback(vec);
|
||||
SimdVector3 aabbMax(1e30f,1e30f,1e30f);
|
||||
m_stridingMesh->InternalProcessAllTriangles(&supportCallback,-aabbMax,aabbMax);
|
||||
supportVerticesOut[j] = supportCallback.GetSupportVertexLocal();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
SimdVector3 ConvexTriangleMeshShape::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 ConvexTriangleMeshShape with the Raytracer Demo
|
||||
int ConvexTriangleMeshShape::GetNumVertices() const
|
||||
{
|
||||
//cache this?
|
||||
assert(0);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int ConvexTriangleMeshShape::GetNumEdges() const
|
||||
{
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ConvexTriangleMeshShape::GetEdge(int i,SimdPoint3& pa,SimdPoint3& pb) const
|
||||
{
|
||||
assert(0);
|
||||
}
|
||||
|
||||
void ConvexTriangleMeshShape::GetVertex(int i,SimdPoint3& vtx) const
|
||||
{
|
||||
assert(0);
|
||||
}
|
||||
|
||||
int ConvexTriangleMeshShape::GetNumPlanes() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ConvexTriangleMeshShape::GetPlane(SimdVector3& planeNormal,SimdPoint3& planeSupport,int i ) const
|
||||
{
|
||||
assert(0);
|
||||
}
|
||||
|
||||
//not yet
|
||||
bool ConvexTriangleMeshShape::IsInside(const SimdPoint3& pt,SimdScalar tolerance) const
|
||||
{
|
||||
assert(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ConvexTriangleMeshShape::setLocalScaling(const SimdVector3& scaling)
|
||||
{
|
||||
m_stridingMesh->setScaling(scaling);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
#ifndef CONVEX_TRIANGLEMESH_SHAPE_H
|
||||
#define CONVEX_TRIANGLEMESH_SHAPE_H
|
||||
|
||||
|
||||
#include "btPolyhedralConvexShape.h"
|
||||
#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
|
||||
|
||||
#include <vector>
|
||||
|
||||
/// ConvexTriangleMeshShape is a convex hull of a triangle mesh. If you just have a point cloud, you can use ConvexHullShape instead.
|
||||
/// It uses the StridingMeshInterface instead of a point cloud. This can avoid the duplication of the triangle mesh data.
|
||||
class ConvexTriangleMeshShape : public PolyhedralConvexShape
|
||||
{
|
||||
|
||||
class StridingMeshInterface* m_stridingMesh;
|
||||
|
||||
public:
|
||||
ConvexTriangleMeshShape(StridingMeshInterface* meshInterface);
|
||||
|
||||
class StridingMeshInterface* GetStridingMesh()
|
||||
{
|
||||
return m_stridingMesh;
|
||||
}
|
||||
|
||||
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_TRIANGLEMESH_SHAPE_PROXYTYPE; }
|
||||
|
||||
//debugging
|
||||
virtual char* GetName()const {return "ConvexTrimesh";}
|
||||
|
||||
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;
|
||||
|
||||
|
||||
void setLocalScaling(const SimdVector3& scaling);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //CONVEX_TRIANGLEMESH_SHAPE_H
|
||||
|
||||
|
||||
196
src/BulletCollision/CollisionShapes/btCylinderShape.cpp
Normal file
196
src/BulletCollision/CollisionShapes/btCylinderShape.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 "btCylinderShape.h"
|
||||
#include "LinearMath/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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
140
src/BulletCollision/CollisionShapes/btCylinderShape.h
Normal file
140
src/BulletCollision/CollisionShapes/btCylinderShape.h
Normal file
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
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 "btBoxShape.h"
|
||||
#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
|
||||
#include "LinearMath/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;
|
||||
}
|
||||
|
||||
virtual int GetUpAxis() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
virtual float GetRadius() const
|
||||
{
|
||||
return GetHalfExtents().getX();
|
||||
}
|
||||
|
||||
//debugging
|
||||
virtual char* GetName()const
|
||||
{
|
||||
return "CylinderY";
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
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;
|
||||
virtual int GetUpAxis() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
//debugging
|
||||
virtual char* GetName()const
|
||||
{
|
||||
return "CylinderX";
|
||||
}
|
||||
|
||||
virtual float GetRadius() const
|
||||
{
|
||||
return GetHalfExtents().getY();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
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;
|
||||
|
||||
virtual int GetUpAxis() const
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
//debugging
|
||||
virtual char* GetName()const
|
||||
{
|
||||
return "CylinderZ";
|
||||
}
|
||||
|
||||
virtual float GetRadius() const
|
||||
{
|
||||
return GetHalfExtents().getX();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //CYLINDER_MINKOWSKI_H
|
||||
|
||||
49
src/BulletCollision/CollisionShapes/btEmptyShape.cpp
Normal file
49
src/BulletCollision/CollisionShapes/btEmptyShape.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 "btEmptyShape.h"
|
||||
|
||||
|
||||
#include "btCollisionShape.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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
71
src/BulletCollision/CollisionShapes/btEmptyShape.h
Normal file
71
src/BulletCollision/CollisionShapes/btEmptyShape.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
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 "btConcaveShape.h"
|
||||
|
||||
#include "LinearMath/SimdVector3.h"
|
||||
#include "LinearMath/SimdTransform.h"
|
||||
#include "LinearMath/SimdMatrix3x3.h"
|
||||
#include <vector>
|
||||
#include "BulletCollision/CollisionShapes/btCollisionMargin.h"
|
||||
|
||||
|
||||
|
||||
|
||||
/// EmptyShape is a collision shape without actual collision detection.
|
||||
///It can be replaced by another shape during runtime
|
||||
class EmptyShape : public ConcaveShape
|
||||
{
|
||||
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 char* GetName()const
|
||||
{
|
||||
return "Empty";
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
SimdVector3 m_localScaling;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //EMPTY_SHAPE_H
|
||||
56
src/BulletCollision/CollisionShapes/btMinkowskiSumShape.cpp
Normal file
56
src/BulletCollision/CollisionShapes/btMinkowskiSumShape.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 "btMinkowskiSumShape.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
src/BulletCollision/CollisionShapes/btMinkowskiSumShape.h
Normal file
62
src/BulletCollision/CollisionShapes/btMinkowskiSumShape.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 "btConvexShape.h"
|
||||
#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.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
src/BulletCollision/CollisionShapes/btMultiSphereShape.cpp
Normal file
148
src/BulletCollision/CollisionShapes/btMultiSphereShape.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 "btMultiSphereShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btCollisionMargin.h"
|
||||
#include "LinearMath/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
src/BulletCollision/CollisionShapes/btMultiSphereShape.h
Normal file
62
src/BulletCollision/CollisionShapes/btMultiSphereShape.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 "btConvexShape.h"
|
||||
#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.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
|
||||
274
src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp
Normal file
274
src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp
Normal file
@@ -0,0 +1,274 @@
|
||||
/*
|
||||
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 "btOptimizedBvh.h"
|
||||
#include "btStridingMeshInterface.h"
|
||||
#include "LinearMath/GenAabbUtil2.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;
|
||||
}
|
||||
|
||||
OptimizedBvh::~OptimizedBvh()
|
||||
{
|
||||
if (m_contiguousNodes)
|
||||
delete m_contiguousNodes;
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
//either choose recursive traversal (WalkTree) or stackless (WalkStacklessTree)
|
||||
|
||||
//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
src/BulletCollision/CollisionShapes/btOptimizedBvh.h
Normal file
100
src/BulletCollision/CollisionShapes/btOptimizedBvh.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 "LinearMath/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
|
||||
|
||||
118
src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp
Normal file
118
src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp
Normal file
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
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 <BulletCollision/CollisionShapes/btPolyhedralConvexShape.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 i=0;i<numVectors;i++)
|
||||
{
|
||||
supportVerticesOut[i][3] = -1e30f;
|
||||
}
|
||||
|
||||
for (int j=0;j<numVectors;j++)
|
||||
{
|
||||
|
||||
const SimdVector3& vec = vectors[j];
|
||||
|
||||
for (i=0;i<GetNumVertices();i++)
|
||||
{
|
||||
GetVertex(i,vtx);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
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));
|
||||
|
||||
}
|
||||
|
||||
@@ -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 <LinearMath/SimdPoint3.h>
|
||||
#include <LinearMath/SimdMatrix3x3.h>
|
||||
#include <BulletCollision/CollisionShapes/btConvexShape.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
|
||||
74
src/BulletCollision/CollisionShapes/btSphereShape.cpp
Normal file
74
src/BulletCollision/CollisionShapes/btSphereShape.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 "btSphereShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btCollisionMargin.h"
|
||||
|
||||
#include "LinearMath/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
src/BulletCollision/CollisionShapes/btSphereShape.h
Normal file
64
src/BulletCollision/CollisionShapes/btSphereShape.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 "btConvexShape.h"
|
||||
#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.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
|
||||
100
src/BulletCollision/CollisionShapes/btStaticPlaneShape.cpp
Normal file
100
src/BulletCollision/CollisionShapes/btStaticPlaneShape.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 "btStaticPlaneShape.h"
|
||||
|
||||
#include "LinearMath/SimdTransformUtil.h"
|
||||
|
||||
|
||||
StaticPlaneShape::StaticPlaneShape(const SimdVector3& planeNormal,SimdScalar planeConstant)
|
||||
:m_planeNormal(planeNormal),
|
||||
m_planeConstant(planeConstant),
|
||||
m_localScaling(0.f,0.f,0.f)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
StaticPlaneShape::~StaticPlaneShape()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
void StaticPlaneShape::GetAabb(const SimdTransform& t,SimdVector3& aabbMin,SimdVector3& aabbMax) const
|
||||
{
|
||||
SimdVector3 infvec (1e30f,1e30f,1e30f);
|
||||
|
||||
SimdVector3 center = m_planeNormal*m_planeConstant;
|
||||
aabbMin = center + infvec*m_planeNormal;
|
||||
aabbMax = aabbMin;
|
||||
aabbMin.setMin(center - infvec*m_planeNormal);
|
||||
aabbMax.setMax(center - infvec*m_planeNormal);
|
||||
|
||||
aabbMin.setValue(-1e30f,-1e30f,-1e30f);
|
||||
aabbMax.setValue(1e30f,1e30f,1e30f);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void StaticPlaneShape::ProcessAllTriangles(TriangleCallback* callback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const
|
||||
{
|
||||
|
||||
SimdVector3 halfExtents = (aabbMax - aabbMin) * 0.5f;
|
||||
SimdScalar radius = halfExtents.length();
|
||||
SimdVector3 center = (aabbMax + aabbMin) * 0.5f;
|
||||
|
||||
//this is where the triangles are generated, given AABB and plane equation (normal/constant)
|
||||
|
||||
SimdVector3 tangentDir0,tangentDir1;
|
||||
|
||||
//tangentDir0/tangentDir1 can be precalculated
|
||||
SimdPlaneSpace1(m_planeNormal,tangentDir0,tangentDir1);
|
||||
|
||||
SimdVector3 supVertex0,supVertex1;
|
||||
|
||||
SimdVector3 projectedCenter = center - (m_planeNormal.dot(center) - m_planeConstant)*m_planeNormal;
|
||||
|
||||
SimdVector3 triangle[3];
|
||||
triangle[0] = projectedCenter + tangentDir0*radius + tangentDir1*radius;
|
||||
triangle[1] = projectedCenter + tangentDir0*radius - tangentDir1*radius;
|
||||
triangle[2] = projectedCenter - tangentDir0*radius - tangentDir1*radius;
|
||||
|
||||
callback->ProcessTriangle(triangle,0,0);
|
||||
|
||||
triangle[0] = projectedCenter - tangentDir0*radius - tangentDir1*radius;
|
||||
triangle[1] = projectedCenter - tangentDir0*radius + tangentDir1*radius;
|
||||
triangle[2] = projectedCenter + tangentDir0*radius + tangentDir1*radius;
|
||||
|
||||
callback->ProcessTriangle(triangle,0,1);
|
||||
|
||||
}
|
||||
|
||||
void StaticPlaneShape::CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia)
|
||||
{
|
||||
//moving concave objects not supported
|
||||
|
||||
inertia.setValue(0.f,0.f,0.f);
|
||||
}
|
||||
|
||||
void StaticPlaneShape::setLocalScaling(const SimdVector3& scaling)
|
||||
{
|
||||
m_localScaling = scaling;
|
||||
}
|
||||
const SimdVector3& StaticPlaneShape::getLocalScaling() const
|
||||
{
|
||||
return m_localScaling;
|
||||
}
|
||||
61
src/BulletCollision/CollisionShapes/btStaticPlaneShape.h
Normal file
61
src/BulletCollision/CollisionShapes/btStaticPlaneShape.h
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.
|
||||
*/
|
||||
|
||||
#ifndef STATIC_PLANE_SHAPE_H
|
||||
#define STATIC_PLANE_SHAPE_H
|
||||
|
||||
#include "BulletCollision/CollisionShapes/btConcaveShape.h"
|
||||
|
||||
|
||||
///StaticPlaneShape simulates an 'infinite' plane by dynamically reporting triangles approximated by intersection of the plane with the AABB.
|
||||
///Assumed is that the other objects is not also infinite, so a reasonable sized AABB.
|
||||
class StaticPlaneShape : public ConcaveShape
|
||||
{
|
||||
protected:
|
||||
SimdVector3 m_localAabbMin;
|
||||
SimdVector3 m_localAabbMax;
|
||||
|
||||
SimdVector3 m_planeNormal;
|
||||
SimdScalar m_planeConstant;
|
||||
SimdVector3 m_localScaling;
|
||||
|
||||
public:
|
||||
StaticPlaneShape(const SimdVector3& planeNormal,SimdScalar planeConstant);
|
||||
|
||||
virtual ~StaticPlaneShape();
|
||||
|
||||
|
||||
virtual int GetShapeType() const
|
||||
{
|
||||
return STATIC_PLANE_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 "STATICPLANE";}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif //STATIC_PLANE_SHAPE_H
|
||||
@@ -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 "btStridingMeshInterface.h"
|
||||
|
||||
StridingMeshInterface::~StridingMeshInterface()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void StridingMeshInterface::InternalProcessAllTriangles(InternalTriangleIndexCallback* callback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const
|
||||
{
|
||||
int numtotalphysicsverts = 0;
|
||||
int part,graphicssubparts = getNumSubParts();
|
||||
const unsigned char * vertexbase;
|
||||
const unsigned char * indexbase;
|
||||
int indexstride;
|
||||
PHY_ScalarType type;
|
||||
PHY_ScalarType gfxindextype;
|
||||
int stride,numverts,numtriangles;
|
||||
int gfxindex;
|
||||
SimdVector3 triangle[3];
|
||||
float* graphicsbase;
|
||||
|
||||
SimdVector3 meshScaling = getScaling();
|
||||
|
||||
///if the number of parts is big, the performance might drop due to the innerloop switch on indextype
|
||||
for (part=0;part<graphicssubparts ;part++)
|
||||
{
|
||||
getLockedReadOnlyVertexIndexBase(&vertexbase,numverts,type,stride,&indexbase,indexstride,numtriangles,gfxindextype,part);
|
||||
numtotalphysicsverts+=numtriangles*3; //upper bound
|
||||
|
||||
switch (gfxindextype)
|
||||
{
|
||||
case PHY_INTEGER:
|
||||
{
|
||||
for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
|
||||
{
|
||||
int* tri_indices= (int*)(indexbase+gfxindex*indexstride);
|
||||
graphicsbase = (float*)(vertexbase+tri_indices[0]*stride);
|
||||
triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());
|
||||
graphicsbase = (float*)(vertexbase+tri_indices[1]*stride);
|
||||
triangle[1].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ());
|
||||
graphicsbase = (float*)(vertexbase+tri_indices[2]*stride);
|
||||
triangle[2].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ());
|
||||
callback->InternalProcessTriangleIndex(triangle,part,gfxindex);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PHY_SHORT:
|
||||
{
|
||||
for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
|
||||
{
|
||||
short int* tri_indices= (short int*)(indexbase+gfxindex*indexstride);
|
||||
graphicsbase = (float*)(vertexbase+tri_indices[0]*stride);
|
||||
triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());
|
||||
graphicsbase = (float*)(vertexbase+tri_indices[1]*stride);
|
||||
triangle[1].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ());
|
||||
graphicsbase = (float*)(vertexbase+tri_indices[2]*stride);
|
||||
triangle[2].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ());
|
||||
callback->InternalProcessTriangleIndex(triangle,part,gfxindex);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ASSERT((gfxindextype == PHY_INTEGER) || (gfxindextype == PHY_SHORT));
|
||||
}
|
||||
|
||||
unLockReadOnlyVertexBase(part);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 "LinearMath/SimdVector3.h"
|
||||
#include "btTriangleCallback.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
|
||||
193
src/BulletCollision/CollisionShapes/btTetrahedronShape.cpp
Normal file
193
src/BulletCollision/CollisionShapes/btTetrahedronShape.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 "btTetrahedronShape.h"
|
||||
#include "LinearMath/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
src/BulletCollision/CollisionShapes/btTetrahedronShape.h
Normal file
75
src/BulletCollision/CollisionShapes/btTetrahedronShape.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 <BulletCollision/CollisionShapes/btPolyhedralConvexShape.h>
|
||||
#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.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
|
||||
28
src/BulletCollision/CollisionShapes/btTriangleCallback.cpp
Normal file
28
src/BulletCollision/CollisionShapes/btTriangleCallback.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 "btTriangleCallback.h"
|
||||
|
||||
TriangleCallback::~TriangleCallback()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
InternalTriangleIndexCallback::~InternalTriangleIndexCallback()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
40
src/BulletCollision/CollisionShapes/btTriangleCallback.h
Normal file
40
src/BulletCollision/CollisionShapes/btTriangleCallback.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 "LinearMath/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
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
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 "btTriangleIndexVertexArray.h"
|
||||
|
||||
TriangleIndexVertexArray::TriangleIndexVertexArray(int numTriangles,int* triangleIndexBase,int triangleIndexStride,int numVertices,float* vertexBase,int vertexStride)
|
||||
{
|
||||
IndexedMesh mesh;
|
||||
|
||||
mesh.m_numTriangles = numTriangles;
|
||||
mesh.m_triangleIndexBase = triangleIndexBase;
|
||||
mesh.m_triangleIndexStride = triangleIndexStride;
|
||||
mesh.m_numVertices = numVertices;
|
||||
mesh.m_vertexBase = vertexBase;
|
||||
mesh.m_vertexStride = vertexStride;
|
||||
|
||||
AddIndexedMesh(mesh);
|
||||
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
ASSERT(subpart< getNumSubParts() );
|
||||
|
||||
IndexedMesh& mesh = m_indexedMeshes[subpart];
|
||||
|
||||
numverts = mesh.m_numVertices;
|
||||
(*vertexbase) = (unsigned char *) mesh.m_vertexBase;
|
||||
type = PHY_FLOAT;
|
||||
vertexStride = mesh.m_vertexStride;
|
||||
|
||||
numfaces = mesh.m_numTriangles;
|
||||
|
||||
(*indexbase) = (unsigned char *)mesh.m_triangleIndexBase;
|
||||
indexstride = mesh.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
|
||||
{
|
||||
const IndexedMesh& mesh = m_indexedMeshes[subpart];
|
||||
|
||||
numverts = mesh.m_numVertices;
|
||||
(*vertexbase) = (const unsigned char *)mesh.m_vertexBase;
|
||||
type = PHY_FLOAT;
|
||||
vertexStride = mesh.m_vertexStride;
|
||||
|
||||
numfaces = mesh.m_numTriangles;
|
||||
(*indexbase) = (const unsigned char *)mesh.m_triangleIndexBase;
|
||||
indexstride = mesh.m_triangleIndexStride;
|
||||
indicestype = PHY_INTEGER;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
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 "btStridingMeshInterface.h"
|
||||
#include <vector>
|
||||
|
||||
///IndexedMesh indexes into existing vertex and index arrays, in a similar way OpenGL glDrawElements
|
||||
///instead of the number of indices, we pass the number of triangles
|
||||
///todo: explain with pictures
|
||||
struct IndexedMesh
|
||||
{
|
||||
int m_numTriangles;
|
||||
int* m_triangleIndexBase;
|
||||
int m_triangleIndexStride;
|
||||
int m_numVertices;
|
||||
float* m_vertexBase;
|
||||
int m_vertexStride;
|
||||
};
|
||||
|
||||
///TriangleIndexVertexArray allows to use multiple meshes, by indexing into existing triangle/index arrays.
|
||||
///Additional meshes can be added using AddIndexedMesh
|
||||
///No duplcate is made of the vertex/index data, it only indexes into external vertex/index arrays.
|
||||
///So keep those arrays around during the lifetime of this TriangleIndexVertexArray.
|
||||
class TriangleIndexVertexArray : public StridingMeshInterface
|
||||
{
|
||||
std::vector<IndexedMesh> m_indexedMeshes;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
TriangleIndexVertexArray()
|
||||
{
|
||||
}
|
||||
|
||||
//just to be backwards compatible
|
||||
TriangleIndexVertexArray(int numTriangleIndices,int* triangleIndexBase,int triangleIndexStride,int numVertices,float* vertexBase,int vertexStride);
|
||||
|
||||
void AddIndexedMesh(const IndexedMesh& mesh)
|
||||
{
|
||||
m_indexedMeshes.push_back(mesh);
|
||||
}
|
||||
|
||||
|
||||
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 (int)m_indexedMeshes.size();
|
||||
}
|
||||
|
||||
virtual void preallocateVertices(int numverts){}
|
||||
virtual void preallocateIndices(int numindices){}
|
||||
|
||||
};
|
||||
|
||||
61
src/BulletCollision/CollisionShapes/btTriangleMesh.cpp
Normal file
61
src/BulletCollision/CollisionShapes/btTriangleMesh.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 "btTriangleMesh.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
src/BulletCollision/CollisionShapes/btTriangleMesh.h
Normal file
73
src/BulletCollision/CollisionShapes/btTriangleMesh.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 "BulletCollision/CollisionShapes/btStridingMeshInterface.h"
|
||||
#include <vector>
|
||||
#include <LinearMath/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
|
||||
|
||||
201
src/BulletCollision/CollisionShapes/btTriangleMeshShape.cpp
Normal file
201
src/BulletCollision/CollisionShapes/btTriangleMeshShape.cpp
Normal file
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
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 "btTriangleMeshShape.h"
|
||||
#include "LinearMath/SimdVector3.h"
|
||||
#include "LinearMath/SimdQuaternion.h"
|
||||
#include "btStridingMeshInterface.h"
|
||||
#include "LinearMath/GenAabbUtil2.h"
|
||||
#include "BulletCollision/CollisionShapes/btCollisionMargin.h"
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
TriangleMeshShape::TriangleMeshShape(StridingMeshInterface* meshInterface)
|
||||
: m_meshInterface(meshInterface)
|
||||
{
|
||||
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;
|
||||
}
|
||||
68
src/BulletCollision/CollisionShapes/btTriangleMeshShape.h
Normal file
68
src/BulletCollision/CollisionShapes/btTriangleMeshShape.h
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
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 "BulletCollision/CollisionShapes/btConcaveShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btStridingMeshInterface.h"
|
||||
|
||||
|
||||
///Concave triangle mesh. Uses an interface to access the triangles to allow for sharing graphics/physics triangles.
|
||||
class TriangleMeshShape : public ConcaveShape
|
||||
{
|
||||
protected:
|
||||
StridingMeshInterface* m_meshInterface;
|
||||
SimdVector3 m_localAabbMin;
|
||||
SimdVector3 m_localAabbMax;
|
||||
|
||||
|
||||
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";}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif //TRIANGLE_MESH_SHAPE_H
|
||||
164
src/BulletCollision/CollisionShapes/btTriangleShape.h
Normal file
164
src/BulletCollision/CollisionShapes/btTriangleShape.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 "btConvexShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btBoxShape.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