btTetrahedronShape.cpp

Go to the documentation of this file.
00001 /*
00002 Bullet Continuous Collision Detection and Physics Library
00003 Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
00004 
00005 This software is provided 'as-is', without any express or implied warranty.
00006 In no event will the authors be held liable for any damages arising from the use of this software.
00007 Permission is granted to anyone to use this software for any purpose, 
00008 including commercial applications, and to alter it and redistribute it freely, 
00009 subject to the following restrictions:
00010 
00011 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.
00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
00013 3. This notice may not be removed or altered from any source distribution.
00014 */
00015 
00016 #include "btTetrahedronShape.h"
00017 #include "LinearMath/btMatrix3x3.h"
00018 
00019 btBU_Simplex1to4::btBU_Simplex1to4() : btPolyhedralConvexAabbCachingShape (),
00020 m_numVertices(0)
00021 {
00022         m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE;
00023 }
00024 
00025 btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0) : btPolyhedralConvexAabbCachingShape (),
00026 m_numVertices(0)
00027 {
00028         m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE;
00029         addVertex(pt0);
00030 }
00031 
00032 btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1) : btPolyhedralConvexAabbCachingShape (),
00033 m_numVertices(0)
00034 {
00035         m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE;
00036         addVertex(pt0);
00037         addVertex(pt1);
00038 }
00039 
00040 btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1,const btVector3& pt2) : btPolyhedralConvexAabbCachingShape (),
00041 m_numVertices(0)
00042 {
00043         m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE;
00044         addVertex(pt0);
00045         addVertex(pt1);
00046         addVertex(pt2);
00047 }
00048 
00049 btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1,const btVector3& pt2,const btVector3& pt3) : btPolyhedralConvexAabbCachingShape (),
00050 m_numVertices(0)
00051 {
00052         m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE;
00053         addVertex(pt0);
00054         addVertex(pt1);
00055         addVertex(pt2);
00056         addVertex(pt3);
00057 }
00058 
00059 
00060 void btBU_Simplex1to4::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
00061 {
00062 #if 1
00063         btPolyhedralConvexAabbCachingShape::getAabb(t,aabbMin,aabbMax);
00064 #else
00065         aabbMin.setValue(BT_LARGE_FLOAT,BT_LARGE_FLOAT,BT_LARGE_FLOAT);
00066         aabbMax.setValue(-BT_LARGE_FLOAT,-BT_LARGE_FLOAT,-BT_LARGE_FLOAT);
00067 
00068         //just transform the vertices in worldspace, and take their AABB
00069         for (int i=0;i<m_numVertices;i++)
00070         {
00071                 btVector3 worldVertex = t(m_vertices[i]);
00072                 aabbMin.setMin(worldVertex);
00073                 aabbMax.setMax(worldVertex);
00074         }
00075 #endif
00076 }
00077 
00078 
00079 
00080 
00081 
00082 void btBU_Simplex1to4::addVertex(const btVector3& pt)
00083 {
00084         m_vertices[m_numVertices++] = pt;
00085         recalcLocalAabb();
00086 }
00087 
00088 
00089 int     btBU_Simplex1to4::getNumVertices() const
00090 {
00091         return m_numVertices;
00092 }
00093 
00094 int btBU_Simplex1to4::getNumEdges() const
00095 {
00096         //euler formula, F-E+V = 2, so E = F+V-2
00097 
00098         switch (m_numVertices)
00099         {
00100         case 0:
00101                 return 0;
00102         case 1: return 0;
00103         case 2: return 1;
00104         case 3: return 3;
00105         case 4: return 6;
00106 
00107 
00108         }
00109 
00110         return 0;
00111 }
00112 
00113 void btBU_Simplex1to4::getEdge(int i,btVector3& pa,btVector3& pb) const
00114 {
00115         
00116     switch (m_numVertices)
00117         {
00118 
00119         case 2: 
00120                 pa = m_vertices[0];
00121                 pb = m_vertices[1];
00122                 break;
00123         case 3:  
00124                 switch (i)
00125                 {
00126                 case 0:
00127                         pa = m_vertices[0];
00128                         pb = m_vertices[1];
00129                         break;
00130                 case 1:
00131                         pa = m_vertices[1];
00132                         pb = m_vertices[2];
00133                         break;
00134                 case 2:
00135                         pa = m_vertices[2];
00136                         pb = m_vertices[0];
00137                         break;
00138 
00139                 }
00140                 break;
00141         case 4: 
00142                 switch (i)
00143                 {
00144                 case 0:
00145                         pa = m_vertices[0];
00146                         pb = m_vertices[1];
00147                         break;
00148                 case 1:
00149                         pa = m_vertices[1];
00150                         pb = m_vertices[2];
00151                         break;
00152                 case 2:
00153                         pa = m_vertices[2];
00154                         pb = m_vertices[0];
00155                         break;
00156                 case 3:
00157                         pa = m_vertices[0];
00158                         pb = m_vertices[3];
00159                         break;
00160                 case 4:
00161                         pa = m_vertices[1];
00162                         pb = m_vertices[3];
00163                         break;
00164                 case 5:
00165                         pa = m_vertices[2];
00166                         pb = m_vertices[3];
00167                         break;
00168                 }
00169 
00170         }
00171 
00172 
00173 
00174 
00175 }
00176 
00177 void btBU_Simplex1to4::getVertex(int i,btVector3& vtx) const
00178 {
00179         vtx = m_vertices[i];
00180 }
00181 
00182 int     btBU_Simplex1to4::getNumPlanes() const
00183 {
00184         switch (m_numVertices)
00185         {
00186         case 0:
00187                         return 0;
00188         case 1:
00189                         return 0;
00190         case 2:
00191                         return 0;
00192         case 3:
00193                         return 2;
00194         case 4:
00195                         return 4;
00196         default:
00197                 {
00198                 }
00199         }
00200         return 0;
00201 }
00202 
00203 
00204 void btBU_Simplex1to4::getPlane(btVector3&, btVector3& ,int ) const
00205 {
00206         
00207 }
00208 
00209 int btBU_Simplex1to4::getIndex(int ) const
00210 {
00211         return 0;
00212 }
00213 
00214 bool btBU_Simplex1to4::isInside(const btVector3& ,btScalar ) const
00215 {
00216         return false;
00217 }
00218