| [1963] | 1 | /* | 
|---|
 | 2 | Bullet Continuous Collision Detection and Physics Library | 
|---|
| [8351] | 3 | Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org | 
|---|
| [1963] | 4 |  | 
|---|
 | 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: | 
|---|
 | 10 |  | 
|---|
 | 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. | 
|---|
 | 14 | */ | 
|---|
| [8351] | 15 |  | 
|---|
| [1963] | 16 | #include "btTetrahedronShape.h" | 
|---|
 | 17 | #include "LinearMath/btMatrix3x3.h" | 
|---|
 | 18 |  | 
|---|
| [8351] | 19 | btBU_Simplex1to4::btBU_Simplex1to4() : btPolyhedralConvexAabbCachingShape (), | 
|---|
| [1963] | 20 | m_numVertices(0) | 
|---|
 | 21 | { | 
|---|
 | 22 |         m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE; | 
|---|
 | 23 | } | 
|---|
 | 24 |  | 
|---|
| [8351] | 25 | btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0) : btPolyhedralConvexAabbCachingShape (), | 
|---|
| [1963] | 26 | m_numVertices(0) | 
|---|
 | 27 | { | 
|---|
 | 28 |         m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE; | 
|---|
 | 29 |         addVertex(pt0); | 
|---|
 | 30 | } | 
|---|
 | 31 |  | 
|---|
| [8351] | 32 | btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1) : btPolyhedralConvexAabbCachingShape (), | 
|---|
| [1963] | 33 | m_numVertices(0) | 
|---|
 | 34 | { | 
|---|
 | 35 |         m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE; | 
|---|
 | 36 |         addVertex(pt0); | 
|---|
 | 37 |         addVertex(pt1); | 
|---|
 | 38 | } | 
|---|
 | 39 |  | 
|---|
| [8351] | 40 | btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1,const btVector3& pt2) : btPolyhedralConvexAabbCachingShape (), | 
|---|
| [1963] | 41 | m_numVertices(0) | 
|---|
 | 42 | { | 
|---|
 | 43 |         m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE; | 
|---|
 | 44 |         addVertex(pt0); | 
|---|
 | 45 |         addVertex(pt1); | 
|---|
 | 46 |         addVertex(pt2); | 
|---|
 | 47 | } | 
|---|
 | 48 |  | 
|---|
| [8351] | 49 | btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1,const btVector3& pt2,const btVector3& pt3) : btPolyhedralConvexAabbCachingShape (), | 
|---|
| [1963] | 50 | m_numVertices(0) | 
|---|
 | 51 | { | 
|---|
 | 52 |         m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE; | 
|---|
 | 53 |         addVertex(pt0); | 
|---|
 | 54 |         addVertex(pt1); | 
|---|
 | 55 |         addVertex(pt2); | 
|---|
 | 56 |         addVertex(pt3); | 
|---|
 | 57 | } | 
|---|
 | 58 |  | 
|---|
 | 59 |  | 
|---|
| [8351] | 60 | void btBU_Simplex1to4::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const | 
|---|
 | 61 | { | 
|---|
 | 62 | #if 1 | 
|---|
 | 63 |         btPolyhedralConvexAabbCachingShape::getAabb(t,aabbMin,aabbMax); | 
|---|
 | 64 | #else | 
|---|
 | 65 |         aabbMin.setValue(BT_LARGE_FLOAT,BT_LARGE_FLOAT,BT_LARGE_FLOAT); | 
|---|
 | 66 |         aabbMax.setValue(-BT_LARGE_FLOAT,-BT_LARGE_FLOAT,-BT_LARGE_FLOAT); | 
|---|
| [1963] | 67 |  | 
|---|
| [8351] | 68 |         //just transform the vertices in worldspace, and take their AABB | 
|---|
 | 69 |         for (int i=0;i<m_numVertices;i++) | 
|---|
 | 70 |         { | 
|---|
 | 71 |                 btVector3 worldVertex = t(m_vertices[i]); | 
|---|
 | 72 |                 aabbMin.setMin(worldVertex); | 
|---|
 | 73 |                 aabbMax.setMax(worldVertex); | 
|---|
 | 74 |         } | 
|---|
 | 75 | #endif | 
|---|
 | 76 | } | 
|---|
| [1963] | 77 |  | 
|---|
 | 78 |  | 
|---|
| [8351] | 79 |  | 
|---|
 | 80 |  | 
|---|
 | 81 |  | 
|---|
| [2430] | 82 | void btBU_Simplex1to4::addVertex(const btVector3& pt) | 
|---|
| [1963] | 83 | { | 
|---|
 | 84 |         m_vertices[m_numVertices++] = pt; | 
|---|
 | 85 |         recalcLocalAabb(); | 
|---|
 | 86 | } | 
|---|
 | 87 |  | 
|---|
 | 88 |  | 
|---|
 | 89 | int     btBU_Simplex1to4::getNumVertices() const | 
|---|
 | 90 | { | 
|---|
 | 91 |         return m_numVertices; | 
|---|
 | 92 | } | 
|---|
 | 93 |  | 
|---|
 | 94 | int btBU_Simplex1to4::getNumEdges() const | 
|---|
 | 95 | { | 
|---|
 | 96 |         //euler formula, F-E+V = 2, so E = F+V-2 | 
|---|
 | 97 |  | 
|---|
 | 98 |         switch (m_numVertices) | 
|---|
 | 99 |         { | 
|---|
 | 100 |         case 0: | 
|---|
 | 101 |                 return 0; | 
|---|
 | 102 |         case 1: return 0; | 
|---|
 | 103 |         case 2: return 1; | 
|---|
 | 104 |         case 3: return 3; | 
|---|
 | 105 |         case 4: return 6; | 
|---|
 | 106 |  | 
|---|
 | 107 |  | 
|---|
 | 108 |         } | 
|---|
 | 109 |  | 
|---|
 | 110 |         return 0; | 
|---|
 | 111 | } | 
