1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
/*
* Copyright (c) 2005 Erwin Coumans http://continuousphysics.com/Bullet/
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies.
* Erwin Coumans makes no representations about the suitability
* of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*/
#include "ConvexHullShape.h"
#include "CollisionShapes/CollisionMargin.h"
#include "SimdQuaternion.h"
ConvexHullShape ::ConvexHullShape (SimdPoint3* points,int numPoints)
{
m_points.resize(numPoints);
for (int i=0;i<numPoints;i++)
m_points[i] = points[i];
}
SimdVector3 ConvexHullShape::LocalGetSupportingVertexWithoutMargin(const SimdVector3& vec0)const
{
SimdVector3 supVec(0.f,0.f,0.f);
SimdScalar newDot,maxDot = -1e30f;
SimdVector3 vec = vec0;
SimdScalar lenSqr = vec.length2();
if (lenSqr < 0.0001f)
{
vec.setValue(1,0,0);
} else
{
float rlen = 1.f / SimdSqrt(lenSqr );
vec *= rlen;
}
for (int 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;
}
SimdVector3 ConvexHullShape::LocalGetSupportingVertex(const SimdVector3& vec)const
{
SimdVector3 supVertex = LocalGetSupportingVertexWithoutMargin(vec);
if ( GetMargin()!=0.f )
{
SimdVector3 vecnorm = vec;
if (vecnorm .length2() == 0.f)
{
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;
}
|