23 #ifndef QGLVIEWER_VEC_H 24 #define QGLVIEWER_VEC_H 29 # include <QDomElement> 70 #if defined (Q_OS_IRIX) || defined (Q_OS_AIX) || defined (Q_OS_HPUX) 71 # define QGLVIEWER_UNION_NOT_SUPPORTED 76 #if defined (DOXYGEN) || defined (QGLVIEWER_UNION_NOT_SUPPORTED) 81 struct { qreal x, y,
z; };
89 Vec() : x(0.0), y(0.0), z(0.0) {}
92 Vec(qreal X, qreal Y, qreal Z) : x(X), y(Y), z(Z) {}
111 explicit Vec(
const C& c) : x(c[0]), y(c[1]), z(c[2]) {}
120 x = v.
x; y = v.
y; z = v.
z;
142 #ifdef QGLVIEWER_UNION_NOT_SUPPORTED 151 #ifdef QGLVIEWER_UNION_NOT_SUPPORTED 160 const double*
address()
const { qWarning(
"Vec::address() is deprecated, use operator const double* instead.");
return operator const double*(); }
171 operator const double*()
const {
172 #ifdef QGLVIEWER_UNION_NOT_SUPPORTED 183 #ifdef QGLVIEWER_UNION_NOT_SUPPORTED 199 operator const float*()
const {
200 static float*
const result =
new float[3];
201 result[0] = (float)x;
202 result[1] = (float)y;
203 result[2] = (float)z;
225 return Vec(-a.
x, -a.
y, -a.
z);
231 return Vec(a.
x*k, a.
y*k, a.
z*k);
247 if (fabs(k) < 1.0E-10)
248 qWarning(
"Vec::operator / : dividing by a null value (%f)", k);
250 return Vec(a.
x/k, a.
y/k, a.
z/k);
262 const qreal epsilon = 1.0E-10;
263 return (a-b).squaredNorm() < epsilon;
269 x += a.
x; y += a.
y; z += a.
z;
276 x -= a.
x; y -= a.
y; z -= a.
z;
283 x *= k; y *= k; z *= k;
295 qWarning(
"Vec::operator /= : dividing by a null value (%f)", k);
297 x /= k; y /= k; z /= k;
304 return a.
x*b.
x + a.
y*b.
y + a.
z*b.
z;
321 Vec orthogonalVec()
const;
328 qreal
sqNorm()
const {
return x*x + y*y + z*z; }
335 qreal
norm()
const {
return sqrt(x*x + y*y + z*z); }
342 const qreal n = norm();
345 qWarning(
"Vec::normalize: normalizing a null vector (norm=%f)", n);
362 void projectOnAxis(
const Vec& direction);
363 void projectOnPlane(
const Vec& normal);
368 explicit Vec(
const QDomElement& element);
369 QDomElement domElement(
const QString& name, QDomDocument& document)
const;
370 void initFromDOMElement(
const QDomElement& element);
390 #endif // QGLVIEWER_VEC_H qreal & operator[](int i)
friend Vec operator^(const Vec &a, const Vec &b)
Vec & operator+=(const Vec &a)
friend Vec operator-(const Vec &a, const Vec &b)
friend Vec operator*(qreal k, const Vec &a)
qreal squaredNorm() const
Vec & operator=(const Vec &v)
Vec & operator-=(const Vec &a)
friend Vec operator/(const Vec &a, qreal k)
The Vec class represents 3D positions and 3D vectors.
friend bool operator!=(const Vec &a, const Vec &b)
Vec(qreal X, qreal Y, qreal Z)
void setValue(qreal X, qreal Y, qreal Z)
qreal operator[](int i) const
std::ostream & operator<<(std::ostream &o, const qglviewer::Vec &)
friend qreal operator*(const Vec &a, const Vec &b)
Vec & operator*=(qreal k)
friend Vec operator-(const Vec &a)
friend Vec cross(const Vec &a, const Vec &b)
const double * address() const
friend bool operator==(const Vec &a, const Vec &b)
Vec & operator/=(qreal k)
friend Vec operator+(const Vec &a, const Vec &b)
friend Vec operator*(const Vec &a, qreal k)