00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef WM4VECTOR3_H
00017 #define WM4VECTOR3_H
00018
00019 #include "Wm4FoundationLIB.h"
00020 #include "Wm4Math.h"
00021
00022 namespace Wm4
00023 {
00024
00025 template <class Real>
00026 class Vector3
00027 {
00028 public:
00029
00030 Vector3 ();
00031 Vector3 (Real fX, Real fY, Real fZ);
00032 Vector3 (const Real* afTuple);
00033 Vector3 (const Vector3& rkV);
00034
00035
00036 inline operator const Real* () const;
00037 inline operator Real* ();
00038 inline Real operator[] (int i) const;
00039 inline Real& operator[] (int i);
00040 inline Real X () const;
00041 inline Real& X ();
00042 inline Real Y () const;
00043 inline Real& Y ();
00044 inline Real Z () const;
00045 inline Real& Z ();
00046
00047
00048 inline Vector3& operator= (const Vector3& rkV);
00049
00050
00051 bool operator== (const Vector3& rkV) const;
00052 bool operator!= (const Vector3& rkV) const;
00053 bool operator< (const Vector3& rkV) const;
00054 bool operator<= (const Vector3& rkV) const;
00055 bool operator> (const Vector3& rkV) const;
00056 bool operator>= (const Vector3& rkV) const;
00057
00058
00059 inline Vector3 operator+ (const Vector3& rkV) const;
00060 inline Vector3 operator- (const Vector3& rkV) const;
00061 inline Vector3 operator* (Real fScalar) const;
00062 inline Vector3 operator/ (Real fScalar) const;
00063 inline Vector3 operator- () const;
00064
00065
00066 inline Vector3& operator+= (const Vector3& rkV);
00067 inline Vector3& operator-= (const Vector3& rkV);
00068 inline Vector3& operator*= (Real fScalar);
00069 inline Vector3& operator/= (Real fScalar);
00070
00071
00072 inline Real Length () const;
00073 inline Real SquaredLength () const;
00074 inline Real Dot (const Vector3& rkV) const;
00075 inline Real Normalize ();
00076
00077
00078
00079
00080
00081
00082 inline Vector3 Cross (const Vector3& rkV) const;
00083 inline Vector3 UnitCross (const Vector3& rkV) const;
00084
00085
00086
00087
00088 void GetBarycentrics (const Vector3& rkV0, const Vector3& rkV1,
00089 const Vector3& rkV2, const Vector3& rkV3, Real afBary[4]) const;
00090
00091
00092
00093
00094 static void Orthonormalize (Vector3& rkU, Vector3& rkV, Vector3& rkW);
00095 static void Orthonormalize (Vector3* akV);
00096
00097
00098
00099
00100
00101 static void GenerateOrthonormalBasis (Vector3& rkU, Vector3& rkV,
00102 Vector3& rkW);
00103
00104
00105
00106
00107 static void GenerateComplementBasis (Vector3& rkU, Vector3& rkV,
00108 const Vector3& rkW);
00109
00110
00111 static void ComputeExtremes (int iVQuantity, const Vector3* akPoint,
00112 Vector3& rkMin, Vector3& rkMax);
00113
00114
00115 WM4_FOUNDATION_ITEM static const Vector3 ZERO;
00116 WM4_FOUNDATION_ITEM static const Vector3 UNIT_X;
00117 WM4_FOUNDATION_ITEM static const Vector3 UNIT_Y;
00118 WM4_FOUNDATION_ITEM static const Vector3 UNIT_Z;
00119 WM4_FOUNDATION_ITEM static const Vector3 ONE;
00120
00121 private:
00122
00123 int CompareArrays (const Vector3& rkV) const;
00124
00125 Real m_afTuple[3];
00126 };
00127
00128
00129 template <class Real>
00130 Vector3<Real> operator* (Real fScalar, const Vector3<Real>& rkV);
00131
00132
00133 template <class Real>
00134 std::ostream& operator<< (std::ostream& rkOStr, const Vector3<Real>& rkV);
00135
00136 #include "Wm4Vector3.inl"
00137
00138 typedef Vector3<float> Vector3f;
00139 typedef Vector3<double> Vector3d;
00140
00141 }
00142
00143 #endif