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.

206 lines
6.9 KiB

4 years ago
  1. ///////////////////////////////////////////////////////////////////////////////////
  2. /// OpenGL Mathematics (glm.g-truc.net)
  3. ///
  4. /// Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
  5. /// Permission is hereby granted, free of charge, to any person obtaining a copy
  6. /// of this software and associated documentation files (the "Software"), to deal
  7. /// in the Software without restriction, including without limitation the rights
  8. /// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. /// copies of the Software, and to permit persons to whom the Software is
  10. /// furnished to do so, subject to the following conditions:
  11. ///
  12. /// The above copyright notice and this permission notice shall be included in
  13. /// all copies or substantial portions of the Software.
  14. ///
  15. /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. /// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. /// THE SOFTWARE.
  22. ///
  23. /// @ref gtx_simd_vec4
  24. /// @file glm/gtx/simd_vec4.hpp
  25. /// @date 2009-05-07 / 2011-06-07
  26. /// @author Christophe Riccio
  27. ///
  28. /// @see core (dependence)
  29. ///
  30. /// @defgroup gtx_simd_mat4 GLM_GTX_simd_mat4
  31. /// @ingroup gtx
  32. ///
  33. /// @brief SIMD implementation of mat4 type.
  34. ///
  35. /// <glm/gtx/simd_mat4.hpp> need to be included to use these functionalities.
  36. ///////////////////////////////////////////////////////////////////////////////////
  37. #ifndef GLM_GTX_simd_mat4
  38. #define GLM_GTX_simd_mat4 GLM_VERSION
  39. // Dependency:
  40. #include "../glm.hpp"
  41. #if(GLM_ARCH != GLM_ARCH_PURE)
  42. #if(GLM_ARCH & GLM_ARCH_SSE2)
  43. # include "../core/intrinsic_matrix.hpp"
  44. # include "../gtx/simd_vec4.hpp"
  45. #else
  46. # error "GLM: GLM_GTX_simd_mat4 requires compiler support of SSE2 through intrinsics"
  47. #endif
  48. #if(defined(GLM_MESSAGES) && !defined(glm_ext))
  49. # pragma message("GLM: GLM_GTX_simd_mat4 extension included")
  50. #endif
  51. namespace glm{
  52. namespace detail
  53. {
  54. /// 4x4 Matrix implemented using SIMD SEE intrinsics.
  55. /// \ingroup gtx_simd_mat4
  56. GLM_ALIGNED_STRUCT(16) fmat4x4SIMD
  57. {
  58. enum ctor{null};
  59. typedef float value_type;
  60. typedef fvec4SIMD col_type;
  61. typedef fvec4SIMD row_type;
  62. typedef std::size_t size_type;
  63. static size_type value_size();
  64. static size_type col_size();
  65. static size_type row_size();
  66. static bool is_matrix();
  67. fvec4SIMD Data[4];
  68. //////////////////////////////////////
  69. // Constructors
  70. fmat4x4SIMD();
  71. explicit fmat4x4SIMD(float const & s);
  72. explicit fmat4x4SIMD(
  73. float const & x0, float const & y0, float const & z0, float const & w0,
  74. float const & x1, float const & y1, float const & z1, float const & w1,
  75. float const & x2, float const & y2, float const & z2, float const & w2,
  76. float const & x3, float const & y3, float const & z3, float const & w3);
  77. explicit fmat4x4SIMD(
  78. fvec4SIMD const & v0,
  79. fvec4SIMD const & v1,
  80. fvec4SIMD const & v2,
  81. fvec4SIMD const & v3);
  82. explicit fmat4x4SIMD(
  83. tmat4x4<float> const & m);
  84. explicit fmat4x4SIMD(
  85. __m128 const in[4]);
  86. // Conversions
  87. //template <typename U>
  88. //explicit tmat4x4(tmat4x4<U> const & m);
  89. //explicit tmat4x4(tmat2x2<T> const & x);
  90. //explicit tmat4x4(tmat3x3<T> const & x);
  91. //explicit tmat4x4(tmat2x3<T> const & x);
  92. //explicit tmat4x4(tmat3x2<T> const & x);
  93. //explicit tmat4x4(tmat2x4<T> const & x);
  94. //explicit tmat4x4(tmat4x2<T> const & x);
  95. //explicit tmat4x4(tmat3x4<T> const & x);
  96. //explicit tmat4x4(tmat4x3<T> const & x);
  97. // Accesses
  98. fvec4SIMD & operator[](size_type i);
  99. fvec4SIMD const & operator[](size_type i) const;
  100. // Unary updatable operators
  101. fmat4x4SIMD & operator= (fmat4x4SIMD const & m);
  102. fmat4x4SIMD & operator+= (float const & s);
  103. fmat4x4SIMD & operator+= (fmat4x4SIMD const & m);
  104. fmat4x4SIMD & operator-= (float const & s);
  105. fmat4x4SIMD & operator-= (fmat4x4SIMD const & m);
  106. fmat4x4SIMD & operator*= (float const & s);
  107. fmat4x4SIMD & operator*= (fmat4x4SIMD const & m);
  108. fmat4x4SIMD & operator/= (float const & s);
  109. fmat4x4SIMD & operator/= (fmat4x4SIMD const & m);
  110. fmat4x4SIMD & operator++ ();
  111. fmat4x4SIMD & operator-- ();
  112. };
  113. // Binary operators
  114. fmat4x4SIMD operator+ (fmat4x4SIMD const & m, float const & s);
  115. fmat4x4SIMD operator+ (float const & s, fmat4x4SIMD const & m);
  116. fmat4x4SIMD operator+ (fmat4x4SIMD const & m1, fmat4x4SIMD const & m2);
  117. fmat4x4SIMD operator- (fmat4x4SIMD const & m, float const & s);
  118. fmat4x4SIMD operator- (float const & s, fmat4x4SIMD const & m);
  119. fmat4x4SIMD operator- (fmat4x4SIMD const & m1, fmat4x4SIMD const & m2);
  120. fmat4x4SIMD operator* (fmat4x4SIMD const & m, float const & s);
  121. fmat4x4SIMD operator* (float const & s, fmat4x4SIMD const & m);
  122. fvec4SIMD operator* (fmat4x4SIMD const & m, fvec4SIMD const & v);
  123. fvec4SIMD operator* (fvec4SIMD const & v, fmat4x4SIMD const & m);
  124. fmat4x4SIMD operator* (fmat4x4SIMD const & m1, fmat4x4SIMD const & m2);
  125. fmat4x4SIMD operator/ (fmat4x4SIMD const & m, float const & s);
  126. fmat4x4SIMD operator/ (float const & s, fmat4x4SIMD const & m);
  127. fvec4SIMD operator/ (fmat4x4SIMD const & m, fvec4SIMD const & v);
  128. fvec4SIMD operator/ (fvec4SIMD const & v, fmat4x4SIMD const & m);
  129. fmat4x4SIMD operator/ (fmat4x4SIMD const & m1, fmat4x4SIMD const & m2);
  130. // Unary constant operators
  131. fmat4x4SIMD const operator- (fmat4x4SIMD const & m);
  132. fmat4x4SIMD const operator-- (fmat4x4SIMD const & m, int);
  133. fmat4x4SIMD const operator++ (fmat4x4SIMD const & m, int);
  134. }//namespace detail
  135. typedef detail::fmat4x4SIMD simdMat4;
  136. /// @addtogroup gtx_simd_mat4
  137. /// @{
  138. //! Convert a simdMat4 to a mat4.
  139. //! (From GLM_GTX_simd_mat4 extension)
  140. detail::tmat4x4<float> mat4_cast(
  141. detail::fmat4x4SIMD const & x);
  142. //! Multiply matrix x by matrix y component-wise, i.e.,
  143. //! result[i][j] is the scalar product of x[i][j] and y[i][j].
  144. //! (From GLM_GTX_simd_mat4 extension).
  145. detail::fmat4x4SIMD matrixCompMult(
  146. detail::fmat4x4SIMD const & x,
  147. detail::fmat4x4SIMD const & y);
  148. //! Treats the first parameter c as a column vector
  149. //! and the second parameter r as a row vector
  150. //! and does a linear algebraic matrix multiply c * r.
  151. //! (From GLM_GTX_simd_mat4 extension).
  152. detail::fmat4x4SIMD outerProduct(
  153. detail::fvec4SIMD const & c,
  154. detail::fvec4SIMD const & r);
  155. //! Returns the transposed matrix of x
  156. //! (From GLM_GTX_simd_mat4 extension).
  157. detail::fmat4x4SIMD transpose(
  158. detail::fmat4x4SIMD const & x);
  159. //! Return the determinant of a mat4 matrix.
  160. //! (From GLM_GTX_simd_mat4 extension).
  161. float determinant(
  162. detail::fmat4x4SIMD const & m);
  163. //! Return the inverse of a mat4 matrix.
  164. //! (From GLM_GTX_simd_mat4 extension).
  165. detail::fmat4x4SIMD inverse(
  166. detail::fmat4x4SIMD const & m);
  167. /// @}
  168. }// namespace glm
  169. #include "simd_mat4.inl"
  170. #endif//(GLM_ARCH != GLM_ARCH_PURE)
  171. #endif//GLM_GTX_simd_mat4