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.1 (2006/07/25) 00016 00017 #ifndef WM4VECTOR4_H 00018 #define WM4VECTOR4_H 00019 00020 #include "Wm4FoundationLIB.h" 00021 #include "Wm4Math.h" 00022 00023 namespace Wm4 00024 { 00025 00026 template <class Real> 00027 class Vector4 00028 { 00029 public: 00030 // construction 00031 Vector4 (); // uninitialized 00032 Vector4 (Real fX, Real fY, Real fZ, Real fW); 00033 Vector4 (const Real* afTuple); 00034 Vector4 (const Vector4& rkV); 00035 00036 // coordinate access 00037 operator const Real* () const; 00038 operator Real* (); 00039 Real operator[] (int i) const; 00040 Real& operator[] (int i); 00041 Real X () const; 00042 Real& X (); 00043 Real Y () const; 00044 Real& Y (); 00045 Real Z () const; 00046 Real& Z (); 00047 Real W () const; 00048 Real& W (); 00049 00050 // assignment 00051 Vector4& operator= (const Vector4& rkV); 00052 00053 // comparison 00054 bool operator== (const Vector4& rkV) const; 00055 bool operator!= (const Vector4& rkV) const; 00056 bool operator< (const Vector4& rkV) const; 00057 bool operator<= (const Vector4& rkV) const; 00058 bool operator> (const Vector4& rkV) const; 00059 bool operator>= (const Vector4& rkV) const; 00060 00061 // arithmetic operations 00062 Vector4 operator+ (const Vector4& rkV) const; 00063 Vector4 operator- (const Vector4& rkV) const; 00064 Vector4 operator* (Real fScalar) const; 00065 Vector4 operator/ (Real fScalar) const; 00066 Vector4 operator- () const; 00067 00068 // arithmetic updates 00069 Vector4& operator+= (const Vector4& rkV); 00070 Vector4& operator-= (const Vector4& rkV); 00071 Vector4& operator*= (Real fScalar); 00072 Vector4& operator/= (Real fScalar); 00073 00074 // vector operations 00075 Real Length () const; 00076 Real SquaredLength () const; 00077 Real Dot (const Vector4& rkV) const; 00078 Real Normalize (); 00079 00080 // special vectors 00081 WM4_FOUNDATION_ITEM static const Vector4 ZERO; 00082 WM4_FOUNDATION_ITEM static const Vector4 UNIT_X; // (1,0,0,0) 00083 WM4_FOUNDATION_ITEM static const Vector4 UNIT_Y; // (0,1,0,0) 00084 WM4_FOUNDATION_ITEM static const Vector4 UNIT_Z; // (0,0,1,0) 00085 WM4_FOUNDATION_ITEM static const Vector4 UNIT_W; // (0,0,0,1) 00086 WM4_FOUNDATION_ITEM static const Vector4 ONE; // (1,1,1,1) 00087 00088 private: 00089 // support for comparisons 00090 int CompareArrays (const Vector4& rkV) const; 00091 00092 Real m_afTuple[4]; 00093 }; 00094 00095 // arithmetic operations 00096 template <class Real> 00097 Vector4<Real> operator* (Real fScalar, const Vector4<Real>& rkV); 00098 00099 // debugging output 00100 template <class Real> 00101 std::ostream& operator<< (std::ostream& rkOStr, const Vector4<Real>& rkV); 00102 00103 } 00104 00105 #include "Wm4Vector4.inl" 00106 00107 namespace Wm4 00108 { 00109 typedef Vector4<float> Vector4f; 00110 typedef Vector4<double> Vector4d; 00111 00112 } 00113 00114 #endif