Back to index

supertuxkart  0.5+dfsg1
btOdeMacros.h
Go to the documentation of this file.
00001 /*
00002  * Quickstep constraint solver re-distributed under the ZLib license with permission from Russell L. Smith
00003  * Original version is from Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith.
00004  * All rights reserved.  Email: russ@q12.org   Web: www.q12.org
00005  Bullet Continuous Collision Detection and Physics Library
00006  Bullet is Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
00007 
00008 This software is provided 'as-is', without any express or implied warranty.
00009 In no event will the authors be held liable for any damages arising from the use of this software.
00010 Permission is granted to anyone to use this software for any purpose, 
00011 including commercial applications, and to alter it and redistribute it freely, 
00012 subject to the following restrictions:
00013 
00014 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
00015 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
00016 3. This notice may not be removed or altered from any source distribution.
00017 */
00018 
00019 #define ODE_MACROS
00020 #ifdef ODE_MACROS
00021 
00022 #include "LinearMath/btScalar.h"
00023 
00024 typedef btScalar dVector4[4];
00025 typedef btScalar dMatrix3[4*3];
00026 #define dInfinity FLT_MAX
00027 
00028 
00029 
00030 #define dRecip(x) ((float)(1.0f/(x)))                          /* reciprocal */
00031 
00032 
00033 
00034 #define dMULTIPLY0_331NEW(A,op,B,C) \
00035 {\
00036        btScalar tmp[3];\
00037        tmp[0] = C.getX();\
00038        tmp[1] = C.getY();\
00039        tmp[2] = C.getZ();\
00040        dMULTIPLYOP0_331(A,op,B,tmp);\
00041 }
00042 
00043 #define dMULTIPLY0_331(A,B,C) dMULTIPLYOP0_331(A,=,B,C)
00044 #define dMULTIPLYOP0_331(A,op,B,C) \
00045   (A)[0] op dDOT1((B),(C)); \
00046   (A)[1] op dDOT1((B+4),(C)); \
00047   (A)[2] op dDOT1((B+8),(C));
00048 
00049 #define dAASSERT btAssert
00050 #define dIASSERT btAssert
00051 
00052 #define REAL float
00053 #define dDOTpq(a,b,p,q) ((a)[0]*(b)[0] + (a)[p]*(b)[q] + (a)[2*(p)]*(b)[2*(q)])
00054 inline btScalar dDOT1 (const btScalar *a, const btScalar *b)
00055 { return dDOTpq(a,b,1,1); }
00056 #define dDOT14(a,b) dDOTpq(a,b,1,4)
00057 
00058 #define dCROSS(a,op,b,c) \
00059   (a)[0] op ((b)[1]*(c)[2] - (b)[2]*(c)[1]); \
00060   (a)[1] op ((b)[2]*(c)[0] - (b)[0]*(c)[2]); \
00061   (a)[2] op ((b)[0]*(c)[1] - (b)[1]*(c)[0]);
00062 
00063 /*
00064  * set a 3x3 submatrix of A to a matrix such that submatrix(A)*b = a x b.
00065  * A is stored by rows, and has `skip' elements per row. the matrix is
00066  * assumed to be already zero, so this does not write zero elements!
00067  * if (plus,minus) is (+,-) then a positive version will be written.
00068  * if (plus,minus) is (-,+) then a negative version will be written.
00069  */
00070 
00071 #define dCROSSMAT(A,a,skip,plus,minus) \
00072 do { \
00073   (A)[1] = minus (a)[2]; \
00074   (A)[2] = plus (a)[1]; \
00075   (A)[(skip)+0] = plus (a)[2]; \
00076   (A)[(skip)+2] = minus (a)[0]; \
00077   (A)[2*(skip)+0] = minus (a)[1]; \
00078   (A)[2*(skip)+1] = plus (a)[0]; \
00079 } while(0)
00080 
00081 
00082 #define dMULTIPLYOP2_333(A,op,B,C) \
00083   (A)[0] op dDOT1((B),(C)); \
00084   (A)[1] op dDOT1((B),(C+4)); \
00085   (A)[2] op dDOT1((B),(C+8)); \
00086   (A)[4] op dDOT1((B+4),(C)); \
00087   (A)[5] op dDOT1((B+4),(C+4)); \
00088   (A)[6] op dDOT1((B+4),(C+8)); \
00089   (A)[8] op dDOT1((B+8),(C)); \
00090   (A)[9] op dDOT1((B+8),(C+4)); \
00091   (A)[10] op dDOT1((B+8),(C+8));
00092 
00093 #define dMULTIPLYOP0_333(A,op,B,C) \
00094   (A)[0] op dDOT14((B),(C)); \
00095   (A)[1] op dDOT14((B),(C+1)); \
00096   (A)[2] op dDOT14((B),(C+2)); \
00097   (A)[4] op dDOT14((B+4),(C)); \
00098   (A)[5] op dDOT14((B+4),(C+1)); \
00099   (A)[6] op dDOT14((B+4),(C+2)); \
00100   (A)[8] op dDOT14((B+8),(C)); \
00101   (A)[9] op dDOT14((B+8),(C+1)); \
00102   (A)[10] op dDOT14((B+8),(C+2));
00103 
00104 #define dMULTIPLY2_333(A,B,C) dMULTIPLYOP2_333(A,=,B,C)
00105 #define dMULTIPLY0_333(A,B,C) dMULTIPLYOP0_333(A,=,B,C)
00106 #define dMULTIPLYADD0_331(A,B,C) dMULTIPLYOP0_331(A,+=,B,C)
00107 
00108 
00110 #define EFFICIENT_ALIGNMENT 16
00111 #define dEFFICIENT_SIZE(x) ((((x)-1)|(EFFICIENT_ALIGNMENT-1))+1)
00112 /* alloca aligned to the EFFICIENT_ALIGNMENT. note that this can waste
00113  * up to 15 bytes per allocation, depending on what alloca() returns.
00114  */
00115 
00116 #define dALLOCA16(n) \
00117   ((char*)dEFFICIENT_SIZE(((size_t)(alloca((n)+(EFFICIENT_ALIGNMENT-1))))))
00118 
00119 //#define ALLOCA dALLOCA16
00120 
00121 typedef const btScalar *dRealPtr;
00122 typedef btScalar *dRealMutablePtr;
00123 //#define dRealArray(name,n) btScalar name[n];
00124 //#define dRealAllocaArray(name,n) btScalar *name = (btScalar*) ALLOCA ((n)*sizeof(btScalar));
00125 
00127 
00128  //Remotion: 10.10.2007
00129 #define ALLOCA(size) stackAlloc->allocate( dEFFICIENT_SIZE(size) );
00130 
00131 //#define dRealAllocaArray(name,size) btScalar *name = (btScalar*) stackAlloc->allocate(dEFFICIENT_SIZE(size)*sizeof(btScalar));
00132 #define dRealAllocaArray(name,size) btScalar *name = NULL; \
00133        int memNeeded_##name = dEFFICIENT_SIZE(size)*sizeof(btScalar); \
00134        if (memNeeded_##name < stackAlloc->getAvailableMemory()) name = (btScalar*) stackAlloc->allocate(memNeeded_##name); \
00135        else{ btAssert(memNeeded_##name < stackAlloc->getAvailableMemory()); name = (btScalar*) alloca(memNeeded_##name); } 
00136 
00137 
00138 
00139 
00140 
00142 #if 0
00143 inline void dSetZero1 (btScalar *a, int n)
00144 {
00145   dAASSERT (a && n >= 0);
00146   while (n > 0) {
00147     *(a++) = 0;
00148     n--;
00149   }
00150 }
00151 
00152 inline void dSetValue1 (btScalar *a, int n, btScalar value)
00153 {
00154   dAASSERT (a && n >= 0);
00155   while (n > 0) {
00156     *(a++) = value;
00157     n--;
00158   }
00159 }
00160 #else
00161 
00163 
00164 
00165 #include <string.h> //for memset
00166 
00167 //Remotion: 10.10.2007
00168 //------------------------------------------------------------------------------
00169 #define IS_ALIGNED_16(x)    ((size_t(x)&15)==0)
00170 //------------------------------------------------------------------------------
00171 inline void dSetZero1 (btScalar *dest, int size)
00172 {
00173        dAASSERT (dest && size >= 0);
00174        memset(dest, 0, size * sizeof(btScalar));
00175 }
00176 //------------------------------------------------------------------------------
00177 inline void dSetValue1 (btScalar *dest, int size, btScalar val)
00178 {
00179        dAASSERT (dest && size >= 0);
00180        int n_mod4 = size & 3;             
00181        int n4 = size - n_mod4;
00182 /*#ifdef __USE_SSE__
00183 //it is not supported on double precision, todo...
00184        if(IS_ALIGNED_16(dest)){
00185               __m128 xmm0 = _mm_set_ps1(val);
00186               for (int i=0; i<n4; i+=4)
00187               {
00188                      _mm_store_ps(&dest[i],xmm0);
00189               }
00190        }else
00191 #endif
00192        */
00193 
00194        {
00195               for (int i=0; i<n4; i+=4) // Unrolled Loop
00196               {
00197                      dest[i  ] = val;
00198                      dest[i+1] = val;
00199                      dest[i+2] = val;
00200                      dest[i+3] = val;
00201               }
00202        }
00203        for (int  i=n4; i<size; i++){
00204               dest[i] = val;
00205        }
00206 }
00207 #endif
00208 
00209 
00210 
00211 #endif //USE_SOR_SOLVER
00212