Changeset 2882 for code/trunk/src/bullet/LinearMath
- Timestamp:
- Mar 31, 2009, 8:05:51 PM (16 years ago)
- Location:
- code/trunk/src/bullet/LinearMath
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/bullet/LinearMath/btAlignedAllocator.cpp
r2662 r2882 20 20 int gTotalBytesAlignedAllocs = 0;//detect memory leaks 21 21 22 static void *btAllocDefault(size_t size) 23 { 24 return malloc(size); 25 } 26 27 static void btFreeDefault(void *ptr) 28 { 29 free(ptr); 30 } 31 32 static btAllocFunc *sAllocFunc = btAllocDefault; 33 static btFreeFunc *sFreeFunc = btFreeDefault; 34 35 36 22 37 #if defined (BT_HAS_ALIGNED_ALLOCATOR) 23 38 #include <malloc.h> … … 50 65 unsigned long offset; 51 66 52 real = (char *) malloc(size + sizeof(void *) + (alignment-1));67 real = (char *)sAllocFunc(size + sizeof(void *) + (alignment-1)); 53 68 if (real) { 54 69 offset = (alignment - (unsigned long)(real + sizeof(void *))) & (alignment-1); … … 67 82 if (ptr) { 68 83 real = *((void **)(ptr)-1); 69 free(real);84 sFreeFunc(real); 70 85 } 71 86 } 72 87 #endif 73 88 74 static void *btAllocDefault(size_t size)75 {76 return malloc(size);77 }78 79 static void btFreeDefault(void *ptr)80 {81 free(ptr);82 }83 89 84 90 static btAlignedAllocFunc *sAlignedAllocFunc = btAlignedAllocDefault; 85 91 static btAlignedFreeFunc *sAlignedFreeFunc = btAlignedFreeDefault; 86 static btAllocFunc *sAllocFunc = btAllocDefault;87 static btFreeFunc *sFreeFunc = btFreeDefault;88 92 89 93 void btAlignedAllocSetCustomAligned(btAlignedAllocFunc *allocFunc, btAlignedFreeFunc *freeFunc) -
code/trunk/src/bullet/LinearMath/btAlignedAllocator.h
r2662 r2882 39 39 void btAlignedFreeInternal (void* ptr); 40 40 41 #define btAlignedAlloc( a,b) btAlignedAllocInternal(a,b)41 #define btAlignedAlloc(size,alignment) btAlignedAllocInternal(size,alignment) 42 42 #define btAlignedFree(ptr) btAlignedFreeInternal(ptr) 43 43 … … 50 50 typedef void (btFreeFunc)(void *memblock); 51 51 52 ///The developer can let all Bullet memory allocations go through a custom memory allocator, using btAlignedAllocSetCustom 53 void btAlignedAllocSetCustom(btAllocFunc *allocFunc, btFreeFunc *freeFunc); 54 ///If the developer has already an custom aligned allocator, then btAlignedAllocSetCustomAligned can be used. The default aligned allocator pre-allocates extra memory using the non-aligned allocator, and instruments it. 52 55 void btAlignedAllocSetCustomAligned(btAlignedAllocFunc *allocFunc, btAlignedFreeFunc *freeFunc); 53 void btAlignedAllocSetCustom(btAllocFunc *allocFunc, btFreeFunc *freeFunc); 56 54 57 55 58 ///The btAlignedAllocator is a portable class for aligned memory allocations. -
code/trunk/src/bullet/LinearMath/btAlignedObjectArray.h
r2662 r2882 59 59 return (size ? size*2 : 1); 60 60 } 61 SIMD_FORCE_INLINE void copy(int start,int end, T* dest) 61 SIMD_FORCE_INLINE void copy(int start,int end, T* dest) const 62 62 { 63 63 int i; … … 121 121 } 122 122 123 SIMD_FORCE_INLINE int capacity() const 124 { // return current length of allocated storage 125 return m_capacity; 126 } 127 123 ///Generally it is best to avoid using the copy constructor of an btAlignedObjectArray, and use a (const) reference to the array instead. 124 btAlignedObjectArray(const btAlignedObjectArray& otherArray) 125 { 126 init(); 127 128 int otherSize = otherArray.size(); 129 resize (otherSize); 130 otherArray.copy(0, otherSize, m_data); 131 } 132 133 134 135 /// return the number of elements in the array 128 136 SIMD_FORCE_INLINE int size() const 129 { // return length of sequence137 { 130 138 return m_size; 131 139 } … … 142 150 143 151 152 ///clear the array, deallocated memory. Generally it is better to use array.resize(0), to reduce performance overhead of run-time memory (de)allocations. 144 153 SIMD_FORCE_INLINE void clear() 145 154 { … … 157 166 } 158 167 168 ///resize changes the number of elements in the array. If the new size is larger, the new elements will be constructed using the optional second argument. 169 ///when the new number of elements is smaller, the destructor will be called, but memory will not be freed, to reduce performance overhead of run-time memory (de)allocations. 159 170 SIMD_FORCE_INLINE void resize(int newsize, const T& fillData=T()) 160 171 { … … 220 231 221 232 233 /// return the pre-allocated (reserved) elements, this is at least as large as the total number of elements,see size() and reserve() 234 SIMD_FORCE_INLINE int capacity() const 235 { 236 return m_capacity; 237 } 222 238 223 239 SIMD_FORCE_INLINE void reserve(int _Count) -
code/trunk/src/bullet/LinearMath/btConvexHull.cpp
r2662 r2882 263 263 for(btScalar x = btScalar(0.0) ; x<= btScalar(360.0) ; x+= btScalar(45.0)) 264 264 { 265 btScalar s = sinf(SIMD_RADS_PER_DEG*(x));266 btScalar c = cosf(SIMD_RADS_PER_DEG*(x));265 btScalar s = btSin(SIMD_RADS_PER_DEG*(x)); 266 btScalar c = btCos(SIMD_RADS_PER_DEG*(x)); 267 267 int mb = maxdirfiltered(p,count,dir+(u*s+v*c)*btScalar(0.025),allow); 268 268 if(ma==m && mb==m) … … 276 276 for(btScalar xx = x-btScalar(40.0) ; xx <= x ; xx+= btScalar(5.0)) 277 277 { 278 btScalar s = sinf(SIMD_RADS_PER_DEG*(xx));279 btScalar c = cosf(SIMD_RADS_PER_DEG*(xx));278 btScalar s = btSin(SIMD_RADS_PER_DEG*(xx)); 279 btScalar c = btCos(SIMD_RADS_PER_DEG*(xx)); 280 280 int md = maxdirfiltered(p,count,dir+(u*s+v*c)*btScalar(0.025),allow); 281 281 if(mc==m && md==m) -
code/trunk/src/bullet/LinearMath/btIDebugDraw.h
r2662 r2882 30 30 31 31 #include "btVector3.h" 32 #include "btTransform.h" 32 33 33 34 … … 53 54 DBG_DisableBulletLCP = 512, 54 55 DBG_EnableCCD = 1024, 56 DBG_DrawConstraints = (1 << 11), 57 DBG_DrawConstraintLimits = (1 << 12), 55 58 DBG_MAX_DEBUG_DRAW_MODE 56 59 }; 57 60 58 61 virtual ~btIDebugDraw() {}; 62 63 virtual void drawLine(const btVector3& from,const btVector3& to, const btVector3& fromColor, const btVector3& toColor) 64 { 65 drawLine (from, to, fromColor); 66 } 67 68 virtual void drawBox (const btVector3& boxMin, const btVector3& boxMax, const btVector3& color, btScalar alpha) 69 { 70 } 71 72 virtual void drawSphere (const btVector3& p, btScalar radius, const btVector3& color) 73 { 74 } 59 75 60 76 virtual void drawLine(const btVector3& from,const btVector3& to,const btVector3& color)=0; … … 110 126 } 111 127 } 128 void drawTransform(const btTransform& transform, btScalar orthoLen) 129 { 130 btVector3 start = transform.getOrigin(); 131 drawLine(start, start+transform.getBasis() * btVector3(orthoLen, 0, 0), btVector3(0.7f,0,0)); 132 drawLine(start, start+transform.getBasis() * btVector3(0, orthoLen, 0), btVector3(0,0.7f,0)); 133 drawLine(start, start+transform.getBasis() * btVector3(0, 0, orthoLen), btVector3(0,0,0.7f)); 134 } 135 136 void drawArc(const btVector3& center, const btVector3& normal, const btVector3& axis, btScalar radiusA, btScalar radiusB, btScalar minAngle, btScalar maxAngle, 137 const btVector3& color, bool drawSect, btScalar stepDegrees = btScalar(10.f)) 138 { 139 const btVector3& vx = axis; 140 btVector3 vy = normal.cross(axis); 141 btScalar step = stepDegrees * SIMD_RADS_PER_DEG; 142 int nSteps = (int)((maxAngle - minAngle) / step); 143 if(!nSteps) nSteps = 1; 144 btVector3 prev = center + radiusA * vx * btCos(minAngle) + radiusB * vy * btSin(minAngle); 145 if(drawSect) 146 { 147 drawLine(center, prev, color); 148 } 149 for(int i = 1; i <= nSteps; i++) 150 { 151 btScalar angle = minAngle + (maxAngle - minAngle) * btScalar(i) / btScalar(nSteps); 152 btVector3 next = center + radiusA * vx * btCos(angle) + radiusB * vy * btSin(angle); 153 drawLine(prev, next, color); 154 prev = next; 155 } 156 if(drawSect) 157 { 158 drawLine(center, prev, color); 159 } 160 } 161 void drawSpherePatch(const btVector3& center, const btVector3& up, const btVector3& axis, btScalar radius, 162 btScalar minTh, btScalar maxTh, btScalar minPs, btScalar maxPs, const btVector3& color, btScalar stepDegrees = btScalar(10.f)) 163 { 164 btVector3 vA[74]; 165 btVector3 vB[74]; 166 btVector3 *pvA = vA, *pvB = vB, *pT; 167 btVector3 npole = center + up * radius; 168 btVector3 spole = center - up * radius; 169 btVector3 arcStart; 170 btScalar step = stepDegrees * SIMD_RADS_PER_DEG; 171 const btVector3& kv = up; 172 const btVector3& iv = axis; 173 btVector3 jv = kv.cross(iv); 174 bool drawN = false; 175 bool drawS = false; 176 if(minTh <= -SIMD_HALF_PI) 177 { 178 minTh = -SIMD_HALF_PI + step; 179 drawN = true; 180 } 181 if(maxTh >= SIMD_HALF_PI) 182 { 183 maxTh = SIMD_HALF_PI - step; 184 drawS = true; 185 } 186 if(minTh > maxTh) 187 { 188 minTh = -SIMD_HALF_PI + step; 189 maxTh = SIMD_HALF_PI - step; 190 drawN = drawS = true; 191 } 192 int n_hor = (int)((maxTh - minTh) / step) + 1; 193 if(n_hor < 2) n_hor = 2; 194 btScalar step_h = (maxTh - minTh) / btScalar(n_hor - 1); 195 bool isClosed = false; 196 if(minPs > maxPs) 197 { 198 minPs = -SIMD_PI + step; 199 maxPs = SIMD_PI; 200 isClosed = true; 201 } 202 else if((maxPs - minPs) >= SIMD_PI * btScalar(2.f)) 203 { 204 isClosed = true; 205 } 206 else 207 { 208 isClosed = false; 209 } 210 int n_vert = (int)((maxPs - minPs) / step) + 1; 211 if(n_vert < 2) n_vert = 2; 212 btScalar step_v = (maxPs - minPs) / btScalar(n_vert - 1); 213 for(int i = 0; i < n_hor; i++) 214 { 215 btScalar th = minTh + btScalar(i) * step_h; 216 btScalar sth = radius * btSin(th); 217 btScalar cth = radius * btCos(th); 218 for(int j = 0; j < n_vert; j++) 219 { 220 btScalar psi = minPs + btScalar(j) * step_v; 221 btScalar sps = btSin(psi); 222 btScalar cps = btCos(psi); 223 pvB[j] = center + cth * cps * iv + cth * sps * jv + sth * kv; 224 if(i) 225 { 226 drawLine(pvA[j], pvB[j], color); 227 } 228 else if(drawS) 229 { 230 drawLine(spole, pvB[j], color); 231 } 232 if(j) 233 { 234 drawLine(pvB[j-1], pvB[j], color); 235 } 236 else 237 { 238 arcStart = pvB[j]; 239 } 240 if((i == (n_hor - 1)) && drawN) 241 { 242 drawLine(npole, pvB[j], color); 243 } 244 if(isClosed) 245 { 246 if(j == (n_vert-1)) 247 { 248 drawLine(arcStart, pvB[j], color); 249 } 250 } 251 else 252 { 253 if(((!i) || (i == (n_hor-1))) && ((!j) || (j == (n_vert-1)))) 254 { 255 drawLine(center, pvB[j], color); 256 } 257 } 258 } 259 pT = pvA; pvA = pvB; pvB = pT; 260 } 261 } 262 263 void drawBox(const btVector3& bbMin, const btVector3& bbMax, const btVector3& color) 264 { 265 drawLine(btVector3(bbMin[0], bbMin[1], bbMin[2]), btVector3(bbMax[0], bbMin[1], bbMin[2]), color); 266 drawLine(btVector3(bbMax[0], bbMin[1], bbMin[2]), btVector3(bbMax[0], bbMax[1], bbMin[2]), color); 267 drawLine(btVector3(bbMax[0], bbMax[1], bbMin[2]), btVector3(bbMin[0], bbMax[1], bbMin[2]), color); 268 drawLine(btVector3(bbMin[0], bbMax[1], bbMin[2]), btVector3(bbMin[0], bbMin[1], bbMin[2]), color); 269 drawLine(btVector3(bbMin[0], bbMin[1], bbMin[2]), btVector3(bbMin[0], bbMin[1], bbMax[2]), color); 270 drawLine(btVector3(bbMax[0], bbMin[1], bbMin[2]), btVector3(bbMax[0], bbMin[1], bbMax[2]), color); 271 drawLine(btVector3(bbMax[0], bbMax[1], bbMin[2]), btVector3(bbMax[0], bbMax[1], bbMax[2]), color); 272 drawLine(btVector3(bbMin[0], bbMax[1], bbMin[2]), btVector3(bbMin[0], bbMax[1], bbMax[2]), color); 273 drawLine(btVector3(bbMin[0], bbMin[1], bbMax[2]), btVector3(bbMax[0], bbMin[1], bbMax[2]), color); 274 drawLine(btVector3(bbMax[0], bbMin[1], bbMax[2]), btVector3(bbMax[0], bbMax[1], bbMax[2]), color); 275 drawLine(btVector3(bbMax[0], bbMax[1], bbMax[2]), btVector3(bbMin[0], bbMax[1], bbMax[2]), color); 276 drawLine(btVector3(bbMin[0], bbMax[1], bbMax[2]), btVector3(bbMin[0], bbMin[1], bbMax[2]), color); 277 } 278 void drawBox(const btVector3& bbMin, const btVector3& bbMax, const btTransform& trans, const btVector3& color) 279 { 280 drawLine(trans * btVector3(bbMin[0], bbMin[1], bbMin[2]), trans * btVector3(bbMax[0], bbMin[1], bbMin[2]), color); 281 drawLine(trans * btVector3(bbMax[0], bbMin[1], bbMin[2]), trans * btVector3(bbMax[0], bbMax[1], bbMin[2]), color); 282 drawLine(trans * btVector3(bbMax[0], bbMax[1], bbMin[2]), trans * btVector3(bbMin[0], bbMax[1], bbMin[2]), color); 283 drawLine(trans * btVector3(bbMin[0], bbMax[1], bbMin[2]), trans * btVector3(bbMin[0], bbMin[1], bbMin[2]), color); 284 drawLine(trans * btVector3(bbMin[0], bbMin[1], bbMin[2]), trans * btVector3(bbMin[0], bbMin[1], bbMax[2]), color); 285 drawLine(trans * btVector3(bbMax[0], bbMin[1], bbMin[2]), trans * btVector3(bbMax[0], bbMin[1], bbMax[2]), color); 286 drawLine(trans * btVector3(bbMax[0], bbMax[1], bbMin[2]), trans * btVector3(bbMax[0], bbMax[1], bbMax[2]), color); 287 drawLine(trans * btVector3(bbMin[0], bbMax[1], bbMin[2]), trans * btVector3(bbMin[0], bbMax[1], bbMax[2]), color); 288 drawLine(trans * btVector3(bbMin[0], bbMin[1], bbMax[2]), trans * btVector3(bbMax[0], bbMin[1], bbMax[2]), color); 289 drawLine(trans * btVector3(bbMax[0], bbMin[1], bbMax[2]), trans * btVector3(bbMax[0], bbMax[1], bbMax[2]), color); 290 drawLine(trans * btVector3(bbMax[0], bbMax[1], bbMax[2]), trans * btVector3(bbMin[0], bbMax[1], bbMax[2]), color); 291 drawLine(trans * btVector3(bbMin[0], bbMax[1], bbMax[2]), trans * btVector3(bbMin[0], bbMin[1], bbMax[2]), color); 292 } 112 293 }; 113 294 -
code/trunk/src/bullet/LinearMath/btMatrix3x3.h
r2662 r2882 193 193 btScalar(0.0), btScalar(0.0), btScalar(1.0)); 194 194 } 195 196 static const btMatrix3x3& getIdentity() 197 { 198 static const btMatrix3x3 identityMatrix(btScalar(1.0), btScalar(0.0), btScalar(0.0), 199 btScalar(0.0), btScalar(1.0), btScalar(0.0), 200 btScalar(0.0), btScalar(0.0), btScalar(1.0)); 201 return identityMatrix; 202 } 203 195 204 /**@brief Fill the values of the matrix into a 9 element array 196 205 * @param m The array to be filled */ -
code/trunk/src/bullet/LinearMath/btQuadWord.h
r2662 r2882 25 25 #endif 26 26 27 /**@brief The btQuadWord Storageclass is base class for btVector3 and btQuaternion.27 /**@brief The btQuadWord class is base class for btVector3 and btQuaternion. 28 28 * Some issues under PS3 Linux with IBM 2.1 SDK, gcc compiler prevent from using aligned quadword. 29 29 */ 30 30 #ifndef USE_LIBSPE2 31 ATTRIBUTE_ALIGNED16(class) btQuadWord Storage31 ATTRIBUTE_ALIGNED16(class) btQuadWord 32 32 #else 33 class btQuadWord Storage33 class btQuadWord 34 34 #endif 35 35 { … … 46 46 return mVec128; 47 47 } 48 protected: 48 49 #else //__CELLOS_LV2__ __SPU__ 49 50 btScalar m_floats[4]; 50 51 #endif //__CELLOS_LV2__ __SPU__ 51 52 52 };53 54 /** @brief The btQuadWord is base-class for vectors, points */55 class btQuadWord : public btQuadWordStorage56 {57 53 public: 58 54 … … 135 131 { 136 132 } 137 /**@brief Copy constructor */ 138 SIMD_FORCE_INLINE btQuadWord(const btQuadWordStorage& q) 139 { 140 *((btQuadWordStorage*)this) = q; 141 } 133 142 134 /**@brief Three argument constructor (zeros w) 143 135 * @param x Value of x -
code/trunk/src/bullet/LinearMath/btQuaternion.h
r2662 r2882 20 20 21 21 #include "btVector3.h" 22 #include "btQuadWord.h" 22 23 23 24 /**@brief The btQuaternion implements quaternion to perform linear algebra rotations in combination with btMatrix3x3, btVector3 and btTransform. */ … … 58 59 { 59 60 btScalar d = axis.length(); 60 assert(d != btScalar(0.0));61 btAssert(d != btScalar(0.0)); 61 62 btScalar s = btSin(angle * btScalar(0.5)) / d; 62 63 setValue(axis.x() * s, axis.y() * s, axis.z() * s, … … 177 178 btQuaternion operator/(const btScalar& s) const 178 179 { 179 assert(s != btScalar(0.0));180 btAssert(s != btScalar(0.0)); 180 181 return *this * (btScalar(1.0) / s); 181 182 } … … 185 186 btQuaternion& operator/=(const btScalar& s) 186 187 { 187 assert(s != btScalar(0.0));188 btAssert(s != btScalar(0.0)); 188 189 return *this *= btScalar(1.0) / s; 189 190 } … … 199 200 { 200 201 btScalar s = btSqrt(length2() * q.length2()); 201 assert(s != btScalar(0.0));202 btAssert(s != btScalar(0.0)); 202 203 return btAcos(dot(q) / s); 203 204 } … … 275 276 } 276 277 278 static const btQuaternion& getIdentity() 279 { 280 static const btQuaternion identityQuat(btScalar(0.),btScalar(0.),btScalar(0.),btScalar(1.)); 281 return identityQuat; 282 } 283 277 284 SIMD_FORCE_INLINE const btScalar& getW() const { return m_floats[3]; } 278 285 -
code/trunk/src/bullet/LinearMath/btScalar.h
r2662 r2882 26 26 #include <float.h> 27 27 28 #define BT_BULLET_VERSION 27 328 #define BT_BULLET_VERSION 274 29 29 30 30 inline int btGetVersion() … … 46 46 #define ATTRIBUTE_ALIGNED128(a) a 47 47 #else 48 #define BT_HAS_ALIGNED_ALLOCATOR48 //#define BT_HAS_ALIGNED_ALLOCATOR 49 49 #pragma warning(disable : 4324) // disable padding warning 50 50 // #pragma warning(disable:4530) // Disable the exception disable but used in MSCV Stl warning. … … 62 62 #define btFsel(a,b,c) __fsel((a),(b),(c)) 63 63 #else 64 65 #if (defined (WIN32) && (_MSC_VER) && _MSC_VER >= 1400) && (!defined (BT_USE_DOUBLE_PRECISION)) 64 66 #define BT_USE_SSE 65 #endif 67 #include <emmintrin.h> 68 #endif 69 70 #endif//_XBOX 71 66 72 #endif //__MINGW32__ 67 73 … … 125 131 126 132 #define SIMD_FORCE_INLINE inline 133 ///@todo: check out alignment methods for other platforms/compilers 134 ///#define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16))) 135 ///#define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128))) 127 136 #define ATTRIBUTE_ALIGNED16(a) a 128 137 #define ATTRIBUTE_ALIGNED128(a) a … … 228 237 SIMD_FORCE_INLINE btScalar btExp(btScalar x) { return expf(x); } 229 238 SIMD_FORCE_INLINE btScalar btLog(btScalar x) { return logf(x); } 230 #if defined( __MINGW32__ ) 231 SIMD_FORCE_INLINE btScalar btPow(btScalar x,btScalar y) { return pow(x,y); } 232 #else 233 SIMD_FORCE_INLINE btScalar btPow(btScalar x,btScalar y) { return powf(x,y); } 234 #endif 235 239 SIMD_FORCE_INLINE btScalar btPow(btScalar x,btScalar y) { return powf(x,y); } 240 236 241 #endif 237 242 -
code/trunk/src/bullet/LinearMath/btTransform.h
r2662 r2882 191 191 192 192 /**@brief Return an identity transform */ 193 static btTransform getIdentity() 194 { 195 btTransform tr; 196 tr.setIdentity(); 197 return tr; 193 static const btTransform& getIdentity() 194 { 195 static const btTransform identityTransform(btMatrix3x3::getIdentity()); 196 return identityTransform; 198 197 } 199 198 -
code/trunk/src/bullet/LinearMath/btVector3.h
r2662 r2882 18 18 #define SIMD__VECTOR3_H 19 19 20 #include "btQuadWord.h" 21 20 21 #include "btScalar.h" 22 #include "btScalar.h" 23 #include "btMinMax.h" 22 24 /**@brief btVector3 can be used to represent 3D points and vectors. 23 25 * It has an un-used w component to suit 16-byte alignment when btVector3 is stored in containers. This extra component can be used by derived classes (Quaternion?) or by user 24 26 * Ideally, this class should be replaced by a platform optimized SIMD version that keeps the data in registers 25 27 */ 26 class btVector3 : public btQuadWord { 27 28 29 ATTRIBUTE_ALIGNED16(class) btVector3 30 { 28 31 public: 32 33 #if defined (__SPU__) && defined (__CELLOS_LV2__) 34 union { 35 vec_float4 mVec128; 36 btScalar m_floats[4]; 37 }; 38 public: 39 vec_float4 get128() const 40 { 41 return mVec128; 42 } 43 public: 44 #else //__CELLOS_LV2__ __SPU__ 45 #ifdef BT_USE_SSE // WIN32 46 union { 47 __m128 mVec128; 48 btScalar m_floats[4]; 49 }; 50 SIMD_FORCE_INLINE __m128 get128() const 51 { 52 return mVec128; 53 } 54 SIMD_FORCE_INLINE void set128(__m128 v128) 55 { 56 mVec128 = v128; 57 } 58 #else 59 btScalar m_floats[4]; 60 #endif 61 #endif //__CELLOS_LV2__ __SPU__ 62 63 public: 64 29 65 /**@brief No initialization constructor */ 30 66 SIMD_FORCE_INLINE btVector3() {} 31 67 32 /**@brief Constructor from btQuadWordStorage (btVector3 inherits from this so is also valid) 33 * Note: Vector3 derives from btQuadWordStorage*/ 34 SIMD_FORCE_INLINE btVector3(const btQuadWordStorage& q) 35 : btQuadWord(q) 36 { 37 } 68 38 69 39 70 /**@brief Constructor from scalars … … 42 73 * @param z Z value 43 74 */ 44 SIMD_FORCE_INLINE btVector3(const btScalar& x, const btScalar& y, const btScalar& z) 45 :btQuadWord(x,y,z,btScalar(0.)) 46 { 47 } 48 49 // SIMD_FORCE_INLINE btVector3(const btScalar& x, const btScalar& y, const btScalar& z,const btScalar& w) 50 // : btQuadWord(x,y,z,w) 51 // { 52 // } 75 SIMD_FORCE_INLINE btVector3(const btScalar& x, const btScalar& y, const btScalar& z) 76 { 77 m_floats[0] = x; 78 m_floats[1] = y; 79 m_floats[2] = z; 80 m_floats[3] = btScalar(0.); 81 } 53 82 54 83 … … 58 87 { 59 88 60 m_floats[0] += v. x(); m_floats[1] += v.y(); m_floats[2] += v.z();89 m_floats[0] += v.m_floats[0]; m_floats[1] += v.m_floats[1];m_floats[2] += v.m_floats[2]; 61 90 return *this; 62 91 } … … 67 96 SIMD_FORCE_INLINE btVector3& operator-=(const btVector3& v) 68 97 { 69 m_floats[0] -= v. x(); m_floats[1] -= v.y(); m_floats[2] -= v.z();98 m_floats[0] -= v.m_floats[0]; m_floats[1] -= v.m_floats[1];m_floats[2] -= v.m_floats[2]; 70 99 return *this; 71 100 } … … 74 103 SIMD_FORCE_INLINE btVector3& operator*=(const btScalar& s) 75 104 { 76 m_floats[0] *= s; m_floats[1] *= s; 105 m_floats[0] *= s; m_floats[1] *= s;m_floats[2] *= s; 77 106 return *this; 78 107 } … … 90 119 SIMD_FORCE_INLINE btScalar dot(const btVector3& v) const 91 120 { 92 return m_floats[0] * v. x() + m_floats[1] * v.y() + m_floats[2] * v.z();121 return m_floats[0] * v.m_floats[0] + m_floats[1] * v.m_floats[1] +m_floats[2] * v.m_floats[2]; 93 122 } 94 123 … … 149 178 { 150 179 return btVector3( 151 m_floats[1] * v. z() - m_floats[2] * v.y(),152 m_floats[2] * v. x() - m_floats[0] * v.z(),153 m_floats[0] * v. y() - m_floats[1] * v.x());180 m_floats[1] * v.m_floats[2] -m_floats[2] * v.m_floats[1], 181 m_floats[2] * v.m_floats[0] - m_floats[0] * v.m_floats[2], 182 m_floats[0] * v.m_floats[1] - m_floats[1] * v.m_floats[0]); 154 183 } 155 184 156 185 SIMD_FORCE_INLINE btScalar triple(const btVector3& v1, const btVector3& v2) const 157 186 { 158 return m_floats[0] * (v1. y() * v2.z() - v1.z() * v2.y()) +159 m_floats[1] * (v1. z() * v2.x() - v1.x() * v2.z()) +160 m_floats[2] * (v1. x() * v2.y() - v1.y() * v2.x());187 return m_floats[0] * (v1.m_floats[1] * v2.m_floats[2] - v1.m_floats[2] * v2.m_floats[1]) + 188 m_floats[1] * (v1.m_floats[2] * v2.m_floats[0] - v1.m_floats[0] * v2.m_floats[2]) + 189 m_floats[2] * (v1.m_floats[0] * v2.m_floats[1] - v1.m_floats[1] * v2.m_floats[0]); 161 190 } 162 191 … … 165 194 SIMD_FORCE_INLINE int minAxis() const 166 195 { 167 return m_floats[0] < m_floats[1] ? (m_floats[0] < m_floats[2] ? 0 : 2) : (m_floats[1] <m_floats[2] ? 1 : 2);196 return m_floats[0] < m_floats[1] ? (m_floats[0] <m_floats[2] ? 0 : 2) : (m_floats[1] <m_floats[2] ? 1 : 2); 168 197 } 169 198 … … 172 201 SIMD_FORCE_INLINE int maxAxis() const 173 202 { 174 return m_floats[0] < m_floats[1] ? (m_floats[1] < m_floats[2] ? 2 : 1) : (m_floats[0] <m_floats[2] ? 2 : 0);203 return m_floats[0] < m_floats[1] ? (m_floats[1] <m_floats[2] ? 2 : 1) : (m_floats[0] <m_floats[2] ? 2 : 0); 175 204 } 176 205 … … 188 217 { 189 218 btScalar s = btScalar(1.0) - rt; 190 m_floats[0] = s * v0. x() + rt * v1.x();191 m_floats[1] = s * v0. y() + rt * v1.y();192 m_floats[2] = s * v0. z() + rt * v1.z();219 m_floats[0] = s * v0.m_floats[0] + rt * v1.m_floats[0]; 220 m_floats[1] = s * v0.m_floats[1] + rt * v1.m_floats[1]; 221 m_floats[2] = s * v0.m_floats[2] + rt * v1.m_floats[2]; 193 222 //don't do the unused w component 194 223 // m_co[3] = s * v0[3] + rt * v1[3]; … … 200 229 SIMD_FORCE_INLINE btVector3 lerp(const btVector3& v, const btScalar& t) const 201 230 { 202 return btVector3(m_floats[0] + (v. x()- m_floats[0]) * t,203 m_floats[1] + (v. y()- m_floats[1]) * t,204 m_floats[2] + (v. z() -m_floats[2]) * t);231 return btVector3(m_floats[0] + (v.m_floats[0] - m_floats[0]) * t, 232 m_floats[1] + (v.m_floats[1] - m_floats[1]) * t, 233 m_floats[2] + (v.m_floats[2] -m_floats[2]) * t); 205 234 } 206 235 … … 209 238 SIMD_FORCE_INLINE btVector3& operator*=(const btVector3& v) 210 239 { 211 m_floats[0] *= v. x(); m_floats[1] *= v.y(); m_floats[2] *= v.z();240 m_floats[0] *= v.m_floats[0]; m_floats[1] *= v.m_floats[1];m_floats[2] *= v.m_floats[2]; 212 241 return *this; 213 242 } 214 243 215 244 /**@brief Return the x value */ 245 SIMD_FORCE_INLINE const btScalar& getX() const { return m_floats[0]; } 246 /**@brief Return the y value */ 247 SIMD_FORCE_INLINE const btScalar& getY() const { return m_floats[1]; } 248 /**@brief Return the z value */ 249 SIMD_FORCE_INLINE const btScalar& getZ() const { return m_floats[2]; } 250 /**@brief Set the x value */ 251 SIMD_FORCE_INLINE void setX(btScalar x) { m_floats[0] = x;}; 252 /**@brief Set the y value */ 253 SIMD_FORCE_INLINE void setY(btScalar y) { m_floats[1] = y;}; 254 /**@brief Set the z value */ 255 SIMD_FORCE_INLINE void setZ(btScalar z) {m_floats[2] = z;}; 256 /**@brief Set the w value */ 257 SIMD_FORCE_INLINE void setW(btScalar w) { m_floats[3] = w;}; 258 /**@brief Return the x value */ 259 SIMD_FORCE_INLINE const btScalar& x() const { return m_floats[0]; } 260 /**@brief Return the y value */ 261 SIMD_FORCE_INLINE const btScalar& y() const { return m_floats[1]; } 262 /**@brief Return the z value */ 263 SIMD_FORCE_INLINE const btScalar& z() const { return m_floats[2]; } 264 /**@brief Return the w value */ 265 SIMD_FORCE_INLINE const btScalar& w() const { return m_floats[3]; } 266 267 //SIMD_FORCE_INLINE btScalar& operator[](int i) { return (&m_floats[0])[i]; } 268 //SIMD_FORCE_INLINE const btScalar& operator[](int i) const { return (&m_floats[0])[i]; } 269 ///operator btScalar*() replaces operator[], using implicit conversion. We added operator != and operator == to avoid pointer comparisons. 270 SIMD_FORCE_INLINE operator btScalar *() { return &m_floats[0]; } 271 SIMD_FORCE_INLINE operator const btScalar *() const { return &m_floats[0]; } 272 273 SIMD_FORCE_INLINE bool operator==(const btVector3& other) const 274 { 275 return ((m_floats[3]==other.m_floats[3]) && (m_floats[2]==other.m_floats[2]) && (m_floats[1]==other.m_floats[1]) && (m_floats[0]==other.m_floats[0])); 276 } 277 278 SIMD_FORCE_INLINE bool operator!=(const btVector3& other) const 279 { 280 return !(*this == other); 281 } 282 283 /**@brief Set each element to the max of the current values and the values of another btVector3 284 * @param other The other btVector3 to compare with 285 */ 286 SIMD_FORCE_INLINE void setMax(const btVector3& other) 287 { 288 btSetMax(m_floats[0], other.m_floats[0]); 289 btSetMax(m_floats[1], other.m_floats[1]); 290 btSetMax(m_floats[2], other.m_floats[2]); 291 btSetMax(m_floats[3], other.w()); 292 } 293 /**@brief Set each element to the min of the current values and the values of another btVector3 294 * @param other The other btVector3 to compare with 295 */ 296 SIMD_FORCE_INLINE void setMin(const btVector3& other) 297 { 298 btSetMin(m_floats[0], other.m_floats[0]); 299 btSetMin(m_floats[1], other.m_floats[1]); 300 btSetMin(m_floats[2], other.m_floats[2]); 301 btSetMin(m_floats[3], other.w()); 302 } 303 304 SIMD_FORCE_INLINE void setValue(const btScalar& x, const btScalar& y, const btScalar& z) 305 { 306 m_floats[0]=x; 307 m_floats[1]=y; 308 m_floats[2]=z; 309 m_floats[3] = 0.f; 310 } 311 312 void getSkewSymmetricMatrix(btVector3* v0,btVector3* v1,btVector3* v2) const 313 { 314 v0->setValue(0. ,-z() ,y()); 315 v1->setValue(z() ,0. ,-x()); 316 v2->setValue(-y() ,x() ,0.); 317 } 216 318 217 319 }; … … 221 323 operator+(const btVector3& v1, const btVector3& v2) 222 324 { 223 return btVector3(v1. x() + v2.x(), v1.y() + v2.y(), v1.z() + v2.z());325 return btVector3(v1.m_floats[0] + v2.m_floats[0], v1.m_floats[1] + v2.m_floats[1], v1.m_floats[2] + v2.m_floats[2]); 224 326 } 225 327 … … 228 330 operator*(const btVector3& v1, const btVector3& v2) 229 331 { 230 return btVector3(v1. x() * v2.x(), v1.y() * v2.y(), v1.z() * v2.z());332 return btVector3(v1.m_floats[0] * v2.m_floats[0], v1.m_floats[1] * v2.m_floats[1], v1.m_floats[2] * v2.m_floats[2]); 231 333 } 232 334 … … 235 337 operator-(const btVector3& v1, const btVector3& v2) 236 338 { 237 return btVector3(v1. x() - v2.x(), v1.y() - v2.y(), v1.z() - v2.z());339 return btVector3(v1.m_floats[0] - v2.m_floats[0], v1.m_floats[1] - v2.m_floats[1], v1.m_floats[2] - v2.m_floats[2]); 238 340 } 239 341 /**@brief Return the negative of the vector */ … … 241 343 operator-(const btVector3& v) 242 344 { 243 return btVector3(-v. x(), -v.y(), -v.z());345 return btVector3(-v.m_floats[0], -v.m_floats[1], -v.m_floats[2]); 244 346 } 245 347 … … 248 350 operator*(const btVector3& v, const btScalar& s) 249 351 { 250 return btVector3(v. x() * s, v.y() * s, v.z()* s);352 return btVector3(v.m_floats[0] * s, v.m_floats[1] * s, v.m_floats[2] * s); 251 353 } 252 354 … … 270 372 operator/(const btVector3& v1, const btVector3& v2) 271 373 { 272 return btVector3(v1. x() / v2.x(),v1.y() / v2.y(),v1.z() / v2.z());374 return btVector3(v1.m_floats[0] / v2.m_floats[0],v1.m_floats[1] / v2.m_floats[1],v1.m_floats[2] / v2.m_floats[2]); 273 375 } 274 376 … … 326 428 } 327 429 328 /**@brief Test if each element of the vector is equivalent */ 329 SIMD_FORCE_INLINE bool operator==(const btVector3& p1, const btVector3& p2) 330 { 331 return p1.x() == p2.x() && p1.y() == p2.y() && p1.z() == p2.z(); 332 } 430 333 431 334 432 SIMD_FORCE_INLINE btScalar btVector3::distance2(const btVector3& v) const … … 405 503 { 406 504 maxIndex = 2; 407 maxVal = 505 maxVal =m_floats[2]; 408 506 } 409 507 if (m_floats[3] > maxVal) … … 438 536 { 439 537 minIndex = 2; 440 minVal = 538 minVal =m_floats[2]; 441 539 } 442 540 if (m_floats[3] < minVal) … … 455 553 return absolute4().maxAxis4(); 456 554 } 555 556 557 558 559 /**@brief Set x,y,z and zero w 560 * @param x Value of x 561 * @param y Value of y 562 * @param z Value of z 563 */ 564 565 566 /* void getValue(btScalar *m) const 567 { 568 m[0] = m_floats[0]; 569 m[1] = m_floats[1]; 570 m[2] =m_floats[2]; 571 } 572 */ 573 /**@brief Set the values 574 * @param x Value of x 575 * @param y Value of y 576 * @param z Value of z 577 * @param w Value of w 578 */ 579 SIMD_FORCE_INLINE void setValue(const btScalar& x, const btScalar& y, const btScalar& z,const btScalar& w) 580 { 581 m_floats[0]=x; 582 m_floats[1]=y; 583 m_floats[2]=z; 584 m_floats[3]=w; 585 } 586 587 588 457 589 458 590 };
Note: See TracChangeset
for help on using the changeset viewer.