col.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "col.h"
  19. #include "matrix3.h"
  20. #include "vector3.h"
  21. BoxClass::BoxClass(Box box)
  22. {
  23. Center.X = box.center[0];
  24. Center.Y = box.center[1];
  25. Center.Z = box.center[2];
  26. Extent.X = box.extent[0];
  27. Extent.Y = box.extent[1];
  28. Extent.Z = box.extent[2];
  29. Velocity.X = box.velocity[0];
  30. Velocity.Y = box.velocity[1];
  31. Velocity.Z = box.velocity[2];
  32. Basis[0][0] = box.basis[0][0];
  33. Basis[0][1] = box.basis[0][1];
  34. Basis[0][2] = box.basis[0][2];
  35. Basis[1][0] = box.basis[1][0];
  36. Basis[1][1] = box.basis[1][1];
  37. Basis[1][2] = box.basis[1][2];
  38. Basis[2][0] = box.basis[2][0];
  39. Basis[2][1] = box.basis[2][1];
  40. Basis[2][2] = box.basis[2][2];
  41. }
  42. //---------------------------------------------------------------------------
  43. IntersectType Boxes_Intersect(const BoxClass & box0, const BoxClass & box1,float dt)
  44. {
  45. // memoized values for Dot_Product(box0.Basis[i],box1.Basis[j]),
  46. Matrix3 AB;
  47. // calculate difference of centers
  48. Vector3 C = box1.Center - box0.Center;
  49. Vector3 V = box1.Velocity - box0.Velocity;
  50. float ra, rb, rsum, u0, u1;
  51. /////////////////////////////////////////////////////////////////////////
  52. // L = A0
  53. //
  54. // Projecting the two boxes onto Box0's X axis. If their intervals
  55. // on this line do not intersect, the boxes are not intersecting!
  56. // Each of the tests in this function work in a similar way.
  57. /////////////////////////////////////////////////////////////////////////
  58. AB[0][0] = Dot_Product(box0.Basis[0],box1.Basis[0]);
  59. AB[0][1] = Dot_Product(box0.Basis[0],box1.Basis[1]);
  60. AB[0][2] = Dot_Product(box0.Basis[0],box1.Basis[2]);
  61. ra = FABS(box0.Extent[0]);
  62. rb = FABS(box1.Extent[0]*AB[0][0])+FABS(box1.Extent[1]*AB[0][1])+FABS(box1.Extent[2]*AB[0][2]);
  63. rsum = ra+rb;
  64. // u0 = projected distance between the box centers at t0
  65. // u1 = projected distance between the box centers at t1
  66. u0 = Dot_Product(C,box0.Basis[0]);
  67. u1 = u0+dt*Dot_Product(V,box0.Basis[0]);
  68. if ((u0 > rsum && u1 > rsum) || (u0 < -rsum && u1 < -rsum) )
  69. return itA0;
  70. /////////////////////////////////////////////////////////////////////////
  71. // L = A1
  72. // Separating Axis is Box0's Y axis
  73. /////////////////////////////////////////////////////////////////////////
  74. AB[1][0] = Dot_Product(box0.Basis[1],box1.Basis[0]);
  75. AB[1][1] = Dot_Product(box0.Basis[1],box1.Basis[1]);
  76. AB[1][2] = Dot_Product(box0.Basis[1],box1.Basis[2]);
  77. ra = FABS(box0.Extent[1]);
  78. rb = FABS(box1.Extent[0]*AB[1][0])+FABS(box1.Extent[1]*AB[1][1])+FABS(box1.Extent[2]*AB[1][2]);
  79. rsum = ra+rb;
  80. u0 = Dot_Product(C,box0.Basis[1]);
  81. u1 = u0+dt*Dot_Product(V,box0.Basis[1]);
  82. if ((u0 > rsum && u1 > rsum) || (u0 < -rsum && u1 < -rsum) )
  83. return itA1;
  84. /////////////////////////////////////////////////////////////////////////
  85. // L = A2
  86. // Separating Axis is Box0's Y axis
  87. /////////////////////////////////////////////////////////////////////////
  88. AB[2][0] = Dot_Product(box0.Basis[2],box1.Basis[0]);
  89. AB[2][1] = Dot_Product(box0.Basis[2],box1.Basis[1]);
  90. AB[2][2] = Dot_Product(box0.Basis[2],box1.Basis[2]);
  91. ra = FABS(box0.Extent[2]);
  92. rb = FABS(box1.Extent[0]*AB[2][0])+FABS(box1.Extent[1]*AB[2][1])+FABS(box1.Extent[2]*AB[2][2]);
  93. rsum = ra+rb;
  94. u0 = Dot_Product(C,box0.Basis[2]);
  95. u1 = u0+dt*Dot_Product(V,box0.Basis[2]);
  96. if ((u0 > rsum && u1 > rsum) || (u0 < -rsum && u1 < -rsum) )
  97. return itA2;
  98. /////////////////////////////////////////////////////////////////////////
  99. // L = B0
  100. // Separating Axis is Box1's X axis
  101. /////////////////////////////////////////////////////////////////////////
  102. ra = FABS(box0.Extent[0]*AB[0][0])+FABS(box0.Extent[1]*AB[1][0])+FABS(box0.Extent[2]*AB[2][0]);
  103. rb = FABS(box1.Extent[0]);
  104. rsum = ra+rb;
  105. u0 = Dot_Product(C,box1.Basis[0]);
  106. u1 = u0+dt*Dot_Product(V,box1.Basis[0]);
  107. if ((u0 > rsum && u1 > rsum) || (u0 < -rsum && u1 < -rsum) )
  108. return itB0;
  109. /////////////////////////////////////////////////////////////////////////
  110. // L = B1
  111. // Separating Axis is Box1's Y axis
  112. /////////////////////////////////////////////////////////////////////////
  113. ra = FABS(box0.Extent[0]*AB[0][1])+FABS(box0.Extent[1]*AB[1][1])+FABS(box0.Extent[2]*AB[2][1]);
  114. rb = FABS(box1.Extent[1]);
  115. rsum = ra+rb;
  116. u0 = Dot_Product(C,box1.Basis[1]);
  117. u1 = u0+dt*Dot_Product(V,box1.Basis[1]);
  118. if ((u0 > rsum && u1 > rsum) || (u0 < -rsum && u1 < -rsum) )
  119. return itB1;
  120. /////////////////////////////////////////////////////////////////////////
  121. // L = B2
  122. // Separating Axis is Box1's Z axis
  123. /////////////////////////////////////////////////////////////////////////
  124. ra = FABS(box0.Extent[0]*AB[0][2])+FABS(box0.Extent[1]*AB[1][2])+FABS(box0.Extent[2]*AB[2][2]);
  125. rb = FABS(box1.Extent[2]);
  126. rsum = ra+rb;
  127. u0 = Dot_Product(C,box1.Basis[2]);
  128. u1 = u0+dt*Dot_Product(V,box1.Basis[2]);
  129. if ((u0 > rsum && u1 > rsum) || (u0 < -rsum && u1 < -rsum) )
  130. return itB2;
  131. /////////////////////////////////////////////////////////////////////////
  132. // None of the aligned axes turned out to be separating axes. Now
  133. // we check all combinations of cross products of the two boxes axes.
  134. /////////////////////////////////////////////////////////////////////////
  135. Matrix3 Ainv = box0.Basis.Transpose();
  136. Matrix3 coeff = AB.Transpose();
  137. // difference of centers in box0's-basis
  138. Vector3 d0, d1, product;
  139. d0 = Ainv * C;
  140. d1 = Ainv * V;
  141. product = dt*d1;
  142. d1 = d0 + product;
  143. /////////////////////////////////////////////////////////////////////////
  144. // L = A0xB0
  145. /////////////////////////////////////////////////////////////////////////
  146. ra = FABS(box0.Extent[1]*coeff[0][2])+FABS(box0.Extent[2]*coeff[0][1]);
  147. rb = FABS(box1.Extent[1]*coeff[2][0])+FABS(box1.Extent[2]*coeff[1][0]);
  148. rsum = ra+rb;
  149. u0 = d0[2]*coeff[1][0]-d0[1]*coeff[2][0];
  150. u1 = d1[2]*coeff[1][0]-d1[1]*coeff[2][0];
  151. if ((u0 > rsum && u1 > rsum) || (u0 < -rsum && u1 < -rsum) )
  152. return itA0B0;
  153. /////////////////////////////////////////////////////////////////////////
  154. // L = A0xB1
  155. /////////////////////////////////////////////////////////////////////////
  156. ra = FABS(box0.Extent[1]*coeff[1][2])+FABS(box0.Extent[2]*coeff[1][1]);
  157. rb = FABS(box1.Extent[0]*coeff[2][0])+FABS(box1.Extent[2]*coeff[0][0]);
  158. rsum = ra+rb;
  159. u0 = d0[2]*coeff[1][1]-d0[1]*coeff[1][2];
  160. u1 = d1[2]*coeff[1][1]-d1[1]*coeff[1][2];
  161. if ((u0 > rsum && u1 > rsum) || (u0 < -rsum && u1 < -rsum) )
  162. return itA0B1;
  163. /////////////////////////////////////////////////////////////////////////
  164. // L = A0xB2
  165. /////////////////////////////////////////////////////////////////////////
  166. ra = FABS(box0.Extent[1]*coeff[2][2])+FABS(box0.Extent[2]*coeff[2][1]);
  167. rb = FABS(box1.Extent[0]*coeff[1][0])+FABS(box1.Extent[1]*coeff[0][0]);
  168. rsum = ra+rb;
  169. u0 = d0[2]*coeff[2][1]-d0[1]*coeff[2][2];
  170. u1 = d1[2]*coeff[2][1]-d1[1]*coeff[2][2];
  171. if ((u0 > rsum && u1 > rsum) || (u0 < -rsum && u1 < -rsum) )
  172. return itA0B2;
  173. /////////////////////////////////////////////////////////////////////////
  174. // L = A1xB0
  175. /////////////////////////////////////////////////////////////////////////
  176. ra = FABS(box0.Extent[0]*coeff[0][2])+FABS(box0.Extent[2]*coeff[0][0]);
  177. rb = FABS(box1.Extent[1]*coeff[2][1])+FABS(box1.Extent[2]*coeff[1][1]);
  178. rsum = ra+rb;
  179. u0 = d0[0]*coeff[0][2]-d0[2]*coeff[0][0];
  180. u1 = d1[0]*coeff[0][2]-d1[2]*coeff[0][0];
  181. if ((u0 > rsum && u1 > rsum) || (u0 < -rsum && u1 < -rsum) )
  182. return itA1B0;
  183. /////////////////////////////////////////////////////////////////////////
  184. // L = A1xB1
  185. /////////////////////////////////////////////////////////////////////////
  186. ra = FABS(box0.Extent[0]*coeff[1][2])+FABS(box0.Extent[2]*coeff[1][0]);
  187. rb = FABS(box1.Extent[0]*coeff[2][1])+FABS(box1.Extent[2]*coeff[0][1]);
  188. rsum = ra+rb;
  189. u0 = d0[0]*coeff[1][2]-d0[2]*coeff[1][0];
  190. u1 = d1[0]*coeff[1][2]-d1[2]*coeff[1][0];
  191. if ((u0 > rsum && u1 > rsum) || (u0 < -rsum && u1 < -rsum) )
  192. return itA1B1;
  193. /////////////////////////////////////////////////////////////////////////
  194. // L = A1xB2
  195. /////////////////////////////////////////////////////////////////////////
  196. ra = FABS(box0.Extent[0]*coeff[2][2])+FABS(box0.Extent[2]*coeff[2][0]);
  197. rb = FABS(box1.Extent[0]*coeff[1][1])+FABS(box1.Extent[1]*coeff[0][1]);
  198. rsum = ra+rb;
  199. u0 = d0[0]*coeff[2][2]-d0[2]*coeff[2][0];
  200. u1 = d1[0]*coeff[2][2]-d1[2]*coeff[2][0];
  201. if ((u0 > rsum && u1 > rsum) || (u0 < -rsum && u1 < -rsum) )
  202. return itA1B2;
  203. /////////////////////////////////////////////////////////////////////////
  204. // L = A2xB0
  205. /////////////////////////////////////////////////////////////////////////
  206. ra = FABS(box0.Extent[0]*coeff[0][1])+FABS(box0.Extent[1]*coeff[0][0]);
  207. rb = FABS(box1.Extent[1]*coeff[2][2])+FABS(box1.Extent[2]*coeff[1][2]);
  208. rsum = ra+rb;
  209. u0 = d0[1]*coeff[0][0]-d0[0]*coeff[0][1];
  210. u1 = d1[1]*coeff[0][0]-d1[0]*coeff[0][1];
  211. if ((u0 > rsum && u1 > rsum) || (u0 < -rsum && u1 < -rsum) )
  212. return itA2B0;
  213. /////////////////////////////////////////////////////////////////////////
  214. // L = A2xB1
  215. /////////////////////////////////////////////////////////////////////////
  216. ra = FABS(box0.Extent[0]*coeff[1][1])+FABS(box0.Extent[1]*coeff[1][0]);
  217. rb = FABS(box1.Extent[0]*coeff[2][2])+FABS(box1.Extent[2]*coeff[0][2]);
  218. rsum = ra+rb;
  219. u0 = d0[1]*coeff[1][0]-d0[0]*coeff[1][1];
  220. u1 = d1[1]*coeff[1][0]-d1[0]*coeff[1][1];
  221. if ((u0 > rsum && u1 > rsum) || (u0 < -rsum && u1 < -rsum) )
  222. return itA2B1;
  223. /////////////////////////////////////////////////////////////////////////
  224. // L = A2xB2
  225. /////////////////////////////////////////////////////////////////////////
  226. ra = FABS(box0.Extent[0]*coeff[2][1])+FABS(box0.Extent[1]*coeff[2][0]);
  227. rb = FABS(box1.Extent[0]*coeff[1][2])+FABS(box1.Extent[1]*coeff[0][2]);
  228. rsum = ra+rb;
  229. u0 = d0[1]*coeff[2][0]-d0[0]*coeff[2][1];
  230. u1 = d1[1]*coeff[2][0]-d1[0]*coeff[2][1];
  231. if ((u0 > rsum && u1 > rsum) || (u0 < -rsum && u1 < -rsum) )
  232. return itA2B2;
  233. return itIntersects;
  234. }
  235. //---------------------------------------------------------------------------
  236. IntersectType Boxes_Intersect(const BoxClass & box0, const BoxClass & box1)
  237. {
  238. // memoized values for Dot_Product(box0.Basis[i],box1.Basis[j]),
  239. Matrix3 AB;
  240. // calculate difference of centers
  241. Vector3 C = box1.Center - box0.Center;
  242. float ra, rb, rsum, u0;
  243. /////////////////////////////////////////////////////////////////////////
  244. // L = A0
  245. //
  246. // Projecting the two boxes onto Box0's X axis. If their intervals
  247. // on this line do not intersect, the boxes are not intersecting!
  248. // Each of the tests in this function work in a similar way.
  249. /////////////////////////////////////////////////////////////////////////
  250. AB[0][0] = Dot_Product(box0.Basis[0],box1.Basis[0]);
  251. AB[0][1] = Dot_Product(box0.Basis[0],box1.Basis[1]);
  252. AB[0][2] = Dot_Product(box0.Basis[0],box1.Basis[2]);
  253. ra = FABS(box0.Extent[0]);
  254. rb = FABS(box1.Extent[0]*AB[0][0])+FABS(box1.Extent[1]*AB[0][1])+FABS(box1.Extent[2]*AB[0][2]);
  255. rsum = ra+rb;
  256. // u0 = projected distance between the box centers at t0
  257. // u1 = projected distance between the box centers at t1
  258. u0 = Dot_Product(C,box0.Basis[0]);
  259. if ((u0 > rsum) || (u0 < -rsum))
  260. return itA0;
  261. /////////////////////////////////////////////////////////////////////////
  262. // L = A1
  263. // Separating Axis is Box0's Y axis
  264. /////////////////////////////////////////////////////////////////////////
  265. AB[1][0] = Dot_Product(box0.Basis[1],box1.Basis[0]);
  266. AB[1][1] = Dot_Product(box0.Basis[1],box1.Basis[1]);
  267. AB[1][2] = Dot_Product(box0.Basis[1],box1.Basis[2]);
  268. ra = FABS(box0.Extent[1]);
  269. rb = FABS(box1.Extent[0]*AB[1][0])+FABS(box1.Extent[1]*AB[1][1])+FABS(box1.Extent[2]*AB[1][2]);
  270. rsum = ra+rb;
  271. u0 = Dot_Product(C,box0.Basis[1]);
  272. if ((u0 > rsum) || (u0 < -rsum))
  273. return itA1;
  274. /////////////////////////////////////////////////////////////////////////
  275. // L = A2
  276. // Separating Axis is Box0's Y axis
  277. /////////////////////////////////////////////////////////////////////////
  278. AB[2][0] = Dot_Product(box0.Basis[2],box1.Basis[0]);
  279. AB[2][1] = Dot_Product(box0.Basis[2],box1.Basis[1]);
  280. AB[2][2] = Dot_Product(box0.Basis[2],box1.Basis[2]);
  281. ra = FABS(box0.Extent[2]);
  282. rb = FABS(box1.Extent[0]*AB[2][0])+FABS(box1.Extent[1]*AB[2][1])+FABS(box1.Extent[2]*AB[2][2]);
  283. rsum = ra+rb;
  284. u0 = Dot_Product(C,box0.Basis[2]);
  285. if ((u0 > rsum) || (u0 < -rsum))
  286. return itA2;
  287. /////////////////////////////////////////////////////////////////////////
  288. // L = B0
  289. // Separating Axis is Box1's X axis
  290. /////////////////////////////////////////////////////////////////////////
  291. ra = FABS(box0.Extent[0]*AB[0][0])+FABS(box0.Extent[1]*AB[1][0])+FABS(box0.Extent[2]*AB[2][0]);
  292. rb = FABS(box1.Extent[0]);
  293. rsum = ra+rb;
  294. u0 = Dot_Product(C,box1.Basis[0]);
  295. if ((u0 > rsum) || (u0 < -rsum))
  296. return itB0;
  297. /////////////////////////////////////////////////////////////////////////
  298. // L = B1
  299. // Separating Axis is Box1's Y axis
  300. /////////////////////////////////////////////////////////////////////////
  301. ra = FABS(box0.Extent[0]*AB[0][1])+FABS(box0.Extent[1]*AB[1][1])+FABS(box0.Extent[2]*AB[2][1]);
  302. rb = FABS(box1.Extent[1]);
  303. rsum = ra+rb;
  304. u0 = Dot_Product(C,box1.Basis[1]);
  305. if ((u0 > rsum) || (u0 < -rsum))
  306. return itB1;
  307. /////////////////////////////////////////////////////////////////////////
  308. // L = B2
  309. // Separating Axis is Box1's Z axis
  310. /////////////////////////////////////////////////////////////////////////
  311. ra = FABS(box0.Extent[0]*AB[0][2])+FABS(box0.Extent[1]*AB[1][2])+FABS(box0.Extent[2]*AB[2][2]);
  312. rb = FABS(box1.Extent[2]);
  313. rsum = ra+rb;
  314. u0 = Dot_Product(C,box1.Basis[2]);
  315. if ((u0 > rsum) || (u0 < -rsum))
  316. return itB2;
  317. /////////////////////////////////////////////////////////////////////////
  318. // None of the aligned axes turned out to be separating axes. Now
  319. // we check all combinations of cross products of the two boxes axes.
  320. /////////////////////////////////////////////////////////////////////////
  321. Matrix3 Ainv = box0.Basis.Transpose();
  322. Matrix3 coeff = AB.Transpose();
  323. // difference of centers in box0's-basis
  324. Vector3 d0, d1, product;
  325. d0 = Ainv * C;
  326. /////////////////////////////////////////////////////////////////////////
  327. // L = A0xB0
  328. /////////////////////////////////////////////////////////////////////////
  329. ra = FABS(box0.Extent[1]*coeff[0][2])+FABS(box0.Extent[2]*coeff[0][1]);
  330. rb = FABS(box1.Extent[1]*coeff[2][0])+FABS(box1.Extent[2]*coeff[1][0]);
  331. rsum = ra+rb;
  332. u0 = d0[2]*coeff[1][0]-d0[1]*coeff[2][0];
  333. if ((u0 > rsum) || (u0 < -rsum))
  334. return itA0B0;
  335. /////////////////////////////////////////////////////////////////////////
  336. // L = A0xB1
  337. /////////////////////////////////////////////////////////////////////////
  338. ra = FABS(box0.Extent[1]*coeff[1][2])+FABS(box0.Extent[2]*coeff[1][1]);
  339. rb = FABS(box1.Extent[0]*coeff[2][0])+FABS(box1.Extent[2]*coeff[0][0]);
  340. rsum = ra+rb;
  341. u0 = d0[2]*coeff[1][1]-d0[1]*coeff[1][2];
  342. if ((u0 > rsum) || (u0 < -rsum))
  343. return itA0B1;
  344. /////////////////////////////////////////////////////////////////////////
  345. // L = A0xB2
  346. /////////////////////////////////////////////////////////////////////////
  347. ra = FABS(box0.Extent[1]*coeff[2][2])+FABS(box0.Extent[2]*coeff[2][1]);
  348. rb = FABS(box1.Extent[0]*coeff[1][0])+FABS(box1.Extent[1]*coeff[0][0]);
  349. rsum = ra+rb;
  350. u0 = d0[2]*coeff[2][1]-d0[1]*coeff[2][2];
  351. if ((u0 > rsum) || (u0 < -rsum))
  352. return itA0B2;
  353. /////////////////////////////////////////////////////////////////////////
  354. // L = A1xB0
  355. /////////////////////////////////////////////////////////////////////////
  356. ra = FABS(box0.Extent[0]*coeff[0][2])+FABS(box0.Extent[2]*coeff[0][0]);
  357. rb = FABS(box1.Extent[1]*coeff[2][1])+FABS(box1.Extent[2]*coeff[1][1]);
  358. rsum = ra+rb;
  359. u0 = d0[0]*coeff[0][2]-d0[2]*coeff[0][0];
  360. if ((u0 > rsum) || (u0 < -rsum))
  361. return itA1B0;
  362. /////////////////////////////////////////////////////////////////////////
  363. // L = A1xB1
  364. /////////////////////////////////////////////////////////////////////////
  365. ra = FABS(box0.Extent[0]*coeff[1][2])+FABS(box0.Extent[2]*coeff[1][0]);
  366. rb = FABS(box1.Extent[0]*coeff[2][1])+FABS(box1.Extent[2]*coeff[0][1]);
  367. rsum = ra+rb;
  368. u0 = d0[0]*coeff[1][2]-d0[2]*coeff[1][0];
  369. if ((u0 > rsum) || (u0 < -rsum))
  370. return itA1B1;
  371. /////////////////////////////////////////////////////////////////////////
  372. // L = A1xB2
  373. /////////////////////////////////////////////////////////////////////////
  374. ra = FABS(box0.Extent[0]*coeff[2][2])+FABS(box0.Extent[2]*coeff[2][0]);
  375. rb = FABS(box1.Extent[0]*coeff[1][1])+FABS(box1.Extent[1]*coeff[0][1]);
  376. rsum = ra+rb;
  377. u0 = d0[0]*coeff[2][2]-d0[2]*coeff[2][0];
  378. if ((u0 > rsum) || (u0 < -rsum))
  379. return itA1B2;
  380. /////////////////////////////////////////////////////////////////////////
  381. // L = A2xB0
  382. /////////////////////////////////////////////////////////////////////////
  383. ra = FABS(box0.Extent[0]*coeff[0][1])+FABS(box0.Extent[1]*coeff[0][0]);
  384. rb = FABS(box1.Extent[1]*coeff[2][2])+FABS(box1.Extent[2]*coeff[1][2]);
  385. rsum = ra+rb;
  386. u0 = d0[1]*coeff[0][0]-d0[0]*coeff[0][1];
  387. if ((u0 > rsum) || (u0 < -rsum))
  388. return itA2B0;
  389. /////////////////////////////////////////////////////////////////////////
  390. // L = A2xB1
  391. /////////////////////////////////////////////////////////////////////////
  392. ra = FABS(box0.Extent[0]*coeff[1][1])+FABS(box0.Extent[1]*coeff[1][0]);
  393. rb = FABS(box1.Extent[0]*coeff[2][2])+FABS(box1.Extent[2]*coeff[0][2]);
  394. rsum = ra+rb;
  395. u0 = d0[1]*coeff[1][0]-d0[0]*coeff[1][1];
  396. if ((u0 > rsum) || (u0 < -rsum))
  397. return itA2B1;
  398. /////////////////////////////////////////////////////////////////////////
  399. // L = A2xB2
  400. /////////////////////////////////////////////////////////////////////////
  401. ra = FABS(box0.Extent[0]*coeff[2][1])+FABS(box0.Extent[1]*coeff[2][0]);
  402. rb = FABS(box1.Extent[0]*coeff[1][2])+FABS(box1.Extent[1]*coeff[0][2]);
  403. rsum = ra+rb;
  404. u0 = d0[1]*coeff[2][0]-d0[0]*coeff[2][1];
  405. if ((u0 > rsum) || (u0 < -rsum))
  406. return itA2B2;
  407. return itIntersects;
  408. }