2 $Id: vector.hxx,v 1.1 2002/11/20 00:46:11 grumbel Exp $
4 ------------------------------------------------------------------------
5 ClanLib, the platform independent game SDK.
7 This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
8 version 2. See COPYING for details.
10 For a total list of contributers see CREDITS.
12 See http://www.clanlib.org
13 ------------------------------------------------------------------------
15 1999/06/19 Daniel Vogel
17 totally replaced old CL_Vector with this code
23 #ifndef header_cl_vector
24 #define header_cl_vector
28 //- <p>This class provides basic functions and operators for working with vectors.</p>
45 //: Constructor that initializes a vector
46 //param x: Initial x coordinate of vector.
47 //param y: Initial y coordinate of vector.
48 //param z: Initial z coordinate of vector.
49 //param w: Initial w coordinate of vector.
50 //param other: vector to copy construct from.
51 CL_Vector(float x
= 0.0, float y
= 0.0, float z
= 0.0, float w
= 1.0);
53 CL_Vector(const CL_Vector
&other
);
56 //: Returns the (euclid) norm of the vector.
57 //- <p>This function does not use the w coordinate of the vector. It only uses
58 //- the x,y,z coordinates.</p>
59 //return: the euclid norm of the vector (in R^3)
62 //: Normalizes the vector (not taking into account the w ordinate!)
65 //: Dot products this vector with an other vector.
66 //param vector: Second vector used for the dot product.
67 //return: The resulting dot product of the two vectors.
68 float dot(const CL_Vector
& vector
) const;
70 //: Calculate the angle between this vector and an other vector.
71 //param vector: Second vector used to calculate angle.
72 //return: The angle between the two vectors.
73 float angle(const CL_Vector
& vector
) const;
75 //: Calculate the cross product between this vector and an other vector.
76 //param vector: Second vector used to perform the calculation.
77 //return: The cross product of the two vectors.
78 CL_Vector
cross(const CL_Vector
& vector
) const;
80 //: Rotate vector around an axis.
81 //param angle: Angle to rotate.
82 //param axis: Rotation axis.
83 //return: The resulting rotated vector.
84 CL_Vector
rotate(float angle
, const CL_Vector
& axis
) const;
86 //: Rounds all components.
90 //: Scalar product (vector * scalar)
91 //return: The scalar product
92 CL_Vector
operator * (float scalar
) const;
94 //: Scalar product (scalar * vector)
95 //return: The scalar product.
96 friend CL_Vector
operator * (float scalar
, const CL_Vector
& vector
);
99 void operator += (const CL_Vector
& v
);
102 void operator -= (const CL_Vector
& v
);
104 //: *= operator (scalar multiplication).
105 void operator *= (float s
);
108 CL_Vector
operator + (const CL_Vector
& v
) const;
111 CL_Vector
operator - (const CL_Vector
& v
) const;
113 //: unary - operator.
114 CL_Vector
operator - () const;
116 //: assignment operator.
117 CL_Vector
& operator = (const CL_Vector
& v
);
119 //: Returns true if current vector equals v.
120 //param v: other vector.
121 //return: true if v equals the current vector, false otherwise.
122 int operator == (const CL_Vector
& v
) const;
124 //: Returns false if current vector equals v.
125 //param v: other vector.
126 //return: false if v equals the current vector, true otherwise.
127 int operator != (const CL_Vector
& v
) const;
129 //: Returns reference to n-th ordinate (0. == x, 1. == y, ...).
130 //param n: number of ordinate (starting with 0).
131 //return: reference to the n-th ordinate.
132 float& operator [] (int n
);
134 //: cout's the x,y,z ordinates (meant for debugging).
135 friend std::ostream
& operator << (std::ostream
&, const CL_Vector
& v
);
138 std::ostream
& operator << (std::ostream
& os
, const CL_Vector
& v
);