GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_vector4d.h
Go to the documentation of this file.
1 /****************************************************************************
2 
3  This file is part of the GLC-lib library.
4  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
5  http://glc-lib.sourceforge.net
6 
7  GLC-lib is free software; you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  GLC-lib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with GLC-lib; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21 *****************************************************************************/
22 
24 
25 #ifndef GLC_VECTOR4D_H_
26 #define GLC_VECTOR4D_H_
27 
28 #include <QVector>
29 #include <QDataStream>
30 
31 #include "glc_utils_maths.h"
32 #include "glc_vector2d.h"
33 #include "glc_vector3d.h"
34 #include "glc_vector3df.h"
35 
36 #include "../glc_config.h"
37 
40 
45 
46 
48 {
50  friend class GLC_Matrix4x4;
51 
53  inline friend GLC_Vector4d operator - (const GLC_Vector4d &Vect)
54  {
55  return GLC_Vector4d(-Vect.vector[0], -Vect.vector[1], -Vect.vector[2]);
56  }
57 
58 
60 
62 
63 public:
70  inline GLC_Vector4d()
71  {
72  vector[0]= 0.0;
73  vector[1]= 0.0;
74  vector[2]= 0.0;
75 
76  vector[3]= 1.0;
77  }
79  inline GLC_Vector4d(const double &dX, const double &dY, const double &dZ, const double &dW= 1.0)
80  {
81  setVect(dX, dY, dZ, dW);
82  }
84  inline GLC_Vector4d(const GLC_Vector4d &Vect)
85  {
86  vector[0]= Vect.vector[0];
87  vector[1]= Vect.vector[1];
88  vector[2]= Vect.vector[2];
89  vector[3]= Vect.vector[3];
90  }
91 
93  inline GLC_Vector4d(const GLC_Vector3d &Vect)
94  {
95  vector[0]= Vect.m_Vector[0];
96  vector[1]= Vect.m_Vector[1];
97  vector[2]= Vect.m_Vector[2];
98  vector[3]= 1.0;
99  }
100 
102  inline GLC_Vector4d(const GLC_Vector3df &Vect)
103  {
104  vector[0]= static_cast<double>(Vect.m_Vector[0]);
105  vector[1]= static_cast<double>(Vect.m_Vector[1]);
106  vector[2]= static_cast<double>(Vect.m_Vector[2]);
107  vector[3]= 1.0;
108  }
109 
111  inline GLC_Vector4d(const GLC_Vector2d &Vect)
112  {
113  vector[0]= Vect.m_Vector[0];
114  vector[1]= Vect.m_Vector[1];
115  vector[2]= 0.0;
116  vector[3]= 1.0;
117  }
118 
120 
122 
124 
125 public:
127  inline GLC_Vector4d operator + (const GLC_Vector4d &Vect) const
128  {
129  GLC_Vector4d VectResult(vector[0] + Vect.vector[0], vector[1] + Vect.vector[1],
130  vector[2] + Vect.vector[2]);
131 
132  return VectResult;
133  }
134 
136  inline GLC_Vector4d& operator = (const GLC_Vector4d &Vect)
137  {
138  vector[0]= Vect.vector[0];
139  vector[1]= Vect.vector[1];
140  vector[2]= Vect.vector[2];
141  vector[3]= Vect.vector[3];
142 
143  return *this;
144  }
145 
147  inline GLC_Vector4d& operator = (const GLC_Vector3d &Vect)
148  {
149  vector[0]= Vect.m_Vector[0];
150  vector[1]= Vect.m_Vector[1];
151  vector[2]= Vect.m_Vector[2];
152  vector[3]= 1.0;
153 
154  return *this;
155  }
156 
159  {
160  vector[0]= static_cast<double>(Vect.m_Vector[0]);
161  vector[1]= static_cast<double>(Vect.m_Vector[1]);
162  vector[2]= static_cast<double>(Vect.m_Vector[2]);
163  vector[3]= 1.0;
164 
165  return *this;
166  }
167 
169  inline GLC_Vector4d& operator = (const GLC_Vector2d &Vect)
170  {
171  vector[0]= Vect.m_Vector[0];
172  vector[1]= Vect.m_Vector[1];
173  vector[2]= 0.0;
174  vector[3]= 1.0;
175 
176  return *this;
177  }
178 
180  inline GLC_Vector4d* operator += (const GLC_Vector4d &Vect)
181  {
182  *this= *this + Vect;
183  return this;
184  }
185 
186 
188  inline GLC_Vector4d operator - (const GLC_Vector4d &Vect) const
189  {
190  GLC_Vector4d VectResult(vector[0] - Vect.vector[0], vector[1] - Vect.vector[1],
191  vector[2] - Vect.vector[2]);
192 
193  return VectResult;
194  }
195 
197  GLC_Vector4d* operator -= (const GLC_Vector4d &Vect)
198  {
199  *this= *this - Vect;
200  return this;
201  }
202 
204  GLC_Vector4d operator ^ (const GLC_Vector4d &Vect) const;
205 
207  inline double operator * (const GLC_Vector4d &Vect) const
208  {
209  // W Component is ignored
210  return vector[0] * Vect.vector[0] + vector[1] * Vect.vector[1] +
211  vector[2] * Vect.vector[2];
212  }
213 
215  inline GLC_Vector4d operator * (double Scalaire) const
216  {
217  return GLC_Vector4d(vector[0] * Scalaire, vector[1] * Scalaire, vector[2] * Scalaire);
218  }
219 
220 
222  bool operator == (const GLC_Vector4d &Vect) const;
223 
225  inline bool operator != (const GLC_Vector4d &Vect) const
226  {
227  return !(*this == Vect);
228  }
229 
231 
233 
235 
236 public:
238  inline GLC_Vector4d& setX(const double &dX)
239  {
240  vector[0]= dX;
241  return *this;
242  }
243 
245  inline GLC_Vector4d& setY(const double &dY)
246  {
247  vector[1]= dY;
248  return *this;
249  }
250 
252  inline GLC_Vector4d& setZ(const double &dZ)
253  {
254  vector[2]= dZ;
255  return *this;
256  }
257 
259  GLC_Vector4d& setW(const double &dW);
260 
262  GLC_Vector4d& setVect(const double &dX, const double &dY, const double &dZ, const double &dW= 1);
263 
265  inline GLC_Vector4d& setVect(const GLC_Vector4d &Vect)
266  {
267  vector[0]= Vect.vector[0];
268  vector[1]= Vect.vector[1];
269  vector[2]= Vect.vector[2];
270  vector[3]= Vect.vector[3];
271  return *this;
272  }
273 
275  GLC_Vector4d& setNormal(const double &Norme);
276 
278  inline GLC_Vector4d& invert(void)
279  {
280  vector[0]= - vector[0];
281  vector[1]= - vector[1];
282  vector[2]= - vector[2];
283  return *this;
284  }
285 
287 
289 
291 
292 public:
294  inline double X(void) const
295  {
296  return vector[0];
297  }
299  inline double Y(void) const
300  {
301  return vector[1];
302  }
304  inline double Z(void) const
305  {
306  return vector[2];
307  }
309  inline double W(void) const
310  {
311  return vector[3];
312  }
313  inline GLC_Vector3d toVector3d() const
314  {
315  return GLC_Vector3d(vector[0], vector[1], vector[2]);
316  }
317  inline GLC_Vector3df toVector3df() const
318  {
319  return GLC_Vector3df(static_cast<float>(vector[0]), static_cast<float>(vector[1]), static_cast<float>(vector[2]));
320  }
322  inline const double *data(void) const
323  {
324  return vector;
325  }
327  inline double norm(void) const
328  {
329  return sqrt(vector[0] * vector[0] + vector[1] * vector[1]
330  + vector[2] * vector[2]);
331  }
333  inline bool isNull(void) const
334  {
335  bool result;
336 
337  result= qFuzzyCompare(vector[0], 0.0) && qFuzzyCompare(vector[1], 0.0)
338  && qFuzzyCompare(vector[2], 0.0);
339 
340  return result;
341  }
342 
344  double getAngleWithVect(GLC_Vector4d Vect) const;
345 
347  QString toString() const;
348 
350 
352  GLC_Vector2d toVector2d(const GLC_Vector4d&) const;
353 
355  inline QVector<float> toFloat3dQVector() const
356  {
357  QVector<float> result;
358  result << static_cast<float>(vector[0]) << static_cast<float>(vector[1]) << static_cast<float>(vector[2]);
359  return result;
360  }
362 
364 // Private services functions
366 private:
367 
369  void normalizeW(void);
370 
372 //name Private attributes
374 private:
381  enum {VECT4DIMENSION = 4};
382  double vector[VECT4DIMENSION];
383 
384 }; //class GLC_Vector4d
385 
387 //typedef GLC_Vector4d GLC_Point4d;
388 
390 QDataStream &operator<<(QDataStream &, const GLC_Vector4d &);
391 QDataStream &operator>>(QDataStream &, GLC_Vector4d &);
392 
393 #endif /*GLC_VECTOR4D_H_*/

©2005-2013 Laurent Ribon