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