|---|
 | 112 |  | 
|---|
| [2430] | 113 | void btBU_Simplex1to4::getEdge(int i,btVector3& pa,btVector3& pb) const | 
|---|
| [1963] | 114 | { | 
|---|
 | 115 |          | 
|---|
 | 116 |     switch (m_numVertices) | 
|---|
 | 117 |         { | 
|---|
 | 118 |  | 
|---|
 | 119 |         case 2:  | 
|---|
 | 120 |                 pa = m_vertices[0]; | 
|---|
 | 121 |                 pb = m_vertices[1]; | 
|---|
 | 122 |                 break; | 
|---|
 | 123 |         case 3:   | 
|---|
 | 124 |                 switch (i) | 
|---|
 | 125 |                 { | 
|---|
 | 126 |                 case 0: | 
|---|
 | 127 |                         pa = m_vertices[0]; | 
|---|
 | 128 |                         pb = m_vertices[1]; | 
|---|
 | 129 |                         break; | 
|---|
 | 130 |                 case 1: | 
|---|
 | 131 |                         pa = m_vertices[1]; | 
|---|
 | 132 |                         pb = m_vertices[2]; | 
|---|
 | 133 |                         break; | 
|---|
 | 134 |                 case 2: | 
|---|
 | 135 |                         pa = m_vertices[2]; | 
|---|
 | 136 |                         pb = m_vertices[0]; | 
|---|
 | 137 |                         break; | 
|---|
 | 138 |  | 
|---|
 | 139 |                 } | 
|---|
 | 140 |                 break; | 
|---|
 | 141 |         case 4:  | 
|---|
 | 142 |                 switch (i) | 
|---|
 | 143 |                 { | 
|---|
 | 144 |                 case 0: | 
|---|
 | 145 |                         pa = m_vertices[0]; | 
|---|
 | 146 |                         pb = m_vertices[1]; | 
|---|
 | 147 |                         break; | 
|---|
 | 148 |                 case 1: | 
|---|
 | 149 |                         pa = m_vertices[1]; | 
|---|
 | 150 |                         pb = m_vertices[2]; | 
|---|
 | 151 |                         break; | 
|---|
 | 152 |                 case 2: | 
|---|
 | 153 |                         pa = m_vertices[2]; | 
|---|
 | 154 |                         pb = m_vertices[0]; | 
|---|
 | 155 |                         break; | 
|---|
 | 156 |                 case 3: | 
|---|
 | 157 |                         pa = m_vertices[0]; | 
|---|
 | 158 |                         pb = m_vertices[3]; | 
|---|
 | 159 |                         break; | 
|---|
 | 160 |                 case 4: | 
|---|
 | 161 |                         pa = m_vertices[1]; | 
|---|
 | 162 |                         pb = m_vertices[3]; | 
|---|
 | 163 |                         break; | 
|---|
 | 164 |                 case 5: | 
|---|
 | 165 |                         pa = m_vertices[2]; | 
|---|
 | 166 |                         pb = m_vertices[3]; | 
|---|
 | 167 |                         break; | 
|---|
 | 168 |                 } | 
|---|
 | 169 |  | 
|---|
 | 170 |         } | 
|---|
 | 171 |  | 
|---|
 | 172 |  | 
|---|
 | 173 |  | 
|---|
 | 174 |  | 
|---|
 | 175 | } | 
|---|
 | 176 |  | 
|---|
| [2430] | 177 | void btBU_Simplex1to4::getVertex(int i,btVector3& vtx) const | 
|---|
| [1963] | 178 | { | 
|---|
 | 179 |         vtx = m_vertices[i]; | 
|---|
 | 180 | } | 
|---|
 | 181 |  | 
|---|
 | 182 | int     btBU_Simplex1to4::getNumPlanes() const | 
|---|
 | 183 | { | 
|---|
 | 184 |         switch (m_numVertices) | 
|---|
 | 185 |         { | 
|---|
 | 186 |         case 0: | 
|---|
 | 187 |                         return 0; | 
|---|
 | 188 |         case 1: | 
|---|
 | 189 |                         return 0; | 
|---|
 | 190 |         case 2: | 
|---|
 | 191 |                         return 0; | 
|---|
 | 192 |         case 3: | 
|---|
 | 193 |                         return 2; | 
|---|
 | 194 |         case 4: | 
|---|
 | 195 |                         return 4; | 
|---|
 | 196 |         default: | 
|---|
 | 197 |                 { | 
|---|
 | 198 |                 } | 
|---|
 | 199 |         } | 
|---|
 | 200 |         return 0; | 
|---|
 | 201 | } | 
|---|
 | 202 |  | 
|---|
 | 203 |  | 
|---|
| [2430] | 204 | void btBU_Simplex1to4::getPlane(btVector3&, btVector3& ,int ) const | 
|---|
| [1963] | 205 | { | 
|---|
 | 206 |          | 
|---|
 | 207 | } | 
|---|
 | 208 |  | 
|---|
 | 209 | int btBU_Simplex1to4::getIndex(int ) const | 
|---|
 | 210 | { | 
|---|
 | 211 |         return 0; | 
|---|
 | 212 | } | 
|---|
 | 213 |  | 
|---|
| [2430] | 214 | bool btBU_Simplex1to4::isInside(const btVector3& ,btScalar ) const | 
|---|
| [1963] | 215 | { | 
|---|
 | 216 |         return false; | 
|---|
 | 217 | } | 
|---|
 | 218 |  | 
|---|