gim_box_collision.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. #ifndef GIM_BOX_COLLISION_H_INCLUDED
  2. #define GIM_BOX_COLLISION_H_INCLUDED
  3. /*! \file gim_box_collision.h
  4. \author Francisco Leon Najera
  5. */
  6. /*
  7. -----------------------------------------------------------------------------
  8. This source file is part of GIMPACT Library.
  9. For the latest info, see http://gimpact.sourceforge.net/
  10. Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371.
  11. email: projectileman@yahoo.com
  12. This library is free software; you can redistribute it and/or
  13. modify it under the terms of EITHER:
  14. (1) The GNU Lesser General Public License as published by the Free
  15. Software Foundation; either version 2.1 of the License, or (at
  16. your option) any later version. The text of the GNU Lesser
  17. General Public License is included with this library in the
  18. file GIMPACT-LICENSE-LGPL.TXT.
  19. (2) The BSD-style license that is included with this library in
  20. the file GIMPACT-LICENSE-BSD.TXT.
  21. (3) The zlib/libpng license that is included with this library in
  22. the file GIMPACT-LICENSE-ZLIB.TXT.
  23. This library is distributed in the hope that it will be useful,
  24. but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files
  26. GIMPACT-LICENSE-LGPL.TXT, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
  27. -----------------------------------------------------------------------------
  28. */
  29. #include "gim_basic_geometry_operations.h"
  30. #include "LinearMath/btTransform.h"
  31. //SIMD_FORCE_INLINE bool test_cross_edge_box(
  32. // const btVector3 & edge,
  33. // const btVector3 & absolute_edge,
  34. // const btVector3 & pointa,
  35. // const btVector3 & pointb, const btVector3 & extend,
  36. // int dir_index0,
  37. // int dir_index1
  38. // int component_index0,
  39. // int component_index1)
  40. //{
  41. // // dir coords are -z and y
  42. //
  43. // const btScalar dir0 = -edge[dir_index0];
  44. // const btScalar dir1 = edge[dir_index1];
  45. // btScalar pmin = pointa[component_index0]*dir0 + pointa[component_index1]*dir1;
  46. // btScalar pmax = pointb[component_index0]*dir0 + pointb[component_index1]*dir1;
  47. // //find minmax
  48. // if(pmin>pmax)
  49. // {
  50. // GIM_SWAP_NUMBERS(pmin,pmax);
  51. // }
  52. // //find extends
  53. // const btScalar rad = extend[component_index0] * absolute_edge[dir_index0] +
  54. // extend[component_index1] * absolute_edge[dir_index1];
  55. //
  56. // if(pmin>rad || -rad>pmax) return false;
  57. // return true;
  58. //}
  59. //
  60. //SIMD_FORCE_INLINE bool test_cross_edge_box_X_axis(
  61. // const btVector3 & edge,
  62. // const btVector3 & absolute_edge,
  63. // const btVector3 & pointa,
  64. // const btVector3 & pointb, btVector3 & extend)
  65. //{
  66. //
  67. // return test_cross_edge_box(edge,absolute_edge,pointa,pointb,extend,2,1,1,2);
  68. //}
  69. //
  70. //
  71. //SIMD_FORCE_INLINE bool test_cross_edge_box_Y_axis(
  72. // const btVector3 & edge,
  73. // const btVector3 & absolute_edge,
  74. // const btVector3 & pointa,
  75. // const btVector3 & pointb, btVector3 & extend)
  76. //{
  77. //
  78. // return test_cross_edge_box(edge,absolute_edge,pointa,pointb,extend,0,2,2,0);
  79. //}
  80. //
  81. //SIMD_FORCE_INLINE bool test_cross_edge_box_Z_axis(
  82. // const btVector3 & edge,
  83. // const btVector3 & absolute_edge,
  84. // const btVector3 & pointa,
  85. // const btVector3 & pointb, btVector3 & extend)
  86. //{
  87. //
  88. // return test_cross_edge_box(edge,absolute_edge,pointa,pointb,extend,1,0,0,1);
  89. //}
  90. #ifndef TEST_CROSS_EDGE_BOX_MCR
  91. #define TEST_CROSS_EDGE_BOX_MCR(edge,absolute_edge,pointa,pointb,_extend,i_dir_0,i_dir_1,i_comp_0,i_comp_1)\
  92. {\
  93. const btScalar dir0 = -edge[i_dir_0];\
  94. const btScalar dir1 = edge[i_dir_1];\
  95. btScalar pmin = pointa[i_comp_0]*dir0 + pointa[i_comp_1]*dir1;\
  96. btScalar pmax = pointb[i_comp_0]*dir0 + pointb[i_comp_1]*dir1;\
  97. if(pmin>pmax)\
  98. {\
  99. GIM_SWAP_NUMBERS(pmin,pmax); \
  100. }\
  101. const btScalar abs_dir0 = absolute_edge[i_dir_0];\
  102. const btScalar abs_dir1 = absolute_edge[i_dir_1];\
  103. const btScalar rad = _extend[i_comp_0] * abs_dir0 + _extend[i_comp_1] * abs_dir1;\
  104. if(pmin>rad || -rad>pmax) return false;\
  105. }\
  106. #endif
  107. #define TEST_CROSS_EDGE_BOX_X_AXIS_MCR(edge,absolute_edge,pointa,pointb,_extend)\
  108. {\
  109. TEST_CROSS_EDGE_BOX_MCR(edge,absolute_edge,pointa,pointb,_extend,2,1,1,2);\
  110. }\
  111. #define TEST_CROSS_EDGE_BOX_Y_AXIS_MCR(edge,absolute_edge,pointa,pointb,_extend)\
  112. {\
  113. TEST_CROSS_EDGE_BOX_MCR(edge,absolute_edge,pointa,pointb,_extend,0,2,2,0);\
  114. }\
  115. #define TEST_CROSS_EDGE_BOX_Z_AXIS_MCR(edge,absolute_edge,pointa,pointb,_extend)\
  116. {\
  117. TEST_CROSS_EDGE_BOX_MCR(edge,absolute_edge,pointa,pointb,_extend,1,0,0,1);\
  118. }\
  119. //! Class for transforming a model1 to the space of model0
  120. class GIM_BOX_BOX_TRANSFORM_CACHE
  121. {
  122. public:
  123. btVector3 m_T1to0;//!< Transforms translation of model1 to model 0
  124. btMatrix3x3 m_R1to0;//!< Transforms Rotation of model1 to model 0, equal to R0' * R1
  125. btMatrix3x3 m_AR;//!< Absolute value of m_R1to0
  126. SIMD_FORCE_INLINE void calc_absolute_matrix()
  127. {
  128. static const btVector3 vepsi(1e-6f,1e-6f,1e-6f);
  129. m_AR[0] = vepsi + m_R1to0[0].absolute();
  130. m_AR[1] = vepsi + m_R1to0[1].absolute();
  131. m_AR[2] = vepsi + m_R1to0[2].absolute();
  132. }
  133. GIM_BOX_BOX_TRANSFORM_CACHE()
  134. {
  135. }
  136. GIM_BOX_BOX_TRANSFORM_CACHE(mat4f trans1_to_0)
  137. {
  138. COPY_MATRIX_3X3(m_R1to0,trans1_to_0)
  139. MAT_GET_TRANSLATION(trans1_to_0,m_T1to0)
  140. calc_absolute_matrix();
  141. }
  142. //! Calc the transformation relative 1 to 0. Inverts matrics by transposing
  143. SIMD_FORCE_INLINE void calc_from_homogenic(const btTransform & trans0,const btTransform & trans1)
  144. {
  145. m_R1to0 = trans0.getBasis().transpose();
  146. m_T1to0 = m_R1to0 * (-trans0.getOrigin());
  147. m_T1to0 += m_R1to0*trans1.getOrigin();
  148. m_R1to0 *= trans1.getBasis();
  149. calc_absolute_matrix();
  150. }
  151. //! Calcs the full invertion of the matrices. Useful for scaling matrices
  152. SIMD_FORCE_INLINE void calc_from_full_invert(const btTransform & trans0,const btTransform & trans1)
  153. {
  154. m_R1to0 = trans0.getBasis().inverse();
  155. m_T1to0 = m_R1to0 * (-trans0.getOrigin());
  156. m_T1to0 += m_R1to0*trans1.getOrigin();
  157. m_R1to0 *= trans1.getBasis();
  158. calc_absolute_matrix();
  159. }
  160. SIMD_FORCE_INLINE btVector3 transform(const btVector3 & point)
  161. {
  162. return point.dot3(m_R1to0[0], m_R1to0[1], m_R1to0[2]) + m_T1to0;
  163. }
  164. };
  165. #ifndef BOX_PLANE_EPSILON
  166. #define BOX_PLANE_EPSILON 0.000001f
  167. #endif
  168. //! Axis aligned box
  169. class GIM_AABB
  170. {
  171. public:
  172. btVector3 m_min;
  173. btVector3 m_max;
  174. GIM_AABB()
  175. {}
  176. GIM_AABB(const btVector3 & V1,
  177. const btVector3 & V2,
  178. const btVector3 & V3)
  179. {
  180. m_min[0] = GIM_MIN3(V1[0],V2[0],V3[0]);
  181. m_min[1] = GIM_MIN3(V1[1],V2[1],V3[1]);
  182. m_min[2] = GIM_MIN3(V1[2],V2[2],V3[2]);
  183. m_max[0] = GIM_MAX3(V1[0],V2[0],V3[0]);
  184. m_max[1] = GIM_MAX3(V1[1],V2[1],V3[1]);
  185. m_max[2] = GIM_MAX3(V1[2],V2[2],V3[2]);
  186. }
  187. GIM_AABB(const btVector3 & V1,
  188. const btVector3 & V2,
  189. const btVector3 & V3,
  190. GREAL margin)
  191. {
  192. m_min[0] = GIM_MIN3(V1[0],V2[0],V3[0]);
  193. m_min[1] = GIM_MIN3(V1[1],V2[1],V3[1]);
  194. m_min[2] = GIM_MIN3(V1[2],V2[2],V3[2]);
  195. m_max[0] = GIM_MAX3(V1[0],V2[0],V3[0]);
  196. m_max[1] = GIM_MAX3(V1[1],V2[1],V3[1]);
  197. m_max[2] = GIM_MAX3(V1[2],V2[2],V3[2]);
  198. m_min[0] -= margin;
  199. m_min[1] -= margin;
  200. m_min[2] -= margin;
  201. m_max[0] += margin;
  202. m_max[1] += margin;
  203. m_max[2] += margin;
  204. }
  205. GIM_AABB(const GIM_AABB &other):
  206. m_min(other.m_min),m_max(other.m_max)
  207. {
  208. }
  209. GIM_AABB(const GIM_AABB &other,btScalar margin ):
  210. m_min(other.m_min),m_max(other.m_max)
  211. {
  212. m_min[0] -= margin;
  213. m_min[1] -= margin;
  214. m_min[2] -= margin;
  215. m_max[0] += margin;
  216. m_max[1] += margin;
  217. m_max[2] += margin;
  218. }
  219. SIMD_FORCE_INLINE void invalidate()
  220. {
  221. m_min[0] = G_REAL_INFINITY;
  222. m_min[1] = G_REAL_INFINITY;
  223. m_min[2] = G_REAL_INFINITY;
  224. m_max[0] = -G_REAL_INFINITY;
  225. m_max[1] = -G_REAL_INFINITY;
  226. m_max[2] = -G_REAL_INFINITY;
  227. }
  228. SIMD_FORCE_INLINE void increment_margin(btScalar margin)
  229. {
  230. m_min[0] -= margin;
  231. m_min[1] -= margin;
  232. m_min[2] -= margin;
  233. m_max[0] += margin;
  234. m_max[1] += margin;
  235. m_max[2] += margin;
  236. }
  237. SIMD_FORCE_INLINE void copy_with_margin(const GIM_AABB &other, btScalar margin)
  238. {
  239. m_min[0] = other.m_min[0] - margin;
  240. m_min[1] = other.m_min[1] - margin;
  241. m_min[2] = other.m_min[2] - margin;
  242. m_max[0] = other.m_max[0] + margin;
  243. m_max[1] = other.m_max[1] + margin;
  244. m_max[2] = other.m_max[2] + margin;
  245. }
  246. template<typename CLASS_POINT>
  247. SIMD_FORCE_INLINE void calc_from_triangle(
  248. const CLASS_POINT & V1,
  249. const CLASS_POINT & V2,
  250. const CLASS_POINT & V3)
  251. {
  252. m_min[0] = GIM_MIN3(V1[0],V2[0],V3[0]);
  253. m_min[1] = GIM_MIN3(V1[1],V2[1],V3[1]);
  254. m_min[2] = GIM_MIN3(V1[2],V2[2],V3[2]);
  255. m_max[0] = GIM_MAX3(V1[0],V2[0],V3[0]);
  256. m_max[1] = GIM_MAX3(V1[1],V2[1],V3[1]);
  257. m_max[2] = GIM_MAX3(V1[2],V2[2],V3[2]);
  258. }
  259. template<typename CLASS_POINT>
  260. SIMD_FORCE_INLINE void calc_from_triangle_margin(
  261. const CLASS_POINT & V1,
  262. const CLASS_POINT & V2,
  263. const CLASS_POINT & V3, btScalar margin)
  264. {
  265. m_min[0] = GIM_MIN3(V1[0],V2[0],V3[0]);
  266. m_min[1] = GIM_MIN3(V1[1],V2[1],V3[1]);
  267. m_min[2] = GIM_MIN3(V1[2],V2[2],V3[2]);
  268. m_max[0] = GIM_MAX3(V1[0],V2[0],V3[0]);
  269. m_max[1] = GIM_MAX3(V1[1],V2[1],V3[1]);
  270. m_max[2] = GIM_MAX3(V1[2],V2[2],V3[2]);
  271. m_min[0] -= margin;
  272. m_min[1] -= margin;
  273. m_min[2] -= margin;
  274. m_max[0] += margin;
  275. m_max[1] += margin;
  276. m_max[2] += margin;
  277. }
  278. //! Apply a transform to an AABB
  279. SIMD_FORCE_INLINE void appy_transform(const btTransform & trans)
  280. {
  281. btVector3 center = (m_max+m_min)*0.5f;
  282. btVector3 extends = m_max - center;
  283. // Compute new center
  284. center = trans(center);
  285. btVector3 textends = extends.dot3(trans.getBasis().getRow(0).absolute(),
  286. trans.getBasis().getRow(1).absolute(),
  287. trans.getBasis().getRow(2).absolute());
  288. m_min = center - textends;
  289. m_max = center + textends;
  290. }
  291. //! Merges a Box
  292. SIMD_FORCE_INLINE void merge(const GIM_AABB & box)
  293. {
  294. m_min[0] = GIM_MIN(m_min[0],box.m_min[0]);
  295. m_min[1] = GIM_MIN(m_min[1],box.m_min[1]);
  296. m_min[2] = GIM_MIN(m_min[2],box.m_min[2]);
  297. m_max[0] = GIM_MAX(m_max[0],box.m_max[0]);
  298. m_max[1] = GIM_MAX(m_max[1],box.m_max[1]);
  299. m_max[2] = GIM_MAX(m_max[2],box.m_max[2]);
  300. }
  301. //! Merges a point
  302. template<typename CLASS_POINT>
  303. SIMD_FORCE_INLINE void merge_point(const CLASS_POINT & point)
  304. {
  305. m_min[0] = GIM_MIN(m_min[0],point[0]);
  306. m_min[1] = GIM_MIN(m_min[1],point[1]);
  307. m_min[2] = GIM_MIN(m_min[2],point[2]);
  308. m_max[0] = GIM_MAX(m_max[0],point[0]);
  309. m_max[1] = GIM_MAX(m_max[1],point[1]);
  310. m_max[2] = GIM_MAX(m_max[2],point[2]);
  311. }
  312. //! Gets the extend and center
  313. SIMD_FORCE_INLINE void get_center_extend(btVector3 & center,btVector3 & extend) const
  314. {
  315. center = (m_max+m_min)*0.5f;
  316. extend = m_max - center;
  317. }
  318. //! Finds the intersecting box between this box and the other.
  319. SIMD_FORCE_INLINE void find_intersection(const GIM_AABB & other, GIM_AABB & intersection) const
  320. {
  321. intersection.m_min[0] = GIM_MAX(other.m_min[0],m_min[0]);
  322. intersection.m_min[1] = GIM_MAX(other.m_min[1],m_min[1]);
  323. intersection.m_min[2] = GIM_MAX(other.m_min[2],m_min[2]);
  324. intersection.m_max[0] = GIM_MIN(other.m_max[0],m_max[0]);
  325. intersection.m_max[1] = GIM_MIN(other.m_max[1],m_max[1]);
  326. intersection.m_max[2] = GIM_MIN(other.m_max[2],m_max[2]);
  327. }
  328. SIMD_FORCE_INLINE bool has_collision(const GIM_AABB & other) const
  329. {
  330. if(m_min[0] > other.m_max[0] ||
  331. m_max[0] < other.m_min[0] ||
  332. m_min[1] > other.m_max[1] ||
  333. m_max[1] < other.m_min[1] ||
  334. m_min[2] > other.m_max[2] ||
  335. m_max[2] < other.m_min[2])
  336. {
  337. return false;
  338. }
  339. return true;
  340. }
  341. /*! \brief Finds the Ray intersection parameter.
  342. \param aabb Aligned box
  343. \param vorigin A vec3f with the origin of the ray
  344. \param vdir A vec3f with the direction of the ray
  345. */
  346. SIMD_FORCE_INLINE bool collide_ray(const btVector3 & vorigin,const btVector3 & vdir)
  347. {
  348. btVector3 extents,center;
  349. this->get_center_extend(center,extents);;
  350. btScalar Dx = vorigin[0] - center[0];
  351. if(GIM_GREATER(Dx, extents[0]) && Dx*vdir[0]>=0.0f) return false;
  352. btScalar Dy = vorigin[1] - center[1];
  353. if(GIM_GREATER(Dy, extents[1]) && Dy*vdir[1]>=0.0f) return false;
  354. btScalar Dz = vorigin[2] - center[2];
  355. if(GIM_GREATER(Dz, extents[2]) && Dz*vdir[2]>=0.0f) return false;
  356. btScalar f = vdir[1] * Dz - vdir[2] * Dy;
  357. if(btFabs(f) > extents[1]*btFabs(vdir[2]) + extents[2]*btFabs(vdir[1])) return false;
  358. f = vdir[2] * Dx - vdir[0] * Dz;
  359. if(btFabs(f) > extents[0]*btFabs(vdir[2]) + extents[2]*btFabs(vdir[0]))return false;
  360. f = vdir[0] * Dy - vdir[1] * Dx;
  361. if(btFabs(f) > extents[0]*btFabs(vdir[1]) + extents[1]*btFabs(vdir[0]))return false;
  362. return true;
  363. }
  364. SIMD_FORCE_INLINE void projection_interval(const btVector3 & direction, btScalar &vmin, btScalar &vmax) const
  365. {
  366. btVector3 center = (m_max+m_min)*0.5f;
  367. btVector3 extend = m_max-center;
  368. btScalar _fOrigin = direction.dot(center);
  369. btScalar _fMaximumExtent = extend.dot(direction.absolute());
  370. vmin = _fOrigin - _fMaximumExtent;
  371. vmax = _fOrigin + _fMaximumExtent;
  372. }
  373. SIMD_FORCE_INLINE ePLANE_INTERSECTION_TYPE plane_classify(const btVector4 &plane) const
  374. {
  375. btScalar _fmin,_fmax;
  376. this->projection_interval(plane,_fmin,_fmax);
  377. if(plane[3] > _fmax + BOX_PLANE_EPSILON)
  378. {
  379. return G_BACK_PLANE; // 0
  380. }
  381. if(plane[3]+BOX_PLANE_EPSILON >=_fmin)
  382. {
  383. return G_COLLIDE_PLANE; //1
  384. }
  385. return G_FRONT_PLANE;//2
  386. }
  387. SIMD_FORCE_INLINE bool overlapping_trans_conservative(const GIM_AABB & box, btTransform & trans1_to_0)
  388. {
  389. GIM_AABB tbox = box;
  390. tbox.appy_transform(trans1_to_0);
  391. return has_collision(tbox);
  392. }
  393. //! transcache is the transformation cache from box to this AABB
  394. SIMD_FORCE_INLINE bool overlapping_trans_cache(
  395. const GIM_AABB & box,const GIM_BOX_BOX_TRANSFORM_CACHE & transcache, bool fulltest)
  396. {
  397. //Taken from OPCODE
  398. btVector3 ea,eb;//extends
  399. btVector3 ca,cb;//extends
  400. get_center_extend(ca,ea);
  401. box.get_center_extend(cb,eb);
  402. btVector3 T;
  403. btScalar t,t2;
  404. int i;
  405. // Class I : A's basis vectors
  406. for(i=0;i<3;i++)
  407. {
  408. T[i] = transcache.m_R1to0[i].dot(cb) + transcache.m_T1to0[i] - ca[i];
  409. t = transcache.m_AR[i].dot(eb) + ea[i];
  410. if(GIM_GREATER(T[i], t)) return false;
  411. }
  412. // Class II : B's basis vectors
  413. for(i=0;i<3;i++)
  414. {
  415. t = MAT_DOT_COL(transcache.m_R1to0,T,i);
  416. t2 = MAT_DOT_COL(transcache.m_AR,ea,i) + eb[i];
  417. if(GIM_GREATER(t,t2)) return false;
  418. }
  419. // Class III : 9 cross products
  420. if(fulltest)
  421. {
  422. int j,m,n,o,p,q,r;
  423. for(i=0;i<3;i++)
  424. {
  425. m = (i+1)%3;
  426. n = (i+2)%3;
  427. o = i==0?1:0;
  428. p = i==2?1:2;
  429. for(j=0;j<3;j++)
  430. {
  431. q = j==2?1:2;
  432. r = j==0?1:0;
  433. t = T[n]*transcache.m_R1to0[m][j] - T[m]*transcache.m_R1to0[n][j];
  434. t2 = ea[o]*transcache.m_AR[p][j] + ea[p]*transcache.m_AR[o][j] +
  435. eb[r]*transcache.m_AR[i][q] + eb[q]*transcache.m_AR[i][r];
  436. if(GIM_GREATER(t,t2)) return false;
  437. }
  438. }
  439. }
  440. return true;
  441. }
  442. //! Simple test for planes.
  443. SIMD_FORCE_INLINE bool collide_plane(
  444. const btVector4 & plane)
  445. {
  446. ePLANE_INTERSECTION_TYPE classify = plane_classify(plane);
  447. return (classify == G_COLLIDE_PLANE);
  448. }
  449. //! test for a triangle, with edges
  450. SIMD_FORCE_INLINE bool collide_triangle_exact(
  451. const btVector3 & p1,
  452. const btVector3 & p2,
  453. const btVector3 & p3,
  454. const btVector4 & triangle_plane)
  455. {
  456. if(!collide_plane(triangle_plane)) return false;
  457. btVector3 center,extends;
  458. this->get_center_extend(center,extends);
  459. const btVector3 v1(p1 - center);
  460. const btVector3 v2(p2 - center);
  461. const btVector3 v3(p3 - center);
  462. //First axis
  463. btVector3 diff(v2 - v1);
  464. btVector3 abs_diff = diff.absolute();
  465. //Test With X axis
  466. TEST_CROSS_EDGE_BOX_X_AXIS_MCR(diff,abs_diff,v1,v3,extends);
  467. //Test With Y axis
  468. TEST_CROSS_EDGE_BOX_Y_AXIS_MCR(diff,abs_diff,v1,v3,extends);
  469. //Test With Z axis
  470. TEST_CROSS_EDGE_BOX_Z_AXIS_MCR(diff,abs_diff,v1,v3,extends);
  471. diff = v3 - v2;
  472. abs_diff = diff.absolute();
  473. //Test With X axis
  474. TEST_CROSS_EDGE_BOX_X_AXIS_MCR(diff,abs_diff,v2,v1,extends);
  475. //Test With Y axis
  476. TEST_CROSS_EDGE_BOX_Y_AXIS_MCR(diff,abs_diff,v2,v1,extends);
  477. //Test With Z axis
  478. TEST_CROSS_EDGE_BOX_Z_AXIS_MCR(diff,abs_diff,v2,v1,extends);
  479. diff = v1 - v3;
  480. abs_diff = diff.absolute();
  481. //Test With X axis
  482. TEST_CROSS_EDGE_BOX_X_AXIS_MCR(diff,abs_diff,v3,v2,extends);
  483. //Test With Y axis
  484. TEST_CROSS_EDGE_BOX_Y_AXIS_MCR(diff,abs_diff,v3,v2,extends);
  485. //Test With Z axis
  486. TEST_CROSS_EDGE_BOX_Z_AXIS_MCR(diff,abs_diff,v3,v2,extends);
  487. return true;
  488. }
  489. };
  490. #ifndef BT_BOX_COLLISION_H_INCLUDED
  491. //! Compairison of transformation objects
  492. SIMD_FORCE_INLINE bool btCompareTransformsEqual(const btTransform & t1,const btTransform & t2)
  493. {
  494. if(!(t1.getOrigin() == t2.getOrigin()) ) return false;
  495. if(!(t1.getBasis().getRow(0) == t2.getBasis().getRow(0)) ) return false;
  496. if(!(t1.getBasis().getRow(1) == t2.getBasis().getRow(1)) ) return false;
  497. if(!(t1.getBasis().getRow(2) == t2.getBasis().getRow(2)) ) return false;
  498. return true;
  499. }
  500. #endif
  501. #endif // GIM_BOX_COLLISION_H_INCLUDED