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_vec4.hpp 25 /// @date 2008-08-22 / 2011-06-15 26 /// @author Christophe Riccio 27 /////////////////////////////////////////////////////////////////////////////////// 28 29 #ifndef glm_core_type_gentype4 30 #define glm_core_type_gentype4 31 32 //#include "../fwd.hpp" 33 #include "setup.hpp" 34 #include "type_vec.hpp" 35 #ifdef GLM_SWIZZLE 36 # if GLM_HAS_ANONYMOUS_UNION 37 # include "_swizzle.hpp" 38 # else 39 # include "_swizzle_func.hpp" 40 # endif 41 #endif //GLM_SWIZZLE 42 #include <cstddef> 43 44 namespace glm{ 45 namespace detail 46 { 47 template <typename T, precision P> 48 struct tvec4 49 { 50 ////////////////////////////////////// 51 // Implementation detail 52 53 enum ctor{_null}; 54 55 typedef tvec4<T, P> type; 56 typedef tvec4<bool, P> bool_type; 57 typedef T value_type; 58 typedef int size_type; 59 60 ////////////////////////////////////// 61 // Helper 62 63 GLM_FUNC_DECL GLM_CONSTEXPR length_t length() const; 64 65 ////////////////////////////////////// 66 // Data 67 68 # if(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE)) 69 union 70 { 71 struct { T r, g, b, a; }; 72 struct { T s, t, p, q; }; 73 struct { T x, y, z, w;}; 74 75 _GLM_SWIZZLE4_2_MEMBERS(T, P, tvec2, x, y, z, w) 76 _GLM_SWIZZLE4_2_MEMBERS(T, P, tvec2, r, g, b, a) 77 _GLM_SWIZZLE4_2_MEMBERS(T, P, tvec2, s, t, p, q) 78 _GLM_SWIZZLE4_3_MEMBERS(T, P, tvec3, x, y, z, w) 79 _GLM_SWIZZLE4_3_MEMBERS(T, P, tvec3, r, g, b, a) 80 _GLM_SWIZZLE4_3_MEMBERS(T, P, tvec3, s, t, p, q) 81 _GLM_SWIZZLE4_4_MEMBERS(T, P, tvec4, x, y, z, w) 82 _GLM_SWIZZLE4_4_MEMBERS(T, P, tvec4, r, g, b, a) 83 _GLM_SWIZZLE4_4_MEMBERS(T, P, tvec4, s, t, p, q) 84 }; 85 # else 86 union { T x, r, s; }; 87 union { T y, g, t; }; 88 union { T z, b, p; }; 89 union { T w, a, q; }; 90 91 # ifdef GLM_SWIZZLE 92 GLM_SWIZZLE_GEN_VEC_FROM_VEC4(T, P, detail::tvec4, detail::tvec2, detail::tvec3, detail::tvec4) 93 # endif 94 # endif//GLM_LANG 95 96 ////////////////////////////////////// 97 // Accesses 98 99 GLM_FUNC_DECL T & operator[](length_t i); 100 GLM_FUNC_DECL T const & operator[](length_t i) const; 101 102 ////////////////////////////////////// 103 // Implicit basic constructors 104 105 GLM_FUNC_DECL tvec4(); 106 GLM_FUNC_DECL tvec4(type const & v); 107 template <precision Q> 108 GLM_FUNC_DECL tvec4(tvec4<T, Q> const & v); 109 110 ////////////////////////////////////// 111 // Explicit basic constructors 112 113 GLM_FUNC_DECL explicit tvec4( 114 ctor); 115 GLM_FUNC_DECL explicit tvec4( 116 T const & s); 117 GLM_FUNC_DECL tvec4( 118 T const & s0, 119 T const & s1, 120 T const & s2, 121 T const & s3); 122 123 ////////////////////////////////////// 124 // Conversion scalar constructors 125 126 /// Explicit converions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) 127 template <typename A, typename B, typename C, typename D> 128 GLM_FUNC_DECL tvec4( 129 A const & x, 130 B const & y, 131 C const & z, 132 D const & w); 133 134 ////////////////////////////////////// 135 // Conversion vector constructors 136 137 //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) 138 template <typename A, typename B, typename C, precision Q> 139 GLM_FUNC_DECL explicit tvec4(tvec2<A, Q> const & v, B const & s1, C const & s2); 140 //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) 141 template <typename A, typename B, typename C, precision Q> 142 GLM_FUNC_DECL explicit tvec4(A const & s1, tvec2<B, Q> const & v, C const & s2); 143 //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) 144 template <typename A, typename B, typename C, precision Q> 145 GLM_FUNC_DECL explicit tvec4(A const & s1, B const & s2, tvec2<C, Q> const & v); 146 //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) 147 template <typename A, typename B, precision Q> 148 GLM_FUNC_DECL explicit tvec4(tvec3<A, Q> const & v, B const & s); 149 //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) 150 template <typename A, typename B, precision Q> 151 GLM_FUNC_DECL explicit tvec4(A const & s, tvec3<B, Q> const & v); 152 //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) 153 template <typename A, typename B, precision Q> 154 GLM_FUNC_DECL explicit tvec4(tvec2<A, Q> const & v1, tvec2<B, Q> const & v2); 155 //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) 156 template <typename U, precision Q> 157 GLM_FUNC_DECL explicit tvec4(tvec4<U, Q> const & v); 158 159 ////////////////////////////////////// 160 // Swizzle constructors 161 162 # if(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE)) 163 template <int E0, int E1, int E2, int E3> 164 GLM_FUNC_DECL tvec4(_swizzle<4, T, P, tvec4<T, P>, E0, E1, E2, E3> const & that) 165 { 166 *this = that(); 167 } 168 169 template <int E0, int E1, int F0, int F1> 170 GLM_FUNC_DECL tvec4(_swizzle<2, T, P, tvec2<T, P>, E0, E1, -1, -2> const & v, _swizzle<2, T, P, tvec2<T, P>, F0, F1, -1, -2> const & u) 171 { 172 *this = tvec4<T, P>(v(), u()); 173 } 174 175 template <int E0, int E1> 176 GLM_FUNC_DECL tvec4(T const & x, T const & y, _swizzle<2, T, P, tvec2<T, P>, E0, E1, -1, -2> const & v) 177 { 178 *this = tvec4<T, P>(x, y, v()); 179 } 180 181 template <int E0, int E1> 182 GLM_FUNC_DECL tvec4(T const & x, _swizzle<2, T, P, tvec2<T, P>, E0, E1, -1, -2> const & v, T const & w) 183 { 184 *this = tvec4<T, P>(x, v(), w); 185 } 186 187 template <int E0, int E1> 188 GLM_FUNC_DECL tvec4(_swizzle<2, T, P, tvec2<T, P>, E0, E1, -1, -2> const & v, T const & z, T const & w) 189 { 190 *this = tvec4<T, P>(v(), z, w); 191 } 192 193 template <int E0, int E1, int E2> 194 GLM_FUNC_DECL tvec4(_swizzle<3, T, P, tvec3<T, P>, E0, E1, E2, -1> const & v, T const & w) 195 { 196 *this = tvec4<T, P>(v(), w); 197 } 198 199 template <int E0, int E1, int E2> 200 GLM_FUNC_DECL tvec4(T const & x, _swizzle<3, T, P, tvec3<T, P>, E0, E1, E2, -1> const & v) 201 { 202 *this = tvec4<T, P>(x, v()); 203 } 204 # endif//(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE)) 205 206 ////////////////////////////////////// 207 // Unary arithmetic operators 208 209 GLM_FUNC_DECL tvec4<T, P> & operator= (tvec4<T, P> const & v); 210 template <typename U, precision Q> 211 GLM_FUNC_DECL tvec4<T, P> & operator= (tvec4<U, Q> const & v); 212 213 template <typename U> 214 GLM_FUNC_DECL tvec4<T, P> & operator+=(U s); 215 template <typename U> 216 GLM_FUNC_DECL tvec4<T, P> & operator+=(tvec4<U, P> const & v); 217 template <typename U> 218 GLM_FUNC_DECL tvec4<T, P> & operator-=(U s); 219 template <typename U> 220 GLM_FUNC_DECL tvec4<T, P> & operator-=(tvec4<U, P> const & v); 221 template <typename U> 222 GLM_FUNC_DECL tvec4<T, P> & operator*=(U s); 223 template <typename U> 224 GLM_FUNC_DECL tvec4<T, P> & operator*=(tvec4<U, P> const & v); 225 template <typename U> 226 GLM_FUNC_DECL tvec4<T, P> & operator/=(U s); 227 template <typename U> 228 GLM_FUNC_DECL tvec4<T, P> & operator/=(tvec4<U, P> const & v); 229 230 ////////////////////////////////////// 231 // Increment and decrement operators 232 233 GLM_FUNC_DECL tvec4<T, P> & operator++(); 234 GLM_FUNC_DECL tvec4<T, P> & operator--(); 235 GLM_FUNC_DECL tvec4<T, P> operator++(int); 236 GLM_FUNC_DECL tvec4<T, P> operator--(int); 237 238 ////////////////////////////////////// 239 // Unary bit operators 240 241 template <typename U> 242 GLM_FUNC_DECL tvec4<T, P> & operator%= (U s); 243 template <typename U> 244 GLM_FUNC_DECL tvec4<T, P> & operator%= (tvec4<U, P> const & v); 245 template <typename U> 246 GLM_FUNC_DECL tvec4<T, P> & operator&= (U s); 247 template <typename U> 248 GLM_FUNC_DECL tvec4<T, P> & operator&= (tvec4<U, P> const & v); 249 template <typename U> 250 GLM_FUNC_DECL tvec4<T, P> & operator|= (U s); 251 template <typename U> 252 GLM_FUNC_DECL tvec4<T, P> & operator|= (tvec4<U, P> const & v); 253 template <typename U> 254 GLM_FUNC_DECL tvec4<T, P> & operator^= (U s); 255 template <typename U> 256 GLM_FUNC_DECL tvec4<T, P> & operator^= (tvec4<U, P> const & v); 257 template <typename U> 258 GLM_FUNC_DECL tvec4<T, P> & operator<<=(U s); 259 template <typename U> 260 GLM_FUNC_DECL tvec4<T, P> & operator<<=(tvec4<U, P> const & v); 261 template <typename U> 262 GLM_FUNC_DECL tvec4<T, P> & operator>>=(U s); 263 template <typename U> 264 GLM_FUNC_DECL tvec4<T, P> & operator>>=(tvec4<U, P> const & v); 265 }; 266 267 template <typename T, precision P> 268 GLM_FUNC_DECL tvec4<T, P> operator+(tvec4<T, P> const & v, T const & s); 269 270 template <typename T, precision P> 271 GLM_FUNC_DECL tvec4<T, P> operator+(T const & s, tvec4<T, P> const & v); 272 273 template <typename T, precision P> 274 GLM_FUNC_DECL tvec4<T, P> operator+(tvec4<T, P> const & v1, tvec4<T, P> const & v2); 275 276 template <typename T, precision P> 277 GLM_FUNC_DECL tvec4<T, P> operator-(tvec4<T, P> const & v, T const & s); 278 279 template <typename T, precision P> 280 GLM_FUNC_DECL tvec4<T, P> operator-(T const & s, tvec4<T, P> const & v); 281 282 template <typename T, precision P> 283 GLM_FUNC_DECL tvec4<T, P> operator- (tvec4<T, P> const & v1, tvec4<T, P> const & v2); 284 285 template <typename T, precision P> 286 GLM_FUNC_DECL tvec4<T, P> operator*(tvec4<T, P> const & v, T const & s); 287 288 template <typename T, precision P> 289 GLM_FUNC_DECL tvec4<T, P> operator*(T const & s, tvec4<T, P> const & v); 290 291 template <typename T, precision P> 292 GLM_FUNC_DECL tvec4<T, P> operator*(tvec4<T, P> const & v1, tvec4<T, P> const & v2); 293 294 template <typename T, precision P> 295 GLM_FUNC_DECL tvec4<T, P> operator/(tvec4<T, P> const & v, T const & s); 296 297 template <typename T, precision P> 298 GLM_FUNC_DECL tvec4<T, P> operator/(T const & s, tvec4<T, P> const & v); 299 300 template <typename T, precision P> 301 GLM_FUNC_DECL tvec4<T, P> operator/(tvec4<T, P> const & v1, tvec4<T, P> const & v2); 302 303 template <typename T, precision P> 304 GLM_FUNC_DECL tvec4<T, P> operator-(tvec4<T, P> const & v); 305 306 template <typename T, precision P> 307 GLM_FUNC_DECL bool operator==(tvec4<T, P> const & v1, tvec4<T, P> const & v2); 308 309 template <typename T, precision P> 310 GLM_FUNC_DECL bool operator!=(tvec4<T, P> const & v1, tvec4<T, P> const & v2); 311 312 template <typename T, precision P> 313 GLM_FUNC_DECL tvec4<T, P> operator%(tvec4<T, P> const & v, T const & s); 314 315 template <typename T, precision P> 316 GLM_FUNC_DECL tvec4<T, P> operator%(T const & s, tvec4<T, P> const & v); 317 318 template <typename T, precision P> 319 GLM_FUNC_DECL tvec4<T, P> operator%(tvec4<T, P> const & v1, tvec4<T, P> const & v2); 320 321 template <typename T, precision P> 322 GLM_FUNC_DECL tvec4<T, P> operator&(tvec4<T, P> const & v, T const & s); 323 324 template <typename T, precision P> 325 GLM_FUNC_DECL tvec4<T, P> operator&(T const & s, tvec4<T, P> const & v); 326 327 template <typename T, precision P> 328 GLM_FUNC_DECL tvec4<T, P> operator&(tvec4<T, P> const & v1, tvec4<T, P> const & v2); 329 330 template <typename T, precision P> 331 GLM_FUNC_DECL tvec4<T, P> operator|(tvec4<T, P> const & v, T const & s); 332 333 template <typename T, precision P> 334 GLM_FUNC_DECL tvec4<T, P> operator|(T const & s, tvec4<T, P> const & v); 335 336 template <typename T, precision P> 337 GLM_FUNC_DECL tvec4<T, P> operator|(tvec4<T, P> const & v1, tvec4<T, P> const & v2); 338 339 template <typename T, precision P> 340 GLM_FUNC_DECL tvec4<T, P> operator^(tvec4<T, P> const & v, T const & s); 341 342 template <typename T, precision P> 343 GLM_FUNC_DECL tvec4<T, P> operator^(T const & s, tvec4<T, P> const & v); 344 345 template <typename T, precision P> 346 GLM_FUNC_DECL tvec4<T, P> operator^(tvec4<T, P> const & v1, tvec4<T, P> const & v2); 347 348 template <typename T, precision P> 349 GLM_FUNC_DECL tvec4<T, P> operator<<(tvec4<T, P> const & v, T const & s); 350 351 template <typename T, precision P> 352 GLM_FUNC_DECL tvec4<T, P> operator<<(T const & s, tvec4<T, P> const & v); 353 354 template <typename T, precision P> 355 GLM_FUNC_DECL tvec4<T, P> operator<<(tvec4<T, P> const & v1, tvec4<T, P> const & v2); 356 357 template <typename T, precision P> 358 GLM_FUNC_DECL tvec4<T, P> operator>>(tvec4<T, P> const & v, T const & s); 359 360 template <typename T, precision P> 361 GLM_FUNC_DECL tvec4<T, P> operator>>(T const & s, tvec4<T, P> const & v); 362 363 template <typename T, precision P> 364 GLM_FUNC_DECL tvec4<T, P> operator>>(tvec4<T, P> const & v1, tvec4<T, P> const & v2); 365 366 template <typename T, precision P> 367 GLM_FUNC_DECL tvec4<T, P> operator~(tvec4<T, P> const & v); 368 369 }//namespace detail 370 }//namespace glm 371 372 #ifndef GLM_EXTERNAL_TEMPLATE 373 #include "type_vec4.inl" 374 #endif//GLM_EXTERNAL_TEMPLATE 375 376 #endif//glm_core_type_gentype4 377