btTetrahedronShape.cpp 4.3 KB

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