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_vec3.hpp 25 /// @date 2008-08-22 / 2011-06-15 26 /// @author Christophe Riccio 27 /////////////////////////////////////////////////////////////////////////////////// 28 29 #ifndef glm_core_type_gentype3 30 #define glm_core_type_gentype3 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 tvec3 48 { 49 ////////////////////////////////////// 50 // Implementation detail 51 52 enum ctor{_null}; 53 54 typedef tvec3<T, P> type; 55 typedef tvec3<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, z; }; 71 struct{ T r, g, b; }; 72 struct{ T s, t, p; }; 73 74 _GLM_SWIZZLE3_2_MEMBERS(T, P, tvec2, x, y, z) 75 _GLM_SWIZZLE3_2_MEMBERS(T, P, tvec2, r, g, b) 76 _GLM_SWIZZLE3_2_MEMBERS(T, P, tvec2, s, t, p) 77 _GLM_SWIZZLE3_3_MEMBERS(T, P, tvec3, x, y, z) 78 _GLM_SWIZZLE3_3_MEMBERS(T, P, tvec3, r, g, b) 79 _GLM_SWIZZLE3_3_MEMBERS(T, P, tvec3, s, t, p) 80 _GLM_SWIZZLE3_4_MEMBERS(T, P, tvec4, x, y, z) 81 _GLM_SWIZZLE3_4_MEMBERS(T, P, tvec4, r, g, b) 82 _GLM_SWIZZLE3_4_MEMBERS(T, P, tvec4, s, t, p) 83 }; 84 # else 85 union { T x, r, s; }; 86 union { T y, g, t; }; 87 union { T z, b, p; }; 88 89 # ifdef GLM_SWIZZLE 90 GLM_SWIZZLE_GEN_VEC_FROM_VEC3(T, P, detail::tvec3, detail::tvec2, detail::tvec3, detail::tvec4) 91 # endif 92 # endif//GLM_LANG 93 94 ////////////////////////////////////// 95 // Accesses 96 97 GLM_FUNC_DECL T & operator[](length_t i); 98 GLM_FUNC_DECL T const & operator[](length_t i) const; 99 100 ////////////////////////////////////// 101 // Implicit basic constructors 102 103 GLM_FUNC_DECL tvec3(); 104 GLM_FUNC_DECL tvec3(tvec3<T, P> const & v); 105 template <precision Q> 106 GLM_FUNC_DECL tvec3(tvec3<T, Q> const & v); 107 108 ////////////////////////////////////// 109 // Explicit basic constructors 110 111 GLM_FUNC_DECL explicit tvec3( 112 ctor); 113 GLM_FUNC_DECL explicit tvec3( 114 T const & s); 115 GLM_FUNC_DECL tvec3( 116 T const & s1, 117 T const & s2, 118 T const & s3); 119 120 ////////////////////////////////////// 121 // Conversion scalar constructors 122 123 //! Explicit converions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) 124 template <typename U, typename V, typename W> 125 GLM_FUNC_DECL tvec3( 126 U const & x, 127 V const & y, 128 W const & z); 129 130 ////////////////////////////////////// 131 // Conversion vector constructors 132 133 //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) 134 template <typename A, typename B, precision Q> 135 GLM_FUNC_DECL explicit tvec3(tvec2<A, Q> const & v, B const & s); 136 //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) 137 template <typename A, typename B, precision Q> 138 GLM_FUNC_DECL explicit tvec3(A const & s, tvec2<B, Q> const & v); 139 //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) 140 template <typename U, precision Q> 141 GLM_FUNC_DECL explicit tvec3(tvec3<U, Q> const & v); 142 //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) 143 template <typename U, precision Q> 144 GLM_FUNC_DECL explicit tvec3(tvec4<U, Q> const & v); 145 146 ////////////////////////////////////// 147 // Swizzle constructors 148 149 # if(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE)) 150 template <int E0, int E1, int E2> tvec3glm::detail::tvec3151 GLM_FUNC_DECL tvec3(_swizzle<3, T, P, tvec3<T, P>, E0, E1, E2, -1> const & that) 152 { 153 *this = that(); 154 } 155 156 template <int E0, int E1> tvec3glm::detail::tvec3157 GLM_FUNC_DECL tvec3(_swizzle<2, T, P, tvec2<T, P>, E0, E1, -1, -2> const & v, T const & s) 158 { 159 *this = tvec3<T, P>(v(), s); 160 } 161 162 template <int E0, int E1> tvec3glm::detail::tvec3163 GLM_FUNC_DECL tvec3(T const & s, _swizzle<2, T, P, tvec2<T, P>, E0, E1, -1, -2> const & v) 164 { 165 *this = tvec3<T, P>(s, v()); 166 } 167 # endif//(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE)) 168 169 ////////////////////////////////////// 170 // Unary arithmetic operators 171 172 GLM_FUNC_DECL tvec3<T, P> & operator= (tvec3<T, P> const & v); 173 template <typename U> 174 GLM_FUNC_DECL tvec3<T, P> & operator= (tvec3<U, P> const & v); 175 176 template <typename U> 177 GLM_FUNC_DECL tvec3<T, P> & operator+=(U s); 178 template <typename U> 179 GLM_FUNC_DECL tvec3<T, P> & operator+=(tvec3<U, P> const & v); 180 template <typename U> 181 GLM_FUNC_DECL tvec3<T, P> & operator-=(U s); 182 template <typename U> 183 GLM_FUNC_DECL tvec3<T, P> & operator-=(tvec3<U, P> const & v); 184 template <typename U> 185 GLM_FUNC_DECL tvec3<T, P> & operator*=(U s); 186 template <typename U> 187 GLM_FUNC_DECL tvec3<T, P> & operator*=(tvec3<U, P> const & v); 188 template <typename U> 189 GLM_FUNC_DECL tvec3<T, P> & operator/=(U s); 190 template <typename U> 191 GLM_FUNC_DECL tvec3<T, P> & operator/=(tvec3<U, P> const & v); 192 193 ////////////////////////////////////// 194 // Increment and decrement operators 195 196 GLM_FUNC_DECL tvec3<T, P> & operator++(); 197 GLM_FUNC_DECL tvec3<T, P> & operator--(); 198 GLM_FUNC_DECL tvec3<T, P> operator++(int); 199 GLM_FUNC_DECL tvec3<T, P> operator--(int); 200 201 ////////////////////////////////////// 202 // Unary bit operators 203 204 template <typename U> 205 GLM_FUNC_DECL tvec3<T, P> & operator%= (U s); 206 template <typename U> 207 GLM_FUNC_DECL tvec3<T, P> & operator%= (tvec3<U, P> const & v); 208 template <typename U> 209 GLM_FUNC_DECL tvec3<T, P> & operator&= (U s); 210 template <typename U> 211 GLM_FUNC_DECL tvec3<T, P> & operator&= (tvec3<U, P> const & v); 212 template <typename U> 213 GLM_FUNC_DECL tvec3<T, P> & operator|= (U s); 214 template <typename U> 215 GLM_FUNC_DECL tvec3<T, P> & operator|= (tvec3<U, P> const & v); 216 template <typename U> 217 GLM_FUNC_DECL tvec3<T, P> & operator^= (U s); 218 template <typename U> 219 GLM_FUNC_DECL tvec3<T, P> & operator^= (tvec3<U, P> const & v); 220 template <typename U> 221 GLM_FUNC_DECL tvec3<T, P> & operator<<=(U s); 222 template <typename U> 223 GLM_FUNC_DECL tvec3<T, P> & operator<<=(tvec3<U, P> const & v); 224 template <typename U> 225 GLM_FUNC_DECL tvec3<T, P> & operator>>=(U s); 226 template <typename U> 227 GLM_FUNC_DECL tvec3<T, P> & operator>>=(tvec3<U, P> const & v); 228 }; 229 230 template <typename T, precision P> 231 GLM_FUNC_DECL tvec3<T, P> operator+(tvec3<T, P> const & v, T const & s); 232 233 template <typename T, precision P> 234 GLM_FUNC_DECL tvec3<T, P> operator+(T const & s, tvec3<T, P> const & v); 235 236 template <typename T, precision P> 237 GLM_FUNC_DECL tvec3<T, P> operator+(tvec3<T, P> const & v1, tvec3<T, P> const & v2); 238 239 template <typename T, precision P> 240 GLM_FUNC_DECL tvec3<T, P> operator-(tvec3<T, P> const & v, T const & s); 241 242 template <typename T, precision P> 243 GLM_FUNC_DECL tvec3<T, P> operator-(T const & s, tvec3<T, P> const & v); 244 245 template <typename T, precision P> 246 GLM_FUNC_DECL tvec3<T, P> operator- (tvec3<T, P> const & v1, tvec3<T, P> const & v2); 247 248 template <typename T, precision P> 249 GLM_FUNC_DECL tvec3<T, P> operator*(tvec3<T, P> const & v, T const & s); 250 251 template <typename T, precision P> 252 GLM_FUNC_DECL tvec3<T, P> operator*(T const & s, tvec3<T, P> const & v); 253 254 template <typename T, precision P> 255 GLM_FUNC_DECL tvec3<T, P> operator*(tvec3<T, P> const & v1, tvec3<T, P> const & v2); 256 257 template <typename T, precision P> 258 GLM_FUNC_DECL tvec3<T, P> operator/(tvec3<T, P> const & v, T const & s); 259 260 template <typename T, precision P> 261 GLM_FUNC_DECL tvec3<T, P> operator/(T const & s, tvec3<T, P> const & v); 262 263 template <typename T, precision P> 264 GLM_FUNC_DECL tvec3<T, P> operator/(tvec3<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 & v); 268 269 template <typename T, precision P> 270 GLM_FUNC_DECL tvec3<T, P> operator%(tvec3<T, P> const & v, T const & s); 271 272 template <typename T, precision P> 273 GLM_FUNC_DECL tvec3<T, P> operator%(T const & s, tvec3<T, P> const & v); 274 275 template <typename T, precision P> 276 GLM_FUNC_DECL tvec3<T, P> operator%(tvec3<T, P> const & v1, tvec3<T, P> const & v2); 277 278 template <typename T, precision P> 279 GLM_FUNC_DECL tvec3<T, P> operator&(tvec3<T, P> const & v, T const & s); 280 281 template <typename T, precision P> 282 GLM_FUNC_DECL tvec3<T, P> operator&(T const & s, tvec3<T, P> const & v); 283 284 template <typename T, precision P> 285 GLM_FUNC_DECL tvec3<T, P> operator&(tvec3<T, P> const & v1, tvec3<T, P> const & v2); 286 287 template <typename T, precision P> 288 GLM_FUNC_DECL tvec3<T, P> operator|(tvec3<T, P> const & v, T const & s); 289 290 template <typename T, precision P> 291 GLM_FUNC_DECL tvec3<T, P> operator|(T const & s, tvec3<T, P> const & v); 292 293 template <typename T, precision P> 294 GLM_FUNC_DECL tvec3<T, P> operator|(tvec3<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 & v, T const & s); 298 299 template <typename T, precision P> 300 GLM_FUNC_DECL tvec3<T, P> operator^(T const & s, tvec3<T, P> const & v); 301 302 template <typename T, precision P> 303 GLM_FUNC_DECL tvec3<T, P> operator^(tvec3<T, P> const & v1, tvec3<T, P> const & v2); 304 305 template <typename T, precision P> 306 GLM_FUNC_DECL tvec3<T, P> operator<<(tvec3<T, P> const & v, T const & s); 307 308 template <typename T, precision P> 309 GLM_FUNC_DECL tvec3<T, P> operator<<(T const & s, tvec3<T, P> const & v); 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 & v, T const & s); 316 317 template <typename T, precision P> 318 GLM_FUNC_DECL tvec3<T, P> operator>>(T const & s, tvec3<T, P> const & v); 319 320 template <typename T, precision P> 321 GLM_FUNC_DECL tvec3<T, P> operator>>(tvec3<T, P> const & v1, tvec3<T, P> const & v2); 322 323 template <typename T, precision P> 324 GLM_FUNC_DECL tvec3<T, P> operator~(tvec3<T, P> const & v); 325 326 }//namespace detail 327 }//namespace glm 328 329 #ifndef GLM_EXTERNAL_TEMPLATE 330 #include "type_vec3.inl" 331 #endif//GLM_EXTERNAL_TEMPLATE 332 333 #endif//glm_core_type_gentype3 334