00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _ODE_ODEMATH_H_
00024 #define _ODE_ODEMATH_H_
00025
00026 #include <ode/common.h>
00027
00028 #ifdef __GNUC__
00029 #define PURE_INLINE extern inline
00030 #else
00031 #define PURE_INLINE inline
00032 #endif
00033
00034
00035
00036
00037
00038 #define dACCESS33(A,i,j) ((A)[(i)*4+(j)])
00039
00040
00041
00042
00043 #define dVALIDVEC3(v) (!(dIsNan(v[0]) || dIsNan(v[1]) || dIsNan(v[2])))
00044 #define dVALIDVEC4(v) (!(dIsNan(v[0]) || dIsNan(v[1]) || dIsNan(v[2]) || dIsNan(v[3])))
00045 #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])))
00046 #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]) ))
00047
00048
00049
00050
00051
00052
00053
00054 #define dOP(a,op,b,c) \
00055 (a)[0] = ((b)[0]) op ((c)[0]); \
00056 (a)[1] = ((b)[1]) op ((c)[1]); \
00057 (a)[2] = ((b)[2]) op ((c)[2]);
00058 #define dOPC(a,op,b,c) \
00059 (a)[0] = ((b)[0]) op (c); \
00060 (a)[1] = ((b)[1]) op (c); \
00061 (a)[2] = ((b)[2]) op (c);
00062 #define dOPE(a,op,b) \
00063 (a)[0] op ((b)[0]); \
00064 (a)[1] op ((b)[1]); \
00065 (a)[2] op ((b)[2]);
00066 #define dOPEC(a,op,c) \
00067 (a)[0] op (c); \
00068 (a)[1] op (c); \
00069 (a)[2] op (c);
00070
00071
00072
00073
00074
00075
00076
00077 #define dLENGTHSQUARED(a) (((a)[0])*((a)[0]) + ((a)[1])*((a)[1]) + ((a)[2])*((a)[2]))
00078
00079 #ifdef __cplusplus
00080
00081 PURE_INLINE dReal dLENGTH (const dReal *a) { return dSqrt(dLENGTHSQUARED(a)); }
00082
00083 #else
00084
00085 #define dLENGTH(a) ( dSqrt( ((a)[0])*((a)[0]) + ((a)[1])*((a)[1]) + ((a)[2])*((a)[2]) ) )
00086
00087 #endif
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 #define dDOTpq(a,b,p,q) ((a)[0]*(b)[0] + (a)[p]*(b)[q] + (a)[2*(p)]*(b)[2*(q)])
00101
00102 #ifdef __cplusplus
00103
00104 PURE_INLINE dReal dDOT (const dReal *a, const dReal *b) { return dDOTpq(a,b,1,1); }
00105 PURE_INLINE dReal dDOT13 (const dReal *a, const dReal *b) { return dDOTpq(a,b,1,3); }
00106 PURE_INLINE dReal dDOT31 (const dReal *a, const dReal *b) { return dDOTpq(a,b,3,1); }
00107 PURE_INLINE dReal dDOT33 (const dReal *a, const dReal *b) { return dDOTpq(a,b,3,3); }
00108 PURE_INLINE dReal dDOT14 (const dReal *a, const dReal *b) { return dDOTpq(a,b,1,4); }
00109 PURE_INLINE dReal dDOT41 (const dReal *a, const dReal *b) { return dDOTpq(a,b,4,1); }
00110 PURE_INLINE dReal dDOT44 (const dReal *a, const dReal *b) { return dDOTpq(a,b,4,4); }
00111
00112 #else
00113
00114 #define dDOT(a,b) dDOTpq(a,b,1,1)
00115 #define dDOT13(a,b) dDOTpq(a,b,1,3)
00116 #define dDOT31(a,b) dDOTpq(a,b,3,1)
00117 #define dDOT33(a,b) dDOTpq(a,b,3,3)
00118 #define dDOT14(a,b) dDOTpq(a,b,1,4)
00119 #define dDOT41(a,b) dDOTpq(a,b,4,1)
00120 #define dDOT44(a,b) dDOTpq(a,b,4,4)
00121
00122 #endif
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 #define dCROSS(a,op,b,c) \
00133 do { \
00134 (a)[0] op ((b)[1]*(c)[2] - (b)[2]*(c)[1]); \
00135 (a)[1] op ((b)[2]*(c)[0] - (b)[0]*(c)[2]); \
00136 (a)[2] op ((b)[0]*(c)[1] - (b)[1]*(c)[0]); \
00137 } while(0)
00138 #define dCROSSpqr(a,op,b,c,p,q,r) \
00139 do { \
00140 (a)[ 0] op ((b)[ q]*(c)[2*r] - (b)[2*q]*(c)[ r]); \
00141 (a)[ p] op ((b)[2*q]*(c)[ 0] - (b)[ 0]*(c)[2*r]); \
00142 (a)[2*p] op ((b)[ 0]*(c)[ r] - (b)[ q]*(c)[ 0]); \
00143 } while(0)
00144 #define dCROSS114(a,op,b,c) dCROSSpqr(a,op,b,c,1,1,4)
00145 #define dCROSS141(a,op,b,c) dCROSSpqr(a,op,b,c,1,4,1)
00146 #define dCROSS144(a,op,b,c) dCROSSpqr(a,op,b,c,1,4,4)
00147 #define dCROSS411(a,op,b,c) dCROSSpqr(a,op,b,c,4,1,1)
00148 #define dCROSS414(a,op,b,c) dCROSSpqr(a,op,b,c,4,1,4)
00149 #define dCROSS441(a,op,b,c) dCROSSpqr(a,op,b,c,4,4,1)
00150 #define dCROSS444(a,op,b,c) dCROSSpqr(a,op,b,c,4,4,4)
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 #define dCROSSMAT(A,a,skip,plus,minus) \
00162 do { \
00163 (A)[1] = minus (a)[2]; \
00164 (A)[2] = plus (a)[1]; \
00165 (A)[(skip)+0] = plus (a)[2]; \
00166 (A)[(skip)+2] = minus (a)[0]; \
00167 (A)[2*(skip)+0] = minus (a)[1]; \
00168 (A)[2*(skip)+1] = plus (a)[0]; \
00169 } while(0)
00170
00171
00172
00173
00174
00175
00176 #ifdef __cplusplus
00177 PURE_INLINE dReal dDISTANCE (const dVector3 a, const dVector3 b)
00178 { return dSqrt( (a[0]-b[0])*(a[0]-b[0]) + (a[1]-b[1])*(a[1]-b[1]) + (a[2]-b[2])*(a[2]-b[2]) ); }
00179 #else
00180 #define dDISTANCE(a,b) \
00181 (dSqrt( ((a)[0]-(b)[0])*((a)[0]-(b)[0]) + ((a)[1]-(b)[1])*((a)[1]-(b)[1]) + ((a)[2]-(b)[2])*((a)[2]-(b)[2]) ))
00182 #endif
00183
00184
00185
00186
00187
00188
00189 #define dMULTIPLYOP0_331(A,op,B,C) \
00190 do { \
00191 (A)[0] op dDOT((B),(C)); \
00192 (A)[1] op dDOT((B+4),(C)); \
00193 (A)[2] op dDOT((B+8),(C)); \
00194 } while(0)
00195 #define dMULTIPLYOP1_331(A,op,B,C) \
00196 do { \
00197 (A)[0] op dDOT41((B),(C)); \
00198 (A)[1] op dDOT41((B+1),(C)); \
00199 (A)[2] op dDOT41((B+2),(C)); \
00200 } while(0)
00201 #define dMULTIPLYOP0_133(A,op,B,C) \
00202 do { \
00203 (A)[0] op dDOT14((B),(C)); \
00204 (A)[1] op dDOT14((B),(C+1)); \
00205 (A)[2] op dDOT14((B),(C+2)); \
00206 } while(0)
00207 #define dMULTIPLYOP0_333(A,op,B,C) \
00208 do { \
00209 (A)[0] op dDOT14((B),(C)); \
00210 (A)[1] op dDOT14((B),(C+1)); \
00211 (A)[2] op dDOT14((B),(C+2)); \
00212 (A)[4] op dDOT14((B+4),(C)); \
00213 (A)[5] op dDOT14((B+4),(C+1)); \
00214 (A)[6] op dDOT14((B+4),(C+2)); \
00215 (A)[8] op dDOT14((B+8),(C)); \
00216 (A)[9] op dDOT14((B+8),(C+1)); \
00217 (A)[10] op dDOT14((B+8),(C+2)); \
00218 } while(0)
00219 #define dMULTIPLYOP1_333(A,op,B,C) \
00220 do { \
00221 (A)[0] op dDOT44((B),(C)); \
00222 (A)[1] op dDOT44((B),(C+1)); \
00223 (A)[2] op dDOT44((B),(C+2)); \
00224 (A)[4] op dDOT44((B+1),(C)); \
00225 (A)[5] op dDOT44((B+1),(C+1)); \
00226 (A)[6] op dDOT44((B+1),(C+2)); \
00227 (A)[8] op dDOT44((B+2),(C)); \
00228 (A)[9] op dDOT44((B+2),(C+1)); \
00229 (A)[10] op dDOT44((B+2),(C+2)); \
00230 } while(0)
00231 #define dMULTIPLYOP2_333(A,op,B,C) \
00232 do { \
00233 (A)[0] op dDOT((B),(C)); \
00234 (A)[1] op dDOT((B),(C+4)); \
00235 (A)[2] op dDOT((B),(C+8)); \
00236 (A)[4] op dDOT((B+4),(C)); \
00237 (A)[5] op dDOT((B+4),(C+4)); \
00238 (A)[6] op dDOT((B+4),(C+8)); \
00239 (A)[8] op dDOT((B+8),(C)); \
00240 (A)[9] op dDOT((B+8),(C+4)); \
00241 (A)[10] op dDOT((B+8),(C+8)); \
00242 } while(0)
00243
00244 #ifdef __cplusplus
00245
00246 #define DECL template <class TA, class TB, class TC> PURE_INLINE void
00247
00248 DECL dMULTIPLY0_331(TA *A, const TB *B, const TC *C) { dMULTIPLYOP0_331(A,=,B,C); }
00249 DECL dMULTIPLY1_331(TA *A, const TB *B, const TC *C) { dMULTIPLYOP1_331(A,=,B,C); }
00250 DECL dMULTIPLY0_133(TA *A, const TB *B, const TC *C) { dMULTIPLYOP0_133(A,=,B,C); }
00251 DECL dMULTIPLY0_333(TA *A, const TB *B, const TC *C) { dMULTIPLYOP0_333(A,=,B,C); }
00252 DECL dMULTIPLY1_333(TA *A, const TB *B, const TC *C) { dMULTIPLYOP1_333(A,=,B,C); }
00253 DECL dMULTIPLY2_333(TA *A, const TB *B, const TC *C) { dMULTIPLYOP2_333(A,=,B,C); }
00254
00255 DECL dMULTIPLYADD0_331(TA *A, const TB *B, const TC *C) { dMULTIPLYOP0_331(A,+=,B,C); }
00256 DECL dMULTIPLYADD1_331(TA *A, const TB *B, const TC *C) { dMULTIPLYOP1_331(A,+=,B,C); }
00257 DECL dMULTIPLYADD0_133(TA *A, const TB *B, const TC *C) { dMULTIPLYOP0_133(A,+=,B,C); }
00258 DECL dMULTIPLYADD0_333(TA *A, const TB *B, const TC *C) { dMULTIPLYOP0_333(A,+=,B,C); }
00259 DECL dMULTIPLYADD1_333(TA *A, const TB *B, const TC *C) { dMULTIPLYOP1_333(A,+=,B,C); }
00260 DECL dMULTIPLYADD2_333(TA *A, const TB *B, const TC *C) { dMULTIPLYOP2_333(A,+=,B,C); }
00261
00262 #undef DECL
00263
00264 #else
00265
00266 #define dMULTIPLY0_331(A,B,C) dMULTIPLYOP0_331(A,=,B,C)
00267 #define dMULTIPLY1_331(A,B,C) dMULTIPLYOP1_331(A,=,B,C)
00268 #define dMULTIPLY0_133(A,B,C) dMULTIPLYOP0_133(A,=,B,C)
00269 #define dMULTIPLY0_333(A,B,C) dMULTIPLYOP0_333(A,=,B,C)
00270 #define dMULTIPLY1_333(A,B,C) dMULTIPLYOP1_333(A,=,B,C)
00271 #define dMULTIPLY2_333(A,B,C) dMULTIPLYOP2_333(A,=,B,C)
00272
00273 #define dMULTIPLYADD0_331(A,B,C) dMULTIPLYOP0_331(A,+=,B,C)
00274 #define dMULTIPLYADD1_331(A,B,C) dMULTIPLYOP1_331(A,+=,B,C)
00275 #define dMULTIPLYADD0_133(A,B,C) dMULTIPLYOP0_133(A,+=,B,C)
00276 #define dMULTIPLYADD0_333(A,B,C) dMULTIPLYOP0_333(A,+=,B,C)
00277 #define dMULTIPLYADD1_333(A,B,C) dMULTIPLYOP1_333(A,+=,B,C)
00278 #define dMULTIPLYADD2_333(A,B,C) dMULTIPLYOP2_333(A,+=,B,C)
00279
00280 #endif
00281
00282
00283 #ifdef __cplusplus
00284 extern "C" {
00285 #endif
00286
00287
00288
00289
00290 ODE_API int dSafeNormalize3 (dVector3 a);
00291 ODE_API int dSafeNormalize4 (dVector4 a);
00292
00293
00294 static __inline void _dNormalize3(dVector3 a)
00295 {
00296 int bNormalizationResult = dSafeNormalize3(a);
00297 dIASSERT(bNormalizationResult);
00298 dVARIABLEUSED(bNormalizationResult);
00299 }
00300
00301 static __inline void _dNormalize4(dVector4 a)
00302 {
00303 int bNormalizationResult = dSafeNormalize4(a);
00304 dIASSERT(bNormalizationResult);
00305 dVARIABLEUSED(bNormalizationResult);
00306 }
00307
00308
00309 ODE_API void dNormalize3 (dVector3 a);
00310 ODE_API void dNormalize4 (dVector4 a);
00311
00312
00313 #define dNormalize3(a) _dNormalize3(a)
00314 #define dNormalize4(a) _dNormalize4(a)
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324 ODE_API void dPlaneSpace (const dVector3 n, dVector3 p, dVector3 q);
00325
00326 #ifdef __cplusplus
00327 }
00328 #endif
00329
00330 #endif