1 /// @ref core 2 /// @file glm/detail/type_vec3.hpp 3 4 #pragma once 5 6 #include "type_vec.hpp" 7 #if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED 8 # if GLM_HAS_UNRESTRICTED_UNIONS 9 # include "_swizzle.hpp" 10 # else 11 # include "_swizzle_func.hpp" 12 # endif 13 #endif //GLM_SWIZZLE == GLM_SWIZZLE_ENABLED 14 #include <cstddef> 15 16 namespace glm 17 { 18 template <typename T, precision P = defaultp> 19 struct tvec3 20 { 21 // -- Implementation detail -- 22 23 typedef T value_type; 24 typedef tvec3<T, P> type; 25 typedef tvec3<bool, P> bool_type; 26 27 // -- Data -- 28 29 # if GLM_HAS_ONLY_XYZW 30 T x, y, z; 31 32 # elif GLM_HAS_ALIGNED_TYPE 33 # if GLM_COMPILER & GLM_COMPILER_GCC 34 # pragma GCC diagnostic push 35 # pragma GCC diagnostic ignored "-Wpedantic" 36 # endif 37 # if GLM_COMPILER & GLM_COMPILER_CLANG 38 # pragma clang diagnostic push 39 # pragma clang diagnostic ignored "-Wgnu-anonymous-struct" 40 # pragma clang diagnostic ignored "-Wnested-anon-types" 41 # endif 42 43 union 44 { 45 struct{ T x, y, z; }; 46 struct{ T r, g, b; }; 47 struct{ T s, t, p; }; 48 49 # if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED 50 _GLM_SWIZZLE3_2_MEMBERS(T, P, glm::tvec2, x, y, z) 51 _GLM_SWIZZLE3_2_MEMBERS(T, P, glm::tvec2, r, g, b) 52 _GLM_SWIZZLE3_2_MEMBERS(T, P, glm::tvec2, s, t, p) 53 _GLM_SWIZZLE3_3_MEMBERS(T, P, glm::tvec3, x, y, z) 54 _GLM_SWIZZLE3_3_MEMBERS(T, P, glm::tvec3, r, g, b) 55 _GLM_SWIZZLE3_3_MEMBERS(T, P, glm::tvec3, s, t, p) 56 _GLM_SWIZZLE3_4_MEMBERS(T, P, glm::tvec4, x, y, z) 57 _GLM_SWIZZLE3_4_MEMBERS(T, P, glm::tvec4, r, g, b) 58 _GLM_SWIZZLE3_4_MEMBERS(T, P, glm::tvec4, s, t, p) 59 # endif//GLM_SWIZZLE 60 }; 61 62 # if GLM_COMPILER & GLM_COMPILER_CLANG 63 # pragma clang diagnostic pop 64 # endif 65 # if GLM_COMPILER & GLM_COMPILER_GCC 66 # pragma GCC diagnostic pop 67 # endif 68 # else 69 union { T x, r, s; }; 70 union { T y, g, t; }; 71 union { T z, b, p; }; 72 73 # if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED 74 GLM_SWIZZLE_GEN_VEC_FROM_VEC3(T, P, tvec3, tvec2, tvec3, tvec4) 75 # endif//GLM_SWIZZLE 76 # endif//GLM_LANG 77 78 // -- Component accesses -- 79 80 /// Return the count of components of the vector 81 typedef length_t length_type; lengthglm::tvec382 GLM_FUNC_DECL static length_type length(){return 3;} 83 84 GLM_FUNC_DECL T & operator[](length_type i); 85 GLM_FUNC_DECL T const & operator[](length_type i) const; 86 87 // -- Implicit basic constructors -- 88 89 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR tvec3() GLM_DEFAULT_CTOR; 90 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR tvec3(tvec3<T, P> const & v) GLM_DEFAULT; 91 template <precision Q> 92 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR tvec3(tvec3<T, Q> const & v); 93 94 // -- Explicit basic constructors -- 95 96 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR explicit tvec3(ctor); 97 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR explicit tvec3(T scalar); 98 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR tvec3(T a, T b, T c); 99 100 // -- Conversion scalar constructors -- 101 102 /// Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) 103 template <typename A, typename B, typename C> 104 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR tvec3(A a, B b, C c); 105 template <typename A, typename B, typename C> 106 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR tvec3(tvec1<A, P> const & a, tvec1<B, P> const & b, tvec1<C, P> const & c); 107 108 // -- Conversion vector constructors -- 109 110 /// Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) 111 template <typename A, typename B, precision Q> 112 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR tvec3(tvec2<A, Q> const & a, B b); 113 /// Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) 114 template <typename A, typename B, precision Q> 115 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR tvec3(tvec2<A, Q> const & a, tvec1<B, Q> const & b); 116 /// Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) 117 template <typename A, typename B, precision Q> 118 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR tvec3(A a, tvec2<B, Q> const & b); 119 /// Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) 120 template <typename A, typename B, precision Q> 121 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR tvec3(tvec1<A, Q> const & a, tvec2<B, Q> const & b); 122 /// Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) 123 template <typename U, precision Q> 124 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR GLM_EXPLICIT tvec3(tvec4<U, Q> const & v); 125 126 /// Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) 127 template <typename U, precision Q> 128 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR GLM_EXPLICIT tvec3(tvec3<U, Q> const & v); 129 130 // -- Swizzle constructors -- 131 # if GLM_HAS_UNRESTRICTED_UNIONS && (GLM_SWIZZLE == GLM_SWIZZLE_ENABLED) 132 template <int E0, int E1, int E2> tvec3glm::tvec3133 GLM_FUNC_DECL tvec3(detail::_swizzle<3, T, P, glm::tvec3, E0, E1, E2, -1> const & that) 134 { 135 *this = that(); 136 } 137 138 template <int E0, int E1> tvec3glm::tvec3139 GLM_FUNC_DECL tvec3(detail::_swizzle<2, T, P, glm::tvec2, E0, E1, -1, -2> const & v, T const & scalar) 140 { 141 *this = tvec3<T, P>(v(), scalar); 142 } 143 144 template <int E0, int E1> tvec3glm::tvec3145 GLM_FUNC_DECL tvec3(T const & scalar, detail::_swizzle<2, T, P, glm::tvec2, E0, E1, -1, -2> const & v) 146 { 147 *this = tvec3<T, P>(scalar, v()); 148 } 149 # endif// GLM_HAS_UNRESTRICTED_UNIONS && (GLM_SWIZZLE == GLM_SWIZZLE_ENABLED) 150 151 // -- Unary arithmetic operators -- 152 153 GLM_FUNC_DECL tvec3<T, P> & operator=(tvec3<T, P> const & v) GLM_DEFAULT; 154 155 template <typename U> 156 GLM_FUNC_DECL tvec3<T, P> & operator=(tvec3<U, P> const & v); 157 template <typename U> 158 GLM_FUNC_DECL tvec3<T, P> & operator+=(U scalar); 159 template <typename U> 160 GLM_FUNC_DECL tvec3<T, P> & operator+=(tvec1<U, P> const & v); 161 template <typename U> 162 GLM_FUNC_DECL tvec3<T, P> & operator+=(tvec3<U, P> const & v); 163 template <typename U> 164 GLM_FUNC_DECL tvec3<T, P> & operator-=(U scalar); 165 template <typename U> 166 GLM_FUNC_DECL tvec3<T, P> & operator-=(tvec1<U, P> const & v); 167 template <typename U> 168 GLM_FUNC_DECL tvec3<T, P> & operator-=(tvec3<U, P> const & v); 169 template <typename U> 170 GLM_FUNC_DECL tvec3<T, P> & operator*=(U scalar); 171 template <typename U> 172 GLM_FUNC_DECL tvec3<T, P> & operator*=(tvec1<U, P> const & v); 173 template <typename U> 174 GLM_FUNC_DECL tvec3<T, P> & operator*=(tvec3<U, P> const & v); 175 template <typename U> 176 GLM_FUNC_DECL tvec3<T, P> & operator/=(U scalar); 177 template <typename U> 178 GLM_FUNC_DECL tvec3<T, P> & operator/=(tvec1<U, P> const & v); 179 template <typename U> 180 GLM_FUNC_DECL tvec3<T, P> & operator/=(tvec3<U, P> const & v); 181 182 // -- Increment and decrement operators -- 183 184 GLM_FUNC_DECL tvec3<T, P> & operator++(); 185 GLM_FUNC_DECL tvec3<T, P> & operator--(); 186 GLM_FUNC_DECL tvec3<T, P> operator++(int); 187 GLM_FUNC_DECL tvec3<T, P> operator--(int); 188 189 // -- Unary bit operators -- 190 191 template <typename U> 192 GLM_FUNC_DECL tvec3<T, P> & operator%=(U scalar); 193 template <typename U> 194 GLM_FUNC_DECL tvec3<T, P> & operator%=(tvec1<U, P> const & v); 195 template <typename U> 196 GLM_FUNC_DECL tvec3<T, P> & operator%=(tvec3<U, P> const & v); 197 template <typename U> 198 GLM_FUNC_DECL tvec3<T, P> & operator&=(U scalar); 199 template <typename U> 200 GLM_FUNC_DECL tvec3<T, P> & operator&=(tvec1<U, P> const & v); 201 template <typename U> 202 GLM_FUNC_DECL tvec3<T, P> & operator&=(tvec3<U, P> const & v); 203 template <typename U> 204 GLM_FUNC_DECL tvec3<T, P> & operator|=(U scalar); 205 template <typename U> 206 GLM_FUNC_DECL tvec3<T, P> & operator|=(tvec1<U, P> const & v); 207 template <typename U> 208 GLM_FUNC_DECL tvec3<T, P> & operator|=(tvec3<U, P> const & v); 209 template <typename U> 210 GLM_FUNC_DECL tvec3<T, P> & operator^=(U scalar); 211 template <typename U> 212 GLM_FUNC_DECL tvec3<T, P> & operator^=(tvec1<U, P> const & v); 213 template <typename U> 214 GLM_FUNC_DECL tvec3<T, P> & operator^=(tvec3<U, P> const & v); 215 template <typename U> 216 GLM_FUNC_DECL tvec3<T, P> & operator<<=(U scalar); 217 template <typename U> 218 GLM_FUNC_DECL tvec3<T, P> & operator<<=(tvec1<U, P> const & v); 219 template <typename U> 220 GLM_FUNC_DECL tvec3<T, P> & operator<<=(tvec3<U, P> const & v); 221 template <typename U> 222 GLM_FUNC_DECL tvec3<T, P> & operator>>=(U scalar); 223 template <typename U> 224 GLM_FUNC_DECL tvec3<T, P> & operator>>=(tvec1<U, P> const & v); 225 template <typename U> 226 GLM_FUNC_DECL tvec3<T, P> & operator>>=(tvec3<U, P> const & v); 227 }; 228 229 // -- Unary operators -- 230 231 template <typename T, precision P> 232 GLM_FUNC_DECL tvec3<T, P> operator+(tvec3<T, P> const & v); 233 234 template <typename T, precision P> 235 GLM_FUNC_DECL tvec3<T, P> operator-(tvec3<T, P> const & v); 236 237 // -- Binary operators -- 238 239 template <typename T, precision P> 240 GLM_FUNC_DECL tvec3<T, P> operator+(tvec3<T, P> const & v, T scalar); 241 242 template <typename T, precision P> 243 GLM_FUNC_DECL tvec3<T, P> operator+(tvec3<T, P> const & v, tvec1<T, P> const & scalar); 244 245 template <typename T, precision P> 246 GLM_FUNC_DECL tvec3<T, P> operator+(T scalar, tvec3<T, P> const & v); 247 248 template <typename T, precision P> 249 GLM_FUNC_DECL tvec3<T, P> operator+(tvec1<T, P> const & v1, tvec3<T, P> const & v2); 250 251 template <typename T, precision P> 252 GLM_FUNC_DECL tvec3<T, P> operator+(tvec3<T, P> const & v1, tvec3<T, P> const & v2); 253 254 template <typename T, precision P> 255 GLM_FUNC_DECL tvec3<T, P> operator-(tvec3<T, P> const & v, T scalar); 256 257 template <typename T, precision P> 258 GLM_FUNC_DECL tvec3<T, P> operator-(tvec3<T, P> const & v1, tvec1<T, P> const & v2); 259 260 template <typename T, precision P> 261 GLM_FUNC_DECL tvec3<T, P> operator-(T scalar, tvec3<T, P> const & v); 262 263 template <typename T, precision P> 264 GLM_FUNC_DECL tvec3<T, P> operator-(tvec1<T, P> const & v1, tvec3<T, P> const & v2); 265 266 template <typename T, precision P> 267 GLM_FUNC_DECL tvec3<T, P> operator-(tvec3<T, P> const & v1, tvec3<T, P> const & v2); 268 269 template <typename T, precision P> 270 GLM_FUNC_DECL tvec3<T, P> operator*(tvec3<T, P> const & v, T scalar); 271 272 template <typename T, precision P> 273 GLM_FUNC_DECL tvec3<T, P> operator*(tvec3<T, P> const & v1, tvec1<T, P> const & v2); 274 275 template <typename T, precision P> 276 GLM_FUNC_DECL tvec3<T, P> operator*(T scalar, tvec3<T, P> const & v); 277 278 template <typename T, precision P> 279 GLM_FUNC_DECL tvec3<T, P> operator*(tvec1<T, P> const & v1, tvec3<T, P> const & v2); 280 281 template <typename T, precision P> 282 GLM_FUNC_DECL tvec3<T, P> operator*(tvec3<T, P> const & v1, tvec3<T, P> const & v2); 283 284 template <typename T, precision P> 285 GLM_FUNC_DECL tvec3<T, P> operator/(tvec3<T, P> const & v, T scalar); 286 287 template <typename T, precision P> 288 GLM_FUNC_DECL tvec3<T, P> operator/(tvec3<T, P> const & v1, tvec1<T, P> const & v2); 289 290 template <typename T, precision P> 291 GLM_FUNC_DECL tvec3<T, P> operator/(T scalar, tvec3<T, P> const & v); 292 293 template <typename T, precision P> 294 GLM_FUNC_DECL tvec3<T, P> operator/(tvec1<T, P> const & v1, tvec3<T, P> const & v2); 295 296 template <typename T, precision P> 297 GLM_FUNC_DECL tvec3<T, P> operator/(tvec3<T, P> const & v1, tvec3<T, P> const & v2); 298 299 template <typename T, precision P> 300 GLM_FUNC_DECL tvec3<T, P> operator%(tvec3<T, P> const & v, T scalar); 301 302 template <typename T, precision P> 303 GLM_FUNC_DECL tvec3<T, P> operator%(tvec3<T, P> const & v1, tvec1<T, P> const & v2); 304 305 template <typename T, precision P> 306 GLM_FUNC_DECL tvec3<T, P> operator%(T const & scalar, tvec3<T, P> const & v); 307 308 template <typename T, precision P> 309 GLM_FUNC_DECL tvec3<T, P> operator%(tvec1<T, P> const & v1, tvec3<T, P> const & v2); 310 311 template <typename T, precision P> 312 GLM_FUNC_DECL tvec3<T, P> operator%(tvec3<T, P> const & v1, tvec3<T, P> const & v2); 313 314 template <typename T, precision P> 315 GLM_FUNC_DECL tvec3<T, P> operator&(tvec3<T, P> const & v1, T scalar); 316 317 template <typename T, precision P> 318 GLM_FUNC_DECL tvec3<T, P> operator&(tvec3<T, P> const & v1, tvec1<T, P> const & v2); 319 320 template <typename T, precision P> 321 GLM_FUNC_DECL tvec3<T, P> operator&(T scalar, tvec3<T, P> const & v); 322 323 template <typename T, precision P> 324 GLM_FUNC_DECL tvec3<T, P> operator&(tvec1<T, P> const & v1, tvec3<T, P> const & v2); 325 326 template <typename T, precision P> 327 GLM_FUNC_DECL tvec3<T, P> operator&(tvec3<T, P> const & v1, tvec3<T, P> const & v2); 328 329 template <typename T, precision P> 330 GLM_FUNC_DECL tvec3<T, P> operator|(tvec3<T, P> const & v, T scalar); 331 332 template <typename T, precision P> 333 GLM_FUNC_DECL tvec3<T, P> operator|(tvec3<T, P> const & v1, tvec1<T, P> const & v2); 334 335 template <typename T, precision P> 336 GLM_FUNC_DECL tvec3<T, P> operator|(T scalar, tvec3<T, P> const & v); 337 338 template <typename T, precision P> 339 GLM_FUNC_DECL tvec3<T, P> operator|(tvec1<T, P> const & v1, tvec3<T, P> const & v2); 340 341 template <typename T, precision P> 342 GLM_FUNC_DECL tvec3<T, P> operator|(tvec3<T, P> const & v1, tvec3<T, P> const & v2); 343 344 template <typename T, precision P> 345 GLM_FUNC_DECL tvec3<T, P> operator^(tvec3<T, P> const & v, T scalar); 346 347 template <typename T, precision P> 348 GLM_FUNC_DECL tvec3<T, P> operator^(tvec3<T, P> const & v1, tvec1<T, P> const & v2); 349 350 template <typename T, precision P> 351 GLM_FUNC_DECL tvec3<T, P> operator^(T scalar, tvec3<T, P> const & v); 352 353 template <typename T, precision P> 354 GLM_FUNC_DECL tvec3<T, P> operator^(tvec1<T, P> const & v1, tvec3<T, P> const & v2); 355 356 template <typename T, precision P> 357 GLM_FUNC_DECL tvec3<T, P> operator^(tvec3<T, P> const & v1, tvec3<T, P> const & v2); 358 359 template <typename T, precision P> 360 GLM_FUNC_DECL tvec3<T, P> operator<<(tvec3<T, P> const & v, T scalar); 361 362 template <typename T, precision P> 363 GLM_FUNC_DECL tvec3<T, P> operator<<(tvec3<T, P> const & v1, tvec1<T, P> const & v2); 364 365 template <typename T, precision P> 366 GLM_FUNC_DECL tvec3<T, P> operator<<(T scalar, tvec3<T, P> const & v); 367 368 template <typename T, precision P> 369 GLM_FUNC_DECL tvec3<T, P> operator<<(tvec1<T, P> const & v1, tvec3<T, P> const & v2); 370 371 template <typename T, precision P> 372 GLM_FUNC_DECL tvec3<T, P> operator<<(tvec3<T, P> const & v1, tvec3<T, P> const & v2); 373 374 template <typename T, precision P> 375 GLM_FUNC_DECL tvec3<T, P> operator>>(tvec3<T, P> const & v, T scalar); 376 377 template <typename T, precision P> 378 GLM_FUNC_DECL tvec3<T, P> operator>>(tvec3<T, P> const & v1, tvec1<T, P> const & v2); 379 380 template <typename T, precision P> 381 GLM_FUNC_DECL tvec3<T, P> operator>>(T scalar, tvec3<T, P> const & v); 382 383 template <typename T, precision P> 384 GLM_FUNC_DECL tvec3<T, P> operator>>(tvec1<T, P> const & v1, tvec3<T, P> const & v2); 385 386 template <typename T, precision P> 387 GLM_FUNC_DECL tvec3<T, P> operator>>(tvec3<T, P> const & v1, tvec3<T, P> const & v2); 388 389 template <typename T, precision P> 390 GLM_FUNC_DECL tvec3<T, P> operator~(tvec3<T, P> const & v); 391 392 // -- Boolean operators -- 393 394 template <typename T, precision P> 395 GLM_FUNC_DECL bool operator==(tvec3<T, P> const & v1, tvec3<T, P> const & v2); 396 397 template <typename T, precision P> 398 GLM_FUNC_DECL bool operator!=(tvec3<T, P> const & v1, tvec3<T, P> const & v2); 399 400 template <precision P> 401 GLM_FUNC_DECL tvec3<bool, P> operator&&(tvec3<bool, P> const & v1, tvec3<bool, P> const & v2); 402 403 template <precision P> 404 GLM_FUNC_DECL tvec3<bool, P> operator||(tvec3<bool, P> const & v1, tvec3<bool, P> const & v2); 405 }//namespace glm 406 407 #ifndef GLM_EXTERNAL_TEMPLATE 408 #include "type_vec3.inl" 409 #endif//GLM_EXTERNAL_TEMPLATE 410