1 /*
  2  * Copyright �� 2008 Danny Baumann
  3  *
  4  * Permission to use, copy, modify, distribute, and sell this software
  5  * and its documentation for any purpose is hereby granted without
  6  * fee, provided that the above copyright notice appear in all copies
  7  * and that both that copyright notice and this permission notice
  8  * appear in supporting documentation, and that the name of
  9  * Dennis Kasprzyk not be used in advertising or publicity pertaining to
 10  * distribution of the software without specific, written prior permission.
 11  * Dennis Kasprzyk makes no representations about the suitability of this
 12  * software for any purpose. It is provided "as is" without express or
 13  * implied warranty.
 14  *
 15  * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 16  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
 17  * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 18  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
 19  * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 20  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 21  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 22  *
 23  * Authors: Danny Baumann <maniac@compiz-fusion.org>
 24  */
 25 
 26 #ifndef _GLVECTOR_H
 27 #define _GLVECTOR_H
 28 
 29 /**
 30  * Class which describes a point or vector
 31  * in 3D space
 32  */
 33 class GLVector {
 34     public:
 35 	typedef enum {
 36 	    x,
 37 	    y,
 38 	    z,
 39 	    w
 40 	} VectorCoordsEnum;
 41 
 42 	GLVector ();
 43 	GLVector (float x, float y, float z, float w);
 44 
 45 	/**
 46 	 * Returns a reference to the x, y, z or w value by using
 47 	 * 0, 1, 2, 3 as array-access items
 48 	 */
 49 	float& operator[] (int item);
 50 
 51 	/**
 52 	 * Returns a reference to the x, y, z or w value by using
 53 	 * x, y, z, w as array-access items
 54 	 */
 55 	float& operator[] (VectorCoordsEnum coord);
 56 
 57 	/**
 58 	 * Returns a readonly x, y, z or w value by using
 59 	 * 0, 1, 2, 3 as array-access items
 60 	 */
CID 10886 - PW.USELESS_TYPE_QUALIFIER_ON_RETURN_TYPE
type qualifier on return type is meaningless
During compilation of file '/tmp/buildd/compiz-0.9.7.0~bzr3025/plugins/opengl/src/matrix.cpp'
 61 	const float operator[] (int item) const;
 62 
 63 	/**
 64 	 * Returns a readonly x, y, z or w value by using
 65 	 * x, y, z, w as array-access items
 66 	 */
 67 	const float operator[] (VectorCoordsEnum coord) const;
 68 
 69 	/**
 70 	 * Adds all elements in a GLVector
 71 	 */
 72 	GLVector& operator+= (const GLVector& rhs);
 73 
 74 	/**
 75 	 * Subtracts all elements in a GLVector
 76 	 */
 77 	GLVector& operator-= (const GLVector& rhs);
 78 
 79 	/**
 80 	 * Scales all elements in a vector
 81 	 * @param k Scale factor
 82 	 */
 83 	GLVector& operator*= (const float k);
 84 
 85 	/**
 86 	 * Scales all elements in a vector by 1 / k
 87 	 * @param k Scale factor
 88 	 */
 89 	GLVector& operator/= (const float k);
 90 	GLVector& operator^= (const GLVector& rhs);
 91 
 92 	/**
 93 	 * Returns the norm of this vector
 94 	 */
 95 	float norm ();
 96 
 97 	/**
 98 	 * Returns the normalized version of the vector
 99 	 */
100 	GLVector& normalize ();
101 	
102 	/**
103 	 * Returns the homogenized version of the vector
104 	 */
105 	GLVector& homogenize ();
106 
107     private:
108 	friend GLVector operator+ (const GLVector& lhs,
109 				   const GLVector& rhs);
110 	friend GLVector operator- (const GLVector& lhs,
111 				   const GLVector& rhs);
112 	friend GLVector operator- (const GLVector& vector);
113 	friend float operator* (const GLVector& lhs,
114 				const GLVector& rhs);
115 	friend GLVector operator* (const float       k,
116 				   const GLVector& vector);
117 	friend GLVector operator* (const GLVector& vector,
118 				   const float       k);
119 	friend GLVector operator/ (const GLVector& lhs,
120 				   const GLVector& rhs);
121 	friend GLVector operator^ (const GLVector& lhs,
122 				   const GLVector& rhs);
123 
124 	float v[4];
125 };
126 
127 #endif