00001 // Magic Software, Inc. 00002 // http://www.magic-software.com 00003 // Copyright (c) 2000-2003. All Rights Reserved 00004 // 00005 // Source code from Magic Software is supplied under the terms of a license 00006 // agreement and may not be copied or disclosed except in accordance with the 00007 // terms of that agreement. The various license agreements may be found at 00008 // the Magic Software web site. This file is subject to the license 00009 // 00010 // FREE SOURCE CODE 00011 // http://www.magic-software.com/License/free.pdf 00012 00013 #ifndef MGCVECTOR3_H 00014 #define MGCVECTOR3_H 00015 00016 #include "MgcMath.h" 00017 00018 namespace Mgc { 00019 00020 00021 class MAGICFM Vector3 00022 { 00023 public: 00024 // construction 00025 Vector3 (); 00026 Vector3 (Real fX, Real fY, Real fZ); 00027 Vector3 (Real afCoordinate[3]); 00028 Vector3 (const Vector3& rkVector); 00029 00030 // coordinates 00031 Real x, y, z; 00032 00033 // access vector V as V[0] = V.x, V[1] = V.y, V[2] = V.z 00034 // 00035 // WARNING. These member functions rely on 00036 // (1) Vector3 not having virtual functions 00037 // (2) the data packed in a 3*sizeof(Real) memory block 00038 Real& operator[] (int i) const; 00039 operator Real* (); 00040 00041 // assignment 00042 Vector3& operator= (const Vector3& rkVector); 00043 00044 // comparison (supports fuzzy arithmetic when FUZZ > 0) 00045 bool operator== (const Vector3& rkVector) const; 00046 bool operator!= (const Vector3& rkVector) const; 00047 bool operator< (const Vector3& rkVector) const; 00048 bool operator<= (const Vector3& rkVector) const; 00049 bool operator> (const Vector3& rkVector) const; 00050 bool operator>= (const Vector3& rkVector) const; 00051 00052 // arithmetic operations 00053 Vector3 operator+ (const Vector3& rkVector) const; 00054 Vector3 operator- (const Vector3& rkVector) const; 00055 Vector3 operator* (Real fScalar) const; 00056 Vector3 operator/ (Real fScalar) const; 00057 Vector3 operator- () const; 00058 MAGICFM friend Vector3 operator* (Real fScalar, const Vector3& rkVector); 00059 00060 // arithmetic updates 00061 Vector3& operator+= (const Vector3& rkVector); 00062 Vector3& operator-= (const Vector3& rkVector); 00063 Vector3& operator*= (Real fScalar); 00064 Vector3& operator/= (Real fScalar); 00065 00066 // vector operations 00067 Real Length () const; 00068 Real SquaredLength () const; 00069 Real Dot (const Vector3& rkVector) const; 00070 Real Unitize (Real fTolerance = 1e-06f); 00071 Vector3 Cross (const Vector3& rkVector) const; 00072 Vector3 UnitCross (const Vector3& rkVector) const; 00073 00074 // Gram-Schmidt orthonormalization. 00075 static void Orthonormalize (Vector3 akVector[/*3*/]); 00076 00077 // Input W must be initialize to a nonzero vector, output is {U,V,W} 00078 // an orthonormal basis. A hint is provided about whether or not W 00079 // is already unit length. 00080 static void GenerateOrthonormalBasis (Vector3& rkU, Vector3& rkV, 00081 Vector3& rkW, bool bUnitLengthW = true); 00082 00083 // special points 00084 static const Vector3 ZERO; 00085 static const Vector3 UNIT_X; 00086 static const Vector3 UNIT_Y; 00087 static const Vector3 UNIT_Z; 00088 00089 // fuzzy arithmetic (set FUZZ > 0 to enable) 00090 static Real FUZZ; 00091 }; 00092 00093 #include "MgcVector3.inl" 00094 00095 } // namespace Mgc 00096 00097 #endif 00098 00099 00100