# GLM: vecx.hpp Source File

- Main Page
- Namespaces
- Files

- File List

# vecx.hpp

    00001
    00002 // OpenGL Mathematics Copyright (c) 2005 - 2009 G-Truc Creation (www.g-truc.net)
    00004 // Created : 2007-02-21
    00005 // Updated : 2007-02-21
    00006 // Licence : This source is under MIT License
    00007 // File    : glm/gtx/vecx.h
    00009 // Dependency:
    00010 // - GLM core
    00012
    00013 #ifndef glm_gtx_vecx
    00014 #define glm_gtx_vecx
    00015
    00016 namespace glm{
    00017 namespace detail{
    00018
    00019         template <int N>
    00020     class _bvecxGTX
    00021     {
    00022         private:
    00023                 bool data[N];
    00024
    00025         public:
    00026                 typedef bool value_type;
    00027                 typedef int size_type;
    00028                 static const size_type value_size;
    00029                 static const size_type col_size;
    00030                 static const size_type row_size;
    00031
    00032         // Common constructors
    00033             _bvecxGTX();
    00034         _bvecxGTX(const _bvecxGTX& v);
    00035
    00036                 // Accesses
    00037         bool& operator[](int i);
    00038         bool operator[](int i) const;
    00039         operator bool*();
    00040             operator const bool*() const;
    00041
    00042         // Bool constructors
    00043         explicit _bvecxGTX(const bool a);
    00044
    00045         // Operators
    00046         _bvecxGTX<N>& operator=(const _bvecxGTX<N>& v);
    00047             _bvecxGTX<N> operator! () const;
    00048     };
    00049
    00050     template <int N, typename T = float>
    00051     class _xvecxGTX
    00052     {
    00053         private:
    00054                 T data[N];
    00055
    00056         public:
    00057                 typedef T value_type;
    00058                 typedef int size_type;
    00059                 static const size_type value_size;
    00060
    00061         // Common constructors
    00062             _xvecxGTX();
    00063         _xvecxGTX(const _xvecxGTX<N, T>& v);
    00064
    00065                 // Accesses
    00066         T& operator[](int i);
    00067         T operator[](int i) const;
    00068         operator T*();
    00069             operator const T*() const;
    00070
    00071         // T constructors
    00072         explicit _xvecxGTX(const T x);
    00073
    00074         // Unary updatable operators
    00075         _xvecxGTX<N, T>& operator= (const _xvecxGTX<N, T>& v);
    00076             _xvecxGTX<N, T>& operator+=(const T s);
    00077             _xvecxGTX<N, T>& operator+=(const _xvecxGTX<N, T>& v);
    00078             _xvecxGTX<N, T>& operator-=(const T s);
    00079             _xvecxGTX<N, T>& operator-=(const _xvecxGTX<N, T>& v);
    00080             _xvecxGTX<N, T>& operator*=(const T s);
    00081             _xvecxGTX<N, T>& operator*=(const _xvecxGTX<N, T>& v);
    00082             _xvecxGTX<N, T>& operator/=(const T s);
    00083             _xvecxGTX<N, T>& operator/=(const _xvecxGTX<N, T>& v);
    00084             _xvecxGTX<N, T>& operator++();
    00085         _xvecxGTX<N, T>& operator--();
    00086     };
    00087
    00088     // Binary operators
    00089     template <int N, typename T>
    00090         detail::_xvecxGTX<N, T> operator+ (const detail::_xvecxGTX<N, T>& v, const T s);
    00091
    00092     template <int N, typename T>
    00093     detail::_xvecxGTX<N, T> operator+ (const T s, const detail::_xvecxGTX<N, T>& v);
    00094
    00095     template <int N, typename T>
    00096     detail::_xvecxGTX<N, T> operator+ (const detail::_xvecxGTX<N, T>& v1, const detail::_xvecxGTX<N, T>& v2);
    00097
    00098     template <int N, typename T>
    00099         detail::_xvecxGTX<N, T> operator- (const detail::_xvecxGTX<N, T>& v, const T s);
    00100
    00101     template <int N, typename T>
    00102     detail::_xvecxGTX<N, T> operator- (const T s, const detail::_xvecxGTX<N, T>& v);
    00103
    00104     template <int N, typename T>
    00105     detail::_xvecxGTX<N, T> operator- (const detail::_xvecxGTX<N, T>& v1, const detail::_xvecxGTX<N, T>& v2);
    00106
    00107     template <int N, typename T>
    00108     detail::_xvecxGTX<N, T> operator* (const detail::_xvecxGTX<N, T>& v, const T s);
    00109
    00110     template <int N, typename T>
    00111     detail::_xvecxGTX<N, T> operator* (const T s, const detail::_xvecxGTX<N, T>& v);
    00112
    00113     template <int N, typename T>
    00114     detail::_xvecxGTX<N, T> operator* (const detail::_xvecxGTX<N, T>& v1, const detail::_xvecxGTX<N, T>& v2);
    00115
    00116     template <int N, typename T>
    00117     detail::_xvecxGTX<N, T> operator/ (const detail::_xvecxGTX<N, T>& v, const T s);
    00118
    00119     template <int N, typename T>
    00120     detail::_xvecxGTX<N, T> operator/ (const T s, const detail::_xvecxGTX<N, T>& v);
    00121
    00122     template <int N, typename T>
    00123     detail::_xvecxGTX<N, T> operator/ (const detail::_xvecxGTX<N, T>& v1, const detail::_xvecxGTX<N, T>& v2);
    00124
    00125     // Unary constant operators
    00126     template <int N, typename T>
    00127     const detail::_xvecxGTX<N, T> operator- (const detail::_xvecxGTX<N, T>& v);
    00128
    00129     template <int N, typename T>
    00130     const detail::_xvecxGTX<N, T> operator-- (const detail::_xvecxGTX<N, T>& v, int);
    00131
    00132     template <int N, typename T>
    00133     const detail::_xvecxGTX<N, T> operator++ (const detail::_xvecxGTX<N, T>& v, int);
    00134
    00135 }//namespace detail
    00136
    00137         namespace gtx
    00138     {
    00140         namespace vecx
    00141         {
    00142                         template<typename T, int N>
    00143                         struct vec
    00144                         {
    00145                                 typedef detail::_xvecxGTX<N, T> type;
    00146                         };
    00147
    00148                         // Trigonometric Functions
    00149                         template <int N, typename T> detail::_xvecxGTX<N, T> radiansGTX(const detail::_xvecxGTX<N, T>& degrees); //< \brief Converts degrees to radians and returns the result. (From GLM_GTX_vecx extension)
    00150                         template <int N, typename T> detail::_xvecxGTX<N, T> degreesGTX(const detail::_xvecxGTX<N, T>& radians); //< \brief Converts radians to degrees and returns the result. (From GLM_GTX_vecx extension)
    00151                         template <int N, typename T> detail::_xvecxGTX<N, T> sinGTX(const detail::_xvecxGTX<N, T>& angle);              //< \brief The standard trigonometric sine function. The values returned by this function will range from [-1, 1]. (From GLM_GTX_vecx extension)
    00152                         template <int N, typename T> detail::_xvecxGTX<N, T> cosGTX(const detail::_xvecxGTX<N, T>& angle);              //< \brief The standard trigonometric cosine function. The values returned by this function will range from [-1, 1]. (From GLM_GTX_vecx extension)
    00153                         template <int N, typename T> detail::_xvecxGTX<N, T> tanGTX(const detail::_xvecxGTX<N, T>& angle);              //< \brief The standard trigonometric tangent function. (From GLM_GTX_vecx extension)
    00154                         template <int N, typename T> detail::_xvecxGTX<N, T> asinGTX(const detail::_xvecxGTX<N, T>& x);                 //< \brief Arc sine. Returns an angle whose sine is x. The range of values returned by this function is [-PI/2, PI/2]. Results are undefined if |x| > 1. (From GLM_GTX_vecx extension)
    00155                         template <int N, typename T> detail::_xvecxGTX<N, T> acosGTX(const detail::_xvecxGTX<N, T>& x);                 //< \brief Arc cosine. Returns an angle whose sine is x. The range of values returned by this function is [0, PI]. Results are undefined if |x| > 1. (From GLM_GTX_vecx extension)
    00156                         template <int N, typename T> detail::_xvecxGTX<N, T> atanGTX(const detail::_xvecxGTX<N, T>& y, const detail::_xvecxGTX<N, T>& x);       //< \brief Arc tangent. Returns an angle whose tangent is y/x. The signs of x and y are used to determine what quadrant the angle is in. The range of values returned by this function is [-PI, PI]. Results are undefined if x and y are both 0. (From GLM_GTX_vecx extension)
    00157                         template <int N, typename T> detail::_xvecxGTX<N, T> atanGTX(const detail::_xvecxGTX<N, T>& y_over_x);                                                          //< \brief Arc tangent. Returns an angle whose tangent is y_over_x. The range of values returned by this function is [-PI/2, PI/2]. (From GLM_GTX_vecx extension)
    00158
    00159                         // Exponential Functions
    00160                         template <int N, typename T> detail::_xvecxGTX<N, T> powGTX(const detail::_xvecxGTX<N, T>& x, const detail::_xvecxGTX<N, T>& y); //< \brief Returns x raised to the y power. (From GLM_GTX_vecx extension)
    00161                         template <int N, typename T> detail::_xvecxGTX<N, T> expGTX(const detail::_xvecxGTX<N, T>& x);  //< \brief Returns the natural exponentiation of x, i.e., e^x. (From GLM_GTX_vecx extension)
    00162                         template <int N, typename T> detail::_xvecxGTX<N, T> logGTX(const detail::_xvecxGTX<N, T>& x);  //< \brief Returns the natural logarithm of x, i.e., returns the value y which satisfies the equation x = e^y. Results are undefined if x <= 0. (From GLM_GTX_vecx extension)
    00163                         template <int N, typename T> detail::_xvecxGTX<N, T> exp2GTX(const detail::_xvecxGTX<N, T>& x); //< \brief Returns 2 raised to the x power. (From GLM_GTX_vecx extension)
    00164                         template <int N, typename T> detail::_xvecxGTX<N, T> log2GTX(const detail::_xvecxGTX<N, T>& x); //< \brief Returns the base 2 log of x, i.e., returns the value y, which satisfies the equation x = 2 ^ y. (From GLM_GTX_vecx extension)
    00165                         template <int N, typename T> detail::_xvecxGTX<N, T> sqrtGTX(const detail::_xvecxGTX<N, T>& x); //< \brief Returns the positive square root of x. (From GLM_GTX_vecx extension)
    00166                         template <int N, typename T> detail::_xvecxGTX<N, T> inversesqrtGTX(const detail::_xvecxGTX<N, T>& x);  //< \brief Returns the reciprocal of the positive square root of x. (From GLM_GTX_vecx extension)
    00167
    00168                         // Common Functions
    00169                         template <int N, typename T> detail::_xvecxGTX<N, T> absGTX(const detail::_xvecxGTX<N, T>& x);          //< \brief Returns x if x >= 0; otherwise, it returns -x. (From GLM_GTX_vecx extension)
    00170                         template <int N, typename T> detail::_xvecxGTX<N, T> floorGTX(const detail::_xvecxGTX<N, T>& x);                //< \brief Returns a value equal to the nearest integer that is less then or equal to x. (From GLM_GTX_vecx extension)
    00171                         template <int N, typename T> detail::_xvecxGTX<N, T> ceilGTX(const detail::_xvecxGTX<N, T>& x);         //< \brief Returns a value equal to the nearest integer that is greater than or equal to x. (From GLM_GTX_vecx extension)
    00172                         template <int N, typename T> detail::_xvecxGTX<N, T> fractGTX(const detail::_xvecxGTX<N, T>& x);                //< \brief Return x - floor(x). (From GLM_GTX_vecx extension)
    00173                         template <int N, typename T> detail::_xvecxGTX<N, T> modGTX(const detail::_xvecxGTX<N, T>& x, T y);                                                                     //< \brief Modulus. Returns x - y * floor(x / y) for each component in x using the floating point value y. (From GLM_GTX_vecx extension)
    00174                         template <int N, typename T> detail::_xvecxGTX<N, T> modGTX(const detail::_xvecxGTX<N, T>& x, const detail::_xvecxGTX<N, T>& y);                //< \brief Modulus. Returns x - y * floor(x / y) for each component in x using the corresponding component of y. (From GLM_GTX_vecx extension)
    00175                         template <int N, typename T> detail::_xvecxGTX<N, T> minGTX(const detail::_xvecxGTX<N, T>& x, T y);                                                                     //< \brief Returns y if y < x; otherwise, it returns x. (From GLM_GTX_vecx extension)
    00176                         template <int N, typename T> detail::_xvecxGTX<N, T> minGTX(const detail::_xvecxGTX<N, T>& x, const detail::_xvecxGTX<N, T>& y);                //< \brief Returns minimum of each component of x compared with the floating-point value y. (From GLM_GTX_vecx extension)
    00177                         template <int N, typename T> detail::_xvecxGTX<N, T> maxGTX(const detail::_xvecxGTX<N, T>& x, T y);                                                                     //< \brief Returns y if x < y; otherwise, it returns x. (From GLM_GTX_vecx extension)
    00178                         template <int N, typename T> detail::_xvecxGTX<N, T> maxGTX(const detail::_xvecxGTX<N, T>& x, const detail::_xvecxGTX<N, T>& y);                //< \brief Returns maximum of each component of x compared with the floating-point value y. (From GLM_GTX_vecx extension)
    00179                         template <int N, typename T> detail::_xvecxGTX<N, T> clampGTX(const detail::_xvecxGTX<N, T>& x, T minVal, T maxVal);                                                                                                                            //< \brief Returns min(max(x, minVal), maxVal) for each component in x using the floating-point values minVal and maxVal. (From GLM_GTX_vecx extension)
    00180                         template <int N, typename T> detail::_xvecxGTX<N, T> clampGTX(const detail::_xvecxGTX<N, T>& x, const detail::_xvecxGTX<N, T>& minVal, const detail::_xvecxGTX<N, T>& maxVal);  //< \brief Returns the component-wise result of min(max(x, minVal), maxVal). (From GLM_GTX_vecx extension)
    00181                         template <int N, typename T> detail::_xvecxGTX<N, T> stepGTX(T edge, const detail::_xvecxGTX<N, T>& x);                                                                                                                                                 //< \brief Returns 0.0 if x <= edge; otherwise, it returns 1.0. (From GLM_GTX_vecx extension)
    00182                         template <int N, typename T> detail::_xvecxGTX<N, T> stepGTX(const detail::_xvecxGTX<N, T>& edge, const detail::_xvecxGTX<N, T>& x);                                                                                            //< \brief Returns 0.0 if x <= edge; otherwise, it returns 1.0. (From GLM_GTX_vecx extension)
    00183                         template <int N, typename T> detail::_xvecxGTX<N, T> smoothstepGTX(T edge0, T edge1, const detail::_xvecxGTX<N, T>& x);                                                                                                                 //< \brief Returns 0.0 if x <= edge0 and 1.0 if x >= edge1 and performs smooth Hermite interpolation between 0 and 1 when edge0 < x, edge1. (From GLM_GTX_vecx extension)
    00184                         template <int N, typename T> detail::_xvecxGTX<N, T> smoothstepGTX(const detail::_xvecxGTX<N, T>& edge0, const detail::_xvecxGTX<N, T>& edge1, const detail::_xvecxGTX<N, T>& x);//< \brief Returns 0.0 if x <= edge0 and 1.0 if x >= edge1 and performs smooth Hermite interpolation between 0 and 1 when edge0 < x, edge1. (From GLM_GTX_vecx extension)
    00185
    00186                         // Geometric Functions
    00187                         template <int N, typename T> T lengthGTX(const detail::_xvecxGTX<N, T>& x);                                                                                     //< \brief Returns the length of x, i.e., sqrt(x * x). (From GLM_GTX_vecx extension)
    00188                         template <int N, typename T> T distanceGTX(const detail::_xvecxGTX<N, T>& p0, const detail::_xvecxGTX<N, T>& p1);       //< \brief Returns the distance betwwen p0 and p1, i.e., length(p0 - p1). (From GLM_GTX_vecx extension)
    00189                         template <int N, typename T> T dotGTX(const detail::_xvecxGTX<N, T>& x, const detail::_xvecxGTX<N, T>& y);                      //< \brief Returns the dot product of x and y, i.e., result = x[0] * y[0] + x[1] * y[1]. (From GLM_GTX_vecx extension)
    00190                         template <int N, typename T> detail::_xvecxGTX<N, T> normalizeGTX(const detail::_xvecxGTX<N, T>& x);                                    //< \brief Returns a vector in the same direction as x but with length of 1. (From GLM_GTX_vecx extension)
    00191                         template <int N, typename T> detail::_xvecxGTX<N, T> faceforwardGTX(const detail::_xvecxGTX<N, T>& Norm, const detail::_xvecxGTX<N, T>& I, const detail::_xvecxGTX<N, T>& Nref);                //< \brief If dot(Nref, I) < 0.0, return N, otherwise, return -N. (From GLM_GTX_vecx extension)
    00192                         template <int N, typename T> detail::_xvecxGTX<N, T> reflectGTX(const detail::_xvecxGTX<N, T>& I, const detail::_xvecxGTX<N, T>& N);                                                                                                    //< \brief For the incident vector I and surface orientation N, returns the reflection direction : result = I - 2.0 * dot(N, I) * N. (From GLM_GTX_vecx extension)
    00193                         template <int N, typename T> detail::_xvecxGTX<N, T> refractGTX(const detail::_xvecxGTX<N, T>& I, const detail::_xvecxGTX<N, T>& N, T eta);                                                                                     //< \brief For the incident vector I and surface normal N, and the ratio of indices of refraction eta, return the refraction vector. (From GLM_GTX_vecx extension)
    00194
    00195                         // Vector Relational Functions
    00196                         template <int N, typename T> detail::_bvecxGTX<N> lessThanGTX(const detail::_xvecxGTX<N, T>& x, const detail::_xvecxGTX<N, T>& y);                      //< \brief Returns the component-wise compare of x < y. (From GLM_GTX_vecx extension)
    00197                         template <int N, typename T> detail::_bvecxGTX<N> lessThanEqualGTX(const detail::_xvecxGTX<N, T>& x, const detail::_xvecxGTX<N, T>& y);         //< \brief Returns the component-wise compare of x <= y. (From GLM_GTX_vecx extension)
    00198                         template <int N, typename T> detail::_bvecxGTX<N> greaterThanGTX(const detail::_xvecxGTX<N, T>& x, const detail::_xvecxGTX<N, T>& y);           //< \brief Returns the component-wise compare of x > y. (From GLM_GTX_vecx extension)
    00199                         template <int N, typename T> detail::_bvecxGTX<N> greaterThanEqualGTX(const detail::_xvecxGTX<N, T>& x, const detail::_xvecxGTX<N, T>& y);      //< \brief Returns the component-wise compare of x >= y. (From GLM_GTX_vecx extension)
    00200                         template <int N> detail::_bvecxGTX<N> equalGTX(const detail::_bvecxGTX<N>& x, const detail::_bvecxGTX<N>& y);                                                           //< \brief Returns the component-wise compare of x == y. (From GLM_GTX_vecx extension)
    00201                         template <int N, typename T> detail::_bvecxGTX<N> equalGTX(const detail::_xvecxGTX<N, T>& x, const detail::_xvecxGTX<N, T>& y);                         //< \brief Returns the component-wise compare of x == y. (From GLM_GTX_vecx extension)
    00202                         template <int N> detail::_bvecxGTX<N> notEqualGTX(const detail::_bvecxGTX<N>& x, const detail::_bvecxGTX<N>& y);                                                                //< \brief Returns the component-wise compare of x != y. (From GLM_GTX_vecx extension)
    00203                         template <int N, typename T> detail::_bvecxGTX<N> notEqualGTX(const detail::_xvecxGTX<N, T>& x, const detail::_xvecxGTX<N, T>& y);                      //< \brief Returns the component-wise compare of x != y. (From GLM_GTX_vecx extension)
    00204                         template <int N> bool anyGTX(const detail::_bvecxGTX<N>& x);                                                                                                                                                                    //< \brief Returns true if any component of x is true. (From GLM_GTX_vecx extension)
    00205                         template <int N> bool allGTX(const detail::_bvecxGTX<N>& x);                                                                                                                                                                    //< \brief Returns true if all component of x is true. (From GLM_GTX_vecx extension)
    00206                         template <int N> detail::_bvecxGTX<N> notGTX(const detail::_bvecxGTX<N>& v); //< \brief Returns the component-wise logical complement of x. (From GLM_GTX_vecx extension)
    00207         }
    00208     }
    00209 }
    00210
    00211 #define GLM_GTX_vecx namespace gtx::vecx
    00212 #ifndef GLM_GTX_GLOBAL
    00213 namespace glm {using GLM_GTX_vecx;}
    00214 #endif//GLM_GTX_GLOBAL
    00215
    00216 #include "vecx.inl"
    00217
    00218 #endif//glm_gtx_vecx