Changeset 2908 for code/branches/questsystem5/src/bullet/LinearMath
- Timestamp:
- Apr 8, 2009, 12:58:47 AM (16 years ago)
- Location:
- code/branches/questsystem5
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/questsystem5
- Property svn:mergeinfo changed
-
code/branches/questsystem5/src/bullet/LinearMath/btAlignedAllocator.cpp
r2907 r2908 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 37 22 #if defined (BT_HAS_ALIGNED_ALLOCATOR) 38 23 #include <malloc.h> … … 65 50 unsigned long offset; 66 51 67 real = (char *) sAllocFunc(size + sizeof(void *) + (alignment-1));52 real = (char *)malloc(size + sizeof(void *) + (alignment-1)); 68 53 if (real) { 69 54 offset = (alignment - (unsigned long)(real + sizeof(void *))) & (alignment-1); … … 82 67 if (ptr) { 83 68 real = *((void **)(ptr)-1); 84 sFreeFunc(real);69 free(real); 85 70 } 86 71 } 87 72 #endif 88 73 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 } 89 83 90 84 static btAlignedAllocFunc *sAlignedAllocFunc = btAlignedAllocDefault; 91 85 static btAlignedFreeFunc *sAlignedFreeFunc = btAlignedFreeDefault; 86 static btAllocFunc *sAllocFunc = btAllocDefault; 87 static btFreeFunc *sFreeFunc = btFreeDefault; 92 88 93 89 void btAlignedAllocSetCustomAligned(btAlignedAllocFunc *allocFunc, btAlignedFreeFunc *freeFunc) -
code/branches/questsystem5/src/bullet/LinearMath/btAlignedAllocator.h
r2907 r2908 39 39 void btAlignedFreeInternal (void* ptr); 40 40 41 #define btAlignedAlloc( size,alignment) btAlignedAllocInternal(size,alignment)41 #define btAlignedAlloc(a,b) btAlignedAllocInternal(a,b) 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 52 void btAlignedAllocSetCustomAligned(btAlignedAllocFunc *allocFunc, btAlignedFreeFunc *freeFunc); 53 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.55 void btAlignedAllocSetCustomAligned(btAlignedAllocFunc *allocFunc, btAlignedFreeFunc *freeFunc);56 57 54 58 55 ///The btAlignedAllocator is a portable class for aligned memory allocations. -
code/branches/questsystem5/src/bullet/LinearMath/btAlignedObjectArray.h
r2907 r2908 59 59 return (size ? size*2 : 1); 60 60 } 61 SIMD_FORCE_INLINE void copy(int start,int end, T* dest) const61 SIMD_FORCE_INLINE void copy(int start,int end, T* dest) 62 62 { 63 63 int i; … … 121 121 } 122 122 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 123 SIMD_FORCE_INLINE int capacity() const 124 { // return current length of allocated storage 125 return m_capacity; 126 } 133 127 134 135 /// return the number of elements in the array136 128 SIMD_FORCE_INLINE int size() const 137 { 129 { // return length of sequence 138 130 return m_size; 139 131 } … … 150 142 151 143 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.153 144 SIMD_FORCE_INLINE void clear() 154 145 { … … 166 157 } 167 158 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.170 159 SIMD_FORCE_INLINE void resize(int newsize, const T& fillData=T()) 171 160 { … … 231 220 232 221 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() const235 {236 return m_capacity;237 }238 222 239 223 SIMD_FORCE_INLINE void reserve(int _Count) -
code/branches/questsystem5/src/bullet/LinearMath/btConvexHull.cpp
r2907 r2908 263 263 for(btScalar x = btScalar(0.0) ; x<= btScalar(360.0) ; x+= btScalar(45.0)) 264 264 { 265 btScalar s = btSin(SIMD_RADS_PER_DEG*(x));266 btScalar c = btCos(SIMD_RADS_PER_DEG*(x));265 btScalar s = sinf(SIMD_RADS_PER_DEG*(x)); 266 btScalar c = cosf(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 = btSin(SIMD_RADS_PER_DEG*(xx));279 btScalar c = btCos(SIMD_RADS_PER_DEG*(xx));278 btScalar s = sinf(SIMD_RADS_PER_DEG*(xx)); 279 btScalar c = cosf(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/branches/questsystem5/src/bullet/LinearMath/btIDebugDraw.h
r2907 r2908 30 30 31 31 #include "btVector3.h" 32 #include "btTransform.h"33 32 34 33 … … 54 53 DBG_DisableBulletLCP = 512, 55 54 DBG_EnableCCD = 1024, 56 DBG_DrawConstraints = (1 << 11),57 DBG_DrawConstraintLimits = (1 << 12),58 55 DBG_MAX_DEBUG_DRAW_MODE 59 56 }; 60 57 61 58 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 }75 59 76 60 virtual void drawLine(const btVector3& from,const btVector3& to,const btVector3& color)=0; … … 126 110 } 127 111 } 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 else207 {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 else237 {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 else252 {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 }293 112 }; 294 113 -
code/branches/questsystem5/src/bullet/LinearMath/btMatrix3x3.h
r2907 r2908 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 204 195 /**@brief Fill the values of the matrix into a 9 element array 205 196 * @param m The array to be filled */ -
code/branches/questsystem5/src/bullet/LinearMath/btQuadWord.h
r2907 r2908 25 25 #endif 26 26 27 /**@brief The btQuadWord class is base class for btVector3 and btQuaternion.27 /**@brief The btQuadWordStorage 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 31 ATTRIBUTE_ALIGNED16(class) btQuadWordStorage 32 32 #else 33 class btQuadWord 33 class btQuadWordStorage 34 34 #endif 35 35 { … … 46 46 return mVec128; 47 47 } 48 protected:49 48 #else //__CELLOS_LV2__ __SPU__ 50 49 btScalar m_floats[4]; 51 50 #endif //__CELLOS_LV2__ __SPU__ 52 51 52 }; 53 54 /** @brief The btQuadWord is base-class for vectors, points */ 55 class btQuadWord : public btQuadWordStorage 56 { 53 57 public: 54 58 … … 131 135 { 132 136 } 133 137 /**@brief Copy constructor */ 138 SIMD_FORCE_INLINE btQuadWord(const btQuadWordStorage& q) 139 { 140 *((btQuadWordStorage*)this) = q; 141 } 134 142 /**@brief Three argument constructor (zeros w) 135 143 * @param x Value of x -
code/branches/questsystem5/src/bullet/LinearMath/btQuaternion.h
r2907 r2908 20 20 21 21 #include "btVector3.h" 22 #include "btQuadWord.h"23 22 24 23 /**@brief The btQuaternion implements quaternion to perform linear algebra rotations in combination with btMatrix3x3, btVector3 and btTransform. */ … … 59 58 { 60 59 btScalar d = axis.length(); 61 btAssert(d != btScalar(0.0));60 assert(d != btScalar(0.0)); 62 61 btScalar s = btSin(angle * btScalar(0.5)) / d; 63 62 setValue(axis.x() * s, axis.y() * s, axis.z() * s, … … 178 177 btQuaternion operator/(const btScalar& s) const 179 178 { 180 btAssert(s != btScalar(0.0));179 assert(s != btScalar(0.0)); 181 180 return *this * (btScalar(1.0) / s); 182 181 } … … 186 185 btQuaternion& operator/=(const btScalar& s) 187 186 { 188 btAssert(s != btScalar(0.0));187 assert(s != btScalar(0.0)); 189 188 return *this *= btScalar(1.0) / s; 190 189 } … … 200 199 { 201 200 btScalar s = btSqrt(length2() * q.length2()); 202 btAssert(s != btScalar(0.0));201 assert(s != btScalar(0.0)); 203 202 return btAcos(dot(q) / s); 204 203 } … … 276 275 } 277 276 278 static const btQuaternion& getIdentity()279 {280 static const btQuaternion identityQuat(btScalar(0.),btScalar(0.),btScalar(0.),btScalar(1.));281 return identityQuat;282 }283 284 277 SIMD_FORCE_INLINE const btScalar& getW() const { return m_floats[3]; } 285 278 -
code/branches/questsystem5/src/bullet/LinearMath/btScalar.h
r2907 r2908 26 26 #include <float.h> 27 27 28 #define BT_BULLET_VERSION 27 428 #define BT_BULLET_VERSION 273 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))66 64 #define BT_USE_SSE 67 #include <emmintrin.h> 68 #endif 69 70 #endif//_XBOX 71 65 #endif 72 66 #endif //__MINGW32__ 73 67 … … 131 125 132 126 #define SIMD_FORCE_INLINE inline 133 ///@todo: check out alignment methods for other platforms/compilers134 ///#define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16)))135 ///#define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128)))136 127 #define ATTRIBUTE_ALIGNED16(a) a 137 128 #define ATTRIBUTE_ALIGNED128(a) a … … 242 233 SIMD_FORCE_INLINE btScalar btPow(btScalar x,btScalar y) { return powf(x,y); } 243 234 #endif 244 235 245 236 #endif 246 237 -
code/branches/questsystem5/src/bullet/LinearMath/btTransform.h
r2907 r2908 191 191 192 192 /**@brief Return an identity transform */ 193 static const btTransform& getIdentity() 194 { 195 static const btTransform identityTransform(btMatrix3x3::getIdentity()); 196 return identityTransform; 193 static btTransform getIdentity() 194 { 195 btTransform tr; 196 tr.setIdentity(); 197 return tr; 197 198 } 198 199 -
code/branches/questsystem5/src/bullet/LinearMath/btVector3.h
r2907 r2908 18 18 #define SIMD__VECTOR3_H 19 19 20 21 #include "btScalar.h" 22 #include "btScalar.h" 23 #include "btMinMax.h" 20 #include "btQuadWord.h" 21 24 22 /**@brief btVector3 can be used to represent 3D points and vectors. 25 23 * 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 26 24 * Ideally, this class should be replaced by a platform optimized SIMD version that keeps the data in registers 27 25 */ 28 29 ATTRIBUTE_ALIGNED16(class) btVector3 30 { 26 class btVector3 : public btQuadWord { 27 31 28 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() const40 {41 return mVec128;42 }43 public:44 #else //__CELLOS_LV2__ __SPU__45 #ifdef BT_USE_SSE // WIN3246 union {47 __m128 mVec128;48 btScalar m_floats[4];49 };50 SIMD_FORCE_INLINE __m128 get128() const51 {52 return mVec128;53 }54 SIMD_FORCE_INLINE void set128(__m128 v128)55 {56 mVec128 = v128;57 }58 #else59 btScalar m_floats[4];60 #endif61 #endif //__CELLOS_LV2__ __SPU__62 63 public:64 65 29 /**@brief No initialization constructor */ 66 30 SIMD_FORCE_INLINE btVector3() {} 67 31 68 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 } 69 38 70 39 /**@brief Constructor from scalars … … 73 42 * @param z Z value 74 43 */ 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 } 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 // } 82 53 83 54 … … 87 58 { 88 59 89 m_floats[0] += v. m_floats[0]; m_floats[1] += v.m_floats[1];m_floats[2] += v.m_floats[2];60 m_floats[0] += v.x(); m_floats[1] += v.y(); m_floats[2] += v.z(); 90 61 return *this; 91 62 } … … 96 67 SIMD_FORCE_INLINE btVector3& operator-=(const btVector3& v) 97 68 { 98 m_floats[0] -= v. m_floats[0]; m_floats[1] -= v.m_floats[1];m_floats[2] -= v.m_floats[2];69 m_floats[0] -= v.x(); m_floats[1] -= v.y(); m_floats[2] -= v.z(); 99 70 return *this; 100 71 } … … 103 74 SIMD_FORCE_INLINE btVector3& operator*=(const btScalar& s) 104 75 { 105 m_floats[0] *= s; m_floats[1] *= s; m_floats[2] *= s;76 m_floats[0] *= s; m_floats[1] *= s; m_floats[2] *= s; 106 77 return *this; 107 78 } … … 119 90 SIMD_FORCE_INLINE btScalar dot(const btVector3& v) const 120 91 { 121 return m_floats[0] * v. m_floats[0] + m_floats[1] * v.m_floats[1] +m_floats[2] * v.m_floats[2];92 return m_floats[0] * v.x() + m_floats[1] * v.y() + m_floats[2] * v.z(); 122 93 } 123 94 … … 178 149 { 179 150 return btVector3( 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]);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()); 183 154 } 184 155 185 156 SIMD_FORCE_INLINE btScalar triple(const btVector3& v1, const btVector3& v2) const 186 157 { 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]);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()); 190 161 } 191 162 … … 194 165 SIMD_FORCE_INLINE int minAxis() const 195 166 { 196 return m_floats[0] < m_floats[1] ? (m_floats[0] < m_floats[2] ? 0 : 2) : (m_floats[1] <m_floats[2] ? 1 : 2);167 return m_floats[0] < m_floats[1] ? (m_floats[0] < m_floats[2] ? 0 : 2) : (m_floats[1] < m_floats[2] ? 1 : 2); 197 168 } 198 169 … … 201 172 SIMD_FORCE_INLINE int maxAxis() const 202 173 { 203 return m_floats[0] < m_floats[1] ? (m_floats[1] < m_floats[2] ? 2 : 1) : (m_floats[0] <m_floats[2] ? 2 : 0);174 return m_floats[0] < m_floats[1] ? (m_floats[1] < m_floats[2] ? 2 : 1) : (m_floats[0] < m_floats[2] ? 2 : 0); 204 175 } 205 176 … … 217 188 { 218 189 btScalar s = btScalar(1.0) - rt; 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];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(); 222 193 //don't do the unused w component 223 194 // m_co[3] = s * v0[3] + rt * v1[3]; … … 229 200 SIMD_FORCE_INLINE btVector3 lerp(const btVector3& v, const btScalar& t) const 230 201 { 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);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); 234 205 } 235 206 … … 238 209 SIMD_FORCE_INLINE btVector3& operator*=(const btVector3& v) 239 210 { 240 m_floats[0] *= v. m_floats[0]; m_floats[1] *= v.m_floats[1];m_floats[2] *= v.m_floats[2];211 m_floats[0] *= v.x(); m_floats[1] *= v.y(); m_floats[2] *= v.z(); 241 212 return *this; 242 213 } 243 214 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 } 215 318 216 319 217 }; … … 323 221 operator+(const btVector3& v1, const btVector3& v2) 324 222 { 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]);223 return btVector3(v1.x() + v2.x(), v1.y() + v2.y(), v1.z() + v2.z()); 326 224 } 327 225 … … 330 228 operator*(const btVector3& v1, const btVector3& v2) 331 229 { 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]);230 return btVector3(v1.x() * v2.x(), v1.y() * v2.y(), v1.z() * v2.z()); 333 231 } 334 232 … … 337 235 operator-(const btVector3& v1, const btVector3& v2) 338 236 { 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]);237 return btVector3(v1.x() - v2.x(), v1.y() - v2.y(), v1.z() - v2.z()); 340 238 } 341 239 /**@brief Return the negative of the vector */ … … 343 241 operator-(const btVector3& v) 344 242 { 345 return btVector3(-v. m_floats[0], -v.m_floats[1], -v.m_floats[2]);243 return btVector3(-v.x(), -v.y(), -v.z()); 346 244 } 347 245 … … 350 248 operator*(const btVector3& v, const btScalar& s) 351 249 { 352 return btVector3(v. m_floats[0] * s, v.m_floats[1] * s, v.m_floats[2]* s);250 return btVector3(v.x() * s, v.y() * s, v.z() * s); 353 251 } 354 252 … … 372 270 operator/(const btVector3& v1, const btVector3& v2) 373 271 { 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]);272 return btVector3(v1.x() / v2.x(),v1.y() / v2.y(),v1.z() / v2.z()); 375 273 } 376 274 … … 428 326 } 429 327 430 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 } 431 333 432 334 SIMD_FORCE_INLINE btScalar btVector3::distance2(const btVector3& v) const … … 503 405 { 504 406 maxIndex = 2; 505 maxVal = m_floats[2];407 maxVal = m_floats[2]; 506 408 } 507 409 if (m_floats[3] > maxVal) … … 536 438 { 537 439 minIndex = 2; 538 minVal = m_floats[2];440 minVal = m_floats[2]; 539 441 } 540 442 if (m_floats[3] < minVal) … … 553 455 return absolute4().maxAxis4(); 554 456 } 555 556 557 558 559 /**@brief Set x,y,z and zero w560 * @param x Value of x561 * @param y Value of y562 * @param z Value of z563 */564 565 566 /* void getValue(btScalar *m) const567 {568 m[0] = m_floats[0];569 m[1] = m_floats[1];570 m[2] =m_floats[2];571 }572 */573 /**@brief Set the values574 * @param x Value of x575 * @param y Value of y576 * @param z Value of z577 * @param w Value of w578 */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 589 457 590 458 };
Note: See TracChangeset
for help on using the changeset viewer.