type_vec2.hpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. ///////////////////////////////////////////////////////////////////////////////////
  2. /// OpenGL Mathematics (glm.g-truc.net)
  3. ///
  4. /// Copyright (c) 2005 - 2014 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 core
  24. /// @file glm/core/type_vec2.hpp
  25. /// @date 2008-08-18 / 2013-08-27
  26. /// @author Christophe Riccio
  27. ///////////////////////////////////////////////////////////////////////////////////
  28. #pragma once
  29. //#include "../fwd.hpp"
  30. #include "type_vec.hpp"
  31. #ifdef GLM_SWIZZLE
  32. # if GLM_HAS_ANONYMOUS_UNION
  33. # include "_swizzle.hpp"
  34. # else
  35. # include "_swizzle_func.hpp"
  36. # endif
  37. #endif //GLM_SWIZZLE
  38. #include <cstddef>
  39. namespace glm{
  40. namespace detail
  41. {
  42. template <typename T, precision P>
  43. struct tvec2
  44. {
  45. //////////////////////////////////////
  46. // Implementation detail
  47. enum ctor{_null};
  48. typedef tvec2<T, P> type;
  49. typedef tvec2<bool, P> bool_type;
  50. typedef T value_type;
  51. typedef int size_type;
  52. //////////////////////////////////////
  53. // Helper
  54. GLM_FUNC_DECL GLM_CONSTEXPR length_t length() const;
  55. //////////////////////////////////////
  56. // Data
  57. # if(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE))
  58. union
  59. {
  60. struct{ T x, y; };
  61. struct{ T r, g; };
  62. struct{ T s, t; };
  63. _GLM_SWIZZLE2_2_MEMBERS(T, P, tvec2, x, y)
  64. _GLM_SWIZZLE2_2_MEMBERS(T, P, tvec2, r, g)
  65. _GLM_SWIZZLE2_2_MEMBERS(T, P, tvec2, s, t)
  66. _GLM_SWIZZLE2_3_MEMBERS(T, P, tvec3, x, y)
  67. _GLM_SWIZZLE2_3_MEMBERS(T, P, tvec3, r, g)
  68. _GLM_SWIZZLE2_3_MEMBERS(T, P, tvec3, s, t)
  69. _GLM_SWIZZLE2_4_MEMBERS(T, P, tvec4, x, y)
  70. _GLM_SWIZZLE2_4_MEMBERS(T, P, tvec4, r, g)
  71. _GLM_SWIZZLE2_4_MEMBERS(T, P, tvec4, s, t)
  72. };
  73. # else
  74. union {T x, r, s;};
  75. union {T y, g, t;};
  76. # ifdef GLM_SWIZZLE
  77. GLM_SWIZZLE_GEN_VEC_FROM_VEC2(T, P, detail::tvec2, detail::tvec2, detail::tvec3, detail::tvec4)
  78. # endif
  79. # endif
  80. //////////////////////////////////////
  81. // Accesses
  82. GLM_FUNC_DECL T & operator[](length_t i);
  83. GLM_FUNC_DECL T const & operator[](length_t i) const;
  84. //////////////////////////////////////
  85. // Implicit basic constructors
  86. GLM_FUNC_DECL tvec2();
  87. GLM_FUNC_DECL tvec2(tvec2<T, P> const & v);
  88. template <precision Q>
  89. GLM_FUNC_DECL tvec2(tvec2<T, Q> const & v);
  90. //////////////////////////////////////
  91. // Explicit basic constructors
  92. GLM_FUNC_DECL explicit tvec2(
  93. ctor);
  94. GLM_FUNC_DECL explicit tvec2(
  95. T const & s);
  96. GLM_FUNC_DECL tvec2(
  97. T const & s1,
  98. T const & s2);
  99. //////////////////////////////////////
  100. // Swizzle constructors
  101. # if(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE))
  102. template <int E0, int E1>
  103. GLM_FUNC_DECL tvec2(_swizzle<2,T, P, tvec2<T, P>, E0, E1,-1,-2> const & that)
  104. {
  105. *this = that();
  106. }
  107. # endif//(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE))
  108. //////////////////////////////////////
  109. // Conversion constructors
  110. //! Explicit converions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  111. template <typename U, typename V>
  112. GLM_FUNC_DECL tvec2(
  113. U const & x,
  114. V const & y);
  115. //////////////////////////////////////
  116. // Conversion vector constructors
  117. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  118. template <typename U, precision Q>
  119. GLM_FUNC_DECL tvec2(tvec2<U, Q> const & v);
  120. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  121. template <typename U, precision Q>
  122. GLM_FUNC_DECL explicit tvec2(tvec3<U, Q> const & v);
  123. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  124. template <typename U, precision Q>
  125. GLM_FUNC_DECL explicit tvec2(tvec4<U, Q> const & v);
  126. //////////////////////////////////////
  127. // Unary arithmetic operators
  128. GLM_FUNC_DECL tvec2<T, P> & operator= (tvec2<T, P> const & v);
  129. template <typename U>
  130. GLM_FUNC_DECL tvec2<T, P> & operator= (tvec2<U, P> const & v);
  131. template <typename U>
  132. GLM_FUNC_DECL tvec2<T, P> & operator+=(U s);
  133. template <typename U>
  134. GLM_FUNC_DECL tvec2<T, P> & operator+=(tvec2<U, P> const & v);
  135. template <typename U>
  136. GLM_FUNC_DECL tvec2<T, P> & operator-=(U s);
  137. template <typename U>
  138. GLM_FUNC_DECL tvec2<T, P> & operator-=(tvec2<U, P> const & v);
  139. template <typename U>
  140. GLM_FUNC_DECL tvec2<T, P> & operator*=(U s);
  141. template <typename U>
  142. GLM_FUNC_DECL tvec2<T, P> & operator*=(tvec2<U, P> const & v);
  143. template <typename U>
  144. GLM_FUNC_DECL tvec2<T, P> & operator/=(U s);
  145. template <typename U>
  146. GLM_FUNC_DECL tvec2<T, P> & operator/=(tvec2<U, P> const & v);
  147. //////////////////////////////////////
  148. // Increment and decrement operators
  149. GLM_FUNC_DECL tvec2<T, P> & operator++();
  150. GLM_FUNC_DECL tvec2<T, P> & operator--();
  151. GLM_FUNC_DECL tvec2<T, P> operator++(int);
  152. GLM_FUNC_DECL tvec2<T, P> operator--(int);
  153. //////////////////////////////////////
  154. // Unary bit operators
  155. template <typename U>
  156. GLM_FUNC_DECL tvec2<T, P> & operator%= (U s);
  157. template <typename U>
  158. GLM_FUNC_DECL tvec2<T, P> & operator%= (tvec2<U, P> const & v);
  159. template <typename U>
  160. GLM_FUNC_DECL tvec2<T, P> & operator&= (U s);
  161. template <typename U>
  162. GLM_FUNC_DECL tvec2<T, P> & operator&= (tvec2<U, P> const & v);
  163. template <typename U>
  164. GLM_FUNC_DECL tvec2<T, P> & operator|= (U s);
  165. template <typename U>
  166. GLM_FUNC_DECL tvec2<T, P> & operator|= (tvec2<U, P> const & v);
  167. template <typename U>
  168. GLM_FUNC_DECL tvec2<T, P> & operator^= (U s);
  169. template <typename U>
  170. GLM_FUNC_DECL tvec2<T, P> & operator^= (tvec2<U, P> const & v);
  171. template <typename U>
  172. GLM_FUNC_DECL tvec2<T, P> & operator<<=(U s);
  173. template <typename U>
  174. GLM_FUNC_DECL tvec2<T, P> & operator<<=(tvec2<U, P> const & v);
  175. template <typename U>
  176. GLM_FUNC_DECL tvec2<T, P> & operator>>=(U s);
  177. template <typename U>
  178. GLM_FUNC_DECL tvec2<T, P> & operator>>=(tvec2<U, P> const & v);
  179. };
  180. template <typename T, precision P>
  181. GLM_FUNC_DECL tvec2<T, P> operator+(tvec2<T, P> const & v, T const & s);
  182. template <typename T, precision P>
  183. GLM_FUNC_DECL tvec2<T, P> operator+(T const & s, tvec2<T, P> const & v);
  184. template <typename T, precision P>
  185. GLM_FUNC_DECL tvec2<T, P> operator+(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
  186. template <typename T, precision P>
  187. GLM_FUNC_DECL tvec2<T, P> operator-(tvec2<T, P> const & v, T const & s);
  188. template <typename T, precision P>
  189. GLM_FUNC_DECL tvec2<T, P> operator-(T const & s, tvec2<T, P> const & v);
  190. template <typename T, precision P>
  191. GLM_FUNC_DECL tvec2<T, P> operator- (tvec2<T, P> const & v1, tvec2<T, P> const & v2);
  192. template <typename T, precision P>
  193. GLM_FUNC_DECL tvec2<T, P> operator*(tvec2<T, P> const & v, T const & s);
  194. template <typename T, precision P>
  195. GLM_FUNC_DECL tvec2<T, P> operator*(T const & s, tvec2<T, P> const & v);
  196. template <typename T, precision P>
  197. GLM_FUNC_DECL tvec2<T, P> operator*(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
  198. template <typename T, precision P>
  199. GLM_FUNC_DECL tvec2<T, P> operator/(tvec2<T, P> const & v, T const & s);
  200. template <typename T, precision P>
  201. GLM_FUNC_DECL tvec2<T, P> operator/(T const & s, tvec2<T, P> const & v);
  202. template <typename T, precision P>
  203. GLM_FUNC_DECL tvec2<T, P> operator/(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
  204. template <typename T, precision P>
  205. GLM_FUNC_DECL tvec2<T, P> operator-(tvec2<T, P> const & v);
  206. template <typename T, precision P>
  207. GLM_FUNC_DECL tvec2<T, P> operator%(tvec2<T, P> const & v, T const & s);
  208. template <typename T, precision P>
  209. GLM_FUNC_DECL tvec2<T, P> operator%(T const & s, tvec2<T, P> const & v);
  210. template <typename T, precision P>
  211. GLM_FUNC_DECL tvec2<T, P> operator%(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
  212. template <typename T, precision P>
  213. GLM_FUNC_DECL tvec2<T, P> operator&(tvec2<T, P> const & v, T const & s);
  214. template <typename T, precision P>
  215. GLM_FUNC_DECL tvec2<T, P> operator&(T const & s, tvec2<T, P> const & v);
  216. template <typename T, precision P>
  217. GLM_FUNC_DECL tvec2<T, P> operator&(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
  218. template <typename T, precision P>
  219. GLM_FUNC_DECL tvec2<T, P> operator|(tvec2<T, P> const & v, T const & s);
  220. template <typename T, precision P>
  221. GLM_FUNC_DECL tvec2<T, P> operator|(T const & s, tvec2<T, P> const & v);
  222. template <typename T, precision P>
  223. GLM_FUNC_DECL tvec2<T, P> operator|(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
  224. template <typename T, precision P>
  225. GLM_FUNC_DECL tvec2<T, P> operator^(tvec2<T, P> const & v, T const & s);
  226. template <typename T, precision P>
  227. GLM_FUNC_DECL tvec2<T, P> operator^(T const & s, tvec2<T, P> const & v);
  228. template <typename T, precision P>
  229. GLM_FUNC_DECL tvec2<T, P> operator^(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
  230. template <typename T, precision P>
  231. GLM_FUNC_DECL tvec2<T, P> operator<<(tvec2<T, P> const & v, T const & s);
  232. template <typename T, precision P>
  233. GLM_FUNC_DECL tvec2<T, P> operator<<(T const & s, tvec2<T, P> const & v);
  234. template <typename T, precision P>
  235. GLM_FUNC_DECL tvec2<T, P> operator<<(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
  236. template <typename T, precision P>
  237. GLM_FUNC_DECL tvec2<T, P> operator>>(tvec2<T, P> const & v, T const & s);
  238. template <typename T, precision P>
  239. GLM_FUNC_DECL tvec2<T, P> operator>>(T const & s, tvec2<T, P> const & v);
  240. template <typename T, precision P>
  241. GLM_FUNC_DECL tvec2<T, P> operator>>(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
  242. template <typename T, precision P>
  243. GLM_FUNC_DECL tvec2<T, P> operator~(tvec2<T, P> const & v);
  244. }//namespace detail
  245. }//namespace glm
  246. #ifndef GLM_EXTERNAL_TEMPLATE
  247. #include "type_vec2.inl"
  248. #endif//GLM_EXTERNAL_TEMPLATE