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.

116 lines
3.0 KiB

  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 gtc_swizzle
  24. /// @file glm/gtc/swizzle.inl
  25. /// @date 2011-01-15 / 2011-06-15
  26. /// @author Christophe Riccio
  27. ///////////////////////////////////////////////////////////////////////////////////
  28. namespace glm
  29. {
  30. template <typename T, template <typename> class vecType>
  31. GLM_FUNC_QUALIFIER T swizzle
  32. (
  33. vecType<T> const & v,
  34. comp x
  35. )
  36. {
  37. assert(int(x) < int(vecType<T>::value_size));
  38. return v[x];
  39. }
  40. template <typename T, template <typename> class vecType>
  41. GLM_FUNC_QUALIFIER detail::tvec2<T> swizzle
  42. (
  43. vecType<T> const & v,
  44. comp x, comp y
  45. )
  46. {
  47. return detail::tvec2<T>(
  48. v[x],
  49. v[y]);
  50. }
  51. template <typename T, template <typename> class vecType>
  52. GLM_FUNC_QUALIFIER detail::tvec3<T> swizzle
  53. (
  54. vecType<T> const & v,
  55. comp x, comp y, comp z
  56. )
  57. {
  58. return detail::tvec3<T>(
  59. v[x],
  60. v[y],
  61. v[z]);
  62. }
  63. template <typename T, template <typename> class vecType>
  64. GLM_FUNC_QUALIFIER detail::tvec4<T> swizzle
  65. (
  66. vecType<T> const & v,
  67. comp x, comp y, comp z, comp w
  68. )
  69. {
  70. return detail::tvec4<T>(v[x], v[y], v[z], v[w]);
  71. }
  72. template <typename T>
  73. GLM_FUNC_QUALIFIER T& swizzle
  74. (
  75. detail::tvec4<T> & v,
  76. comp x
  77. )
  78. {
  79. return v[x];
  80. }
  81. template <typename T>
  82. GLM_FUNC_QUALIFIER detail::tref2<T> swizzle
  83. (
  84. detail::tvec4<T> & v,
  85. comp x, comp y
  86. )
  87. {
  88. return detail::tref2<T>(v[x], v[y]);
  89. }
  90. template <typename T>
  91. GLM_FUNC_QUALIFIER detail::tref3<T> swizzle
  92. (
  93. detail::tvec4<T> & v,
  94. comp x, comp y, comp z
  95. )
  96. {
  97. return detail::tref3<T>(v[x], v[y], v[z]);
  98. }
  99. template <typename T>
  100. GLM_FUNC_QUALIFIER detail::tref4<T> swizzle
  101. (
  102. detail::tvec4<T> & v,
  103. comp x, comp y, comp z, comp w
  104. )
  105. {
  106. return detail::tref4<T>(v[x], v[y], v[z], v[w]);
  107. }
  108. }//namespace glm