Blender V4.3
btTetrahedronShape.cpp
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. 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.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. This notice may not be removed or altered from any source distribution.
14*/
15
16#include "btTetrahedronShape.h"
18
19btBU_Simplex1to4::btBU_Simplex1to4() : btPolyhedralConvexAabbCachingShape(),
21{
22 m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE;
23}
24
25btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0) : btPolyhedralConvexAabbCachingShape(),
27{
28 m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE;
29 addVertex(pt0);
30}
31
32btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0, const btVector3& pt1) : btPolyhedralConvexAabbCachingShape(),
34{
35 m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE;
36 addVertex(pt0);
37 addVertex(pt1);
38}
39
40btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0, const btVector3& pt1, const btVector3& pt2) : btPolyhedralConvexAabbCachingShape(),
42{
43 m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE;
44 addVertex(pt0);
45 addVertex(pt1);
46 addVertex(pt2);
47}
48
49btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0, const btVector3& pt1, const btVector3& pt2, const btVector3& pt3) : btPolyhedralConvexAabbCachingShape(),
51{
52 m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE;
53 addVertex(pt0);
54 addVertex(pt1);
55 addVertex(pt2);
56 addVertex(pt3);
57}
58
59void btBU_Simplex1to4::getAabb(const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const
60{
61#if 1
63#else
65 aabbMax.setValue(-BT_LARGE_FLOAT, -BT_LARGE_FLOAT, -BT_LARGE_FLOAT);
66
67 //just transform the vertices in worldspace, and take their AABB
68 for (int i = 0; i < m_numVertices; i++)
69 {
70 btVector3 worldVertex = t(m_vertices[i]);
71 aabbMin.setMin(worldVertex);
72 aabbMax.setMax(worldVertex);
73 }
74#endif
75}
76
77void btBU_Simplex1to4::addVertex(const btVector3& pt)
78{
81}
82
83int btBU_Simplex1to4::getNumVertices() const
84{
85 return m_numVertices;
86}
87
88int btBU_Simplex1to4::getNumEdges() const
89{
90 //euler formula, F-E+V = 2, so E = F+V-2
91
92 switch (m_numVertices)
93 {
94 case 0:
95 return 0;
96 case 1:
97 return 0;
98 case 2:
99 return 1;
100 case 3:
101 return 3;
102 case 4:
103 return 6;
104 }
105
106 return 0;
107}
108
109void btBU_Simplex1to4::getEdge(int i, btVector3& pa, btVector3& pb) const
110{
111 switch (m_numVertices)
112 {
113 case 2:
114 pa = m_vertices[0];
115 pb = m_vertices[1];
116 break;
117 case 3:
118 switch (i)
119 {
120 case 0:
121 pa = m_vertices[0];
122 pb = m_vertices[1];
123 break;
124 case 1:
125 pa = m_vertices[1];
126 pb = m_vertices[2];
127 break;
128 case 2:
129 pa = m_vertices[2];
130 pb = m_vertices[0];
131 break;
132 }
133 break;
134 case 4:
135 switch (i)
136 {
137 case 0:
138 pa = m_vertices[0];
139 pb = m_vertices[1];
140 break;
141 case 1:
142 pa = m_vertices[1];
143 pb = m_vertices[2];
144 break;
145 case 2:
146 pa = m_vertices[2];
147 pb = m_vertices[0];
148 break;
149 case 3:
150 pa = m_vertices[0];
151 pb = m_vertices[3];
152 break;
153 case 4:
154 pa = m_vertices[1];
155 pb = m_vertices[3];
156 break;
157 case 5:
158 pa = m_vertices[2];
159 pb = m_vertices[3];
160 break;
161 }
162 }
163}
164
165void btBU_Simplex1to4::getVertex(int i, btVector3& vtx) const
166{
167 vtx = m_vertices[i];
168}
169
170int btBU_Simplex1to4::getNumPlanes() const
171{
172 switch (m_numVertices)
173 {
174 case 0:
175 return 0;
176 case 1:
177 return 0;
178 case 2:
179 return 0;
180 case 3:
181 return 2;
182 case 4:
183 return 4;
184 default:
185 {
186 }
187 }
188 return 0;
189}
190
191void btBU_Simplex1to4::getPlane(btVector3&, btVector3&, int) const
192{
193}
194
195int btBU_Simplex1to4::getIndex(int) const
196{
197 return 0;
198}
199
200bool btBU_Simplex1to4::isInside(const btVector3&, btScalar) const
201{
202 return false;
203}
btVector3 m_vertices[4]
@ TETRAHEDRAL_SHAPE_PROXYTYPE
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition btScalar.h:314
#define BT_LARGE_FLOAT
Definition btScalar.h:316
void addVertex(const btVector3 &pt)
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition btTransform.h:30
void recalcLocalAabb()
The btPolyhedralConvexAabbCachingShape adds aabb caching to the btPolyhedralConvexShape.
virtual void getAabb(const btTransform &t, btVector3 &aabbMin, btVector3 &aabbMax) const