btQuadWord.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. Copyright (c) 2003-2006 Gino van den Bergen / Erwin Coumans http://continuousphysics.com/Bullet/
  3. This software is provided 'as-is', without any express or implied warranty.
  4. In no event will the authors be held liable for any damages arising from the use of this software.
  5. Permission is granted to anyone to use this software for any purpose,
  6. including commercial applications, and to alter it and redistribute it freely,
  7. subject to the following restrictions:
  8. 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  9. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  10. 3. This notice may not be removed or altered from any source distribution.
  11. */
  12. #ifndef SIMD_QUADWORD_H
  13. #define SIMD_QUADWORD_H
  14. #include "btScalar.h"
  15. #include "btMinMax.h"
  16. #if defined (__CELLOS_LV2) && defined (__SPU__)
  17. #include <altivec.h>
  18. #endif
  19. /**@brief The btQuadWord class is base class for btVector3 and btQuaternion.
  20. * Some issues under PS3 Linux with IBM 2.1 SDK, gcc compiler prevent from using aligned quadword.
  21. */
  22. #ifndef USE_LIBSPE2
  23. ATTRIBUTE_ALIGNED16(class) btQuadWord
  24. #else
  25. class btQuadWord
  26. #endif
  27. {
  28. protected:
  29. #if defined (__SPU__) && defined (__CELLOS_LV2__)
  30. union {
  31. vec_float4 mVec128;
  32. btScalar m_floats[4];
  33. };
  34. public:
  35. vec_float4 get128() const
  36. {
  37. return mVec128;
  38. }
  39. protected:
  40. #else //__CELLOS_LV2__ __SPU__
  41. btScalar m_floats[4];
  42. #endif //__CELLOS_LV2__ __SPU__
  43. public:
  44. /**@brief Return the x value */
  45. SIMD_FORCE_INLINE const btScalar& getX() const { return m_floats[0]; }
  46. /**@brief Return the y value */
  47. SIMD_FORCE_INLINE const btScalar& getY() const { return m_floats[1]; }
  48. /**@brief Return the z value */
  49. SIMD_FORCE_INLINE const btScalar& getZ() const { return m_floats[2]; }
  50. /**@brief Set the x value */
  51. SIMD_FORCE_INLINE void setX(btScalar x) { m_floats[0] = x;};
  52. /**@brief Set the y value */
  53. SIMD_FORCE_INLINE void setY(btScalar y) { m_floats[1] = y;};
  54. /**@brief Set the z value */
  55. SIMD_FORCE_INLINE void setZ(btScalar z) { m_floats[2] = z;};
  56. /**@brief Set the w value */
  57. SIMD_FORCE_INLINE void setW(btScalar w) { m_floats[3] = w;};
  58. /**@brief Return the x value */
  59. SIMD_FORCE_INLINE const btScalar& x() const { return m_floats[0]; }
  60. /**@brief Return the y value */
  61. SIMD_FORCE_INLINE const btScalar& y() const { return m_floats[1]; }
  62. /**@brief Return the z value */
  63. SIMD_FORCE_INLINE const btScalar& z() const { return m_floats[2]; }
  64. /**@brief Return the w value */
  65. SIMD_FORCE_INLINE const btScalar& w() const { return m_floats[3]; }
  66. //SIMD_FORCE_INLINE btScalar& operator[](int i) { return (&m_floats[0])[i]; }
  67. //SIMD_FORCE_INLINE const btScalar& operator[](int i) const { return (&m_floats[0])[i]; }
  68. ///operator btScalar*() replaces operator[], using implicit conversion. We added operator != and operator == to avoid pointer comparisons.
  69. SIMD_FORCE_INLINE operator btScalar *() { return &m_floats[0]; }
  70. SIMD_FORCE_INLINE operator const btScalar *() const { return &m_floats[0]; }
  71. SIMD_FORCE_INLINE bool operator==(const btQuadWord& other) const
  72. {
  73. 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]));
  74. }
  75. SIMD_FORCE_INLINE bool operator!=(const btQuadWord& other) const
  76. {
  77. return !(*this == other);
  78. }
  79. /**@brief Set x,y,z and zero w
  80. * @param x Value of x
  81. * @param y Value of y
  82. * @param z Value of z
  83. */
  84. SIMD_FORCE_INLINE void setValue(const btScalar& x, const btScalar& y, const btScalar& z)
  85. {
  86. m_floats[0]=x;
  87. m_floats[1]=y;
  88. m_floats[2]=z;
  89. m_floats[3] = 0.f;
  90. }
  91. /* void getValue(btScalar *m) const
  92. {
  93. m[0] = m_floats[0];
  94. m[1] = m_floats[1];
  95. m[2] = m_floats[2];
  96. }
  97. */
  98. /**@brief Set the values
  99. * @param x Value of x
  100. * @param y Value of y
  101. * @param z Value of z
  102. * @param w Value of w
  103. */
  104. SIMD_FORCE_INLINE void setValue(const btScalar& x, const btScalar& y, const btScalar& z,const btScalar& w)
  105. {
  106. m_floats[0]=x;
  107. m_floats[1]=y;
  108. m_floats[2]=z;
  109. m_floats[3]=w;
  110. }
  111. /**@brief No initialization constructor */
  112. SIMD_FORCE_INLINE btQuadWord()
  113. // :m_floats[0](btScalar(0.)),m_floats[1](btScalar(0.)),m_floats[2](btScalar(0.)),m_floats[3](btScalar(0.))
  114. {
  115. }
  116. /**@brief Three argument constructor (zeros w)
  117. * @param x Value of x
  118. * @param y Value of y
  119. * @param z Value of z
  120. */
  121. SIMD_FORCE_INLINE btQuadWord(const btScalar& x, const btScalar& y, const btScalar& z)
  122. {
  123. m_floats[0] = x, m_floats[1] = y, m_floats[2] = z, m_floats[3] = 0.0f;
  124. }
  125. /**@brief Initializing constructor
  126. * @param x Value of x
  127. * @param y Value of y
  128. * @param z Value of z
  129. * @param w Value of w
  130. */
  131. SIMD_FORCE_INLINE btQuadWord(const btScalar& x, const btScalar& y, const btScalar& z,const btScalar& w)
  132. {
  133. m_floats[0] = x, m_floats[1] = y, m_floats[2] = z, m_floats[3] = w;
  134. }
  135. /**@brief Set each element to the max of the current values and the values of another btQuadWord
  136. * @param other The other btQuadWord to compare with
  137. */
  138. SIMD_FORCE_INLINE void setMax(const btQuadWord& other)
  139. {
  140. btSetMax(m_floats[0], other.m_floats[0]);
  141. btSetMax(m_floats[1], other.m_floats[1]);
  142. btSetMax(m_floats[2], other.m_floats[2]);
  143. btSetMax(m_floats[3], other.m_floats[3]);
  144. }
  145. /**@brief Set each element to the min of the current values and the values of another btQuadWord
  146. * @param other The other btQuadWord to compare with
  147. */
  148. SIMD_FORCE_INLINE void setMin(const btQuadWord& other)
  149. {
  150. btSetMin(m_floats[0], other.m_floats[0]);
  151. btSetMin(m_floats[1], other.m_floats[1]);
  152. btSetMin(m_floats[2], other.m_floats[2]);
  153. btSetMin(m_floats[3], other.m_floats[3]);
  154. }
  155. };
  156. #endif //SIMD_QUADWORD_H