odemath.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. /*************************************************************************
  2. * *
  3. * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
  4. * All rights reserved. Email: [email protected] Web: www.q12.org *
  5. * *
  6. * This library is free software; you can redistribute it and/or *
  7. * modify it under the terms of EITHER: *
  8. * (1) The GNU Lesser General Public License as published by the Free *
  9. * Software Foundation; either version 2.1 of the License, or (at *
  10. * your option) any later version. The text of the GNU Lesser *
  11. * General Public License is included with this library in the *
  12. * file LICENSE.TXT. *
  13. * (2) The BSD-style license that is included with this library in *
  14. * the file LICENSE-BSD.TXT. *
  15. * *
  16. * This library is distributed in the hope that it will be useful, *
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
  19. * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
  20. * *
  21. *************************************************************************/
  22. #ifndef _ODE_ODEMATH_H_
  23. #define _ODE_ODEMATH_H_
  24. #include <ode/common.h>
  25. /*
  26. * macro to access elements i,j in an NxM matrix A, independent of the
  27. * matrix storage convention.
  28. */
  29. #define dACCESS33(A,i,j) ((A)[(i)*4+(j)])
  30. /*
  31. * Macro to test for valid floating point values
  32. */
  33. #define dVALIDVEC3(v) (!(dIsNan(v[0]) || dIsNan(v[1]) || dIsNan(v[2])))
  34. #define dVALIDVEC4(v) (!(dIsNan(v[0]) || dIsNan(v[1]) || dIsNan(v[2]) || dIsNan(v[3])))
  35. #define dVALIDMAT3(m) (!(dIsNan(m[0]) || dIsNan(m[1]) || dIsNan(m[2]) || dIsNan(m[3]) || dIsNan(m[4]) || dIsNan(m[5]) || dIsNan(m[6]) || dIsNan(m[7]) || dIsNan(m[8]) || dIsNan(m[9]) || dIsNan(m[10]) || dIsNan(m[11])))
  36. #define dVALIDMAT4(m) (!(dIsNan(m[0]) || dIsNan(m[1]) || dIsNan(m[2]) || dIsNan(m[3]) || dIsNan(m[4]) || dIsNan(m[5]) || dIsNan(m[6]) || dIsNan(m[7]) || dIsNan(m[8]) || dIsNan(m[9]) || dIsNan(m[10]) || dIsNan(m[11]) || dIsNan(m[12]) || dIsNan(m[13]) || dIsNan(m[14]) || dIsNan(m[15]) ))
  37. /* Some vector math */
  38. ODE_PURE_INLINE void dAddVectors3(dReal *res, const dReal *a, const dReal *b)
  39. {
  40. const dReal res_0 = a[0] + b[0];
  41. const dReal res_1 = a[1] + b[1];
  42. const dReal res_2 = a[2] + b[2];
  43. /* Only assign after all the calculations are over to avoid incurring memory aliasing*/
  44. res[0] = res_0; res[1] = res_1; res[2] = res_2;
  45. }
  46. ODE_PURE_INLINE void dSubtractVectors3(dReal *res, const dReal *a, const dReal *b)
  47. {
  48. const dReal res_0 = a[0] - b[0];
  49. const dReal res_1 = a[1] - b[1];
  50. const dReal res_2 = a[2] - b[2];
  51. /* Only assign after all the calculations are over to avoid incurring memory aliasing*/
  52. res[0] = res_0; res[1] = res_1; res[2] = res_2;
  53. }
  54. ODE_PURE_INLINE void dAddScaledVectors3(dReal *res, const dReal *a, const dReal *b, dReal a_scale, dReal b_scale)
  55. {
  56. const dReal res_0 = a_scale * a[0] + b_scale * b[0];
  57. const dReal res_1 = a_scale * a[1] + b_scale * b[1];
  58. const dReal res_2 = a_scale * a[2] + b_scale * b[2];
  59. /* Only assign after all the calculations are over to avoid incurring memory aliasing*/
  60. res[0] = res_0; res[1] = res_1; res[2] = res_2;
  61. }
  62. ODE_PURE_INLINE void dScaleVector3(dReal *res, dReal nScale)
  63. {
  64. res[0] *= nScale ;
  65. res[1] *= nScale ;
  66. res[2] *= nScale ;
  67. }
  68. ODE_PURE_INLINE void dNegateVector3(dReal *res)
  69. {
  70. res[0] = -res[0];
  71. res[1] = -res[1];
  72. res[2] = -res[2];
  73. }
  74. ODE_PURE_INLINE void dCopyVector3(dReal *res, const dReal *a)
  75. {
  76. const dReal res_0 = a[0];
  77. const dReal res_1 = a[1];
  78. const dReal res_2 = a[2];
  79. /* Only assign after all the calculations are over to avoid incurring memory aliasing*/
  80. res[0] = res_0; res[1] = res_1; res[2] = res_2;
  81. }
  82. ODE_PURE_INLINE void dCopyScaledVector3(dReal *res, const dReal *a, dReal nScale)
  83. {
  84. const dReal res_0 = a[0] * nScale;
  85. const dReal res_1 = a[1] * nScale;
  86. const dReal res_2 = a[2] * nScale;
  87. /* Only assign after all the calculations are over to avoid incurring memory aliasing*/
  88. res[0] = res_0; res[1] = res_1; res[2] = res_2;
  89. }
  90. ODE_PURE_INLINE void dCopyNegatedVector3(dReal *res, const dReal *a)
  91. {
  92. const dReal res_0 = -a[0];
  93. const dReal res_1 = -a[1];
  94. const dReal res_2 = -a[2];
  95. /* Only assign after all the calculations are over to avoid incurring memory aliasing*/
  96. res[0] = res_0; res[1] = res_1; res[2] = res_2;
  97. }
  98. ODE_PURE_INLINE void dCopyVector4(dReal *res, const dReal *a)
  99. {
  100. const dReal res_0 = a[0];
  101. const dReal res_1 = a[1];
  102. const dReal res_2 = a[2];
  103. const dReal res_3 = a[3];
  104. /* Only assign after all the calculations are over to avoid incurring memory aliasing*/
  105. res[0] = res_0; res[1] = res_1; res[2] = res_2; res[3] = res_3;
  106. }
  107. ODE_PURE_INLINE void dCopyMatrix4x4(dReal *res, const dReal *a)
  108. {
  109. dCopyVector4(res + 0, a + 0);
  110. dCopyVector4(res + 4, a + 4);
  111. dCopyVector4(res + 8, a + 8);
  112. }
  113. ODE_PURE_INLINE void dCopyMatrix4x3(dReal *res, const dReal *a)
  114. {
  115. dCopyVector3(res + 0, a + 0);
  116. dCopyVector3(res + 4, a + 4);
  117. dCopyVector3(res + 8, a + 8);
  118. }
  119. ODE_PURE_INLINE void dGetMatrixColumn3(dReal *res, const dReal *a, unsigned n)
  120. {
  121. const dReal res_0 = a[n + 0];
  122. const dReal res_1 = a[n + 4];
  123. const dReal res_2 = a[n + 8];
  124. /* Only assign after all the calculations are over to avoid incurring memory aliasing*/
  125. res[0] = res_0; res[1] = res_1; res[2] = res_2;
  126. }
  127. ODE_PURE_INLINE dReal dCalcVectorLength3(const dReal *a)
  128. {
  129. return dSqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]);
  130. }
  131. ODE_PURE_INLINE dReal dCalcVectorLengthSquare3(const dReal *a)
  132. {
  133. return (a[0] * a[0] + a[1] * a[1] + a[2] * a[2]);
  134. }
  135. ODE_PURE_INLINE dReal dCalcPointDepth3(const dReal *test_p, const dReal *plane_p, const dReal *plane_n)
  136. {
  137. return (plane_p[0] - test_p[0]) * plane_n[0] + (plane_p[1] - test_p[1]) * plane_n[1] + (plane_p[2] - test_p[2]) * plane_n[2];
  138. }
  139. /*
  140. * 3-way dot product. _dCalcVectorDot3 means that elements of `a' and `b' are spaced
  141. * step_a and step_b indexes apart respectively. dCalcVectorDot3() means dDot311.
  142. */
  143. ODE_PURE_INLINE dReal _dCalcVectorDot3(const dReal *a, const dReal *b, unsigned step_a, unsigned step_b)
  144. {
  145. return a[0] * b[0] + a[step_a] * b[step_b] + a[2 * step_a] * b[2 * step_b];
  146. }
  147. ODE_PURE_INLINE dReal dCalcVectorDot3 (const dReal *a, const dReal *b) { return _dCalcVectorDot3(a,b,1,1); }
  148. ODE_PURE_INLINE dReal dCalcVectorDot3_13 (const dReal *a, const dReal *b) { return _dCalcVectorDot3(a,b,1,3); }
  149. ODE_PURE_INLINE dReal dCalcVectorDot3_31 (const dReal *a, const dReal *b) { return _dCalcVectorDot3(a,b,3,1); }
  150. ODE_PURE_INLINE dReal dCalcVectorDot3_33 (const dReal *a, const dReal *b) { return _dCalcVectorDot3(a,b,3,3); }
  151. ODE_PURE_INLINE dReal dCalcVectorDot3_14 (const dReal *a, const dReal *b) { return _dCalcVectorDot3(a,b,1,4); }
  152. ODE_PURE_INLINE dReal dCalcVectorDot3_41 (const dReal *a, const dReal *b) { return _dCalcVectorDot3(a,b,4,1); }
  153. ODE_PURE_INLINE dReal dCalcVectorDot3_44 (const dReal *a, const dReal *b) { return _dCalcVectorDot3(a,b,4,4); }
  154. /*
  155. * cross product, set res = a x b. _dCalcVectorCross3 means that elements of `res', `a'
  156. * and `b' are spaced step_res, step_a and step_b indexes apart respectively.
  157. * dCalcVectorCross3() means dCross3111.
  158. */
  159. ODE_PURE_INLINE void _dCalcVectorCross3(dReal *res, const dReal *a, const dReal *b, unsigned step_res, unsigned step_a, unsigned step_b)
  160. {
  161. const dReal res_0 = a[ step_a]*b[2*step_b] - a[2*step_a]*b[ step_b];
  162. const dReal res_1 = a[2*step_a]*b[ 0] - a[ 0]*b[2*step_b];
  163. const dReal res_2 = a[ 0]*b[ step_b] - a[ step_a]*b[ 0];
  164. /* Only assign after all the calculations are over to avoid incurring memory aliasing*/
  165. res[ 0] = res_0;
  166. res[ step_res] = res_1;
  167. res[2*step_res] = res_2;
  168. }
  169. ODE_PURE_INLINE void dCalcVectorCross3 (dReal *res, const dReal *a, const dReal *b) { _dCalcVectorCross3(res, a, b, 1, 1, 1); }
  170. ODE_PURE_INLINE void dCalcVectorCross3_114(dReal *res, const dReal *a, const dReal *b) { _dCalcVectorCross3(res, a, b, 1, 1, 4); }
  171. ODE_PURE_INLINE void dCalcVectorCross3_141(dReal *res, const dReal *a, const dReal *b) { _dCalcVectorCross3(res, a, b, 1, 4, 1); }
  172. ODE_PURE_INLINE void dCalcVectorCross3_144(dReal *res, const dReal *a, const dReal *b) { _dCalcVectorCross3(res, a, b, 1, 4, 4); }
  173. ODE_PURE_INLINE void dCalcVectorCross3_411(dReal *res, const dReal *a, const dReal *b) { _dCalcVectorCross3(res, a, b, 4, 1, 1); }
  174. ODE_PURE_INLINE void dCalcVectorCross3_414(dReal *res, const dReal *a, const dReal *b) { _dCalcVectorCross3(res, a, b, 4, 1, 4); }
  175. ODE_PURE_INLINE void dCalcVectorCross3_441(dReal *res, const dReal *a, const dReal *b) { _dCalcVectorCross3(res, a, b, 4, 4, 1); }
  176. ODE_PURE_INLINE void dCalcVectorCross3_444(dReal *res, const dReal *a, const dReal *b) { _dCalcVectorCross3(res, a, b, 4, 4, 4); }
  177. ODE_PURE_INLINE void dAddVectorCross3(dReal *res, const dReal *a, const dReal *b)
  178. {
  179. dReal tmp[3];
  180. dCalcVectorCross3(tmp, a, b);
  181. dAddVectors3(res, res, tmp);
  182. }
  183. ODE_PURE_INLINE void dSubtractVectorCross3(dReal *res, const dReal *a, const dReal *b)
  184. {
  185. dReal tmp[3];
  186. dCalcVectorCross3(tmp, a, b);
  187. dSubtractVectors3(res, res, tmp);
  188. }
  189. /*
  190. * set a 3x3 submatrix of A to a matrix such that submatrix(A)*b = a x b.
  191. * A is stored by rows, and has `skip' elements per row. the matrix is
  192. * assumed to be already zero, so this does not write zero elements!
  193. * if (plus,minus) is (+,-) then a positive version will be written.
  194. * if (plus,minus) is (-,+) then a negative version will be written.
  195. */
  196. ODE_PURE_INLINE void dSetCrossMatrixPlus(dReal *res, const dReal *a, unsigned skip)
  197. {
  198. const dReal a_0 = a[0], a_1 = a[1], a_2 = a[2];
  199. res[1] = -a_2;
  200. res[2] = +a_1;
  201. res[skip+0] = +a_2;
  202. res[skip+2] = -a_0;
  203. res[2*skip+0] = -a_1;
  204. res[2*skip+1] = +a_0;
  205. }
  206. ODE_PURE_INLINE void dSetCrossMatrixMinus(dReal *res, const dReal *a, unsigned skip)
  207. {
  208. const dReal a_0 = a[0], a_1 = a[1], a_2 = a[2];
  209. res[1] = +a_2;
  210. res[2] = -a_1;
  211. res[skip+0] = -a_2;
  212. res[skip+2] = +a_0;
  213. res[2*skip+0] = +a_1;
  214. res[2*skip+1] = -a_0;
  215. }
  216. /*
  217. * compute the distance between two 3D-vectors
  218. */
  219. ODE_PURE_INLINE dReal dCalcPointsDistance3(const dReal *a, const dReal *b)
  220. {
  221. dReal res;
  222. dReal tmp[3];
  223. dSubtractVectors3(tmp, a, b);
  224. res = dCalcVectorLength3(tmp);
  225. return res;
  226. }
  227. /*
  228. * special case matrix multiplication, with operator selection
  229. */
  230. ODE_PURE_INLINE void dMultiplyHelper0_331(dReal *res, const dReal *a, const dReal *b)
  231. {
  232. const dReal res_0 = dCalcVectorDot3(a, b);
  233. const dReal res_1 = dCalcVectorDot3(a + 4, b);
  234. const dReal res_2 = dCalcVectorDot3(a + 8, b);
  235. /* Only assign after all the calculations are over to avoid incurring memory aliasing*/
  236. res[0] = res_0; res[1] = res_1; res[2] = res_2;
  237. }
  238. ODE_PURE_INLINE void dMultiplyHelper1_331(dReal *res, const dReal *a, const dReal *b)
  239. {
  240. const dReal res_0 = dCalcVectorDot3_41(a, b);
  241. const dReal res_1 = dCalcVectorDot3_41(a + 1, b);
  242. const dReal res_2 = dCalcVectorDot3_41(a + 2, b);
  243. /* Only assign after all the calculations are over to avoid incurring memory aliasing*/
  244. res[0] = res_0; res[1] = res_1; res[2] = res_2;
  245. }
  246. ODE_PURE_INLINE void dMultiplyHelper0_133(dReal *res, const dReal *a, const dReal *b)
  247. {
  248. dMultiplyHelper1_331(res, b, a);
  249. }
  250. ODE_PURE_INLINE void dMultiplyHelper1_133(dReal *res, const dReal *a, const dReal *b)
  251. {
  252. const dReal res_0 = dCalcVectorDot3_44(a, b);
  253. const dReal res_1 = dCalcVectorDot3_44(a + 1, b);
  254. const dReal res_2 = dCalcVectorDot3_44(a + 2, b);
  255. /* Only assign after all the calculations are over to avoid incurring memory aliasing*/
  256. res[0] = res_0; res[1] = res_1; res[2] = res_2;
  257. }
  258. /*
  259. Note: NEVER call any of these functions/macros with the same variable for A and C,
  260. it is not equivalent to A*=B.
  261. */
  262. ODE_PURE_INLINE void dMultiply0_331(dReal *res, const dReal *a, const dReal *b)
  263. {
  264. dMultiplyHelper0_331(res, a, b);
  265. }
  266. ODE_PURE_INLINE void dMultiply1_331(dReal *res, const dReal *a, const dReal *b)
  267. {
  268. dMultiplyHelper1_331(res, a, b);
  269. }
  270. ODE_PURE_INLINE void dMultiply0_133(dReal *res, const dReal *a, const dReal *b)
  271. {
  272. dMultiplyHelper0_133(res, a, b);
  273. }
  274. ODE_PURE_INLINE void dMultiply0_333(dReal *res, const dReal *a, const dReal *b)
  275. {
  276. dMultiplyHelper0_133(res + 0, a + 0, b);
  277. dMultiplyHelper0_133(res + 4, a + 4, b);
  278. dMultiplyHelper0_133(res + 8, a + 8, b);
  279. }
  280. ODE_PURE_INLINE void dMultiply1_333(dReal *res, const dReal *a, const dReal *b)
  281. {
  282. dMultiplyHelper1_133(res + 0, b, a + 0);
  283. dMultiplyHelper1_133(res + 4, b, a + 1);
  284. dMultiplyHelper1_133(res + 8, b, a + 2);
  285. }
  286. ODE_PURE_INLINE void dMultiply2_333(dReal *res, const dReal *a, const dReal *b)
  287. {
  288. dMultiplyHelper0_331(res + 0, b, a + 0);
  289. dMultiplyHelper0_331(res + 4, b, a + 4);
  290. dMultiplyHelper0_331(res + 8, b, a + 8);
  291. }
  292. ODE_PURE_INLINE void dMultiplyAdd0_331(dReal *res, const dReal *a, const dReal *b)
  293. {
  294. dReal tmp[3];
  295. dMultiplyHelper0_331(tmp, a, b);
  296. dAddVectors3(res, res, tmp);
  297. }
  298. ODE_PURE_INLINE void dMultiplyAdd1_331(dReal *res, const dReal *a, const dReal *b)
  299. {
  300. dReal tmp[3];
  301. dMultiplyHelper1_331(tmp, a, b);
  302. dAddVectors3(res, res, tmp);
  303. }
  304. ODE_PURE_INLINE void dMultiplyAdd0_133(dReal *res, const dReal *a, const dReal *b)
  305. {
  306. dReal tmp[3];
  307. dMultiplyHelper0_133(tmp, a, b);
  308. dAddVectors3(res, res, tmp);
  309. }
  310. ODE_PURE_INLINE void dMultiplyAdd0_333(dReal *res, const dReal *a, const dReal *b)
  311. {
  312. dReal tmp[3];
  313. dMultiplyHelper0_133(tmp, a + 0, b);
  314. dAddVectors3(res+ 0, res + 0, tmp);
  315. dMultiplyHelper0_133(tmp, a + 4, b);
  316. dAddVectors3(res + 4, res + 4, tmp);
  317. dMultiplyHelper0_133(tmp, a + 8, b);
  318. dAddVectors3(res + 8, res + 8, tmp);
  319. }
  320. ODE_PURE_INLINE void dMultiplyAdd1_333(dReal *res, const dReal *a, const dReal *b)
  321. {
  322. dReal tmp[3];
  323. dMultiplyHelper1_133(tmp, b, a + 0);
  324. dAddVectors3(res + 0, res + 0, tmp);
  325. dMultiplyHelper1_133(tmp, b, a + 1);
  326. dAddVectors3(res + 4, res + 4, tmp);
  327. dMultiplyHelper1_133(tmp, b, a + 2);
  328. dAddVectors3(res + 8, res + 8, tmp);
  329. }
  330. ODE_PURE_INLINE void dMultiplyAdd2_333(dReal *res, const dReal *a, const dReal *b)
  331. {
  332. dReal tmp[3];
  333. dMultiplyHelper0_331(tmp, b, a + 0);
  334. dAddVectors3(res + 0, res + 0, tmp);
  335. dMultiplyHelper0_331(tmp, b, a + 4);
  336. dAddVectors3(res + 4, res + 4, tmp);
  337. dMultiplyHelper0_331(tmp, b, a + 8);
  338. dAddVectors3(res + 8, res + 8, tmp);
  339. }
  340. ODE_PURE_INLINE dReal dCalcMatrix3Det( const dReal* mat )
  341. {
  342. dReal det;
  343. det = mat[0] * ( mat[5]*mat[10] - mat[9]*mat[6] )
  344. - mat[1] * ( mat[4]*mat[10] - mat[8]*mat[6] )
  345. + mat[2] * ( mat[4]*mat[9] - mat[8]*mat[5] );
  346. return( det );
  347. }
  348. /**
  349. Closed form matrix inversion, copied from
  350. collision_util.h for use in the stepper.
  351. Returns the determinant.
  352. returns 0 and does nothing
  353. if the matrix is singular.
  354. */
  355. ODE_PURE_INLINE dReal dInvertMatrix3(dReal *dst, const dReal *ma)
  356. {
  357. dReal det;
  358. dReal detRecip;
  359. det = dCalcMatrix3Det( ma );
  360. /* Setting an arbitrary non-zero threshold
  361. for the determinant doesn't do anyone
  362. any favors. The condition number is the
  363. important thing. If all the eigen-values
  364. of the matrix are small, so is the
  365. determinant, but it can still be well
  366. conditioned.
  367. A single extremely large eigen-value could
  368. push the determinant over threshold, but
  369. produce a very unstable result if the other
  370. eigen-values are small. So we just say that
  371. the determinant must be non-zero and trust the
  372. caller to provide well-conditioned matrices.
  373. */
  374. if ( det == 0 )
  375. {
  376. return 0;
  377. }
  378. detRecip = dRecip(det);
  379. dst[0] = ( ma[5]*ma[10] - ma[6]*ma[9] ) * detRecip;
  380. dst[1] = ( ma[9]*ma[2] - ma[1]*ma[10] ) * detRecip;
  381. dst[2] = ( ma[1]*ma[6] - ma[5]*ma[2] ) * detRecip;
  382. dst[4] = ( ma[6]*ma[8] - ma[4]*ma[10] ) * detRecip;
  383. dst[5] = ( ma[0]*ma[10] - ma[8]*ma[2] ) * detRecip;
  384. dst[6] = ( ma[4]*ma[2] - ma[0]*ma[6] ) * detRecip;
  385. dst[8] = ( ma[4]*ma[9] - ma[8]*ma[5] ) * detRecip;
  386. dst[9] = ( ma[8]*ma[1] - ma[0]*ma[9] ) * detRecip;
  387. dst[10] = ( ma[0]*ma[5] - ma[1]*ma[4] ) * detRecip;
  388. return det;
  389. }
  390. /* Include legacy macros here */
  391. #include <ode/odemath_legacy.h>
  392. #ifdef __cplusplus
  393. extern "C" {
  394. #endif
  395. /*
  396. * normalize 3x1 and 4x1 vectors (i.e. scale them to unit length)
  397. */
  398. /* For DLL export*/
  399. ODE_API int dSafeNormalize3 (dVector3 a);
  400. ODE_API int dSafeNormalize4 (dVector4 a);
  401. ODE_API void dNormalize3 (dVector3 a); /* Potentially asserts on zero vec*/
  402. ODE_API void dNormalize4 (dVector4 a); /* Potentially asserts on zero vec*/
  403. /*
  404. * given a unit length "normal" vector n, generate vectors p and q vectors
  405. * that are an orthonormal basis for the plane space perpendicular to n.
  406. * i.e. this makes p,q such that n,p,q are all perpendicular to each other.
  407. * q will equal n x p. if n is not unit length then p will be unit length but
  408. * q wont be.
  409. */
  410. ODE_API void dPlaneSpace (const dVector3 n, dVector3 p, dVector3 q);
  411. /* Makes sure the matrix is a proper rotation */
  412. ODE_API void dOrthogonalizeR(dMatrix3 m);
  413. #ifdef __cplusplus
  414. }
  415. #endif
  416. #endif