odemath_legacy.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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_LEGACY_H_
  23. #define _ODE_ODEMATH_LEGACY_H_
  24. /*
  25. * These macros are not used any more inside of ODE
  26. * They are kept for backward compatibility with external code that
  27. * might still be using them.
  28. */
  29. /*
  30. * General purpose vector operations with other vectors or constants.
  31. */
  32. #define dOP(a,op,b,c) do { \
  33. (a)[0] = ((b)[0]) op ((c)[0]); \
  34. (a)[1] = ((b)[1]) op ((c)[1]); \
  35. (a)[2] = ((b)[2]) op ((c)[2]); \
  36. } while (0)
  37. #define dOPC(a,op,b,c) do { \
  38. (a)[0] = ((b)[0]) op (c); \
  39. (a)[1] = ((b)[1]) op (c); \
  40. (a)[2] = ((b)[2]) op (c); \
  41. } while (0)
  42. #define dOPE(a,op,b) do {\
  43. (a)[0] op ((b)[0]); \
  44. (a)[1] op ((b)[1]); \
  45. (a)[2] op ((b)[2]); \
  46. } while (0)
  47. #define dOPEC(a,op,c) do { \
  48. (a)[0] op (c); \
  49. (a)[1] op (c); \
  50. (a)[2] op (c); \
  51. } while (0)
  52. /* Define an equation with operators
  53. * For example this function can be used to replace
  54. * <PRE>
  55. * for (int i=0; i<3; ++i)
  56. * a[i] += b[i] + c[i];
  57. * </PRE>
  58. */
  59. #define dOPE2(a,op1,b,op2,c) do { \
  60. (a)[0] op1 ((b)[0]) op2 ((c)[0]); \
  61. (a)[1] op1 ((b)[1]) op2 ((c)[1]); \
  62. (a)[2] op1 ((b)[2]) op2 ((c)[2]); \
  63. } while (0)
  64. #define dLENGTHSQUARED(a) dCalcVectorLengthSquare3(a)
  65. #define dLENGTH(a) dCalcVectorLength3(a)
  66. #define dDISTANCE(a, b) dCalcPointsDistance3(a, b)
  67. #define dDOT(a, b) dCalcVectorDot3(a, b)
  68. #define dDOT13(a, b) dCalcVectorDot3_13(a, b)
  69. #define dDOT31(a, b) dCalcVectorDot3_31(a, b)
  70. #define dDOT33(a, b) dCalcVectorDot3_33(a, b)
  71. #define dDOT14(a, b) dCalcVectorDot3_14(a, b)
  72. #define dDOT41(a, b) dCalcVectorDot3_41(a, b)
  73. #define dDOT44(a, b) dCalcVectorDot3_44(a, b)
  74. /*
  75. * cross product, set a = b x c. dCROSSpqr means that elements of `a', `b'
  76. * and `c' are spaced p, q and r indexes apart respectively.
  77. * dCROSS() means dCROSS111. `op' is normally `=', but you can set it to
  78. * +=, -= etc to get other effects.
  79. */
  80. #define dCROSS(a,op,b,c) \
  81. do { \
  82. (a)[0] op ((b)[1]*(c)[2] - (b)[2]*(c)[1]); \
  83. (a)[1] op ((b)[2]*(c)[0] - (b)[0]*(c)[2]); \
  84. (a)[2] op ((b)[0]*(c)[1] - (b)[1]*(c)[0]); \
  85. } while(0)
  86. #define dCROSSpqr(a,op,b,c,p,q,r) \
  87. do { \
  88. (a)[ 0] op ((b)[ q]*(c)[2*r] - (b)[2*q]*(c)[ r]); \
  89. (a)[ p] op ((b)[2*q]*(c)[ 0] - (b)[ 0]*(c)[2*r]); \
  90. (a)[2*p] op ((b)[ 0]*(c)[ r] - (b)[ q]*(c)[ 0]); \
  91. } while(0)
  92. #define dCROSS114(a,op,b,c) dCROSSpqr(a,op,b,c,1,1,4)
  93. #define dCROSS141(a,op,b,c) dCROSSpqr(a,op,b,c,1,4,1)
  94. #define dCROSS144(a,op,b,c) dCROSSpqr(a,op,b,c,1,4,4)
  95. #define dCROSS411(a,op,b,c) dCROSSpqr(a,op,b,c,4,1,1)
  96. #define dCROSS414(a,op,b,c) dCROSSpqr(a,op,b,c,4,1,4)
  97. #define dCROSS441(a,op,b,c) dCROSSpqr(a,op,b,c,4,4,1)
  98. #define dCROSS444(a,op,b,c) dCROSSpqr(a,op,b,c,4,4,4)
  99. /*
  100. * set a 3x3 submatrix of A to a matrix such that submatrix(A)*b = a x b.
  101. * A is stored by rows, and has `skip' elements per row. the matrix is
  102. * assumed to be already zero, so this does not write zero elements!
  103. * if (plus,minus) is (+,-) then a positive version will be written.
  104. * if (plus,minus) is (-,+) then a negative version will be written.
  105. */
  106. #define dCROSSMAT(A,a,skip,plus,minus) \
  107. do { \
  108. (A)[1] = minus (a)[2]; \
  109. (A)[2] = plus (a)[1]; \
  110. (A)[(skip)+0] = plus (a)[2]; \
  111. (A)[(skip)+2] = minus (a)[0]; \
  112. (A)[2*(skip)+0] = minus (a)[1]; \
  113. (A)[2*(skip)+1] = plus (a)[0]; \
  114. } while(0)
  115. /*
  116. Note: NEVER call any of these functions/macros with the same variable for A and C,
  117. it is not equivalent to A*=B.
  118. */
  119. #define dMULTIPLY0_331(A, B, C) dMultiply0_331(A, B, C)
  120. #define dMULTIPLY1_331(A, B, C) dMultiply1_331(A, B, C)
  121. #define dMULTIPLY0_133(A, B, C) dMultiply0_133(A, B, C)
  122. #define dMULTIPLY0_333(A, B, C) dMultiply0_333(A, B, C)
  123. #define dMULTIPLY1_333(A, B, C) dMultiply1_333(A, B, C)
  124. #define dMULTIPLY2_333(A, B, C) dMultiply2_333(A, B, C)
  125. #define dMULTIPLYADD0_331(A, B, C) dMultiplyAdd0_331(A, B, C)
  126. #define dMULTIPLYADD1_331(A, B, C) dMultiplyAdd1_331(A, B, C)
  127. #define dMULTIPLYADD0_133(A, B, C) dMultiplyAdd0_133(A, B, C)
  128. #define dMULTIPLYADD0_333(A, B, C) dMultiplyAdd0_333(A, B, C)
  129. #define dMULTIPLYADD1_333(A, B, C) dMultiplyAdd1_333(A, B, C)
  130. #define dMULTIPLYADD2_333(A, B, C) dMultiplyAdd2_333(A, B, C)
  131. /*
  132. * These macros are not used any more inside of ODE
  133. * They are kept for backward compatibility with external code that
  134. * might still be using them.
  135. */
  136. #endif /* #ifndef _ODE_ODEMATH_LEGACY_H_ */