23 #ifndef QGLVIEWER_VEC_H 24 #define QGLVIEWER_VEC_H 29 #if QT_VERSION >= 0x040000 30 # include <QDomElement> 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;
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;
229 return Vec(-a.
x, -a.
y, -a.
z);
235 return Vec(a.
x*k, a.
y*k, a.
z*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);
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;
308 return a.
x*b.
x + a.
y*b.
y + a.
z*b.
z;
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 void setValue(double X, double Y, double Z)
friend Vec operator*(double k, const Vec &a)
friend Vec operator^(const Vec &a, const Vec &b)
Vec & operator+=(const Vec &a)
friend Vec operator-(const Vec &a, const Vec &b)
Vec & operator=(const Vec &v)
Vec & operator-=(const Vec &a)
The Vec class represents 3D positions and 3D vectors.
friend bool operator!=(const Vec &a, const Vec &b)
friend Vec operator/(const Vec &a, double k)
std::ostream & operator<<(std::ostream &o, const qglviewer::Vec &)
friend double operator*(const Vec &a, const Vec &b)
double squaredNorm() const
friend Vec operator-(const Vec &a)
friend Vec cross(const Vec &a, const Vec &b)
Vec & operator*=(double k)
const double * address() const
double & operator[](int i)
Vec(double X, double Y, double Z)
friend bool operator==(const Vec &a, const Vec &b)
friend Vec operator*(const Vec &a, double k)
friend Vec operator+(const Vec &a, const Vec &b)
double operator[](int i) const
Vec & operator/=(double k)