Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/physics_merge/src/bullet/LinearMath/btQuadWord.h @ 2442

Last change on this file since 2442 was 2442, checked in by rgrieder, 15 years ago

Finally merged physics stuff. Target is physics_merge because I'll have to do some testing first.

  • Property svn:eol-style set to native
File size: 6.1 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#ifndef SIMD_QUADWORD_H
17#define SIMD_QUADWORD_H
18
19#include "btScalar.h"
20#include "btMinMax.h"
21
22
23#if defined (__CELLOS_LV2) && defined (__SPU__)
24#include <altivec.h>
25#endif
26
27/**@brief The btQuadWordStorage class is base class for btVector3 and btQuaternion.
28 * Some issues under PS3 Linux with IBM 2.1 SDK, gcc compiler prevent from using aligned quadword.
29 */
30#ifndef USE_LIBSPE2
31ATTRIBUTE_ALIGNED16(class) btQuadWordStorage
32#else
33class btQuadWordStorage
34#endif
35{
36protected:
37
38#if defined (__SPU__) && defined (__CELLOS_LV2__)
39        union {
40                vec_float4 mVec128;
41                btScalar        m_floats[4];
42        };
43public:
44        vec_float4      get128() const
45        {
46                return mVec128;
47        }
48#else //__CELLOS_LV2__ __SPU__
49        btScalar        m_floats[4];
50#endif //__CELLOS_LV2__ __SPU__
51
52};
53
54/** @brief The btQuadWord is base-class for vectors, points */
55class   btQuadWord : public btQuadWordStorage
56{
57        public:
58 
59
60  /**@brief Return the x value */
61                SIMD_FORCE_INLINE const btScalar& getX() const { return m_floats[0]; }
62  /**@brief Return the y value */
63                SIMD_FORCE_INLINE const btScalar& getY() const { return m_floats[1]; }
64  /**@brief Return the z value */
65                SIMD_FORCE_INLINE const btScalar& getZ() const { return m_floats[2]; }
66  /**@brief Set the x value */
67                SIMD_FORCE_INLINE void  setX(btScalar x) { m_floats[0] = x;};
68  /**@brief Set the y value */
69                SIMD_FORCE_INLINE void  setY(btScalar y) { m_floats[1] = y;};
70  /**@brief Set the z value */
71                SIMD_FORCE_INLINE void  setZ(btScalar z) { m_floats[2] = z;};
72  /**@brief Set the w value */
73                SIMD_FORCE_INLINE void  setW(btScalar w) { m_floats[3] = w;};
74  /**@brief Return the x value */
75                SIMD_FORCE_INLINE const btScalar& x() const { return m_floats[0]; }
76  /**@brief Return the y value */
77                SIMD_FORCE_INLINE const btScalar& y() const { return m_floats[1]; }
78  /**@brief Return the z value */
79                SIMD_FORCE_INLINE const btScalar& z() const { return m_floats[2]; }
80  /**@brief Return the w value */
81                SIMD_FORCE_INLINE const btScalar& w() const { return m_floats[3]; }
82
83        //SIMD_FORCE_INLINE btScalar&       operator[](int i)       { return (&m_floats[0])[i]; }     
84        //SIMD_FORCE_INLINE const btScalar& operator[](int i) const { return (&m_floats[0])[i]; }
85        ///operator btScalar*() replaces operator[], using implicit conversion. We added operator != and operator == to avoid pointer comparisons.
86        SIMD_FORCE_INLINE       operator       btScalar *()       { return &m_floats[0]; }
87        SIMD_FORCE_INLINE       operator const btScalar *() const { return &m_floats[0]; }
88
89        SIMD_FORCE_INLINE       bool    operator==(const btQuadWord& other) const
90        {
91                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]));
92        }
93
94        SIMD_FORCE_INLINE       bool    operator!=(const btQuadWord& other) const
95        {
96                return !(*this == other);
97        }
98
99  /**@brief Set x,y,z and zero w
100   * @param x Value of x
101   * @param y Value of y
102   * @param z Value of z
103   */
104                SIMD_FORCE_INLINE void  setValue(const btScalar& x, const btScalar& y, const btScalar& z)
105                {
106                        m_floats[0]=x;
107                        m_floats[1]=y;
108                        m_floats[2]=z;
109                        m_floats[3] = 0.f;
110                }
111
112/*              void getValue(btScalar *m) const
113                {
114                        m[0] = m_floats[0];
115                        m[1] = m_floats[1];
116                        m[2] = m_floats[2];
117                }
118*/
119/**@brief Set the values
120   * @param x Value of x
121   * @param y Value of y
122   * @param z Value of z
123   * @param w Value of w
124   */
125                SIMD_FORCE_INLINE void  setValue(const btScalar& x, const btScalar& y, const btScalar& z,const btScalar& w)
126                {
127                        m_floats[0]=x;
128                        m_floats[1]=y;
129                        m_floats[2]=z;
130                        m_floats[3]=w;
131                }
132  /**@brief No initialization constructor */
133                SIMD_FORCE_INLINE btQuadWord()
134                //      :m_floats[0](btScalar(0.)),m_floats[1](btScalar(0.)),m_floats[2](btScalar(0.)),m_floats[3](btScalar(0.))
135                {
136                }
137  /**@brief Copy constructor */
138                SIMD_FORCE_INLINE btQuadWord(const btQuadWordStorage& q)
139                {
140                        *((btQuadWordStorage*)this) = q;
141                }
142  /**@brief Three argument constructor (zeros w)
143   * @param x Value of x
144   * @param y Value of y
145   * @param z Value of z
146   */
147                SIMD_FORCE_INLINE btQuadWord(const btScalar& x, const btScalar& y, const btScalar& z)           
148                {
149                        m_floats[0] = x, m_floats[1] = y, m_floats[2] = z, m_floats[3] = 0.0f;
150                }
151
152/**@brief Initializing constructor
153   * @param x Value of x
154   * @param y Value of y
155   * @param z Value of z
156   * @param w Value of w
157   */
158                SIMD_FORCE_INLINE btQuadWord(const btScalar& x, const btScalar& y, const btScalar& z,const btScalar& w) 
159                {
160                        m_floats[0] = x, m_floats[1] = y, m_floats[2] = z, m_floats[3] = w;
161                }
162
163  /**@brief Set each element to the max of the current values and the values of another btQuadWord
164   * @param other The other btQuadWord to compare with
165   */
166                SIMD_FORCE_INLINE void  setMax(const btQuadWord& other)
167                {
168                        btSetMax(m_floats[0], other.m_floats[0]);
169                        btSetMax(m_floats[1], other.m_floats[1]);
170                        btSetMax(m_floats[2], other.m_floats[2]);
171                        btSetMax(m_floats[3], other.m_floats[3]);
172                }
173  /**@brief Set each element to the min of the current values and the values of another btQuadWord
174   * @param other The other btQuadWord to compare with
175   */
176                SIMD_FORCE_INLINE void  setMin(const btQuadWord& other)
177                {
178                        btSetMin(m_floats[0], other.m_floats[0]);
179                        btSetMin(m_floats[1], other.m_floats[1]);
180                        btSetMin(m_floats[2], other.m_floats[2]);
181                        btSetMin(m_floats[3], other.m_floats[3]);
182                }
183
184
185
186};
187
188#endif //SIMD_QUADWORD_H
Note: See TracBrowser for help on using the repository browser.