00001 /* 00002 $Id: cl_vector.h,v 1.5 2001/03/27 19:34:37 grumbel Exp $ 00003 00004 ------------------------------------------------------------------------ 00005 ClanLib, the platform independent game SDK. 00006 00007 This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE 00008 version 2. See COPYING for details. 00009 00010 For a total list of contributers see CREDITS. 00011 00012 ------------------------------------------------------------------------ 00013 00014 1999/06/19 Daniel Vogel 00015 00016 totally replaced old CL_Vector with this code 00017 */ 00018 00020 00021 #ifndef header_cl_vector 00022 #define header_cl_vector 00023 #include <iostream> 00024 00025 class CL_Vector 00026 //: Vector class 00027 // This class provides basic functions and operators for working with vectors 00028 { 00029 public: 00030 float x,y,z,w; 00031 00032 CL_Vector(float x = 0.0, float y = 0.0, float z = 0.0, float w = 1.0); 00033 //: Constructor that initializes a vector 00034 00035 CL_Vector(const CL_Vector &other); 00036 //: Copy Constructor 00038 00039 float norm() const; // not using w component 00040 //: Returns the (euclid) norm of the vector. It only uses the x,y,z ordinates! 00042 00043 void normalize(); // not using w component 00044 //: Normalizes the vector (not taking into account the w ordinate!) 00045 00046 float dot(const CL_Vector& v) const; 00047 //: Returns the dot product of the current vector and v 00050 00051 float angle(const CL_Vector& v) const; 00052 //: Returns the angle between the current vector and v 00055 00056 CL_Vector cross(const CL_Vector& v) const; 00057 //: Returns the cross product of the current vector and v 00060 00061 CL_Vector rotate(float angle, const CL_Vector& a) const; 00062 //: Returns the current vector rotated around vector a and angle angle 00066 00067 void round(); 00068 //: rounds all components 00069 00070 CL_Vector operator * (float s); 00071 //: Scalar product (vector * scalar) 00073 00074 friend CL_Vector operator * (float s, const CL_Vector& v); 00075 //: Scalar product (scalar * vector) 00077 00078 void operator += (const CL_Vector& v); 00079 //: += operator 00080 00081 void operator -= (const CL_Vector& v); 00082 //: -= operator 00083 00084 void operator *= (float s); 00085 //: *= operator (scalar multiplication) 00086 00087 CL_Vector operator + (const CL_Vector& v); 00088 //: + operator 00089 00090 CL_Vector operator - (const CL_Vector& v); 00091 //: - operator 00092 00093 CL_Vector operator - (); 00094 //: unary - operator 00095 00096 CL_Vector& operator = (const CL_Vector& v); 00097 //: assignment operator 00098 00099 int operator == (const CL_Vector& v) const; 00100 //: Returns true if current vector equals v 00103 00104 int operator != (const CL_Vector& v) const; 00105 //: Returns false if current vector equals v 00108 00109 float& operator [] (int n); 00110 //: Returns reference to n-th ordinate (0. == x, 1. == y, ...) 00113 00114 friend std::ostream& operator << (std::ostream&, CL_Vector& v); 00115 //: cout's the x,y,z ordinates (meant for debugging) 00116 }; 00117 00118 #endif
1.2.6 written by Dimitri van Heesch,
© 1997-2001