Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

vector.hxx

Go to the documentation of this file.
00001 /*
00002         $Id: vector.hxx,v 1.1 2002/11/20 00:46:11 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         See http://www.clanlib.org
00013         ------------------------------------------------------------------------
00014 
00015         1999/06/19 Daniel Vogel
00016         
00017         totally replaced old CL_Vector with this code
00018 */
00019 
00022 
00023 #ifndef header_cl_vector
00024 #define header_cl_vector
00025 #include <iostream>
00026 
00027 //: Vector class.
00028 //- <p>This class provides basic functions and operators for working with vectors.</p>
00029 class CL_Vector
00030 {
00031 public:
00033         //: x coordinate
00034         float x;
00035         //: y coordinate
00036         float y;
00037         //: z coordinate
00038         float z;
00039         //: w coordinate
00040         float w;
00041       
00042 public:
00043         
00045         //: Constructor that initializes a vector
00046         //param x: Initial x coordinate of vector.
00047         //param y: Initial y coordinate of vector.
00048         //param z: Initial z coordinate of vector.
00049         //param w: Initial w coordinate of vector.
00050         //param other: vector to copy construct from.
00051         CL_Vector(float x = 0.0, float y = 0.0, float z = 0.0, float w = 1.0);
00052 
00053         CL_Vector(const CL_Vector &other);
00054 
00056         //: Returns the (euclid) norm of the vector.
00057         //- <p>This function does not use the w coordinate of the vector. It only uses
00058         //- the x,y,z coordinates.</p>
00059         //return: the euclid norm of the vector (in R^3)
00060         float norm() const;
00061 
00062         //: Normalizes the vector (not taking into account the w ordinate!)
00063         void normalize();
00064 
00065         //: Dot products this vector with an other vector.
00066         //param vector: Second vector used for the dot product.
00067         //return: The resulting dot product of the two vectors.
00068         float dot(const CL_Vector& vector) const;
00069         
00070         //: Calculate the angle between this vector and an other vector.
00071         //param vector: Second vector used to calculate angle.
00072         //return: The angle between the two vectors.
00073         float angle(const CL_Vector& vector) const;
00074 
00075         //: Calculate the cross product between this vector and an other vector.
00076         //param vector: Second vector used to perform the calculation.
00077         //return: The cross product of the two vectors.
00078         CL_Vector cross(const CL_Vector& vector) const;
00079         
00080         //: Rotate vector around an axis.
00081         //param angle: Angle to rotate.
00082         //param axis: Rotation axis.
00083         //return: The resulting rotated vector.
00084         CL_Vector rotate(float angle, const CL_Vector& axis) const;
00085 
00086         //: Rounds all components.
00087         void round();
00088 
00090         //: Scalar product (vector * scalar)
00091         //return: The scalar product
00092         CL_Vector operator * (float scalar) const;  
00093 
00094         //: Scalar product (scalar * vector)
00095         //return: The scalar product.
00096         friend CL_Vector operator *  (float scalar, const CL_Vector& vector);
00097 
00098         //: += operator.
00099         void operator += (const CL_Vector& v);
00100 
00101         //: -= operator.
00102         void operator -= (const CL_Vector& v);  
00103 
00104         //: *= operator (scalar multiplication).
00105         void operator *= (float s);  
00106 
00107         //: + operator.
00108         CL_Vector operator + (const CL_Vector& v) const;
00109         
00110         //: - operator.
00111         CL_Vector operator - (const CL_Vector& v) const;
00112         
00113         //: unary - operator.
00114         CL_Vector operator - () const;
00115 
00116         //: assignment operator.
00117         CL_Vector& operator = (const CL_Vector& v);
00118 
00119         //: Returns true if current vector equals v.
00120         //param v: other vector.
00121         //return: true if v equals the current vector, false otherwise.
00122         int operator == (const CL_Vector& v) const;
00123         
00124         //: Returns false if current vector equals v.
00125         //param v: other vector.
00126         //return: false if v equals the current vector, true otherwise.
00127         int operator != (const CL_Vector& v) const;
00128         
00129         //: Returns reference to n-th ordinate (0. == x, 1. == y, ...).
00130         //param n: number of ordinate (starting with 0).
00131         //return: reference to the n-th ordinate.
00132         float& operator [] (int n);
00133         
00134         //: cout's the x,y,z ordinates (meant for debugging).
00135         friend std::ostream& operator << (std::ostream&, const CL_Vector& v);
00136 };
00137 
00138 std::ostream& operator << (std::ostream& os, const CL_Vector& v);
00139 
00140 #endif

Generated on Thu Jul 24 10:24:31 2003 for Construo by doxygen1.3-rc3