/glm/core/type_vec3.hpp

https://bitbucket.org/ggerganov/test_opengl · C++ Header · 344 lines · 186 code · 53 blank · 105 comment · 7 complexity · 54a5106ec4915d439f37720104098c79 MD5 · raw file

  1. ///////////////////////////////////////////////////////////////////////////////////
  2. /// OpenGL Mathematics (glm.g-truc.net)
  3. ///
  4. /// Copyright (c) 2005 - 2012 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_vec3.hpp
  25. /// @date 2008-08-22 / 2011-06-15
  26. /// @author Christophe Riccio
  27. ///////////////////////////////////////////////////////////////////////////////////
  28. #ifndef glm_core_type_gentype3
  29. #define glm_core_type_gentype3
  30. #include "type_vec.hpp"
  31. #include "type_float.hpp"
  32. #include "type_int.hpp"
  33. #include "type_size.hpp"
  34. #include "_swizzle.hpp"
  35. namespace glm{
  36. namespace detail
  37. {
  38. template <typename T> struct tref2;
  39. template <typename T> struct tref3;
  40. template <typename T> struct tref4;
  41. template <typename T> struct tvec2;
  42. template <typename T> struct tvec4;
  43. // Basic 3D vector type.
  44. // \ingroup core_template
  45. template <typename T>
  46. struct tvec3
  47. {
  48. enum ctor{null};
  49. typedef T value_type;
  50. typedef std::size_t size_type;
  51. GLM_FUNC_DECL size_type length() const;
  52. typedef tvec3<T> type;
  53. typedef tvec3<bool> bool_type;
  54. //////////////////////////////////////
  55. // Data
  56. # if(GLM_COMPONENT == GLM_COMPONENT_CXX11)
  57. union
  58. {
  59. # if(defined(GLM_SWIZZLE))
  60. _GLM_SWIZZLE3_2_MEMBERS(value_type, glm::detail::tvec2<value_type>, x, y, z)
  61. _GLM_SWIZZLE3_2_MEMBERS(value_type, glm::detail::tvec2<value_type>, r, g, b)
  62. _GLM_SWIZZLE3_2_MEMBERS(value_type, glm::detail::tvec2<value_type>, s, t, p)
  63. _GLM_SWIZZLE3_3_MEMBERS(value_type, glm::detail::tvec3<value_type>, x, y, z)
  64. _GLM_SWIZZLE3_3_MEMBERS(value_type, glm::detail::tvec3<value_type>, r, g, b)
  65. _GLM_SWIZZLE3_3_MEMBERS(value_type, glm::detail::tvec3<value_type>, s, t, p)
  66. _GLM_SWIZZLE3_4_MEMBERS(value_type, glm::detail::tvec4<value_type>, x, y, z)
  67. _GLM_SWIZZLE3_4_MEMBERS(value_type, glm::detail::tvec4<value_type>, r, g, b)
  68. _GLM_SWIZZLE3_4_MEMBERS(value_type, glm::detail::tvec4<value_type>, s, t, p)
  69. # endif//(defined(GLM_SWIZZLE))
  70. struct{value_type r, g, b;};
  71. struct{value_type s, t, p;};
  72. struct{value_type x, y, z;};
  73. };
  74. # elif(GLM_COMPONENT == GLM_COMPONENT_CXX98)
  75. union {value_type x, r, s;};
  76. union {value_type y, g, t;};
  77. union {value_type z, b, p;};
  78. # if(defined(GLM_SWIZZLE))
  79. // Defines all he swizzle operator as functions
  80. GLM_SWIZZLE_GEN_REF_FROM_VEC3(T, detail::tvec3, detail::tref2, detail::tref3)
  81. GLM_SWIZZLE_GEN_VEC_FROM_VEC3(T, detail::tvec3, detail::tvec2, detail::tvec3, detail::tvec4)
  82. # endif//(defined(GLM_SWIZZLE))
  83. # else //(GLM_COMPONENT == GLM_COMPONENT_ONLY_XYZW)
  84. value_type x, y, z;
  85. # if(defined(GLM_SWIZZLE))
  86. // Defines all he swizzle operator as functions
  87. GLM_SWIZZLE_GEN_REF_FROM_VEC3_COMP(T, detail::tvec3, detail::tref2, detail::tref3, x, y, z)
  88. GLM_SWIZZLE_GEN_VEC_FROM_VEC3_COMP(T, detail::tvec3, detail::tvec2, detail::tvec3, detail::tvec4, x, y, z)
  89. # endif//(defined(GLM_SWIZZLE))
  90. # endif//GLM_COMPONENT
  91. //////////////////////////////////////
  92. // Accesses
  93. GLM_FUNC_DECL value_type & operator[](size_type i);
  94. GLM_FUNC_DECL value_type const & operator[](size_type i) const;
  95. //////////////////////////////////////
  96. // Implicit basic constructors
  97. GLM_FUNC_DECL tvec3();
  98. GLM_FUNC_DECL tvec3(tvec3<T> const & v);
  99. //////////////////////////////////////
  100. // Explicit basic constructors
  101. GLM_FUNC_DECL explicit tvec3(
  102. ctor);
  103. GLM_FUNC_DECL explicit tvec3(
  104. value_type const & s);
  105. GLM_FUNC_DECL explicit tvec3(
  106. value_type const & s1,
  107. value_type const & s2,
  108. value_type const & s3);
  109. //////////////////////////////////////
  110. // Convertion scalar constructors
  111. //! Explicit converions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  112. template <typename U>
  113. GLM_FUNC_DECL explicit tvec3(
  114. U const & x);
  115. //! Explicit converions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  116. template <typename U, typename V, typename W>
  117. GLM_FUNC_DECL explicit tvec3(
  118. U const & x,
  119. V const & y,
  120. W const & z);
  121. //////////////////////////////////////
  122. // Convertion vector constructors
  123. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  124. template <typename A, typename B>
  125. GLM_FUNC_DECL explicit tvec3(tvec2<A> const & v, B const & s);
  126. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  127. template <typename A, typename B>
  128. GLM_FUNC_DECL explicit tvec3(A const & s, tvec2<B> const & v);
  129. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  130. template <typename U>
  131. GLM_FUNC_DECL explicit tvec3(tvec3<U> const & v);
  132. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  133. template <typename U>
  134. GLM_FUNC_DECL explicit tvec3(tvec4<U> const & v);
  135. //////////////////////////////////////
  136. // Swizzle constructors
  137. GLM_FUNC_DECL tvec3(tref3<T> const & r);
  138. template <typename A, typename B>
  139. GLM_FUNC_DECL explicit tvec3(tref2<A> const & v, B const & s);
  140. template <typename A, typename B>
  141. GLM_FUNC_DECL explicit tvec3(A const & s, tref2<B> const & v);
  142. template <int E0, int E1, int E2>
  143. GLM_FUNC_DECL tvec3(glm::detail::swizzle<3, T, tvec3<T>, E0, E1, E2, -1> const & that)
  144. {
  145. *this = that();
  146. }
  147. template <int E0, int E1>
  148. GLM_FUNC_DECL tvec3(glm::detail::swizzle<2, T, tvec2<T>, E0, E1, -1, -2> const & v, T const & s)
  149. {
  150. *this = tvec3<T>(v(), s);
  151. }
  152. template <int E0, int E1>
  153. GLM_FUNC_DECL tvec3(T const & s, glm::detail::swizzle<2, T, tvec2<T>, E0, E1, -1, -2> const & v)
  154. {
  155. *this = tvec3<T>(s, v());
  156. }
  157. //////////////////////////////////////
  158. // Unary arithmetic operators
  159. GLM_FUNC_DECL tvec3<T> & operator= (tvec3<T> const & v);
  160. template <typename U>
  161. GLM_FUNC_DECL tvec3<T> & operator= (tvec3<U> const & v);
  162. template <typename U>
  163. GLM_FUNC_DECL tvec3<T> & operator+=(U const & s);
  164. template <typename U>
  165. GLM_FUNC_DECL tvec3<T> & operator+=(tvec3<U> const & v);
  166. template <typename U>
  167. GLM_FUNC_DECL tvec3<T> & operator-=(U const & s);
  168. template <typename U>
  169. GLM_FUNC_DECL tvec3<T> & operator-=(tvec3<U> const & v);
  170. template <typename U>
  171. GLM_FUNC_DECL tvec3<T> & operator*=(U const & s);
  172. template <typename U>
  173. GLM_FUNC_DECL tvec3<T> & operator*=(tvec3<U> const & v);
  174. template <typename U>
  175. GLM_FUNC_DECL tvec3<T> & operator/=(U const & s);
  176. template <typename U>
  177. GLM_FUNC_DECL tvec3<T> & operator/=(tvec3<U> const & v);
  178. GLM_FUNC_DECL tvec3<T> & operator++();
  179. GLM_FUNC_DECL tvec3<T> & operator--();
  180. //////////////////////////////////////
  181. // Unary bit operators
  182. template <typename U>
  183. GLM_FUNC_DECL tvec3<T> & operator%= (U const & s);
  184. template <typename U>
  185. GLM_FUNC_DECL tvec3<T> & operator%= (tvec3<U> const & v);
  186. template <typename U>
  187. GLM_FUNC_DECL tvec3<T> & operator&= (U const & s);
  188. template <typename U>
  189. GLM_FUNC_DECL tvec3<T> & operator&= (tvec3<U> const & v);
  190. template <typename U>
  191. GLM_FUNC_DECL tvec3<T> & operator|= (U const & s);
  192. template <typename U>
  193. GLM_FUNC_DECL tvec3<T> & operator|= (tvec3<U> const & v);
  194. template <typename U>
  195. GLM_FUNC_DECL tvec3<T> & operator^= (U const & s);
  196. template <typename U>
  197. GLM_FUNC_DECL tvec3<T> & operator^= (tvec3<U> const & v);
  198. template <typename U>
  199. GLM_FUNC_DECL tvec3<T> & operator<<=(U const & s);
  200. template <typename U>
  201. GLM_FUNC_DECL tvec3<T> & operator<<=(tvec3<U> const & v);
  202. template <typename U>
  203. GLM_FUNC_DECL tvec3<T> & operator>>=(U const & s);
  204. template <typename U>
  205. GLM_FUNC_DECL tvec3<T> & operator>>=(tvec3<U> const & v);
  206. //////////////////////////////////////
  207. // Swizzle operators
  208. GLM_FUNC_DECL value_type swizzle(comp X) const;
  209. GLM_FUNC_DECL tvec2<T> swizzle(comp X, comp Y) const;
  210. GLM_FUNC_DECL tvec3<T> swizzle(comp X, comp Y, comp Z) const;
  211. GLM_FUNC_DECL tvec4<T> swizzle(comp X, comp Y, comp Z, comp W) const;
  212. GLM_FUNC_DECL tref2<T> swizzle(comp X, comp Y);
  213. GLM_FUNC_DECL tref3<T> swizzle(comp X, comp Y, comp Z);
  214. };
  215. template <typename T>
  216. struct tref3
  217. {
  218. GLM_FUNC_DECL tref3(T & x, T & y, T & z);
  219. GLM_FUNC_DECL tref3(tref3<T> const & r);
  220. GLM_FUNC_DECL explicit tref3(tvec3<T> const & v);
  221. GLM_FUNC_DECL tref3<T> & operator= (tref3<T> const & r);
  222. GLM_FUNC_DECL tref3<T> & operator= (tvec3<T> const & v);
  223. GLM_FUNC_DECL tvec3<T> operator() ();
  224. T & x;
  225. T & y;
  226. T & z;
  227. };
  228. GLM_DETAIL_IS_VECTOR(tvec3);
  229. } //namespace detail
  230. /// @addtogroup core_precision
  231. /// @{
  232. /// 3 components vector of high precision floating-point numbers.
  233. /// There is no guarantee on the actual precision.
  234. ///
  235. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.1.5 Vectors</a>
  236. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.7.2 Precision Qualifier</a>
  237. typedef detail::tvec3<highp_float> highp_vec3;
  238. /// 3 components vector of medium precision floating-point numbers.
  239. /// There is no guarantee on the actual precision.
  240. ///
  241. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.1.5 Vectors</a>
  242. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.7.2 Precision Qualifier</a>
  243. typedef detail::tvec3<mediump_float> mediump_vec3;
  244. /// 3 components vector of low precision floating-point numbers.
  245. /// There is no guarantee on the actual precision.
  246. ///
  247. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.1.5 Vectors</a>
  248. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.7.2 Precision Qualifier</a>
  249. typedef detail::tvec3<lowp_float> lowp_vec3;
  250. /// 3 components vector of high precision signed integer numbers.
  251. /// There is no guarantee on the actual precision.
  252. ///
  253. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.1.5 Vectors</a>
  254. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.7.2 Precision Qualifier</a>
  255. typedef detail::tvec3<highp_int> highp_ivec3;
  256. /// 3 components vector of medium precision signed integer numbers.
  257. /// There is no guarantee on the actual precision.
  258. ///
  259. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.1.5 Vectors</a>
  260. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.7.2 Precision Qualifier</a>
  261. typedef detail::tvec3<mediump_int> mediump_ivec3;
  262. /// 3 components vector of low precision signed integer numbers.
  263. /// There is no guarantee on the actual precision.
  264. ///
  265. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.1.5 Vectors</a>
  266. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.7.2 Precision Qualifier</a>
  267. typedef detail::tvec3<lowp_int> lowp_ivec3;
  268. /// 3 components vector of high precision unsigned integer numbers.
  269. /// There is no guarantee on the actual precision.
  270. ///
  271. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.1.5 Vectors</a>
  272. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.7.2 Precision Qualifier</a>
  273. typedef detail::tvec3<highp_uint> highp_uvec3;
  274. /// 3 components vector of medium precision unsigned integer numbers.
  275. /// There is no guarantee on the actual precision.
  276. ///
  277. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.1.5 Vectors</a>
  278. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.7.2 Precision Qualifier</a>
  279. typedef detail::tvec3<mediump_uint> mediump_uvec3;
  280. /// 3 components vector of low precision unsigned integer numbers.
  281. /// There is no guarantee on the actual precision.
  282. ///
  283. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.1.5 Vectors</a>
  284. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.7.2 Precision Qualifier</a>
  285. typedef detail::tvec3<lowp_uint> lowp_uvec3;
  286. /// @}
  287. }//namespace glm
  288. #ifndef GLM_EXTERNAL_TEMPLATE
  289. #include "type_vec3.inl"
  290. #endif//GLM_EXTERNAL_TEMPLATE
  291. #endif//glm_core_type_gentype3