You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

191 regels
6.0 KiB

  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 BT_SIMD_QUADWORD_H
  13. #define BT_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. // LOL BEGIN
  51. /**@brief Set the x value */
  52. SIMD_FORCE_INLINE void setX(btScalar _x) { m_floats[0] = _x;};
  53. /**@brief Set the y value */
  54. SIMD_FORCE_INLINE void setY(btScalar _y) { m_floats[1] = _y;};
  55. /**@brief Set the z value */
  56. SIMD_FORCE_INLINE void setZ(btScalar _z) { m_floats[2] = _z;};
  57. /**@brief Set the w value */
  58. SIMD_FORCE_INLINE void setW(btScalar _w) { m_floats[3] = _w;};
  59. // LOL END
  60. /**@brief Return the x value */
  61. SIMD_FORCE_INLINE const btScalar& x() const { return m_floats[0]; }
  62. /**@brief Return the y value */
  63. SIMD_FORCE_INLINE const btScalar& y() const { return m_floats[1]; }
  64. /**@brief Return the z value */
  65. SIMD_FORCE_INLINE const btScalar& z() const { return m_floats[2]; }
  66. /**@brief Return the w value */
  67. SIMD_FORCE_INLINE const btScalar& w() const { return m_floats[3]; }
  68. //SIMD_FORCE_INLINE btScalar& operator[](int i) { return (&m_floats[0])[i]; }
  69. //SIMD_FORCE_INLINE const btScalar& operator[](int i) const { return (&m_floats[0])[i]; }
  70. ///operator btScalar*() replaces operator[], using implicit conversion. We added operator != and operator == to avoid pointer comparisons.
  71. SIMD_FORCE_INLINE operator btScalar *() { return &m_floats[0]; }
  72. SIMD_FORCE_INLINE operator const btScalar *() const { return &m_floats[0]; }
  73. SIMD_FORCE_INLINE bool operator==(const btQuadWord& other) const
  74. {
  75. 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]));
  76. }
  77. SIMD_FORCE_INLINE bool operator!=(const btQuadWord& other) const
  78. {
  79. return !(*this == other);
  80. }
  81. /**@brief Set x,y,z and zero w
  82. * @param x Value of x
  83. * @param y Value of y
  84. * @param z Value of z
  85. */
  86. // LOL BEGIN
  87. SIMD_FORCE_INLINE void setValue(const btScalar& _x, const btScalar& _y, const btScalar& _z)
  88. {
  89. m_floats[0]=_x;
  90. m_floats[1]=_y;
  91. m_floats[2]=_z;
  92. m_floats[3] = 0.f;
  93. }
  94. // LOL END
  95. /* void getValue(btScalar *m) const
  96. {
  97. m[0] = m_floats[0];
  98. m[1] = m_floats[1];
  99. m[2] = m_floats[2];
  100. }
  101. */
  102. /**@brief Set the values
  103. * @param x Value of x
  104. * @param y Value of y
  105. * @param z Value of z
  106. * @param w Value of w
  107. */
  108. // LOL BEGIN
  109. SIMD_FORCE_INLINE void setValue(const btScalar& _x, const btScalar& _y, const btScalar& _z,const btScalar& _w)
  110. {
  111. m_floats[0]=_x;
  112. m_floats[1]=_y;
  113. m_floats[2]=_z;
  114. m_floats[3]=_w;
  115. }
  116. // LOL END
  117. /**@brief No initialization constructor */
  118. SIMD_FORCE_INLINE btQuadWord()
  119. // :m_floats[0](btScalar(0.)),m_floats[1](btScalar(0.)),m_floats[2](btScalar(0.)),m_floats[3](btScalar(0.))
  120. {
  121. }
  122. /**@brief Three argument constructor (zeros w)
  123. * @param x Value of x
  124. * @param y Value of y
  125. * @param z Value of z
  126. */
  127. // LOL BEGIN
  128. SIMD_FORCE_INLINE btQuadWord(const btScalar& _x, const btScalar& _y, const btScalar& _z)
  129. {
  130. m_floats[0] = _x, m_floats[1] = _y, m_floats[2] = _z, m_floats[3] = 0.0f;
  131. }
  132. // LOL END
  133. /**@brief Initializing constructor
  134. * @param x Value of x
  135. * @param y Value of y
  136. * @param z Value of z
  137. * @param w Value of w
  138. */
  139. // LOL BEGIN
  140. SIMD_FORCE_INLINE btQuadWord(const btScalar& _x, const btScalar& _y, const btScalar& _z,const btScalar& _w)
  141. {
  142. m_floats[0] = _x, m_floats[1] = _y, m_floats[2] = _z, m_floats[3] = _w;
  143. }
  144. // LOL END
  145. /**@brief Set each element to the max 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 setMax(const btQuadWord& other)
  149. {
  150. btSetMax(m_floats[0], other.m_floats[0]);
  151. btSetMax(m_floats[1], other.m_floats[1]);
  152. btSetMax(m_floats[2], other.m_floats[2]);
  153. btSetMax(m_floats[3], other.m_floats[3]);
  154. }
  155. /**@brief Set each element to the min of the current values and the values of another btQuadWord
  156. * @param other The other btQuadWord to compare with
  157. */
  158. SIMD_FORCE_INLINE void setMin(const btQuadWord& other)
  159. {
  160. btSetMin(m_floats[0], other.m_floats[0]);
  161. btSetMin(m_floats[1], other.m_floats[1]);
  162. btSetMin(m_floats[2], other.m_floats[2]);
  163. btSetMin(m_floats[3], other.m_floats[3]);
  164. }
  165. };
  166. #endif //BT_SIMD_QUADWORD_H