type_vec2.hpp

00001 
00002 // OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
00004 // Created : 2008-08-18
00005 // Updated : 2010-02-04
00006 // Licence : This source is under MIT License
00007 // File    : glm/core/type_tvec2.hpp
00009 
00010 #ifndef glm_core_type_gentype2
00011 #define glm_core_type_gentype2
00012 
00013 #include "type_vec.hpp"
00014 #include "type_float.hpp"
00015 #include "type_int.hpp"
00016 #include "type_size.hpp"
00017 #include "_swizzle.hpp"
00018 
00019 namespace glm{
00020 namespace detail
00021 {
00022         template <typename T> struct tref2;
00023         template <typename T> struct tref3;
00024         template <typename T> struct tref4;
00025         template <typename T> struct tvec3;
00026         template <typename T> struct tvec4;
00027 
00030         template <typename T>
00031         struct tvec2
00032         {
00033                 enum ctor{null};
00034 
00035                 typedef T value_type;
00036                 typedef std::size_t size_type;
00037                 GLM_FUNC_DECL size_type length() const;
00038                 static GLM_FUNC_DECL size_type value_size();
00039 
00040                 typedef tvec2<T> type;
00041                 typedef tvec2<bool> bool_type;
00042 
00044                 // Data
00045 
00046 #               if(GLM_COMPONENT == GLM_COMPONENT_ONLY_XYZW)
00047                 value_type x, y;
00048 #               elif(GLM_COMPONENT == GLM_COMPONENT_MS_EXT)
00049                 union 
00050                 {
00051                         struct{value_type x, y;};
00052                         struct{value_type r, g;};
00053                         struct{value_type s, t;};
00054                 };
00055 #               else//(GLM_COMPONENT == GLM_COMPONENT_GLSL_NAMES)
00056                 union {value_type x, r, s;};
00057                 union {value_type y, g, t;};
00058 #               endif//GLM_COMPONENT
00059 
00061                 // Accesses
00062 
00063                 GLM_FUNC_DECL value_type & operator[](size_type i);
00064                 GLM_FUNC_DECL value_type const & operator[](size_type i) const;
00065 
00067                 // Implicit basic constructors
00068 
00069                 GLM_FUNC_DECL tvec2();
00070                 GLM_FUNC_DECL tvec2(tvec2<T> const & v);
00071 
00073                 // Explicit basic constructors
00074 
00075                 GLM_FUNC_DECL explicit tvec2(
00076                         ctor);
00077                 GLM_FUNC_DECL explicit tvec2(
00078                         value_type const & s);
00079                 GLM_FUNC_DECL explicit tvec2(
00080                         value_type const & s1, 
00081                         value_type const & s2);
00082 
00084                 // Swizzle constructors
00085 
00086                 tvec2(tref2<T> const & r);
00087 
00089                 // Convertion constructors
00090 
00092                 template <typename U> 
00093                 GLM_FUNC_DECL explicit tvec2(
00094                         U const & x);
00096                 template <typename U, typename V> 
00097                 GLM_FUNC_DECL explicit tvec2(
00098                         U const & x, 
00099                         V const & y);
00100 
00102                 // Convertion vector constructors
00103 
00105                 template <typename U> 
00106                 GLM_FUNC_DECL explicit tvec2(tvec2<U> const & v);
00108                 template <typename U> 
00109                 GLM_FUNC_DECL explicit tvec2(tvec3<U> const & v);
00111                 template <typename U> 
00112                 GLM_FUNC_DECL explicit tvec2(tvec4<U> const & v);
00113 
00115                 // Unary arithmetic operators
00116 
00117                 GLM_FUNC_DECL tvec2<T> & operator= (tvec2<T> const & v);
00118                 template <typename U> 
00119                 GLM_FUNC_DECL tvec2<T> & operator= (tvec2<U> const & v);
00120 
00121                 template <typename U> 
00122                 GLM_FUNC_DECL tvec2<T> & operator+=(U const & s);
00123                 template <typename U> 
00124                 GLM_FUNC_DECL tvec2<T> & operator+=(tvec2<U> const & v);
00125                 template <typename U> 
00126                 GLM_FUNC_DECL tvec2<T> & operator-=(U const & s);
00127                 template <typename U> 
00128                 GLM_FUNC_DECL tvec2<T> & operator-=(tvec2<U> const & v);
00129                 template <typename U> 
00130                 GLM_FUNC_DECL tvec2<T> & operator*=(U const & s);
00131                 template <typename U> 
00132                 GLM_FUNC_DECL tvec2<T> & operator*=(tvec2<U> const & v);
00133                 template <typename U> 
00134                 GLM_FUNC_DECL tvec2<T> & operator/=(U const & s);
00135                 template <typename U> 
00136                 GLM_FUNC_DECL tvec2<T> & operator/=(tvec2<U> const & v);
00137                 GLM_FUNC_DECL tvec2<T> & operator++();
00138                 GLM_FUNC_DECL tvec2<T> & operator--();
00139 
00141                 // Unary bit operators
00142 
00143                 template <typename U> 
00144                 GLM_FUNC_DECL tvec2<T> & operator%= (U const & s);
00145                 template <typename U> 
00146                 GLM_FUNC_DECL tvec2<T> & operator%= (tvec2<U> const & v);
00147                 template <typename U> 
00148                 GLM_FUNC_DECL tvec2<T> & operator&= (U const & s);
00149                 template <typename U> 
00150                 GLM_FUNC_DECL tvec2<T> & operator&= (tvec2<U> const & v);
00151                 template <typename U> 
00152                 GLM_FUNC_DECL tvec2<T> & operator|= (U const & s);
00153                 template <typename U> 
00154                 GLM_FUNC_DECL tvec2<T> & operator|= (tvec2<U> const & v);
00155                 template <typename U> 
00156                 GLM_FUNC_DECL tvec2<T> & operator^= (U const & s);
00157                 template <typename U> 
00158                 GLM_FUNC_DECL tvec2<T> & operator^= (tvec2<U> const & v);
00159                 template <typename U> 
00160                 GLM_FUNC_DECL tvec2<T> & operator<<=(U const & s);
00161                 template <typename U> 
00162                 GLM_FUNC_DECL tvec2<T> & operator<<=(tvec2<U> const & v);
00163                 template <typename U> 
00164                 GLM_FUNC_DECL tvec2<T> & operator>>=(U const & s);
00165                 template <typename U> 
00166                 GLM_FUNC_DECL tvec2<T> & operator>>=(tvec2<U> const & v);
00167 
00169                 // Swizzle operators
00170 
00171                 GLM_FUNC_DECL value_type swizzle(comp X) const;
00172                 GLM_FUNC_DECL tvec2<T> swizzle(comp X, comp Y) const;
00173                 GLM_FUNC_DECL tvec3<T> swizzle(comp X, comp Y, comp Z) const;
00174                 GLM_FUNC_DECL tvec4<T> swizzle(comp X, comp Y, comp Z, comp W) const;
00175                 GLM_FUNC_DECL tref2<T> swizzle(comp X, comp Y);
00176         };
00177 
00178         template <typename T>
00179         struct tref2
00180         {
00181                 GLM_FUNC_DECL tref2(T & x, T & y);
00182                 GLM_FUNC_DECL tref2(tref2<T> const & r);
00183                 GLM_FUNC_DECL tref2(tvec2<T> const & v);
00184 
00185                 GLM_FUNC_DECL tref2<T> & operator= (tref2<T> const & r);
00186                 GLM_FUNC_DECL tref2<T> & operator= (tvec2<T> const & v);
00187 
00188                 T& x;
00189                 T& y;
00190         };
00191 
00192         GLM_DETAIL_IS_VECTOR(tvec2);
00193 
00194 } //namespace detail
00195 
00196 namespace core{
00197 namespace type{
00198 namespace precision
00199 {
00204         typedef detail::tvec2<highp_float>              highp_vec2;
00205 
00210         typedef detail::tvec2<mediump_float>    mediump_vec2;
00211 
00216         typedef detail::tvec2<lowp_float>               lowp_vec2;
00217 
00222         typedef detail::tvec2<highp_int>                highp_ivec2;
00223 
00228         typedef detail::tvec2<mediump_int>              mediump_ivec2;
00229 
00234         typedef detail::tvec2<lowp_int>                 lowp_ivec2;
00235         
00240         typedef detail::tvec2<highp_uint>               highp_uvec2;
00241 
00246         typedef detail::tvec2<mediump_uint>             mediump_uvec2;
00247 
00252         typedef detail::tvec2<lowp_uint>                lowp_uvec2;
00253 
00254 }//namespace precision
00255 }//namespace type
00256 }//namespace core
00257 }//namespace glm
00258 
00259 #ifndef GLM_EXTERNAL_TEMPLATE
00260 #include "type_vec2.inl"
00261 #endif//GLM_EXTERNAL_TEMPLATE
00262 
00263 #endif//glm_core_type_gentype2