1 /*************************************************************************
3 * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
4 * All rights reserved. Email: russ@q12.org Web: www.q12.org *
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 *
13 * (2) The BSD-style license that is included with this library in *
14 * the file LICENSE-BSD.TXT. *
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. *
21 *************************************************************************/
23 #ifndef _ODE_ODEMATH_LEGACY_H_
24 #define _ODE_ODEMATH_LEGACY_H_
27 ///////////////////////////////////////////////////////////////////////////////
28 ///////////////////////////////////////////////////////////////////////////////
29 ///////////////////////////////////////////////////////////////////////////////
30 ///////////////////////////////////////////////////////////////////////////////
31 ///////////////////////////////////////////////////////////////////////////////
33 * These macros are not used any more inside of ODE
34 * They are kept for backward compatibility with external code that
35 * might still be using them.
37 ///////////////////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////////////
39 ///////////////////////////////////////////////////////////////////////////////
40 ///////////////////////////////////////////////////////////////////////////////
41 ///////////////////////////////////////////////////////////////////////////////
44 * General purpose vector operations with other vectors or constants.
47 #define dOP(a,op,b,c) do { \
48 (a)[0] = ((b)[0]) op ((c)[0]); \
49 (a)[1] = ((b)[1]) op ((c)[1]); \
50 (a)[2] = ((b)[2]) op ((c)[2]); \
52 #define dOPC(a,op,b,c) do { \
53 (a)[0] = ((b)[0]) op (c); \
54 (a)[1] = ((b)[1]) op (c); \
55 (a)[2] = ((b)[2]) op (c); \
57 #define dOPE(a,op,b) do {\
62 #define dOPEC(a,op,c) do { \
68 /// Define an equation with operators
69 /// For example this function can be used to replace
71 /// for (int i=0; i<3; ++i)
72 /// a[i] += b[i] + c[i];
74 #define dOPE2(a,op1,b,op2,c) do { \
75 (a)[0] op1 ((b)[0]) op2 ((c)[0]); \
76 (a)[1] op1 ((b)[1]) op2 ((c)[1]); \
77 (a)[2] op1 ((b)[2]) op2 ((c)[2]); \
81 #define dLENGTHSQUARED(a) dCalcVectorLengthSquare3(a)
82 #define dLENGTH(a) dCalcVectorLength3(a)
83 #define dDISTANCE(a, b) dCalcPointsDistance3(a, b)
86 #define dDOT(a, b) dCalcVectorDot3(a, b)
87 #define dDOT13(a, b) dCalcVectorDot3_13(a, b)
88 #define dDOT31(a, b) dCalcVectorDot3_31(a, b)
89 #define dDOT33(a, b) dCalcVectorDot3_33(a, b)
90 #define dDOT14(a, b) dCalcVectorDot3_14(a, b)
91 #define dDOT41(a, b) dCalcVectorDot3_41(a, b)
92 #define dDOT44(a, b) dCalcVectorDot3_44(a, b)
96 * cross product, set a = b x c. dCROSSpqr means that elements of `a', `b'
97 * and `c' are spaced p, q and r indexes apart respectively.
98 * dCROSS() means dCROSS111. `op' is normally `=', but you can set it to
99 * +=, -= etc to get other effects.
102 #define dCROSS(a,op,b,c) \
104 (a)[0] op ((b)[1]*(c)[2] - (b)[2]*(c)[1]); \
105 (a)[1] op ((b)[2]*(c)[0] - (b)[0]*(c)[2]); \
106 (a)[2] op ((b)[0]*(c)[1] - (b)[1]*(c)[0]); \
108 #define dCROSSpqr(a,op,b,c,p,q,r) \
110 (a)[ 0] op ((b)[ q]*(c)[2*r] - (b)[2*q]*(c)[ r]); \
111 (a)[ p] op ((b)[2*q]*(c)[ 0] - (b)[ 0]*(c)[2*r]); \
112 (a)[2*p] op ((b)[ 0]*(c)[ r] - (b)[ q]*(c)[ 0]); \
114 #define dCROSS114(a,op,b,c) dCROSSpqr(a,op,b,c,1,1,4)
115 #define dCROSS141(a,op,b,c) dCROSSpqr(a,op,b,c,1,4,1)
116 #define dCROSS144(a,op,b,c) dCROSSpqr(a,op,b,c,1,4,4)
117 #define dCROSS411(a,op,b,c) dCROSSpqr(a,op,b,c,4,1,1)
118 #define dCROSS414(a,op,b,c) dCROSSpqr(a,op,b,c,4,1,4)
119 #define dCROSS441(a,op,b,c) dCROSSpqr(a,op,b,c,4,4,1)
120 #define dCROSS444(a,op,b,c) dCROSSpqr(a,op,b,c,4,4,4)
124 * set a 3x3 submatrix of A to a matrix such that submatrix(A)*b = a x b.
125 * A is stored by rows, and has `skip' elements per row. the matrix is
126 * assumed to be already zero, so this does not write zero elements!
127 * if (plus,minus) is (+,-) then a positive version will be written.
128 * if (plus,minus) is (-,+) then a negative version will be written.
131 #define dCROSSMAT(A,a,skip,plus,minus) \
133 (A)[1] = minus (a)[2]; \
134 (A)[2] = plus (a)[1]; \
135 (A)[(skip)+0] = plus (a)[2]; \
136 (A)[(skip)+2] = minus (a)[0]; \
137 (A)[2*(skip)+0] = minus (a)[1]; \
138 (A)[2*(skip)+1] = plus (a)[0]; \
145 Note: NEVER call any of these functions/macros with the same variable for A and C,
146 it is not equivalent to A*=B.
149 #define dMULTIPLY0_331(A, B, C) dMultiply0_331(A, B, C)
150 #define dMULTIPLY1_331(A, B, C) dMultiply1_331(A, B, C)
151 #define dMULTIPLY0_133(A, B, C) dMultiply0_133(A, B, C)
152 #define dMULTIPLY0_333(A, B, C) dMultiply0_333(A, B, C)
153 #define dMULTIPLY1_333(A, B, C) dMultiply1_333(A, B, C)
154 #define dMULTIPLY2_333(A, B, C) dMultiply2_333(A, B, C)
156 #define dMULTIPLYADD0_331(A, B, C) dMultiplyAdd0_331(A, B, C)
157 #define dMULTIPLYADD1_331(A, B, C) dMultiplyAdd1_331(A, B, C)
158 #define dMULTIPLYADD0_133(A, B, C) dMultiplyAdd0_133(A, B, C)
159 #define dMULTIPLYADD0_333(A, B, C) dMultiplyAdd0_333(A, B, C)
160 #define dMULTIPLYADD1_333(A, B, C) dMultiplyAdd1_333(A, B, C)
161 #define dMULTIPLYADD2_333(A, B, C) dMultiplyAdd2_333(A, B, C)
164 ///////////////////////////////////////////////////////////////////////////////
165 ///////////////////////////////////////////////////////////////////////////////
166 ///////////////////////////////////////////////////////////////////////////////
167 ///////////////////////////////////////////////////////////////////////////////
168 ///////////////////////////////////////////////////////////////////////////////
170 * These macros are not used any more inside of ODE
171 * They are kept for backward compatibility with external code that
172 * might still be using them.
174 ///////////////////////////////////////////////////////////////////////////////
175 ///////////////////////////////////////////////////////////////////////////////
176 ///////////////////////////////////////////////////////////////////////////////
177 ///////////////////////////////////////////////////////////////////////////////
178 ///////////////////////////////////////////////////////////////////////////////
181 #endif // #ifndef _ODE_ODEMATH_LEGACY_H_