23 #ifndef QGLVIEWER_VEC_H
24 #define QGLVIEWER_VEC_H
29 #if QT_VERSION >= 0x040000
30 # include <QDomElement>
69 class QGLVIEWER_EXPORT
Vec
74 #if defined (Q_OS_IRIX) || defined (Q_OS_AIX) || defined (Q_OS_HPUX)
75 # define QGLVIEWER_UNION_NOT_SUPPORTED
80 #if defined (DOXYGEN) || defined (QGLVIEWER_UNION_NOT_SUPPORTED)
85 struct {
double x, y, z; };
93 Vec() : x(0.0), y(0.0), z(0.0) {}
96 Vec(
double X,
double Y,
double Z) : x(X), y(Y), z(Z) {}
115 explicit Vec(
const C& c) : x(c[0]), y(c[1]), z(c[2]) {}
124 x = v.x; y = v.y; z = v.z;
129 void setValue(
double X,
double Y,
double Z)
146 #ifdef QGLVIEWER_UNION_NOT_SUPPORTED
155 #ifdef QGLVIEWER_UNION_NOT_SUPPORTED
164 const double*
address()
const { qWarning(
"Vec::address() is deprecated, use operator const double* instead.");
return operator const double*(); };
175 operator const double*()
const {
176 #ifdef QGLVIEWER_UNION_NOT_SUPPORTED
187 #ifdef QGLVIEWER_UNION_NOT_SUPPORTED
203 operator const float*()
const {
204 static float*
const result =
new float[3];
205 result[0] = (float)x;
206 result[1] = (float)y;
207 result[2] = (float)z;
217 return Vec(a.x+b.x, a.y+b.y, a.z+b.z);
223 return Vec(a.x-b.x, a.y-b.y, a.z-b.z);
229 return Vec(-a.x, -a.y, -a.z);
233 friend Vec operator*(
const Vec &a,
double k)
235 return Vec(a.x*k, a.y*k, a.z*k);
239 friend Vec operator*(
double k,
const Vec &a)
248 friend Vec operator/(
const Vec &a,
double k)
251 if (fabs(k) < 1.0E-10)
252 qWarning(
"Vec::operator / : dividing by a null value (%f)", k);
254 return Vec(a.x/k, a.y/k, a.z/k);
258 friend bool operator!=(
const Vec &a,
const Vec &b)
264 friend bool operator==(
const Vec &a,
const Vec &b)
266 const double epsilon = 1.0E-10f;
267 return (a-b).squaredNorm() < epsilon;
273 x += a.x; y += a.y; z += a.z;
280 x -= a.x; y -= a.y; z -= a.z;
287 x *= k; y *= k; z *= k;
299 qWarning(
"Vec::operator /= : dividing by a null value (%f)", k);
301 x /= k; y /= k; z /= k;
306 friend double operator*(
const Vec &a,
const Vec &b)
308 return a.x*b.x + a.y*b.y + a.z*b.z;
320 return Vec(a.y*b.z - a.z*b.y,
325 Vec orthogonalVec()
const;
332 double sqNorm()
const {
return x*x + y*y + z*z; }
339 double norm()
const {
return sqrt(x*x + y*y + z*z); }
346 const double n = norm();
349 qWarning(
"Vec::normalize: normalizing a null vector (norm=%f)", n);
366 void projectOnAxis(
const Vec& direction);
367 void projectOnPlane(
const Vec& normal);
372 explicit Vec(
const QDomElement& element);
373 QDomElement domElement(
const QString& name, QDomDocument& document)
const;
374 void initFromDOMElement(
const QDomElement& element);
394 #endif // QGLVIEWER_VEC_H