glc_vector4d.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00026
00027 #ifndef GLC_VECTOR4D_H_
00028 #define GLC_VECTOR4D_H_
00029
00030 #include <QVector>
00031 #include <QDataStream>
00032
00033 #include "glc_utils_maths.h"
00034 #include "glc_vector2d.h"
00035 #include "glc_vector3d.h"
00036 #include "glc_vector3df.h"
00037
00038 #include "../glc_config.h"
00039
00042
00047
00048
00049 class GLC_LIB_EXPORT GLC_Vector4d
00050 {
00052 friend class GLC_Matrix4x4;
00053
00055 inline friend GLC_Vector4d operator - (const GLC_Vector4d &Vect)
00056 {
00057 return GLC_Vector4d(-Vect.vector[0], -Vect.vector[1], -Vect.vector[2]);
00058 }
00059
00060
00062
00064
00065 public:
00072 inline GLC_Vector4d()
00073 {
00074 vector[0]= 0.0;
00075 vector[1]= 0.0;
00076 vector[2]= 0.0;
00077
00078 vector[3]= 1.0;
00079 }
00081 inline GLC_Vector4d(const double &dX, const double &dY, const double &dZ, const double &dW= 1.0)
00082 {
00083 setVect(dX, dY, dZ, dW);
00084 }
00086 inline GLC_Vector4d(const GLC_Vector4d &Vect)
00087 {
00088 vector[0]= Vect.vector[0];
00089 vector[1]= Vect.vector[1];
00090 vector[2]= Vect.vector[2];
00091 vector[3]= Vect.vector[3];
00092 }
00093
00095 inline GLC_Vector4d(const GLC_Vector3d &Vect)
00096 {
00097 vector[0]= Vect.m_Vector[0];
00098 vector[1]= Vect.m_Vector[1];
00099 vector[2]= Vect.m_Vector[2];
00100 vector[3]= 1.0;
00101 }
00102
00104 inline GLC_Vector4d(const GLC_Vector3df &Vect)
00105 {
00106 vector[0]= static_cast<double>(Vect.m_Vector[0]);
00107 vector[1]= static_cast<double>(Vect.m_Vector[1]);
00108 vector[2]= static_cast<double>(Vect.m_Vector[2]);
00109 vector[3]= 1.0;
00110 }
00111
00113 inline GLC_Vector4d(const GLC_Vector2d &Vect)
00114 {
00115 vector[0]= Vect.dVecteur[0];
00116 vector[1]= Vect.dVecteur[1];
00117 vector[2]= 0.0;
00118 vector[3]= 1.0;
00119 }
00120
00122
00124
00126
00127 public:
00129 inline GLC_Vector4d operator + (const GLC_Vector4d &Vect) const
00130 {
00131 GLC_Vector4d VectResult(vector[0] + Vect.vector[0], vector[1] + Vect.vector[1],
00132 vector[2] + Vect.vector[2]);
00133
00134 return VectResult;
00135 }
00136
00138 inline GLC_Vector4d& operator = (const GLC_Vector4d &Vect)
00139 {
00140 vector[0]= Vect.vector[0];
00141 vector[1]= Vect.vector[1];
00142 vector[2]= Vect.vector[2];
00143 vector[3]= Vect.vector[3];
00144
00145 return *this;
00146 }
00147
00149 inline GLC_Vector4d& operator = (const GLC_Vector3d &Vect)
00150 {
00151 vector[0]= Vect.m_Vector[0];
00152 vector[1]= Vect.m_Vector[1];
00153 vector[2]= Vect.m_Vector[2];
00154 vector[3]= 1.0;
00155
00156 return *this;
00157 }
00158
00160 inline GLC_Vector4d& operator = (const GLC_Vector3df &Vect)
00161 {
00162 vector[0]= static_cast<double>(Vect.m_Vector[0]);
00163 vector[1]= static_cast<double>(Vect.m_Vector[1]);
00164 vector[2]= static_cast<double>(Vect.m_Vector[2]);
00165 vector[3]= 1.0;
00166
00167 return *this;
00168 }
00169
00171 inline GLC_Vector4d& operator = (const GLC_Vector2d &Vect)
00172 {
00173 vector[0]= Vect.dVecteur[0];
00174 vector[1]= Vect.dVecteur[1];
00175 vector[2]= 0.0;
00176 vector[3]= 1.0;
00177
00178 return *this;
00179 }
00180
00182 inline GLC_Vector4d* operator += (const GLC_Vector4d &Vect)
00183 {
00184 *this= *this + Vect;
00185 return this;
00186 }
00187
00188
00190 inline GLC_Vector4d operator - (const GLC_Vector4d &Vect) const
00191 {
00192 GLC_Vector4d VectResult(vector[0] - Vect.vector[0], vector[1] - Vect.vector[1],
00193 vector[2] - Vect.vector[2]);
00194
00195 return VectResult;
00196 }
00197
00199 GLC_Vector4d* operator -= (const GLC_Vector4d &Vect)
00200 {
00201 *this= *this - Vect;
00202 return this;
00203 }
00204
00206 GLC_Vector4d operator ^ (const GLC_Vector4d &Vect) const;
00207
00209 inline double operator * (const GLC_Vector4d &Vect) const
00210 {
00211
00212 return vector[0] * Vect.vector[0] + vector[1] * Vect.vector[1] +
00213 vector[2] * Vect.vector[2];
00214 }
00215
00217 inline GLC_Vector4d operator * (double Scalaire) const
00218 {
00219 return GLC_Vector4d(vector[0] * Scalaire, vector[1] * Scalaire, vector[2] * Scalaire);
00220 }
00221
00222
00224 bool operator == (const GLC_Vector4d &Vect) const;
00225
00227 inline bool operator != (const GLC_Vector4d &Vect) const
00228 {
00229 return !(*this == Vect);
00230 }
00231
00233
00235
00237
00238 public:
00240 inline GLC_Vector4d& setX(const double &dX)
00241 {
00242 vector[0]= dX;
00243 return *this;
00244 }
00245
00247 inline GLC_Vector4d& setY(const double &dY)
00248 {
00249 vector[1]= dY;
00250 return *this;
00251 }
00252
00254 inline GLC_Vector4d& setZ(const double &dZ)
00255 {
00256 vector[2]= dZ;
00257 return *this;
00258 }
00259
00261 GLC_Vector4d& setW(const double &dW);
00262
00264 GLC_Vector4d& setVect(const double &dX, const double &dY, const double &dZ, const double &dW= 1);
00265
00267 inline GLC_Vector4d& setVect(const GLC_Vector4d &Vect)
00268 {
00269 vector[0]= Vect.vector[0];
00270 vector[1]= Vect.vector[1];
00271 vector[2]= Vect.vector[2];
00272 vector[3]= Vect.vector[3];
00273 return *this;
00274 }
00275
00277 GLC_Vector4d& setNormal(const double &Norme);
00278
00280 inline GLC_Vector4d& invert(void)
00281 {
00282 vector[0]= - vector[0];
00283 vector[1]= - vector[1];
00284 vector[2]= - vector[2];
00285 return *this;
00286 }
00287
00289
00291
00293
00294 public:
00296 inline double X(void) const
00297 {
00298 return vector[0];
00299 }
00301 inline double Y(void) const
00302 {
00303 return vector[1];
00304 }
00306 inline double Z(void) const
00307 {
00308 return vector[2];
00309 }
00311 inline double W(void) const
00312 {
00313 return vector[3];
00314 }
00315 inline GLC_Vector3d toVector3d() const
00316 {
00317 return GLC_Vector3d(vector[0], vector[1], vector[2]);
00318 }
00319 inline GLC_Vector3df toVector3df() const
00320 {
00321 return GLC_Vector3df(static_cast<float>(vector[0]), static_cast<float>(vector[1]), static_cast<float>(vector[2]));
00322 }
00324 inline const double *data(void) const
00325 {
00326 return vector;
00327 }
00329 inline double norm(void) const
00330 {
00331 return sqrt(vector[0] * vector[0] + vector[1] * vector[1]
00332 + vector[2] * vector[2]);
00333 }
00335 inline bool isNull(void) const
00336 {
00337 bool result;
00338
00339 result= qFuzzyCompare(vector[0], 0.0) && qFuzzyCompare(vector[1], 0.0)
00340 && qFuzzyCompare(vector[2], 0.0);
00341
00342 return result;
00343 }
00344
00346 double getAngleWithVect(GLC_Vector4d Vect) const;
00347
00349 QString toString() const;
00350
00352
00354 GLC_Vector2d toVector2d(const GLC_Vector4d&) const;
00355
00357 inline QVector<float> toFloat3dQVector() const
00358 {
00359 QVector<float> result;
00360 result << static_cast<float>(vector[0]) << static_cast<float>(vector[1]) << static_cast<float>(vector[2]);
00361 return result;
00362 }
00364
00366
00368 private:
00369
00371 void normalizeW(void);
00372
00374
00376 private:
00383 enum {VECT4DIMENSION = 4};
00384 double vector[VECT4DIMENSION];
00385
00386 };
00387
00389
00390
00392 QDataStream &operator<<(QDataStream &, const GLC_Vector4d &);
00393 QDataStream &operator>>(QDataStream &, GLC_Vector4d &);
00394
00395 #endif