type_vec3.hpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. /// @ref core
  2. /// @file glm/detail/type_vec3.hpp
  3. #pragma once
  4. #include "type_vec.hpp"
  5. #if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
  6. # if GLM_HAS_UNRESTRICTED_UNIONS
  7. # include "_swizzle.hpp"
  8. # else
  9. # include "_swizzle_func.hpp"
  10. # endif
  11. #endif //GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
  12. #include <cstddef>
  13. namespace glm
  14. {
  15. template<typename T, qualifier P>
  16. struct vec<3, T, P>
  17. {
  18. // -- Implementation detail --
  19. typedef T value_type;
  20. typedef vec type;
  21. typedef vec<3, bool, P> bool_type;
  22. // -- Data --
  23. # if GLM_HAS_ONLY_XYZW
  24. T x, y, z;
  25. # elif GLM_HAS_ALIGNED_TYPE
  26. # if GLM_COMPILER & GLM_COMPILER_GCC
  27. # pragma GCC diagnostic push
  28. # pragma GCC diagnostic ignored "-Wpedantic"
  29. # endif
  30. # if GLM_COMPILER & GLM_COMPILER_CLANG
  31. # pragma clang diagnostic push
  32. # pragma clang diagnostic ignored "-Wgnu-anonymous-struct"
  33. # pragma clang diagnostic ignored "-Wnested-anon-types"
  34. # endif
  35. union
  36. {
  37. struct{ T x, y, z; };
  38. struct{ T r, g, b; };
  39. struct{ T s, t, p; };
  40. # if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
  41. GLM_SWIZZLE3_2_MEMBERS(T, P, x, y, z)
  42. GLM_SWIZZLE3_2_MEMBERS(T, P, r, g, b)
  43. GLM_SWIZZLE3_2_MEMBERS(T, P, s, t, p)
  44. GLM_SWIZZLE3_3_MEMBERS(T, P, x, y, z)
  45. GLM_SWIZZLE3_3_MEMBERS(T, P, r, g, b)
  46. GLM_SWIZZLE3_3_MEMBERS(T, P, s, t, p)
  47. GLM_SWIZZLE3_4_MEMBERS(T, P, x, y, z)
  48. GLM_SWIZZLE3_4_MEMBERS(T, P, r, g, b)
  49. GLM_SWIZZLE3_4_MEMBERS(T, P, s, t, p)
  50. # endif//GLM_SWIZZLE
  51. };
  52. # if GLM_COMPILER & GLM_COMPILER_CLANG
  53. # pragma clang diagnostic pop
  54. # endif
  55. # if GLM_COMPILER & GLM_COMPILER_GCC
  56. # pragma GCC diagnostic pop
  57. # endif
  58. # else
  59. union { T x, r, s; };
  60. union { T y, g, t; };
  61. union { T z, b, p; };
  62. # if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
  63. GLM_SWIZZLE_GEN_VEC_FROM_VEC3(T, P)
  64. # endif//GLM_SWIZZLE
  65. # endif//GLM_LANG
  66. // -- Component accesses --
  67. /// Return the count of components of the vector
  68. typedef length_t length_type;
  69. GLM_FUNC_DECL static GLM_CONSTEXPR length_type length(){return 3;}
  70. GLM_FUNC_DECL T & operator[](length_type i);
  71. GLM_FUNC_DECL T const & operator[](length_type i) const;
  72. // -- Implicit basic constructors --
  73. GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec() GLM_DEFAULT;
  74. GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec const & v) GLM_DEFAULT;
  75. template<qualifier Q>
  76. GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<3, T, Q> const & v);
  77. // -- Explicit basic constructors --
  78. GLM_FUNC_DECL GLM_CONSTEXPR_CTOR explicit vec(T scalar);
  79. GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(T a, T b, T c);
  80. // -- Conversion scalar constructors --
  81. /// Explicit converions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  82. template<typename X, typename Y, typename Z>
  83. GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(X x, Y y, Z z);
  84. template<typename X, typename Y, typename Z>
  85. GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<1, X, P> const& _x, vec<1, Y, P> const& _y, vec<1, Z, P> const& _z);
  86. // -- Conversion vector constructors --
  87. /// Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  88. template<typename A, typename B, qualifier Q>
  89. GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<2, A, Q> const& _xy, B _z);
  90. /// Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  91. template<typename A, typename B, qualifier Q>
  92. GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<2, A, Q> const& _xy, vec<1, B, Q> const& _z);
  93. /// Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  94. template<typename A, typename B, qualifier Q>
  95. GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(A _x, vec<2, B, Q> const& _yz);
  96. /// Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  97. template<typename A, typename B, qualifier Q>
  98. GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<1, A, Q> const& _x, vec<2, B, Q> const& _yz);
  99. /// Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  100. template<typename U, qualifier Q>
  101. GLM_FUNC_DECL GLM_CONSTEXPR_CTOR GLM_EXPLICIT vec(vec<4, U, Q> const& v);
  102. /// Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  103. template<typename U, qualifier Q>
  104. GLM_FUNC_DECL GLM_CONSTEXPR_CTOR GLM_EXPLICIT vec(vec<3, U, Q> const& v);
  105. // -- Swizzle constructors --
  106. # if GLM_HAS_UNRESTRICTED_UNIONS && (GLM_SWIZZLE == GLM_SWIZZLE_ENABLED)
  107. template<int E0, int E1, int E2>
  108. GLM_FUNC_DECL vec(detail::_swizzle<3, T, P, E0, E1, E2, -1> const & that)
  109. {
  110. *this = that();
  111. }
  112. template<int E0, int E1>
  113. GLM_FUNC_DECL vec(detail::_swizzle<2, T, P, E0, E1, -1, -2> const & v, T const & scalar)
  114. {
  115. *this = vec(v(), scalar);
  116. }
  117. template<int E0, int E1>
  118. GLM_FUNC_DECL vec(T const & scalar, detail::_swizzle<2, T, P, E0, E1, -1, -2> const & v)
  119. {
  120. *this = vec(scalar, v());
  121. }
  122. # endif// GLM_HAS_UNRESTRICTED_UNIONS && (GLM_SWIZZLE == GLM_SWIZZLE_ENABLED)
  123. // -- Unary arithmetic operators --
  124. GLM_FUNC_DECL vec & operator=(vec const & v) GLM_DEFAULT;
  125. template<typename U>
  126. GLM_FUNC_DECL vec & operator=(vec<3, U, P> const & v);
  127. template<typename U>
  128. GLM_FUNC_DECL vec & operator+=(U scalar);
  129. template<typename U>
  130. GLM_FUNC_DECL vec & operator+=(vec<1, U, P> const & v);
  131. template<typename U>
  132. GLM_FUNC_DECL vec & operator+=(vec<3, U, P> const & v);
  133. template<typename U>
  134. GLM_FUNC_DECL vec & operator-=(U scalar);
  135. template<typename U>
  136. GLM_FUNC_DECL vec & operator-=(vec<1, U, P> const & v);
  137. template<typename U>
  138. GLM_FUNC_DECL vec & operator-=(vec<3, U, P> const & v);
  139. template<typename U>
  140. GLM_FUNC_DECL vec & operator*=(U scalar);
  141. template<typename U>
  142. GLM_FUNC_DECL vec & operator*=(vec<1, U, P> const & v);
  143. template<typename U>
  144. GLM_FUNC_DECL vec & operator*=(vec<3, U, P> const & v);
  145. template<typename U>
  146. GLM_FUNC_DECL vec & operator/=(U scalar);
  147. template<typename U>
  148. GLM_FUNC_DECL vec & operator/=(vec<1, U, P> const & v);
  149. template<typename U>
  150. GLM_FUNC_DECL vec & operator/=(vec<3, U, P> const & v);
  151. // -- Increment and decrement operators --
  152. GLM_FUNC_DECL vec & operator++();
  153. GLM_FUNC_DECL vec & operator--();
  154. GLM_FUNC_DECL vec operator++(int);
  155. GLM_FUNC_DECL vec operator--(int);
  156. // -- Unary bit operators --
  157. template<typename U>
  158. GLM_FUNC_DECL vec & operator%=(U scalar);
  159. template<typename U>
  160. GLM_FUNC_DECL vec & operator%=(vec<1, U, P> const & v);
  161. template<typename U>
  162. GLM_FUNC_DECL vec & operator%=(vec<3, U, P> const & v);
  163. template<typename U>
  164. GLM_FUNC_DECL vec & operator&=(U scalar);
  165. template<typename U>
  166. GLM_FUNC_DECL vec & operator&=(vec<1, U, P> const & v);
  167. template<typename U>
  168. GLM_FUNC_DECL vec & operator&=(vec<3, U, P> const & v);
  169. template<typename U>
  170. GLM_FUNC_DECL vec & operator|=(U scalar);
  171. template<typename U>
  172. GLM_FUNC_DECL vec & operator|=(vec<1, U, P> const & v);
  173. template<typename U>
  174. GLM_FUNC_DECL vec & operator|=(vec<3, U, P> const & v);
  175. template<typename U>
  176. GLM_FUNC_DECL vec & operator^=(U scalar);
  177. template<typename U>
  178. GLM_FUNC_DECL vec & operator^=(vec<1, U, P> const & v);
  179. template<typename U>
  180. GLM_FUNC_DECL vec & operator^=(vec<3, U, P> const & v);
  181. template<typename U>
  182. GLM_FUNC_DECL vec & operator<<=(U scalar);
  183. template<typename U>
  184. GLM_FUNC_DECL vec & operator<<=(vec<1, U, P> const & v);
  185. template<typename U>
  186. GLM_FUNC_DECL vec & operator<<=(vec<3, U, P> const & v);
  187. template<typename U>
  188. GLM_FUNC_DECL vec & operator>>=(U scalar);
  189. template<typename U>
  190. GLM_FUNC_DECL vec & operator>>=(vec<1, U, P> const & v);
  191. template<typename U>
  192. GLM_FUNC_DECL vec & operator>>=(vec<3, U, P> const & v);
  193. };
  194. // -- Unary operators --
  195. template<typename T, qualifier P>
  196. GLM_FUNC_DECL vec<3, T, P> operator+(vec<3, T, P> const & v);
  197. template<typename T, qualifier P>
  198. GLM_FUNC_DECL vec<3, T, P> operator-(vec<3, T, P> const & v);
  199. // -- Binary operators --
  200. template<typename T, qualifier P>
  201. GLM_FUNC_DECL vec<3, T, P> operator+(vec<3, T, P> const & v, T scalar);
  202. template<typename T, qualifier P>
  203. GLM_FUNC_DECL vec<3, T, P> operator+(vec<3, T, P> const & v, vec<1, T, P> const & scalar);
  204. template<typename T, qualifier P>
  205. GLM_FUNC_DECL vec<3, T, P> operator+(T scalar, vec<3, T, P> const & v);
  206. template<typename T, qualifier P>
  207. GLM_FUNC_DECL vec<3, T, P> operator+(vec<1, T, P> const & v1, vec<3, T, P> const & v2);
  208. template<typename T, qualifier P>
  209. GLM_FUNC_DECL vec<3, T, P> operator+(vec<3, T, P> const & v1, vec<3, T, P> const & v2);
  210. template<typename T, qualifier P>
  211. GLM_FUNC_DECL vec<3, T, P> operator-(vec<3, T, P> const & v, T scalar);
  212. template<typename T, qualifier P>
  213. GLM_FUNC_DECL vec<3, T, P> operator-(vec<3, T, P> const & v1, vec<1, T, P> const & v2);
  214. template<typename T, qualifier P>
  215. GLM_FUNC_DECL vec<3, T, P> operator-(T scalar, vec<3, T, P> const & v);
  216. template<typename T, qualifier P>
  217. GLM_FUNC_DECL vec<3, T, P> operator-(vec<1, T, P> const & v1, vec<3, T, P> const & v2);
  218. template<typename T, qualifier P>
  219. GLM_FUNC_DECL vec<3, T, P> operator-(vec<3, T, P> const & v1, vec<3, T, P> const & v2);
  220. template<typename T, qualifier P>
  221. GLM_FUNC_DECL vec<3, T, P> operator*(vec<3, T, P> const & v, T scalar);
  222. template<typename T, qualifier P>
  223. GLM_FUNC_DECL vec<3, T, P> operator*(vec<3, T, P> const & v1, vec<1, T, P> const & v2);
  224. template<typename T, qualifier P>
  225. GLM_FUNC_DECL vec<3, T, P> operator*(T scalar, vec<3, T, P> const & v);
  226. template<typename T, qualifier P>
  227. GLM_FUNC_DECL vec<3, T, P> operator*(vec<1, T, P> const & v1, vec<3, T, P> const & v2);
  228. template<typename T, qualifier P>
  229. GLM_FUNC_DECL vec<3, T, P> operator*(vec<3, T, P> const & v1, vec<3, T, P> const & v2);
  230. template<typename T, qualifier P>
  231. GLM_FUNC_DECL vec<3, T, P> operator/(vec<3, T, P> const & v, T scalar);
  232. template<typename T, qualifier P>
  233. GLM_FUNC_DECL vec<3, T, P> operator/(vec<3, T, P> const & v1, vec<1, T, P> const & v2);
  234. template<typename T, qualifier P>
  235. GLM_FUNC_DECL vec<3, T, P> operator/(T scalar, vec<3, T, P> const & v);
  236. template<typename T, qualifier P>
  237. GLM_FUNC_DECL vec<3, T, P> operator/(vec<1, T, P> const & v1, vec<3, T, P> const & v2);
  238. template<typename T, qualifier P>
  239. GLM_FUNC_DECL vec<3, T, P> operator/(vec<3, T, P> const & v1, vec<3, T, P> const & v2);
  240. template<typename T, qualifier P>
  241. GLM_FUNC_DECL vec<3, T, P> operator%(vec<3, T, P> const & v, T scalar);
  242. template<typename T, qualifier P>
  243. GLM_FUNC_DECL vec<3, T, P> operator%(vec<3, T, P> const & v1, vec<1, T, P> const & v2);
  244. template<typename T, qualifier P>
  245. GLM_FUNC_DECL vec<3, T, P> operator%(T const & scalar, vec<3, T, P> const & v);
  246. template<typename T, qualifier P>
  247. GLM_FUNC_DECL vec<3, T, P> operator%(vec<1, T, P> const & v1, vec<3, T, P> const & v2);
  248. template<typename T, qualifier P>
  249. GLM_FUNC_DECL vec<3, T, P> operator%(vec<3, T, P> const & v1, vec<3, T, P> const & v2);
  250. template<typename T, qualifier P>
  251. GLM_FUNC_DECL vec<3, T, P> operator&(vec<3, T, P> const & v1, T scalar);
  252. template<typename T, qualifier P>
  253. GLM_FUNC_DECL vec<3, T, P> operator&(vec<3, T, P> const & v1, vec<1, T, P> const & v2);
  254. template<typename T, qualifier P>
  255. GLM_FUNC_DECL vec<3, T, P> operator&(T scalar, vec<3, T, P> const & v);
  256. template<typename T, qualifier P>
  257. GLM_FUNC_DECL vec<3, T, P> operator&(vec<1, T, P> const & v1, vec<3, T, P> const & v2);
  258. template<typename T, qualifier P>
  259. GLM_FUNC_DECL vec<3, T, P> operator&(vec<3, T, P> const & v1, vec<3, T, P> const & v2);
  260. template<typename T, qualifier P>
  261. GLM_FUNC_DECL vec<3, T, P> operator|(vec<3, T, P> const & v, T scalar);
  262. template<typename T, qualifier P>
  263. GLM_FUNC_DECL vec<3, T, P> operator|(vec<3, T, P> const & v1, vec<1, T, P> const & v2);
  264. template<typename T, qualifier P>
  265. GLM_FUNC_DECL vec<3, T, P> operator|(T scalar, vec<3, T, P> const & v);
  266. template<typename T, qualifier P>
  267. GLM_FUNC_DECL vec<3, T, P> operator|(vec<1, T, P> const & v1, vec<3, T, P> const & v2);
  268. template<typename T, qualifier P>
  269. GLM_FUNC_DECL vec<3, T, P> operator|(vec<3, T, P> const & v1, vec<3, T, P> const & v2);
  270. template<typename T, qualifier P>
  271. GLM_FUNC_DECL vec<3, T, P> operator^(vec<3, T, P> const & v, T scalar);
  272. template<typename T, qualifier P>
  273. GLM_FUNC_DECL vec<3, T, P> operator^(vec<3, T, P> const & v1, vec<1, T, P> const & v2);
  274. template<typename T, qualifier P>
  275. GLM_FUNC_DECL vec<3, T, P> operator^(T scalar, vec<3, T, P> const & v);
  276. template<typename T, qualifier P>
  277. GLM_FUNC_DECL vec<3, T, P> operator^(vec<1, T, P> const & v1, vec<3, T, P> const & v2);
  278. template<typename T, qualifier P>
  279. GLM_FUNC_DECL vec<3, T, P> operator^(vec<3, T, P> const & v1, vec<3, T, P> const & v2);
  280. template<typename T, qualifier P>
  281. GLM_FUNC_DECL vec<3, T, P> operator<<(vec<3, T, P> const & v, T scalar);
  282. template<typename T, qualifier P>
  283. GLM_FUNC_DECL vec<3, T, P> operator<<(vec<3, T, P> const & v1, vec<1, T, P> const & v2);
  284. template<typename T, qualifier P>
  285. GLM_FUNC_DECL vec<3, T, P> operator<<(T scalar, vec<3, T, P> const & v);
  286. template<typename T, qualifier P>
  287. GLM_FUNC_DECL vec<3, T, P> operator<<(vec<1, T, P> const & v1, vec<3, T, P> const & v2);
  288. template<typename T, qualifier P>
  289. GLM_FUNC_DECL vec<3, T, P> operator<<(vec<3, T, P> const & v1, vec<3, T, P> const & v2);
  290. template<typename T, qualifier P>
  291. GLM_FUNC_DECL vec<3, T, P> operator>>(vec<3, T, P> const & v, T scalar);
  292. template<typename T, qualifier P>
  293. GLM_FUNC_DECL vec<3, T, P> operator>>(vec<3, T, P> const & v1, vec<1, T, P> const & v2);
  294. template<typename T, qualifier P>
  295. GLM_FUNC_DECL vec<3, T, P> operator>>(T scalar, vec<3, T, P> const & v);
  296. template<typename T, qualifier P>
  297. GLM_FUNC_DECL vec<3, T, P> operator>>(vec<1, T, P> const & v1, vec<3, T, P> const & v2);
  298. template<typename T, qualifier P>
  299. GLM_FUNC_DECL vec<3, T, P> operator>>(vec<3, T, P> const & v1, vec<3, T, P> const & v2);
  300. template<typename T, qualifier P>
  301. GLM_FUNC_DECL vec<3, T, P> operator~(vec<3, T, P> const & v);
  302. // -- Boolean operators --
  303. template<typename T, qualifier P>
  304. GLM_FUNC_DECL bool operator==(vec<3, T, P> const & v1, vec<3, T, P> const & v2);
  305. template<typename T, qualifier P>
  306. GLM_FUNC_DECL bool operator!=(vec<3, T, P> const & v1, vec<3, T, P> const & v2);
  307. template<qualifier P>
  308. GLM_FUNC_DECL vec<3, bool, P> operator&&(vec<3, bool, P> const & v1, vec<3, bool, P> const & v2);
  309. template<qualifier P>
  310. GLM_FUNC_DECL vec<3, bool, P> operator||(vec<3, bool, P> const & v1, vec<3, bool, P> const & v2);
  311. }//namespace glm
  312. #ifndef GLM_EXTERNAL_TEMPLATE
  313. #include "type_vec3.inl"
  314. #endif//GLM_EXTERNAL_TEMPLATE