TAPs 0.7.7.3
TAPsVector4.hpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsVector4.hpp
00003 ******************************************************************************/
00007 /******************************************************************************
00008 SUKITTI PUNAK   (09/10/2004)
00009 UPDATE          (08/27/2010)
00010 ******************************************************************************/
00011 #ifndef TAPs_VECTOR4_HPP
00012 #define TAPs_VECTOR4_HPP
00013 
00014 #include "TAPsVector.hpp"
00015 #include "TAPsVector3.hpp"
00016 
00017 template <typename T> class ColMatrix4x4;
00018 
00019 BEGIN_NAMESPACE_TAPs
00020 //=============================================================================
00021 template <typename T>
00022 class Vector4 : public Vector<T,4> {
00023 //=============================================================================
00024 public:
00025     //-------------------------------------------------------------------------
00026     // Constructors
00027     Vector4 ();
00028     Vector4 ( T const af[4] );
00029     Vector4 ( Vector4<T> const &v );
00030     Vector4 ( Vector3<T> const &v, T w = 1 );
00031     Vector4 ( T x, T y, T z, T w );
00032     //-------------------------------------------------------------------------
00033     // Assignment Operator
00034     inline Vector4<T> & operator= ( Vector4<T> const &v );
00035     //-------------------------------------------------------------------------
00036     // Comparison Operators
00037     inline bool operator== ( Vector4<T> const &v ) const;
00038     inline bool operator!= ( Vector4<T> const &v ) const;
00039     inline bool operator<= ( Vector4<T> const &v ) const;
00040     inline bool operator<  ( Vector4<T> const &v ) const;
00041     inline bool operator>= ( Vector4<T> const &v ) const;
00042     inline bool operator>  ( Vector4<T> const &v ) const;
00043     //-------------------------------------------------------------------------
00044     // Arithmetic Operators
00045     inline Vector4<T> operator- () const;   // negation
00046     inline Vector4<T> operator+ ( Vector4<T> const &v ) const;
00047     inline Vector4<T> operator- ( Vector4<T> const &v ) const;
00048     inline Vector4<T> operator* ( T s ) const;
00049     inline Vector4<T> operator/ ( T s ) const;
00050     friend inline Vector4<T> operator* ( T s, Vector4<T> const &v ) { return v*s; }
00051     //-------------------------------------------------------------------------
00052     // Arithmetic Update Operators
00053     inline Vector4<T> & operator+= ( Vector4<T> const &v );
00054     inline Vector4<T> & operator-= ( Vector4<T> const &v );
00055     inline Vector4<T> & operator*= ( T s );
00056     inline Vector4<T> & operator/= ( T s );
00057     //-------------------------------------------------------------------------
00058     // Vector Operations
00059     inline T Length () const;
00060     inline T Magnitude () const;
00061     inline T SquaredLength () const;
00062     inline Vector4<T> GetUnit ( T tolerance = TAPs::Math<T>::EPSILON ) const;
00063     inline Vector4<T> & Normalized ( T tolerance = TAPs::Math<T>::EPSILON );
00064     inline T Dot ( Vector4<T> const &v ) const;         // Dot Product
00065     inline T operator* ( Vector4<T> const &v ) const;   // Dot Product Operator
00066 
00068     inline Vector4<T> ComponentWiseMult ( Vector4<T> const &v ) const;
00070     inline Vector4<T> ComponentWiseDivs ( Vector4<T> const &v ) const;
00072     inline void UpdateByComponentWiseMult ( Vector4<T> const &v );
00074     inline void UpdateByComponentWiseDivs ( Vector4<T> const &v );
00075 
00076     //-------------------------------------------------------------------------
00077     // Get/Set Fn(s)
00078     inline T GetX() const { return this->t[0]; }
00079     inline T GetY() const { return this->t[1]; }
00080     inline T GetZ() const { return this->t[2]; }
00081     inline T GetW() const { return this->t[3]; }
00082     inline void GetXYZW( T &x, T &y, T &z, T &w ) const 
00083     { x = this->t[0]; y = this->t[1]; z = this->t[2]; w = this->t[3]; }
00084     inline void GetXYZ( T &x, T &y, T &z ) const 
00085     { x = this->t[0]; y = this->t[1]; z = this->t[2]; }
00086     inline void SetX( T x ) { this->t[0] = x; }
00087     inline void SetY( T y ) { this->t[1] = y; }
00088     inline void SetZ( T z ) { this->t[2] = z; }
00089     inline void SetW( T w ) { this->t[3] = w; }
00090     inline void SetXYZW( T x, T y, T z, T w ) 
00091     { this->t[0] = x; this->t[1] = y; this->t[2] = z; this->t[3] = w; }
00092     inline void SetXYZ( T x, T y, T z ) 
00093     { this->t[0] = x; this->t[1] = y; this->t[2] = z; }
00094     inline void SetXYZW( Vector4<T> v ) 
00095     { this->t[0] = v[0]; this->t[1] = v[1]; this->t[2] = v[2]; this->t[3] = v[3]; }
00096     inline void SetXYZ( Vector3<T> v ) 
00097     { this->t[0] = v[0]; this->t[1] = v[1]; this->t[2] = v[2]; }
00098     inline Vector3<T> GetVector3() const
00099     { return Vector3<T>( t[0], t[1], t[2] ); }
00100     //-------------------------------------------------------------------------
00101     // Vector * ColMatrix
00102     Vector4<T> operator* ( ColMatrix4x4<T> const &M ) const;
00103     //-------------------------------------------------------------------------
00104 }; // END CLASS Vector4
00105 //=============================================================================
00106 //-----------------------------------------------------------------------------
00107 // Define Vector4s
00108 typedef Vector4<int>            Vector4i;
00109 typedef Vector4<float>          Vector4f;
00110 typedef Vector4<double>         Vector4d;
00111 typedef Vector4<long double>    Vector4ld;
00112 //-----------------------------------------------------------------------------
00113 //=============================================================================
00114 // class Point4 is a vector4.
00115 template <typename T>
00116 class Point4 : public Vector4<T> {
00117 public:
00118     //-------------------------------------------------------------------------
00119     // Output Operator <<
00120     friend std::ostream & operator<< ( std::ostream &output, Point4<T> const &p )
00121     {
00122         output  << "Point4<" << typeid(T).name() << ">( "
00123                 << p.t[0] << ", " << p.t[1] << ", " << p.t[2] << ", " << p.t[3]
00124                 << " )'";
00125         return output;
00126     }
00127     //-------------------------------------------------------------------------
00128     // Constructors
00129     Point4 () : Vector4<T>() {}
00130     Point4 ( T const at[4] ) : Vector4<T>( at ) {}
00131     Point4 ( Point4<T> const &p ) : Vector4<T>( p ) {}
00132     Point4 ( T x, T y, T z, T w ) : Vector4<T>( x, y, z, w ) {}
00133     //-------------------------------------------------------------------------
00134 }; // END CLASS Point4
00135 //=============================================================================
00136 //-----------------------------------------------------------------------------
00137 typedef Point4<int>    Point4i;
00138 typedef Point4<float>  Point4f;
00139 typedef Point4<double> Point4d;
00140 //-----------------------------------------------------------------------------
00141 //=============================================================================
00142 END_NAMESPACE_TAPs
00143 //-----------------------------------------------------------------------------
00144 // Include definition if TAPs_USE_EXPORT is not defined
00145 //#if !defined( TAPs_USE_EXPORT )
00146     #include "TAPsVector4.cpp"
00147 //#endif
00148 //-----------------------------------------------------------------------------
00149 #endif
00150 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00151 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines