Home | History | Annotate | Download | only in detail
      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 
     29 #ifndef glm_core_type_gentype2
     30 #define glm_core_type_gentype2
     31 
     32 //#include "../fwd.hpp"
     33 #include "type_vec.hpp"
     34 #ifdef GLM_SWIZZLE
     35 #	if GLM_HAS_ANONYMOUS_UNION
     36 #		include "_swizzle.hpp"
     37 #	else
     38 #		include "_swizzle_func.hpp"
     39 #	endif
     40 #endif //GLM_SWIZZLE
     41 #include <cstddef>
     42 
     43 namespace glm{
     44 namespace detail
     45 {
     46 	template <typename T, precision P>
     47 	struct tvec2
     48 	{
     49 		//////////////////////////////////////
     50 		// Implementation detail
     51 
     52 		enum ctor{_null};
     53 
     54 		typedef tvec2<T, P> type;
     55 		typedef tvec2<bool, P> bool_type;
     56 		typedef T value_type;
     57 		typedef int size_type;
     58 
     59 		//////////////////////////////////////
     60 		// Helper
     61 
     62 		GLM_FUNC_DECL GLM_CONSTEXPR length_t length() const;
     63 
     64 		//////////////////////////////////////
     65 		// Data
     66 
     67 #		if(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE))
     68 			union
     69 			{
     70 				struct{ T x, y; };
     71 				struct{ T r, g; };
     72 				struct{ T s, t; };
     73 
     74 				_GLM_SWIZZLE2_2_MEMBERS(T, P, tvec2, x, y)
     75 				_GLM_SWIZZLE2_2_MEMBERS(T, P, tvec2, r, g)
     76 				_GLM_SWIZZLE2_2_MEMBERS(T, P, tvec2, s, t)
     77 				_GLM_SWIZZLE2_3_MEMBERS(T, P, tvec3, x, y)
     78 				_GLM_SWIZZLE2_3_MEMBERS(T, P, tvec3, r, g)
     79 				_GLM_SWIZZLE2_3_MEMBERS(T, P, tvec3, s, t)
     80 				_GLM_SWIZZLE2_4_MEMBERS(T, P, tvec4, x, y)
     81 				_GLM_SWIZZLE2_4_MEMBERS(T, P, tvec4, r, g)
     82 				_GLM_SWIZZLE2_4_MEMBERS(T, P, tvec4, s, t)
     83 			};
     84 #		else
     85 			union {T x, r, s;};
     86 			union {T y, g, t;};
     87 
     88 #			ifdef GLM_SWIZZLE
     89 				GLM_SWIZZLE_GEN_VEC_FROM_VEC2(T, P, detail::tvec2, detail::tvec2, detail::tvec3, detail::tvec4)
     90 #			endif
     91 #		endif
     92 
     93 		//////////////////////////////////////
     94 		// Accesses
     95 
     96 		GLM_FUNC_DECL T & operator[](length_t i);
     97 		GLM_FUNC_DECL T const & operator[](length_t i) const;
     98 
     99 		//////////////////////////////////////
    100 		// Implicit basic constructors
    101 
    102 		GLM_FUNC_DECL tvec2();
    103 		GLM_FUNC_DECL tvec2(tvec2<T, P> const & v);
    104 		template <precision Q>
    105 		GLM_FUNC_DECL tvec2(tvec2<T, Q> const & v);
    106 
    107 		//////////////////////////////////////
    108 		// Explicit basic constructors
    109 
    110 		GLM_FUNC_DECL explicit tvec2(
    111 			ctor);
    112 		GLM_FUNC_DECL explicit tvec2(
    113 			T const & s);
    114 		GLM_FUNC_DECL tvec2(
    115 			T const & s1,
    116 			T const & s2);
    117 
    118 		//////////////////////////////////////
    119 		// Swizzle constructors
    120 
    121 #		if(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE))
    122 		template <int E0, int E1>
    123 		GLM_FUNC_DECL tvec2(_swizzle<2,T, P, tvec2<T, P>, E0, E1,-1,-2> const & that)
    124 		{
    125 			*this = that();
    126 		}
    127 #		endif//(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE))
    128 
    129 		//////////////////////////////////////
    130 		// Conversion constructors
    131 
    132 		//! Explicit converions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
    133 		template <typename U, typename V>
    134 		GLM_FUNC_DECL tvec2(
    135 			U const & x,
    136 			V const & y);
    137 
    138 		//////////////////////////////////////
    139 		// Conversion vector constructors
    140 
    141 		//! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
    142 		template <typename U, precision Q>
    143 		GLM_FUNC_DECL tvec2(tvec2<U, Q> const & v);
    144 		//! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
    145 		template <typename U, precision Q>
    146 		GLM_FUNC_DECL explicit tvec2(tvec3<U, Q> const & v);
    147 		//! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
    148 		template <typename U, precision Q>
    149 		GLM_FUNC_DECL explicit tvec2(tvec4<U, Q> const & v);
    150 
    151 		//////////////////////////////////////
    152 		// Unary arithmetic operators
    153 
    154 		GLM_FUNC_DECL tvec2<T, P> & operator= (tvec2<T, P> const & v);
    155 		template <typename U>
    156 		GLM_FUNC_DECL tvec2<T, P> & operator= (tvec2<U, P> const & v);
    157 
    158 		template <typename U>
    159 		GLM_FUNC_DECL tvec2<T, P> & operator+=(U s);
    160 		template <typename U>
    161 		GLM_FUNC_DECL tvec2<T, P> & operator+=(tvec2<U, P> const & v);
    162 		template <typename U>
    163 		GLM_FUNC_DECL tvec2<T, P> & operator-=(U s);
    164 		template <typename U>
    165 		GLM_FUNC_DECL tvec2<T, P> & operator-=(tvec2<U, P> const & v);
    166 		template <typename U>
    167 		GLM_FUNC_DECL tvec2<T, P> & operator*=(U s);
    168 		template <typename U>
    169 		GLM_FUNC_DECL tvec2<T, P> & operator*=(tvec2<U, P> const & v);
    170 		template <typename U>
    171 		GLM_FUNC_DECL tvec2<T, P> & operator/=(U s);
    172 		template <typename U>
    173 		GLM_FUNC_DECL tvec2<T, P> & operator/=(tvec2<U, P> const & v);
    174 
    175 		//////////////////////////////////////
    176 		// Increment and decrement operators
    177 
    178 		GLM_FUNC_DECL tvec2<T, P> & operator++();
    179 		GLM_FUNC_DECL tvec2<T, P> & operator--();
    180 		GLM_FUNC_DECL tvec2<T, P> operator++(int);
    181 		GLM_FUNC_DECL tvec2<T, P> operator--(int);
    182 
    183 		//////////////////////////////////////
    184 		// Unary bit operators
    185 
    186 		template <typename U>
    187 		GLM_FUNC_DECL tvec2<T, P> & operator%= (U s);
    188 		template <typename U>
    189 		GLM_FUNC_DECL tvec2<T, P> & operator%= (tvec2<U, P> const & v);
    190 		template <typename U>
    191 		GLM_FUNC_DECL tvec2<T, P> & operator&= (U s);
    192 		template <typename U>
    193 		GLM_FUNC_DECL tvec2<T, P> & operator&= (tvec2<U, P> const & v);
    194 		template <typename U>
    195 		GLM_FUNC_DECL tvec2<T, P> & operator|= (U s);
    196 		template <typename U>
    197 		GLM_FUNC_DECL tvec2<T, P> & operator|= (tvec2<U, P> const & v);
    198 		template <typename U>
    199 		GLM_FUNC_DECL tvec2<T, P> & operator^= (U s);
    200 		template <typename U>
    201 		GLM_FUNC_DECL tvec2<T, P> & operator^= (tvec2<U, P> const & v);
    202 		template <typename U>
    203 		GLM_FUNC_DECL tvec2<T, P> & operator<<=(U s);
    204 		template <typename U>
    205 		GLM_FUNC_DECL tvec2<T, P> & operator<<=(tvec2<U, P> const & v);
    206 		template <typename U>
    207 		GLM_FUNC_DECL tvec2<T, P> & operator>>=(U s);
    208 		template <typename U>
    209 		GLM_FUNC_DECL tvec2<T, P> & operator>>=(tvec2<U, P> const & v);
    210 	};
    211 
    212 	template <typename T, precision P>
    213 	GLM_FUNC_DECL tvec2<T, P> operator+(tvec2<T, P> const & v, T const & s);
    214 
    215 	template <typename T, precision P>
    216 	GLM_FUNC_DECL tvec2<T, P> operator+(T const & s, tvec2<T, P> const & v);
    217 
    218 	template <typename T, precision P>
    219 	GLM_FUNC_DECL tvec2<T, P> operator+(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
    220 
    221 	template <typename T, precision P>
    222 	GLM_FUNC_DECL tvec2<T, P> operator-(tvec2<T, P> const & v, T const & s);
    223 
    224 	template <typename T, precision P>
    225 	GLM_FUNC_DECL tvec2<T, P> operator-(T const & s, tvec2<T, P> const & v);
    226 
    227 	template <typename T, precision P>
    228 	GLM_FUNC_DECL tvec2<T, P> operator-	(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
    229 
    230 	template <typename T, precision P>
    231 	GLM_FUNC_DECL tvec2<T, P> operator*(tvec2<T, P> const & v, T const & s);
    232 
    233 	template <typename T, precision P>
    234 	GLM_FUNC_DECL tvec2<T, P> operator*(T const & s, tvec2<T, P> const & v);
    235 
    236 	template <typename T, precision P>
    237 	GLM_FUNC_DECL tvec2<T, P> operator*(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
    238 
    239 	template <typename T, precision P>
    240 	GLM_FUNC_DECL tvec2<T, P> operator/(tvec2<T, P> const & v, T const & s);
    241 
    242 	template <typename T, precision P>
    243 	GLM_FUNC_DECL tvec2<T, P> operator/(T const & s, tvec2<T, P> const & v);
    244 
    245 	template <typename T, precision P>
    246 	GLM_FUNC_DECL tvec2<T, P> operator/(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
    247 
    248 	template <typename T, precision P>
    249 	GLM_FUNC_DECL tvec2<T, P> operator-(tvec2<T, P> const & v);
    250 
    251 	template <typename T, precision P>
    252 	GLM_FUNC_DECL tvec2<T, P> operator%(tvec2<T, P> const & v, T const & s);
    253 
    254 	template <typename T, precision P>
    255 	GLM_FUNC_DECL tvec2<T, P> operator%(T const & s, tvec2<T, P> const & v);
    256 
    257 	template <typename T, precision P>
    258 	GLM_FUNC_DECL tvec2<T, P> operator%(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
    259 
    260 	template <typename T, precision P>
    261 	GLM_FUNC_DECL tvec2<T, P> operator&(tvec2<T, P> const & v, T const & s);
    262 
    263 	template <typename T, precision P>
    264 	GLM_FUNC_DECL tvec2<T, P> operator&(T const & s, tvec2<T, P> const & v);
    265 
    266 	template <typename T, precision P>
    267 	GLM_FUNC_DECL tvec2<T, P> operator&(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
    268 
    269 	template <typename T, precision P>
    270 	GLM_FUNC_DECL tvec2<T, P> operator|(tvec2<T, P> const & v, T const & s);
    271 
    272 	template <typename T, precision P>
    273 	GLM_FUNC_DECL tvec2<T, P> operator|(T const & s, tvec2<T, P> const & v);
    274 
    275 	template <typename T, precision P>
    276 	GLM_FUNC_DECL tvec2<T, P> operator|(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
    277 
    278 	template <typename T, precision P>
    279 	GLM_FUNC_DECL tvec2<T, P> operator^(tvec2<T, P> const & v, T const & s);
    280 
    281 	template <typename T, precision P>
    282 	GLM_FUNC_DECL tvec2<T, P> operator^(T const & s, tvec2<T, P> const & v);
    283 
    284 	template <typename T, precision P>
    285 	GLM_FUNC_DECL tvec2<T, P> operator^(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
    286 
    287 	template <typename T, precision P>
    288 	GLM_FUNC_DECL tvec2<T, P> operator<<(tvec2<T, P> const & v, T const & s);
    289 
    290 	template <typename T, precision P>
    291 	GLM_FUNC_DECL tvec2<T, P> operator<<(T const & s, tvec2<T, P> const & v);
    292 
    293 	template <typename T, precision P>
    294 	GLM_FUNC_DECL tvec2<T, P> operator<<(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
    295 
    296 	template <typename T, precision P>
    297 	GLM_FUNC_DECL tvec2<T, P> operator>>(tvec2<T, P> const & v, T const & s);
    298 
    299 	template <typename T, precision P>
    300 	GLM_FUNC_DECL tvec2<T, P> operator>>(T const & s, tvec2<T, P> const & v);
    301 
    302 	template <typename T, precision P>
    303 	GLM_FUNC_DECL tvec2<T, P> operator>>(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
    304 
    305 	template <typename T, precision P>
    306 	GLM_FUNC_DECL tvec2<T, P> operator~(tvec2<T, P> const & v);
    307 
    308 }//namespace detail
    309 }//namespace glm
    310 
    311 #ifndef GLM_EXTERNAL_TEMPLATE
    312 #include "type_vec2.inl"
    313 #endif//GLM_EXTERNAL_TEMPLATE
    314 
    315 #endif//glm_core_type_gentype2
    316