source: trunk/src/bullet/LinearMath/btVector3.h @ 1640

Last change on this file since 1640 was 1640, checked in by sam, 9 years ago

core: fix shitloads of compiler warnings in the Bullet source code.

  • Property svn:keywords set to Id
File size: 20.6 KB
Line 
1/*
2Copyright (c) 2003-2006 Gino van den Bergen / Erwin Coumans  http://continuousphysics.com/Bullet/
3
4This software is provided 'as-is', without any express or implied warranty.
5In no event will the authors be held liable for any damages arising from the use of this software.
6Permission is granted to anyone to use this software for any purpose,
7including commercial applications, and to alter it and redistribute it freely,
8subject to the following restrictions:
9
101. 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.
112. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
123. This notice may not be removed or altered from any source distribution.
13*/
14
15
16
17#ifndef BT_VECTOR3_H
18#define BT_VECTOR3_H
19
20
21#include "btScalar.h"
22#include "btMinMax.h"
23
24#ifdef BT_USE_DOUBLE_PRECISION
25#define btVector3Data btVector3DoubleData
26#define btVector3DataName "btVector3DoubleData"
27#else
28#define btVector3Data btVector3FloatData
29#define btVector3DataName "btVector3FloatData"
30#endif //BT_USE_DOUBLE_PRECISION
31
32
33
34
35/**@brief btVector3 can be used to represent 3D points and vectors.
36 * 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
37 * Ideally, this class should be replaced by a platform optimized SIMD version that keeps the data in registers
38 */
39ATTRIBUTE_ALIGNED16(class) btVector3
40{
41public:
42
43#if defined (__SPU__) && defined (__CELLOS_LV2__)
44                btScalar        m_floats[4];
45public:
46        SIMD_FORCE_INLINE const vec_float4&     get128() const
47        {
48                return *((const vec_float4*)&m_floats[0]);
49        }
50public:
51#else //__CELLOS_LV2__ __SPU__
52#ifdef BT_USE_SSE // _WIN32
53        union {
54                __m128 mVec128;
55                btScalar        m_floats[4];
56        };
57        SIMD_FORCE_INLINE       __m128  get128() const
58        {
59                return mVec128;
60        }
61        SIMD_FORCE_INLINE       void    set128(__m128 v128)
62        {
63                mVec128 = v128;
64        }
65#else
66        btScalar        m_floats[4];
67#endif
68#endif //__CELLOS_LV2__ __SPU__
69
70        public:
71
72  /**@brief No initialization constructor */
73        SIMD_FORCE_INLINE btVector3() {}
74
75 
76       
77  /**@brief Constructor from scalars
78   * @param x X value
79   * @param y Y value
80   * @param z Z value
81   */
82// LOL BEGIN
83        SIMD_FORCE_INLINE btVector3(const btScalar& _x, const btScalar& _y, const btScalar& _z)
84        {
85                m_floats[0] = _x;
86                m_floats[1] = _y;
87                m_floats[2] = _z;
88                m_floats[3] = btScalar(0.);
89        }
90// LOL END
91
92       
93/**@brief Add a vector to this one
94 * @param The vector to add to this one */
95        SIMD_FORCE_INLINE btVector3& operator+=(const btVector3& v)
96        {
97
98                m_floats[0] += v.m_floats[0]; m_floats[1] += v.m_floats[1];m_floats[2] += v.m_floats[2];
99                return *this;
100        }
101
102
103  /**@brief Subtract a vector from this one
104   * @param The vector to subtract */
105        SIMD_FORCE_INLINE btVector3& operator-=(const btVector3& v)
106        {
107                m_floats[0] -= v.m_floats[0]; m_floats[1] -= v.m_floats[1];m_floats[2] -= v.m_floats[2];
108                return *this;
109        }
110  /**@brief Scale the vector
111   * @param s Scale factor */
112        SIMD_FORCE_INLINE btVector3& operator*=(const btScalar& s)
113        {
114                m_floats[0] *= s; m_floats[1] *= s;m_floats[2] *= s;
115                return *this;
116        }
117
118  /**@brief Inversely scale the vector
119   * @param s Scale factor to divide by */
120        SIMD_FORCE_INLINE btVector3& operator/=(const btScalar& s)
121        {
122                btFullAssert(s != btScalar(0.0));
123                return *this *= btScalar(1.0) / s;
124        }
125
126  /**@brief Return the dot product
127   * @param v The other vector in the dot product */
128        SIMD_FORCE_INLINE btScalar dot(const btVector3& v) const
129        {
130                return m_floats[0] * v.m_floats[0] + m_floats[1] * v.m_floats[1] +m_floats[2] * v.m_floats[2];
131        }
132
133  /**@brief Return the length of the vector squared */
134        SIMD_FORCE_INLINE btScalar length2() const
135        {
136                return dot(*this);
137        }
138
139  /**@brief Return the length of the vector */
140        SIMD_FORCE_INLINE btScalar length() const
141        {
142                return btSqrt(length2());
143        }
144
145  /**@brief Return the distance squared between the ends of this and another vector
146   * This is symantically treating the vector like a point */
147        SIMD_FORCE_INLINE btScalar distance2(const btVector3& v) const;
148
149  /**@brief Return the distance between the ends of this and another vector
150   * This is symantically treating the vector like a point */
151        SIMD_FORCE_INLINE btScalar distance(const btVector3& v) const;
152
153        SIMD_FORCE_INLINE btVector3& safeNormalize()
154        {
155                btVector3 absVec = this->absolute();
156                int maxIndex = absVec.maxAxis();
157                if (absVec[maxIndex]>0)
158                {
159                        *this /= absVec[maxIndex];
160                        return *this /= length();
161                }
162                setValue(1,0,0);
163                return *this;
164        }
165
166  /**@brief Normalize this vector
167   * x^2 + y^2 + z^2 = 1 */
168        SIMD_FORCE_INLINE btVector3& normalize()
169        {
170                return *this /= length();
171        }
172
173  /**@brief Return a normalized version of this vector */
174        SIMD_FORCE_INLINE btVector3 normalized() const;
175
176  /**@brief Return a rotated version of this vector
177   * @param wAxis The axis to rotate about
178   * @param angle The angle to rotate by */
179        SIMD_FORCE_INLINE btVector3 rotate( const btVector3& wAxis, const btScalar angle ) const;
180
181  /**@brief Return the angle between this and another vector
182   * @param v The other vector */
183        SIMD_FORCE_INLINE btScalar angle(const btVector3& v) const
184        {
185                btScalar s = btSqrt(length2() * v.length2());
186                btFullAssert(s != btScalar(0.0));
187                return btAcos(dot(v) / s);
188        }
189  /**@brief Return a vector will the absolute values of each element */
190        SIMD_FORCE_INLINE btVector3 absolute() const
191        {
192                return btVector3(
193                        btFabs(m_floats[0]),
194                        btFabs(m_floats[1]),
195                        btFabs(m_floats[2]));
196        }
197  /**@brief Return the cross product between this and another vector
198   * @param v The other vector */
199        SIMD_FORCE_INLINE btVector3 cross(const btVector3& v) const
200        {
201                return btVector3(
202                        m_floats[1] * v.m_floats[2] -m_floats[2] * v.m_floats[1],
203                        m_floats[2] * v.m_floats[0] - m_floats[0] * v.m_floats[2],
204                        m_floats[0] * v.m_floats[1] - m_floats[1] * v.m_floats[0]);
205        }
206
207        SIMD_FORCE_INLINE btScalar triple(const btVector3& v1, const btVector3& v2) const
208        {
209                return m_floats[0] * (v1.m_floats[1] * v2.m_floats[2] - v1.m_floats[2] * v2.m_floats[1]) +
210                        m_floats[1] * (v1.m_floats[2] * v2.m_floats[0] - v1.m_floats[0] * v2.m_floats[2]) +
211                        m_floats[2] * (v1.m_floats[0] * v2.m_floats[1] - v1.m_floats[1] * v2.m_floats[0]);
212        }
213
214  /**@brief Return the axis with the smallest value
215   * Note return values are 0,1,2 for x, y, or z */
216        SIMD_FORCE_INLINE int minAxis() const
217        {
218                return m_floats[0] < m_floats[1] ? (m_floats[0] <m_floats[2] ? 0 : 2) : (m_floats[1] <m_floats[2] ? 1 : 2);
219        }
220
221  /**@brief Return the axis with the largest value
222   * Note return values are 0,1,2 for x, y, or z */
223        SIMD_FORCE_INLINE int maxAxis() const
224        {
225                return m_floats[0] < m_floats[1] ? (m_floats[1] <m_floats[2] ? 2 : 1) : (m_floats[0] <m_floats[2] ? 2 : 0);
226        }
227
228        SIMD_FORCE_INLINE int furthestAxis() const
229        {
230                return absolute().minAxis();
231        }
232
233        SIMD_FORCE_INLINE int closestAxis() const
234        {
235                return absolute().maxAxis();
236        }
237
238        SIMD_FORCE_INLINE void setInterpolate3(const btVector3& v0, const btVector3& v1, btScalar rt)
239        {
240                btScalar s = btScalar(1.0) - rt;
241                m_floats[0] = s * v0.m_floats[0] + rt * v1.m_floats[0];
242                m_floats[1] = s * v0.m_floats[1] + rt * v1.m_floats[1];
243                m_floats[2] = s * v0.m_floats[2] + rt * v1.m_floats[2];
244                //don't do the unused w component
245                //              m_co[3] = s * v0[3] + rt * v1[3];
246        }
247
248  /**@brief Return the linear interpolation between this and another vector
249   * @param v The other vector
250   * @param t The ration of this to v (t = 0 => return this, t=1 => return other) */
251        SIMD_FORCE_INLINE btVector3 lerp(const btVector3& v, const btScalar& t) const
252        {
253                return btVector3(m_floats[0] + (v.m_floats[0] - m_floats[0]) * t,
254                        m_floats[1] + (v.m_floats[1] - m_floats[1]) * t,
255                        m_floats[2] + (v.m_floats[2] -m_floats[2]) * t);
256        }
257
258  /**@brief Elementwise multiply this vector by the other
259   * @param v The other vector */
260        SIMD_FORCE_INLINE btVector3& operator*=(const btVector3& v)
261        {
262                m_floats[0] *= v.m_floats[0]; m_floats[1] *= v.m_floats[1];m_floats[2] *= v.m_floats[2];
263                return *this;
264        }
265
266         /**@brief Return the x value */
267                SIMD_FORCE_INLINE const btScalar& getX() const { return m_floats[0]; }
268  /**@brief Return the y value */
269                SIMD_FORCE_INLINE const btScalar& getY() const { return m_floats[1]; }
270  /**@brief Return the z value */
271                SIMD_FORCE_INLINE const btScalar& getZ() const { return m_floats[2]; }
272// LOL BEGIN
273  /**@brief Set the x value */
274                SIMD_FORCE_INLINE void  setX(btScalar _x) { m_floats[0] = _x;};
275  /**@brief Set the y value */
276                SIMD_FORCE_INLINE void  setY(btScalar _y) { m_floats[1] = _y;};
277  /**@brief Set the z value */
278                SIMD_FORCE_INLINE void  setZ(btScalar _z) {m_floats[2] = _z;};
279  /**@brief Set the w value */
280                SIMD_FORCE_INLINE void  setW(btScalar _w) { m_floats[3] = _w;};
281// LOL END
282  /**@brief Return the x value */
283                SIMD_FORCE_INLINE const btScalar& x() const { return m_floats[0]; }
284  /**@brief Return the y value */
285                SIMD_FORCE_INLINE const btScalar& y() const { return m_floats[1]; }
286  /**@brief Return the z value */
287                SIMD_FORCE_INLINE const btScalar& z() const { return m_floats[2]; }
288  /**@brief Return the w value */
289                SIMD_FORCE_INLINE const btScalar& w() const { return m_floats[3]; }
290
291        //SIMD_FORCE_INLINE btScalar&       operator[](int i)       { return (&m_floats[0])[i]; }     
292        //SIMD_FORCE_INLINE const btScalar& operator[](int i) const { return (&m_floats[0])[i]; }
293        ///operator btScalar*() replaces operator[], using implicit conversion. We added operator != and operator == to avoid pointer comparisons.
294        SIMD_FORCE_INLINE       operator       btScalar *()       { return &m_floats[0]; }
295        SIMD_FORCE_INLINE       operator const btScalar *() const { return &m_floats[0]; }
296
297        SIMD_FORCE_INLINE       bool    operator==(const btVector3& other) const
298        {
299                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]));
300        }
301
302        SIMD_FORCE_INLINE       bool    operator!=(const btVector3& other) const
303        {
304                return !(*this == other);
305        }
306
307         /**@brief Set each element to the max of the current values and the values of another btVector3
308   * @param other The other btVector3 to compare with
309   */
310                SIMD_FORCE_INLINE void  setMax(const btVector3& other)
311                {
312                        btSetMax(m_floats[0], other.m_floats[0]);
313                        btSetMax(m_floats[1], other.m_floats[1]);
314                        btSetMax(m_floats[2], other.m_floats[2]);
315                        btSetMax(m_floats[3], other.w());
316                }
317  /**@brief Set each element to the min of the current values and the values of another btVector3
318   * @param other The other btVector3 to compare with
319   */
320                SIMD_FORCE_INLINE void  setMin(const btVector3& other)
321                {
322                        btSetMin(m_floats[0], other.m_floats[0]);
323                        btSetMin(m_floats[1], other.m_floats[1]);
324                        btSetMin(m_floats[2], other.m_floats[2]);
325                        btSetMin(m_floats[3], other.w());
326                }
327
328// LOL BEGIN
329                SIMD_FORCE_INLINE void  setValue(const btScalar& _x, const btScalar& _y, const btScalar& _z)
330                {
331                        m_floats[0]=_x;
332                        m_floats[1]=_y;
333                        m_floats[2]=_z;
334                        m_floats[3] = btScalar(0.);
335                }
336// LOL END
337
338                void    getSkewSymmetricMatrix(btVector3* v0,btVector3* v1,btVector3* v2) const
339                {
340                        v0->setValue(0.         ,-z()           ,y());
341                        v1->setValue(z()        ,0.                     ,-x());
342                        v2->setValue(-y()       ,x()    ,0.);
343                }
344
345                void    setZero()
346                {
347                        setValue(btScalar(0.),btScalar(0.),btScalar(0.));
348                }
349
350                SIMD_FORCE_INLINE bool isZero() const
351                {
352                        return m_floats[0] == btScalar(0) && m_floats[1] == btScalar(0) && m_floats[2] == btScalar(0);
353                }
354
355                SIMD_FORCE_INLINE bool fuzzyZero() const
356                {
357                        return length2() < SIMD_EPSILON;
358                }
359
360                SIMD_FORCE_INLINE       void    serialize(struct        btVector3Data& dataOut) const;
361
362                SIMD_FORCE_INLINE       void    deSerialize(const struct        btVector3Data& dataIn);
363
364                SIMD_FORCE_INLINE       void    serializeFloat(struct   btVector3FloatData& dataOut) const;
365
366                SIMD_FORCE_INLINE       void    deSerializeFloat(const struct   btVector3FloatData& dataIn);
367
368                SIMD_FORCE_INLINE       void    serializeDouble(struct  btVector3DoubleData& dataOut) const;
369
370                SIMD_FORCE_INLINE       void    deSerializeDouble(const struct  btVector3DoubleData& dataIn);
371
372};
373
374/**@brief Return the sum of two vectors (Point symantics)*/
375SIMD_FORCE_INLINE btVector3
376operator+(const btVector3& v1, const btVector3& v2)
377{
378        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]);
379}
380
381/**@brief Return the elementwise product of two vectors */
382SIMD_FORCE_INLINE btVector3
383operator*(const btVector3& v1, const btVector3& v2)
384{
385        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]);
386}
387
388/**@brief Return the difference between two vectors */
389SIMD_FORCE_INLINE btVector3
390operator-(const btVector3& v1, const btVector3& v2)
391{
392        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]);
393}
394/**@brief Return the negative of the vector */
395SIMD_FORCE_INLINE btVector3
396operator-(const btVector3& v)
397{
398        return btVector3(-v.m_floats[0], -v.m_floats[1], -v.m_floats[2]);
399}
400
401/**@brief Return the vector scaled by s */
402SIMD_FORCE_INLINE btVector3
403operator*(const btVector3& v, const btScalar& s)
404{
405        return btVector3(v.m_floats[0] * s, v.m_floats[1] * s, v.m_floats[2] * s);
406}
407
408/**@brief Return the vector scaled by s */
409SIMD_FORCE_INLINE btVector3
410operator*(const btScalar& s, const btVector3& v)
411{
412        return v * s;
413}
414
415/**@brief Return the vector inversely scaled by s */
416SIMD_FORCE_INLINE btVector3
417operator/(const btVector3& v, const btScalar& s)
418{
419        btFullAssert(s != btScalar(0.0));
420        return v * (btScalar(1.0) / s);
421}
422
423/**@brief Return the vector inversely scaled by s */
424SIMD_FORCE_INLINE btVector3
425operator/(const btVector3& v1, const btVector3& v2)
426{
427        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]);
428}
429
430/**@brief Return the dot product between two vectors */
431SIMD_FORCE_INLINE btScalar
432btDot(const btVector3& v1, const btVector3& v2)
433{
434        return v1.dot(v2);
435}
436
437
438/**@brief Return the distance squared between two vectors */
439SIMD_FORCE_INLINE btScalar
440btDistance2(const btVector3& v1, const btVector3& v2)
441{
442        return v1.distance2(v2);
443}
444
445
446/**@brief Return the distance between two vectors */
447SIMD_FORCE_INLINE btScalar
448btDistance(const btVector3& v1, const btVector3& v2)
449{
450        return v1.distance(v2);
451}
452
453/**@brief Return the angle between two vectors */
454SIMD_FORCE_INLINE btScalar
455btAngle(const btVector3& v1, const btVector3& v2)
456{
457        return v1.angle(v2);
458}
459
460/**@brief Return the cross product of two vectors */
461SIMD_FORCE_INLINE btVector3
462btCross(const btVector3& v1, const btVector3& v2)
463{
464        return v1.cross(v2);
465}
466
467SIMD_FORCE_INLINE btScalar
468btTriple(const btVector3& v1, const btVector3& v2, const btVector3& v3)
469{
470        return v1.triple(v2, v3);
471}
472
473/**@brief Return the linear interpolation between two vectors
474 * @param v1 One vector
475 * @param v2 The other vector
476 * @param t The ration of this to v (t = 0 => return v1, t=1 => return v2) */
477SIMD_FORCE_INLINE btVector3
478lerp(const btVector3& v1, const btVector3& v2, const btScalar& t)
479{
480        return v1.lerp(v2, t);
481}
482
483
484
485SIMD_FORCE_INLINE btScalar btVector3::distance2(const btVector3& v) const
486{
487        return (v - *this).length2();
488}
489
490SIMD_FORCE_INLINE btScalar btVector3::distance(const btVector3& v) const
491{
492        return (v - *this).length();
493}
494
495SIMD_FORCE_INLINE btVector3 btVector3::normalized() const
496{
497        return *this / length();
498}
499
500// LOL BEGIN
501SIMD_FORCE_INLINE btVector3 btVector3::rotate( const btVector3& wAxis, const btScalar _angle ) const
502{
503        // wAxis must be a unit lenght vector
504
505        btVector3 o = wAxis * wAxis.dot( *this );
506        btVector3 _x = *this - o;
507        btVector3 _y;
508
509        _y = wAxis.cross( *this );
510
511        return ( o + _x * btCos( _angle ) + _y * btSin( _angle ) );
512}
513// LOL END
514
515class btVector4 : public btVector3
516{
517public:
518
519        SIMD_FORCE_INLINE btVector4() {}
520
521
522// LOL BEGIN
523        SIMD_FORCE_INLINE btVector4(const btScalar& _x, const btScalar& _y, const btScalar& _z,const btScalar& _w)
524                : btVector3(_x,_y,_z)
525        {
526                m_floats[3] = _w;
527        }
528// LOL END
529
530
531        SIMD_FORCE_INLINE btVector4 absolute4() const
532        {
533                return btVector4(
534                        btFabs(m_floats[0]),
535                        btFabs(m_floats[1]),
536                        btFabs(m_floats[2]),
537                        btFabs(m_floats[3]));
538        }
539
540
541
542        btScalar        getW() const { return m_floats[3];}
543
544
545                SIMD_FORCE_INLINE int maxAxis4() const
546        {
547                int maxIndex = -1;
548                btScalar maxVal = btScalar(-BT_LARGE_FLOAT);
549                if (m_floats[0] > maxVal)
550                {
551                        maxIndex = 0;
552                        maxVal = m_floats[0];
553                }
554                if (m_floats[1] > maxVal)
555                {
556                        maxIndex = 1;
557                        maxVal = m_floats[1];
558                }
559                if (m_floats[2] > maxVal)
560                {
561                        maxIndex = 2;
562                        maxVal =m_floats[2];
563                }
564                if (m_floats[3] > maxVal)
565                {
566                        maxIndex = 3;
567                        maxVal = m_floats[3];
568                }
569               
570               
571               
572
573                return maxIndex;
574
575        }
576
577
578        SIMD_FORCE_INLINE int minAxis4() const
579        {
580                int minIndex = -1;
581                btScalar minVal = btScalar(BT_LARGE_FLOAT);
582                if (m_floats[0] < minVal)
583                {
584                        minIndex = 0;
585                        minVal = m_floats[0];
586                }
587                if (m_floats[1] < minVal)
588                {
589                        minIndex = 1;
590                        minVal = m_floats[1];
591                }
592                if (m_floats[2] < minVal)
593                {
594                        minIndex = 2;
595                        minVal =m_floats[2];
596                }
597                if (m_floats[3] < minVal)
598                {
599                        minIndex = 3;
600                        minVal = m_floats[3];
601                }
602               
603                return minIndex;
604
605        }
606
607
608        SIMD_FORCE_INLINE int closestAxis4() const
609        {
610                return absolute4().maxAxis4();
611        }
612
613       
614 
615
616  /**@brief Set x,y,z and zero w
617   * @param x Value of x
618   * @param y Value of y
619   * @param z Value of z
620   */
621               
622
623/*              void getValue(btScalar *m) const
624                {
625                        m[0] = m_floats[0];
626                        m[1] = m_floats[1];
627                        m[2] =m_floats[2];
628                }
629*/
630/**@brief Set the values
631   * @param x Value of x
632   * @param y Value of y
633   * @param z Value of z
634   * @param w Value of w
635   */
636// LOL BEGIN
637                SIMD_FORCE_INLINE void  setValue(const btScalar& _x, const btScalar& _y, const btScalar& _z,const btScalar& _w)
638                {
639                        m_floats[0]=_x;
640                        m_floats[1]=_y;
641                        m_floats[2]=_z;
642                        m_floats[3]=_w;
643                }
644// LOL END
645
646
647};
648
649
650///btSwapVector3Endian swaps vector endianness, useful for network and cross-platform serialization
651SIMD_FORCE_INLINE void  btSwapScalarEndian(const btScalar& sourceVal, btScalar& destVal)
652{
653        #ifdef BT_USE_DOUBLE_PRECISION
654        unsigned char* dest = (unsigned char*) &destVal;
655// LOL BEGIN
656        unsigned char const* src  = (unsigned char const*) &sourceVal;
657// LOL END
658        dest[0] = src[7];
659    dest[1] = src[6];
660    dest[2] = src[5];
661    dest[3] = src[4];
662    dest[4] = src[3];
663    dest[5] = src[2];
664    dest[6] = src[1];
665    dest[7] = src[0];
666#else
667        unsigned char* dest = (unsigned char*) &destVal;
668// LOL BEGIN
669        unsigned char const* src  = (unsigned char const*) &sourceVal;
670// LOL END
671        dest[0] = src[3];
672    dest[1] = src[2];
673    dest[2] = src[1];
674    dest[3] = src[0];
675#endif //BT_USE_DOUBLE_PRECISION
676}
677///btSwapVector3Endian swaps vector endianness, useful for network and cross-platform serialization
678SIMD_FORCE_INLINE void  btSwapVector3Endian(const btVector3& sourceVec, btVector3& destVec)
679{
680        for (int i=0;i<4;i++)
681        {
682                btSwapScalarEndian(sourceVec[i],destVec[i]);
683        }
684
685}
686
687///btUnSwapVector3Endian swaps vector endianness, useful for network and cross-platform serialization
688SIMD_FORCE_INLINE void  btUnSwapVector3Endian(btVector3& vector)
689{
690
691        btVector3       swappedVec;
692        for (int i=0;i<4;i++)
693        {
694                btSwapScalarEndian(vector[i],swappedVec[i]);
695        }
696        vector = swappedVec;
697}
698
699template <class T>
700SIMD_FORCE_INLINE void btPlaneSpace1 (const T& n, T& p, T& q)
701{
702  if (btFabs(n[2]) > SIMDSQRT12) {
703    // choose p in y-z plane
704    btScalar a = n[1]*n[1] + n[2]*n[2];
705    btScalar k = btRecipSqrt (a);
706    p[0] = 0;
707        p[1] = -n[2]*k;
708        p[2] = n[1]*k;
709    // set q = n x p
710    q[0] = a*k;
711        q[1] = -n[0]*p[2];
712        q[2] = n[0]*p[1];
713  }
714  else {
715    // choose p in x-y plane
716    btScalar a = n[0]*n[0] + n[1]*n[1];
717    btScalar k = btRecipSqrt (a);
718    p[0] = -n[1]*k;
719        p[1] = n[0]*k;
720        p[2] = 0;
721    // set q = n x p
722    q[0] = -n[2]*p[1];
723        q[1] = n[2]*p[0];
724        q[2] = a*k;
725  }
726}
727
728
729struct  btVector3FloatData
730{
731        float   m_floats[4];
732};
733
734struct  btVector3DoubleData
735{
736        double  m_floats[4];
737
738};
739
740SIMD_FORCE_INLINE       void    btVector3::serializeFloat(struct        btVector3FloatData& dataOut) const
741{
742        ///could also do a memcpy, check if it is worth it
743        for (int i=0;i<4;i++)
744                dataOut.m_floats[i] = float(m_floats[i]);
745}
746
747SIMD_FORCE_INLINE void  btVector3::deSerializeFloat(const struct        btVector3FloatData& dataIn)
748{
749        for (int i=0;i<4;i++)
750                m_floats[i] = btScalar(dataIn.m_floats[i]);
751}
752
753
754SIMD_FORCE_INLINE       void    btVector3::serializeDouble(struct       btVector3DoubleData& dataOut) const
755{
756        ///could also do a memcpy, check if it is worth it
757        for (int i=0;i<4;i++)
758                dataOut.m_floats[i] = double(m_floats[i]);
759}
760
761SIMD_FORCE_INLINE void  btVector3::deSerializeDouble(const struct       btVector3DoubleData& dataIn)
762{
763        for (int i=0;i<4;i++)
764                m_floats[i] = btScalar(dataIn.m_floats[i]);
765}
766
767
768SIMD_FORCE_INLINE       void    btVector3::serialize(struct     btVector3Data& dataOut) const
769{
770        ///could also do a memcpy, check if it is worth it
771        for (int i=0;i<4;i++)
772                dataOut.m_floats[i] = m_floats[i];
773}
774
775SIMD_FORCE_INLINE void  btVector3::deSerialize(const struct     btVector3Data& dataIn)
776{
777        for (int i=0;i<4;i++)
778                m_floats[i] = dataIn.m_floats[i];
779}
780
781
782#endif //BT_VECTOR3_H
Note: See TracBrowser for help on using the repository browser.