matrix_operation.inl 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /// @ref gtx_matrix_operation
  2. namespace glm
  3. {
  4. template<typename T, qualifier Q>
  5. GLM_FUNC_QUALIFIER mat<2, 2, T, Q> diagonal2x2
  6. (
  7. vec<2, T, Q> const& v
  8. )
  9. {
  10. mat<2, 2, T, Q> Result(static_cast<T>(1));
  11. Result[0][0] = v[0];
  12. Result[1][1] = v[1];
  13. return Result;
  14. }
  15. template<typename T, qualifier Q>
  16. GLM_FUNC_QUALIFIER mat<2, 3, T, Q> diagonal2x3
  17. (
  18. vec<2, T, Q> const& v
  19. )
  20. {
  21. mat<2, 3, T, Q> Result(static_cast<T>(1));
  22. Result[0][0] = v[0];
  23. Result[1][1] = v[1];
  24. return Result;
  25. }
  26. template<typename T, qualifier Q>
  27. GLM_FUNC_QUALIFIER mat<2, 4, T, Q> diagonal2x4
  28. (
  29. vec<2, T, Q> const& v
  30. )
  31. {
  32. mat<2, 4, T, Q> Result(static_cast<T>(1));
  33. Result[0][0] = v[0];
  34. Result[1][1] = v[1];
  35. return Result;
  36. }
  37. template<typename T, qualifier Q>
  38. GLM_FUNC_QUALIFIER mat<3, 2, T, Q> diagonal3x2
  39. (
  40. vec<2, T, Q> const& v
  41. )
  42. {
  43. mat<3, 2, T, Q> Result(static_cast<T>(1));
  44. Result[0][0] = v[0];
  45. Result[1][1] = v[1];
  46. return Result;
  47. }
  48. template<typename T, qualifier Q>
  49. GLM_FUNC_QUALIFIER mat<3, 3, T, Q> diagonal3x3
  50. (
  51. vec<3, T, Q> const& v
  52. )
  53. {
  54. mat<3, 3, T, Q> Result(static_cast<T>(1));
  55. Result[0][0] = v[0];
  56. Result[1][1] = v[1];
  57. Result[2][2] = v[2];
  58. return Result;
  59. }
  60. template<typename T, qualifier Q>
  61. GLM_FUNC_QUALIFIER mat<3, 4, T, Q> diagonal3x4
  62. (
  63. vec<3, T, Q> const& v
  64. )
  65. {
  66. mat<3, 4, T, Q> Result(static_cast<T>(1));
  67. Result[0][0] = v[0];
  68. Result[1][1] = v[1];
  69. Result[2][2] = v[2];
  70. return Result;
  71. }
  72. template<typename T, qualifier Q>
  73. GLM_FUNC_QUALIFIER mat<4, 4, T, Q> diagonal4x4
  74. (
  75. vec<4, T, Q> const& v
  76. )
  77. {
  78. mat<4, 4, T, Q> Result(static_cast<T>(1));
  79. Result[0][0] = v[0];
  80. Result[1][1] = v[1];
  81. Result[2][2] = v[2];
  82. Result[3][3] = v[3];
  83. return Result;
  84. }
  85. template<typename T, qualifier Q>
  86. GLM_FUNC_QUALIFIER mat<4, 3, T, Q> diagonal4x3
  87. (
  88. vec<3, T, Q> const& v
  89. )
  90. {
  91. mat<4, 3, T, Q> Result(static_cast<T>(1));
  92. Result[0][0] = v[0];
  93. Result[1][1] = v[1];
  94. Result[2][2] = v[2];
  95. return Result;
  96. }
  97. template<typename T, qualifier Q>
  98. GLM_FUNC_QUALIFIER mat<4, 2, T, Q> diagonal4x2
  99. (
  100. vec<2, T, Q> const& v
  101. )
  102. {
  103. mat<4, 2, T, Q> Result(static_cast<T>(1));
  104. Result[0][0] = v[0];
  105. Result[1][1] = v[1];
  106. return Result;
  107. }
  108. template<typename T, qualifier Q>
  109. GLM_FUNC_QUALIFIER mat<2, 2, T, Q> adjugate(mat<2, 2, T, Q> const& m)
  110. {
  111. return mat<2, 2, T, Q>(
  112. +m[1][1], -m[1][0],
  113. -m[0][1], +m[0][0]);
  114. }
  115. template<typename T, qualifier Q>
  116. GLM_FUNC_QUALIFIER mat<3, 3, T, Q> adjugate(mat<3, 3, T, Q> const& m)
  117. {
  118. T const m00 = determinant(mat<2, 2, T, Q>(m[1][1], m[2][1], m[1][2], m[2][2]));
  119. T const m01 = determinant(mat<2, 2, T, Q>(m[0][1], m[2][1], m[0][2], m[2][2]));
  120. T const m02 = determinant(mat<2, 2, T, Q>(m[0][1], m[1][1], m[0][2], m[1][2]));
  121. T const m10 = determinant(mat<2, 2, T, Q>(m[1][0], m[2][0], m[1][2], m[2][2]));
  122. T const m11 = determinant(mat<2, 2, T, Q>(m[0][0], m[2][0], m[0][2], m[2][2]));
  123. T const m12 = determinant(mat<2, 2, T, Q>(m[0][0], m[1][0], m[0][2], m[1][2]));
  124. T const m20 = determinant(mat<2, 2, T, Q>(m[1][0], m[2][0], m[1][1], m[2][1]));
  125. T const m21 = determinant(mat<2, 2, T, Q>(m[0][0], m[2][0], m[0][1], m[2][1]));
  126. T const m22 = determinant(mat<2, 2, T, Q>(m[0][0], m[1][0], m[0][1], m[1][1]));
  127. return mat<3, 3, T, Q>(
  128. +m00, -m01, +m02,
  129. -m10, +m11, -m12,
  130. +m20, -m21, +m22);
  131. }
  132. template<typename T, qualifier Q>
  133. GLM_FUNC_QUALIFIER mat<4, 4, T, Q> adjugate(mat<4, 4, T, Q> const& m)
  134. {
  135. T const m00 = determinant(mat<3, 3, T, Q>(m[1][1], m[1][2], m[1][3], m[2][1], m[2][2], m[2][3], m[3][1], m[3][2], m[3][3]));
  136. T const m01 = determinant(mat<3, 3, T, Q>(m[1][0], m[1][2], m[1][3], m[2][0], m[2][2], m[2][3], m[3][0], m[3][2], m[3][3]));
  137. T const m02 = determinant(mat<3, 3, T, Q>(m[1][0], m[1][1], m[1][3], m[2][0], m[2][2], m[2][3], m[3][0], m[3][1], m[3][3]));
  138. T const m03 = determinant(mat<3, 3, T, Q>(m[1][0], m[1][1], m[1][2], m[2][0], m[2][1], m[2][2], m[3][0], m[3][1], m[3][2]));
  139. T const m10 = determinant(mat<3, 3, T, Q>(m[0][1], m[0][2], m[0][3], m[2][1], m[2][2], m[2][3], m[3][1], m[3][2], m[3][3]));
  140. T const m11 = determinant(mat<3, 3, T, Q>(m[0][0], m[0][2], m[0][3], m[2][0], m[2][2], m[2][3], m[3][0], m[3][2], m[3][3]));
  141. T const m12 = determinant(mat<3, 3, T, Q>(m[0][0], m[0][1], m[0][3], m[2][0], m[2][1], m[2][3], m[3][0], m[3][1], m[3][3]));
  142. T const m13 = determinant(mat<3, 3, T, Q>(m[0][0], m[0][1], m[0][2], m[2][0], m[2][1], m[2][2], m[3][0], m[3][1], m[3][2]));
  143. T const m20 = determinant(mat<3, 3, T, Q>(m[0][1], m[0][2], m[0][3], m[1][1], m[1][2], m[1][3], m[3][1], m[3][2], m[3][3]));
  144. T const m21 = determinant(mat<3, 3, T, Q>(m[0][0], m[0][2], m[0][3], m[1][0], m[1][2], m[1][3], m[3][0], m[3][2], m[3][3]));
  145. T const m22 = determinant(mat<3, 3, T, Q>(m[0][0], m[0][1], m[0][3], m[1][0], m[1][1], m[1][3], m[3][0], m[3][1], m[3][3]));
  146. T const m23 = determinant(mat<3, 3, T, Q>(m[0][0], m[0][1], m[0][2], m[1][0], m[1][1], m[1][2], m[3][0], m[3][1], m[3][2]));
  147. T const m30 = determinant(mat<3, 3, T, Q>(m[0][1], m[0][2], m[0][3], m[1][1], m[1][2], m[1][3], m[2][1], m[2][2], m[2][3]));
  148. T const m31 = determinant(mat<3, 3, T, Q>(m[0][0], m[0][2], m[0][3], m[1][0], m[1][2], m[1][3], m[2][0], m[2][2], m[2][3]));
  149. T const m32 = determinant(mat<3, 3, T, Q>(m[0][0], m[0][1], m[0][3], m[1][0], m[1][1], m[1][3], m[2][0], m[2][1], m[2][3]));
  150. T const m33 = determinant(mat<3, 3, T, Q>(m[0][0], m[0][1], m[0][2], m[1][0], m[1][1], m[1][2], m[2][0], m[2][1], m[2][2]));
  151. return mat<4, 4, T, Q>(
  152. +m00, -m01, +m02, -m03,
  153. -m10, +m11, -m12, +m13,
  154. +m20, -m21, +m22, -m23,
  155. -m30, +m31, -m32, +m33);
  156. }
  157. }//namespace glm