2
Bullet Continuous Collision Detection and Physics Library
3
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
5
This software is provided 'as-is', without any express or implied warranty.
6
In no event will the authors be held liable for any damages arising from the use of this software.
7
Permission is granted to anyone to use this software for any purpose,
8
including commercial applications, and to alter it and redistribute it freely,
9
subject to the following restrictions:
11
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.
12
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13
3. This notice may not be removed or altered from any source distribution.
15
#include "ConvexHullShape.h"
16
#include "CollisionShapes/CollisionMargin.h"
18
#include "SimdQuaternion.h"
21
ConvexHullShape ::ConvexHullShape (SimdPoint3* points,int numPoints)
23
m_points.resize(numPoints);
24
for (int i=0;i<numPoints;i++)
25
m_points[i] = points[i];
28
SimdVector3 ConvexHullShape::LocalGetSupportingVertexWithoutMargin(const SimdVector3& vec0)const
30
SimdVector3 supVec(0.f,0.f,0.f);
31
SimdScalar newDot,maxDot = -1e30f;
33
SimdVector3 vec = vec0;
34
SimdScalar lenSqr = vec.length2();
40
float rlen = 1.f / SimdSqrt(lenSqr );
45
for (size_t i=0;i<m_points.size();i++)
47
SimdPoint3 vtx = m_points[i] * m_localScaling;
49
newDot = vec.dot(vtx);
59
void ConvexHullShape::BatchedUnitVectorGetSupportingVertexWithoutMargin(const SimdVector3* vectors,SimdVector3* supportVerticesOut,int numVectors) const
62
//use 'w' component of supportVerticesOut?
64
for (int i=0;i<numVectors;i++)
66
supportVerticesOut[i][3] = -1e30f;
69
for (size_t i=0;i<m_points.size();i++)
71
SimdPoint3 vtx = m_points[i] * m_localScaling;
73
for (int j=0;j<numVectors;j++)
75
const SimdVector3& vec = vectors[j];
77
newDot = vec.dot(vtx);
78
if (newDot > supportVerticesOut[j][3])
80
//WARNING: don't swap next lines, the w component would get overwritten!
81
supportVerticesOut[j] = vtx;
82
supportVerticesOut[j][3] = newDot;
93
SimdVector3 ConvexHullShape::LocalGetSupportingVertex(const SimdVector3& vec)const
95
SimdVector3 supVertex = LocalGetSupportingVertexWithoutMargin(vec);
97
if ( GetMargin()!=0.f )
99
SimdVector3 vecnorm = vec;
100
if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON))
102
vecnorm.setValue(-1.f,-1.f,-1.f);
105
supVertex+= GetMargin() * vecnorm;
118
//currently just for debugging (drawing), perhaps future support for algebraic continuous collision detection
119
//Please note that you can debug-draw ConvexHullShape with the Raytracer Demo
120
int ConvexHullShape::GetNumVertices() const
122
return m_points.size();
125
int ConvexHullShape::GetNumEdges() const
127
return m_points.size()*m_points.size();
130
void ConvexHullShape::GetEdge(int i,SimdPoint3& pa,SimdPoint3& pb) const
133
int index0 = i%m_points.size();
134
int index1 = i/m_points.size();
135
pa = m_points[index0]*m_localScaling;
136
pb = m_points[index1]*m_localScaling;
139
void ConvexHullShape::GetVertex(int i,SimdPoint3& vtx) const
141
vtx = m_points[i]*m_localScaling;
144
int ConvexHullShape::GetNumPlanes() const
149
void ConvexHullShape::GetPlane(SimdVector3& planeNormal,SimdPoint3& planeSupport,int i ) const
155
bool ConvexHullShape::IsInside(const SimdPoint3& pt,SimdScalar tolerance) const