00001 // Wild Magic Source Code 00002 // David Eberly 00003 // http://www.geometrictools.com 00004 // Copyright (c) 1998-2007 00005 // 00006 // This library is free software; you can redistribute it and/or modify it 00007 // under the terms of the GNU Lesser General Public License as published by 00008 // the Free Software Foundation; either version 2.1 of the License, or (at 00009 // your option) any later version. The license is available for reading at 00010 // either of the locations: 00011 // http://www.gnu.org/copyleft/lgpl.html 00012 // http://www.geometrictools.com/License/WildMagicLicense.pdf 00013 // The license applies to versions 0 through 4 of Wild Magic. 00014 // 00015 // Version: 4.0.0 (2006/06/28) 00016 00017 #ifndef WM4GVECTOR_H 00018 #define WM4GVECTOR_H 00019 00020 #include "Wm4FoundationLIB.h" 00021 #include "Wm4Math.h" 00022 00023 namespace Wm4 00024 { 00025 00026 template <class Real> 00027 class GVector 00028 { 00029 public: 00030 // construction 00031 GVector (int iSize = 0); 00032 GVector (int iSize, const Real* afTuple); 00033 GVector (const GVector& rkV); 00034 ~GVector (); 00035 00036 // coordinate access 00037 void SetSize (int iSize); 00038 int GetSize () const; 00039 operator const Real* () const; 00040 operator Real* (); 00041 Real operator[] (int i) const; 00042 Real& operator[] (int i); 00043 00044 // assignment 00045 GVector& operator= (const GVector& rkV); 00046 00047 // comparison 00048 bool operator== (const GVector& rkV) const; 00049 bool operator!= (const GVector& rkV) const; 00050 bool operator< (const GVector& rkV) const; 00051 bool operator<= (const GVector& rkV) const; 00052 bool operator> (const GVector& rkV) const; 00053 bool operator>= (const GVector& rkV) const; 00054 00055 // arithmetic operations 00056 GVector operator+ (const GVector& rkV) const; 00057 GVector operator- (const GVector& rkV) const; 00058 GVector operator* (Real fScalar) const; 00059 GVector operator/ (Real fScalar) const; 00060 GVector operator- () const; 00061 00062 // arithmetic updates 00063 GVector& operator+= (const GVector& rkV); 00064 GVector& operator-= (const GVector& rkV); 00065 GVector& operator*= (Real fScalar); 00066 GVector& operator/= (Real fScalar); 00067 00068 // vector operations 00069 Real Length () const; 00070 Real SquaredLength () const; 00071 Real Dot (const GVector& rkV) const; 00072 Real Normalize (); 00073 00074 protected: 00075 // support for comparisons 00076 int CompareArrays (const GVector& rkV) const; 00077 00078 int m_iSize; 00079 Real* m_afTuple; 00080 }; 00081 00082 template <class Real> 00083 GVector<Real> operator* (Real fScalar, const GVector<Real>& rkV); 00084 00085 } //namespace Wm4 00086 00087 #include "Wm4GVector.inl" 00088 00089 namespace Wm4 00090 { 00091 typedef GVector<float> GVectorf; 00092 typedef GVector<double> GVectord; 00093 } 00094 00095 #endif