matrix_major_storage.inl 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /// @ref gtx_matrix_major_storage
  2. namespace glm
  3. {
  4. template<typename T, qualifier Q>
  5. GLM_FUNC_QUALIFIER mat<2, 2, T, Q> rowMajor2
  6. (
  7. vec<2, T, Q> const& v1,
  8. vec<2, T, Q> const& v2
  9. )
  10. {
  11. mat<2, 2, T, Q> Result;
  12. Result[0][0] = v1.x;
  13. Result[1][0] = v1.y;
  14. Result[0][1] = v2.x;
  15. Result[1][1] = v2.y;
  16. return Result;
  17. }
  18. template<typename T, qualifier Q>
  19. GLM_FUNC_QUALIFIER mat<2, 2, T, Q> rowMajor2(
  20. const mat<2, 2, T, Q>& m)
  21. {
  22. mat<2, 2, T, Q> Result;
  23. Result[0][0] = m[0][0];
  24. Result[0][1] = m[1][0];
  25. Result[1][0] = m[0][1];
  26. Result[1][1] = m[1][1];
  27. return Result;
  28. }
  29. template<typename T, qualifier Q>
  30. GLM_FUNC_QUALIFIER mat<3, 3, T, Q> rowMajor3(
  31. const vec<3, T, Q>& v1,
  32. const vec<3, T, Q>& v2,
  33. const vec<3, T, Q>& v3)
  34. {
  35. mat<3, 3, T, Q> Result;
  36. Result[0][0] = v1.x;
  37. Result[1][0] = v1.y;
  38. Result[2][0] = v1.z;
  39. Result[0][1] = v2.x;
  40. Result[1][1] = v2.y;
  41. Result[2][1] = v2.z;
  42. Result[0][2] = v3.x;
  43. Result[1][2] = v3.y;
  44. Result[2][2] = v3.z;
  45. return Result;
  46. }
  47. template<typename T, qualifier Q>
  48. GLM_FUNC_QUALIFIER mat<3, 3, T, Q> rowMajor3(
  49. const mat<3, 3, T, Q>& m)
  50. {
  51. mat<3, 3, T, Q> Result;
  52. Result[0][0] = m[0][0];
  53. Result[0][1] = m[1][0];
  54. Result[0][2] = m[2][0];
  55. Result[1][0] = m[0][1];
  56. Result[1][1] = m[1][1];
  57. Result[1][2] = m[2][1];
  58. Result[2][0] = m[0][2];
  59. Result[2][1] = m[1][2];
  60. Result[2][2] = m[2][2];
  61. return Result;
  62. }
  63. template<typename T, qualifier Q>
  64. GLM_FUNC_QUALIFIER mat<4, 4, T, Q> rowMajor4(
  65. const vec<4, T, Q>& v1,
  66. const vec<4, T, Q>& v2,
  67. const vec<4, T, Q>& v3,
  68. const vec<4, T, Q>& v4)
  69. {
  70. mat<4, 4, T, Q> Result;
  71. Result[0][0] = v1.x;
  72. Result[1][0] = v1.y;
  73. Result[2][0] = v1.z;
  74. Result[3][0] = v1.w;
  75. Result[0][1] = v2.x;
  76. Result[1][1] = v2.y;
  77. Result[2][1] = v2.z;
  78. Result[3][1] = v2.w;
  79. Result[0][2] = v3.x;
  80. Result[1][2] = v3.y;
  81. Result[2][2] = v3.z;
  82. Result[3][2] = v3.w;
  83. Result[0][3] = v4.x;
  84. Result[1][3] = v4.y;
  85. Result[2][3] = v4.z;
  86. Result[3][3] = v4.w;
  87. return Result;
  88. }
  89. template<typename T, qualifier Q>
  90. GLM_FUNC_QUALIFIER mat<4, 4, T, Q> rowMajor4(
  91. const mat<4, 4, T, Q>& m)
  92. {
  93. mat<4, 4, T, Q> Result;
  94. Result[0][0] = m[0][0];
  95. Result[0][1] = m[1][0];
  96. Result[0][2] = m[2][0];
  97. Result[0][3] = m[3][0];
  98. Result[1][0] = m[0][1];
  99. Result[1][1] = m[1][1];
  100. Result[1][2] = m[2][1];
  101. Result[1][3] = m[3][1];
  102. Result[2][0] = m[0][2];
  103. Result[2][1] = m[1][2];
  104. Result[2][2] = m[2][2];
  105. Result[2][3] = m[3][2];
  106. Result[3][0] = m[0][3];
  107. Result[3][1] = m[1][3];
  108. Result[3][2] = m[2][3];
  109. Result[3][3] = m[3][3];
  110. return Result;
  111. }
  112. template<typename T, qualifier Q>
  113. GLM_FUNC_QUALIFIER mat<2, 2, T, Q> colMajor2(
  114. const vec<2, T, Q>& v1,
  115. const vec<2, T, Q>& v2)
  116. {
  117. return mat<2, 2, T, Q>(v1, v2);
  118. }
  119. template<typename T, qualifier Q>
  120. GLM_FUNC_QUALIFIER mat<2, 2, T, Q> colMajor2(
  121. const mat<2, 2, T, Q>& m)
  122. {
  123. return mat<2, 2, T, Q>(m);
  124. }
  125. template<typename T, qualifier Q>
  126. GLM_FUNC_QUALIFIER mat<3, 3, T, Q> colMajor3(
  127. const vec<3, T, Q>& v1,
  128. const vec<3, T, Q>& v2,
  129. const vec<3, T, Q>& v3)
  130. {
  131. return mat<3, 3, T, Q>(v1, v2, v3);
  132. }
  133. template<typename T, qualifier Q>
  134. GLM_FUNC_QUALIFIER mat<3, 3, T, Q> colMajor3(
  135. const mat<3, 3, T, Q>& m)
  136. {
  137. return mat<3, 3, T, Q>(m);
  138. }
  139. template<typename T, qualifier Q>
  140. GLM_FUNC_QUALIFIER mat<4, 4, T, Q> colMajor4(
  141. const vec<4, T, Q>& v1,
  142. const vec<4, T, Q>& v2,
  143. const vec<4, T, Q>& v3,
  144. const vec<4, T, Q>& v4)
  145. {
  146. return mat<4, 4, T, Q>(v1, v2, v3, v4);
  147. }
  148. template<typename T, qualifier Q>
  149. GLM_FUNC_QUALIFIER mat<4, 4, T, Q> colMajor4(
  150. const mat<4, 4, T, Q>& m)
  151. {
  152. return mat<4, 4, T, Q>(m);
  153. }
  154. }//namespace glm