OpenVDB  7.0.0
Quat.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3 
4 #ifndef OPENVDB_MATH_QUAT_H_HAS_BEEN_INCLUDED
5 #define OPENVDB_MATH_QUAT_H_HAS_BEEN_INCLUDED
6 
7 #include "Mat.h"
8 #include "Mat3.h"
9 #include "Math.h"
10 #include "Vec3.h"
11 #include <openvdb/Exceptions.h>
12 #include <cmath>
13 #include <iostream>
14 #include <sstream>
15 #include <string>
16 
17 
18 namespace openvdb {
20 namespace OPENVDB_VERSION_NAME {
21 namespace math {
22 
23 template<typename T> class Quat;
24 
26 template <typename T>
27 Quat<T> slerp(const Quat<T> &q1, const Quat<T> &q2, T t, T tolerance=0.00001)
28 {
29  T qdot, angle, sineAngle;
30 
31  qdot = q1.dot(q2);
32 
33  if (fabs(qdot) >= 1.0) {
34  angle = 0; // not necessary but suppresses compiler warning
35  sineAngle = 0;
36  } else {
37  angle = acos(qdot);
38  sineAngle = sin(angle);
39  }
40 
41  //
42  // Denominator close to 0 corresponds to the case where the
43  // two quaternions are close to the same rotation. In this
44  // case linear interpolation is used but we normalize to
45  // guarantee unit length
46  //
47  if (sineAngle <= tolerance) {
48  T s = 1.0 - t;
49 
50  Quat<T> qtemp(s * q1[0] + t * q2[0], s * q1[1] + t * q2[1],
51  s * q1[2] + t * q2[2], s * q1[3] + t * q2[3]);
52  //
53  // Check the case where two close to antipodal quaternions were
54  // blended resulting in a nearly zero result which can happen,
55  // for example, if t is close to 0.5. In this case it is not safe
56  // to project back onto the sphere.
57  //
58  double lengthSquared = qtemp.dot(qtemp);
59 
60  if (lengthSquared <= tolerance * tolerance) {
61  qtemp = (t < 0.5) ? q1 : q2;
62  } else {
63  qtemp *= 1.0 / sqrt(lengthSquared);
64  }
65  return qtemp;
66  } else {
67 
68  T sine = 1.0 / sineAngle;
69  T a = sin((1.0 - t) * angle) * sine;
70  T b = sin(t * angle) * sine;
71  return Quat<T>(a * q1[0] + b * q2[0], a * q1[1] + b * q2[1],
72  a * q1[2] + b * q2[2], a * q1[3] + b * q2[3]);
73  }
74 
75 }
76 
77 template<typename T>
78 class Quat
79 {
80 public:
81  using value_type = T;
82  using ValueType = T;
83  static const int size = 4;
84 
86  Quat() {}
87 
89  Quat(T x, T y, T z, T w)
90  {
91  mm[0] = x;
92  mm[1] = y;
93  mm[2] = z;
94  mm[3] = w;
95 
96  }
97 
99  Quat(T *a)
100  {
101  mm[0] = a[0];
102  mm[1] = a[1];
103  mm[2] = a[2];
104  mm[3] = a[3];
105 
106  }
107 
110  Quat(const Vec3<T> &axis, T angle)
111  {
112  // assert( REL_EQ(axis.length(), 1.) );
113 
114  T s = T(sin(angle*T(0.5)));
115 
116  mm[0] = axis.x() * s;
117  mm[1] = axis.y() * s;
118  mm[2] = axis.z() * s;
119 
120  mm[3] = T(cos(angle*T(0.5)));
121 
122  }
123 
126  {
127  T s = T(sin(angle*T(0.5)));
128 
129  mm[0] = (axis==math::X_AXIS) * s;
130  mm[1] = (axis==math::Y_AXIS) * s;
131  mm[2] = (axis==math::Z_AXIS) * s;
132 
133  mm[3] = T(cos(angle*T(0.5)));
134  }
135 
137  template<typename T1>
138  Quat(const Mat3<T1> &rot) {
139 
140  // verify that the matrix is really a rotation
141  if(!isUnitary(rot)) { // unitary is reflection or rotation
143  "A non-rotation matrix can not be used to construct a quaternion");
144  }
145  if (!isApproxEqual(rot.det(), T1(1))) { // rule out reflection
147  "A reflection matrix can not be used to construct a quaternion");
148  }
149 
150  T trace(rot.trace());
151  if (trace > 0) {
152 
153  T q_w = 0.5 * std::sqrt(trace+1);
154  T factor = 0.25 / q_w;
155 
156  mm[0] = factor * (rot(1,2) - rot(2,1));
157  mm[1] = factor * (rot(2,0) - rot(0,2));
158  mm[2] = factor * (rot(0,1) - rot(1,0));
159  mm[3] = q_w;
160  } else if (rot(0,0) > rot(1,1) && rot(0,0) > rot(2,2)) {
161 
162  T q_x = 0.5 * sqrt(rot(0,0)- rot(1,1)-rot(2,2)+1);
163  T factor = 0.25 / q_x;
164 
165  mm[0] = q_x;
166  mm[1] = factor * (rot(0,1) + rot(1,0));
167  mm[2] = factor * (rot(2,0) + rot(0,2));
168  mm[3] = factor * (rot(1,2) - rot(2,1));
169  } else if (rot(1,1) > rot(2,2)) {
170 
171  T q_y = 0.5 * sqrt(rot(1,1)-rot(0,0)-rot(2,2)+1);
172  T factor = 0.25 / q_y;
173 
174  mm[0] = factor * (rot(0,1) + rot(1,0));
175  mm[1] = q_y;
176  mm[2] = factor * (rot(1,2) + rot(2,1));
177  mm[3] = factor * (rot(2,0) - rot(0,2));
178  } else {
179 
180  T q_z = 0.5 * sqrt(rot(2,2)-rot(0,0)-rot(1,1)+1);
181  T factor = 0.25 / q_z;
182 
183  mm[0] = factor * (rot(2,0) + rot(0,2));
184  mm[1] = factor * (rot(1,2) + rot(2,1));
185  mm[2] = q_z;
186  mm[3] = factor * (rot(0,1) - rot(1,0));
187  }
188  }
189 
191  Quat(const Quat &q)
192  {
193  mm[0] = q.mm[0];
194  mm[1] = q.mm[1];
195  mm[2] = q.mm[2];
196  mm[3] = q.mm[3];
197 
198  }
199 
201  T& x() { return mm[0]; }
202  T& y() { return mm[1]; }
203  T& z() { return mm[2]; }
204  T& w() { return mm[3]; }
205 
207  T x() const { return mm[0]; }
208  T y() const { return mm[1]; }
209  T z() const { return mm[2]; }
210  T w() const { return mm[3]; }
211 
212  // Number of elements
213  static unsigned numElements() { return 4; }
214 
216  T& operator[](int i) { return mm[i]; }
217 
219  T operator[](int i) const { return mm[i]; }
220 
222  operator T*() { return mm; }
223  operator const T*() const { return mm; }
224 
226  T& operator()(int i) { return mm[i]; }
227 
229  T operator()(int i) const { return mm[i]; }
230 
232  T angle() const
233  {
234  T sqrLength = mm[0]*mm[0] + mm[1]*mm[1] + mm[2]*mm[2];
235 
236  if ( sqrLength > 1.0e-8 ) {
237 
238  return T(T(2.0) * acos(mm[3]));
239 
240  } else {
241 
242  return T(0.0);
243  }
244  }
245 
247  Vec3<T> axis() const
248  {
249  T sqrLength = mm[0]*mm[0] + mm[1]*mm[1] + mm[2]*mm[2];
250 
251  if ( sqrLength > 1.0e-8 ) {
252 
253  T invLength = T(T(1)/sqrt(sqrLength));
254 
255  return Vec3<T>( mm[0]*invLength, mm[1]*invLength, mm[2]*invLength );
256  } else {
257 
258  return Vec3<T>(1,0,0);
259  }
260  }
261 
262 
264  Quat& init(T x, T y, T z, T w)
265  {
266  mm[0] = x; mm[1] = y; mm[2] = z; mm[3] = w;
267  return *this;
268  }
269 
271  Quat& init() { return setIdentity(); }
272 
275  Quat& setAxisAngle(const Vec3<T>& axis, T angle)
276  {
277 
278  T s = T(sin(angle*T(0.5)));
279 
280  mm[0] = axis.x() * s;
281  mm[1] = axis.y() * s;
282  mm[2] = axis.z() * s;
283 
284  mm[3] = T(cos(angle*T(0.5)));
285 
286  return *this;
287  } // axisAngleTest
288 
291  {
292  mm[0] = mm[1] = mm[2] = mm[3] = 0;
293  return *this;
294  }
295 
298  {
299  mm[0] = mm[1] = mm[2] = 0;
300  mm[3] = 1;
301  return *this;
302  }
303 
305  Vec3<T> eulerAngles(RotationOrder rotationOrder) const
306  { return math::eulerAngles(Mat3<T>(*this), rotationOrder); }
307 
309  Quat& operator=(const Quat &q)
310  {
311  mm[0] = q.mm[0];
312  mm[1] = q.mm[1];
313  mm[2] = q.mm[2];
314  mm[3] = q.mm[3];
315 
316  return *this;
317  }
318 
320  bool operator==(const Quat &q) const
321  {
322  return (isExactlyEqual(mm[0],q.mm[0]) &&
323  isExactlyEqual(mm[1],q.mm[1]) &&
324  isExactlyEqual(mm[2],q.mm[2]) &&
325  isExactlyEqual(mm[3],q.mm[3]) );
326  }
327 
329  bool eq(const Quat &q, T eps=1.0e-7) const
330  {
331  return isApproxEqual(mm[0],q.mm[0],eps) && isApproxEqual(mm[1],q.mm[1],eps) &&
332  isApproxEqual(mm[2],q.mm[2],eps) && isApproxEqual(mm[3],q.mm[3],eps) ;
333  } // trivial
334 
336  Quat& operator+=(const Quat &q)
337  {
338  mm[0] += q.mm[0];
339  mm[1] += q.mm[1];
340  mm[2] += q.mm[2];
341  mm[3] += q.mm[3];
342 
343  return *this;
344  }
345 
347  Quat& operator-=(const Quat &q)
348  {
349  mm[0] -= q.mm[0];
350  mm[1] -= q.mm[1];
351  mm[2] -= q.mm[2];
352  mm[3] -= q.mm[3];
353 
354  return *this;
355  }
356 
358  Quat& operator*=(T scalar)
359  {
360  mm[0] *= scalar;
361  mm[1] *= scalar;
362  mm[2] *= scalar;
363  mm[3] *= scalar;
364 
365  return *this;
366  }
367 
369  Quat operator+(const Quat &q) const
370  {
371  return Quat<T>(mm[0]+q.mm[0], mm[1]+q.mm[1], mm[2]+q.mm[2], mm[3]+q.mm[3]);
372  }
373 
375  Quat operator-(const Quat &q) const
376  {
377  return Quat<T>(mm[0]-q.mm[0], mm[1]-q.mm[1], mm[2]-q.mm[2], mm[3]-q.mm[3]);
378  }
379 
381  Quat operator*(const Quat &q) const
382  {
383  Quat<T> prod;
384 
385  prod.mm[0] = mm[3]*q.mm[0] + mm[0]*q.mm[3] + mm[1]*q.mm[2] - mm[2]*q.mm[1];
386  prod.mm[1] = mm[3]*q.mm[1] + mm[1]*q.mm[3] + mm[2]*q.mm[0] - mm[0]*q.mm[2];
387  prod.mm[2] = mm[3]*q.mm[2] + mm[2]*q.mm[3] + mm[0]*q.mm[1] - mm[1]*q.mm[0];
388  prod.mm[3] = mm[3]*q.mm[3] - mm[0]*q.mm[0] - mm[1]*q.mm[1] - mm[2]*q.mm[2];
389 
390  return prod;
391 
392  }
393 
395  Quat operator*=(const Quat &q)
396  {
397  *this = *this * q;
398  return *this;
399  }
400 
402  Quat operator*(T scalar) const
403  {
404  return Quat<T>(mm[0]*scalar, mm[1]*scalar, mm[2]*scalar, mm[3]*scalar);
405  }
406 
408  Quat operator/(T scalar) const
409  {
410  return Quat<T>(mm[0]/scalar, mm[1]/scalar, mm[2]/scalar, mm[3]/scalar);
411  }
412 
414  Quat operator-() const
415  { return Quat<T>(-mm[0], -mm[1], -mm[2], -mm[3]); }
416 
419  Quat& add(const Quat &q1, const Quat &q2)
420  {
421  mm[0] = q1.mm[0] + q2.mm[0];
422  mm[1] = q1.mm[1] + q2.mm[1];
423  mm[2] = q1.mm[2] + q2.mm[2];
424  mm[3] = q1.mm[3] + q2.mm[3];
425 
426  return *this;
427  }
428 
431  Quat& sub(const Quat &q1, const Quat &q2)
432  {
433  mm[0] = q1.mm[0] - q2.mm[0];
434  mm[1] = q1.mm[1] - q2.mm[1];
435  mm[2] = q1.mm[2] - q2.mm[2];
436  mm[3] = q1.mm[3] - q2.mm[3];
437 
438  return *this;
439  }
440 
443  Quat& mult(const Quat &q1, const Quat &q2)
444  {
445  mm[0] = q1.mm[3]*q2.mm[0] + q1.mm[0]*q2.mm[3] +
446  q1.mm[1]*q2.mm[2] - q1.mm[2]*q2.mm[1];
447  mm[1] = q1.mm[3]*q2.mm[1] + q1.mm[1]*q2.mm[3] +
448  q1.mm[2]*q2.mm[0] - q1.mm[0]*q2.mm[2];
449  mm[2] = q1.mm[3]*q2.mm[2] + q1.mm[2]*q2.mm[3] +
450  q1.mm[0]*q2.mm[1] - q1.mm[1]*q2.mm[0];
451  mm[3] = q1.mm[3]*q2.mm[3] - q1.mm[0]*q2.mm[0] -
452  q1.mm[1]*q2.mm[1] - q1.mm[2]*q2.mm[2];
453 
454  return *this;
455  }
456 
459  Quat& scale(T scale, const Quat &q)
460  {
461  mm[0] = scale * q.mm[0];
462  mm[1] = scale * q.mm[1];
463  mm[2] = scale * q.mm[2];
464  mm[3] = scale * q.mm[3];
465 
466  return *this;
467  }
468 
470  T dot(const Quat &q) const
471  {
472  return (mm[0]*q.mm[0] + mm[1]*q.mm[1] + mm[2]*q.mm[2] + mm[3]*q.mm[3]);
473  }
474 
477  Quat derivative(const Vec3<T>& omega) const
478  {
479  return Quat<T>( +w()*omega.x() -z()*omega.y() +y()*omega.z() ,
480  +z()*omega.x() +w()*omega.y() -x()*omega.z() ,
481  -y()*omega.x() +x()*omega.y() +w()*omega.z() ,
482  -x()*omega.x() -y()*omega.y() -z()*omega.z() );
483  }
484 
486  bool normalize(T eps = T(1.0e-8))
487  {
488  T d = T(sqrt(mm[0]*mm[0] + mm[1]*mm[1] + mm[2]*mm[2] + mm[3]*mm[3]));
489  if( isApproxEqual(d, T(0.0), eps) ) return false;
490  *this *= ( T(1)/d );
491  return true;
492  }
493 
495  Quat unit() const
496  {
497  T d = sqrt(mm[0]*mm[0] + mm[1]*mm[1] + mm[2]*mm[2] + mm[3]*mm[3]);
498  if( isExactlyEqual(d , T(0.0) ) )
500  "Normalizing degenerate quaternion");
501  return *this / d;
502  }
503 
505  Quat inverse(T tolerance = T(0))
506  {
507  T d = mm[0]*mm[0] + mm[1]*mm[1] + mm[2]*mm[2] + mm[3]*mm[3];
508  if( isApproxEqual(d, T(0.0), tolerance) )
510  "Cannot invert degenerate quaternion");
511  Quat result = *this/-d;
512  result.mm[3] = -result.mm[3];
513  return result;
514  }
515 
516 
519  Quat conjugate() const
520  {
521  return Quat<T>(-mm[0], -mm[1], -mm[2], mm[3]);
522  }
523 
525  Vec3<T> rotateVector(const Vec3<T> &v) const
526  {
527  Mat3<T> m(*this);
528  return m.transform(v);
529  }
530 
532  static Quat zero() { return Quat<T>(0,0,0,0); }
533  static Quat identity() { return Quat<T>(0,0,0,1); }
534 
536  std::string str() const
537  {
538  std::ostringstream buffer;
539 
540  buffer << "[";
541 
542  // For each column
543  for (unsigned j(0); j < 4; j++) {
544  if (j) buffer << ", ";
545  buffer << mm[j];
546  }
547 
548  buffer << "]";
549 
550  return buffer.str();
551  }
552 
554  friend std::ostream& operator<<(std::ostream &stream, const Quat &q)
555  {
556  stream << q.str();
557  return stream;
558  }
559 
560  friend Quat slerp<>(const Quat &q1, const Quat &q2, T t, T tolerance);
561 
562  void write(std::ostream& os) const { os.write(static_cast<char*>(&mm), sizeof(T) * 4); }
563  void read(std::istream& is) { is.read(static_cast<char*>(&mm), sizeof(T) * 4); }
564 
565 protected:
566  T mm[4];
567 };
568 
570 template <typename S, typename T>
571 Quat<T> operator*(S scalar, const Quat<T> &q) { return q*scalar; }
572 
573 
577 template <typename T, typename T0>
578 Mat3<T> slerp(const Mat3<T0> &m1, const Mat3<T0> &m2, T t)
579 {
580  using MatType = Mat3<T>;
581 
582  Quat<T> q1(m1);
583  Quat<T> q2(m2);
584 
585  if (q1.dot(q2) < 0) q2 *= -1;
586 
587  Quat<T> qslerp = slerp<T>(q1, q2, static_cast<T>(t));
588  MatType m = rotation<MatType>(qslerp);
589  return m;
590 }
591 
592 
593 
602 template <typename T, typename T0>
603 Mat3<T> bezLerp(const Mat3<T0> &m1, const Mat3<T0> &m2,
604  const Mat3<T0> &m3, const Mat3<T0> &m4,
605  T t)
606 {
607  Mat3<T> m00, m01, m02, m10, m11;
608 
609  m00 = slerp(m1, m2, t);
610  m01 = slerp(m2, m3, t);
611  m02 = slerp(m3, m4, t);
612 
613  m10 = slerp(m00, m01, t);
614  m11 = slerp(m01, m02, t);
615 
616  return slerp(m10, m11, t);
617 }
618 
621 
622 } // namespace math
623 
624 
625 template<> inline math::Quats zeroVal<math::Quats >() { return math::Quats::zero(); }
626 template<> inline math::Quatd zeroVal<math::Quatd >() { return math::Quatd::zero(); }
627 
628 } // namespace OPENVDB_VERSION_NAME
629 } // namespace openvdb
630 
631 #endif //OPENVDB_MATH_QUAT_H_HAS_BEEN_INCLUDED
friend std::ostream & operator<<(std::ostream &stream, const Quat &q)
Output to the stream, e.g. std::cout << q << std::endl;.
Definition: Quat.h:554
Quat operator*(const Quat &q) const
Return (this*q), e.g. q = q1 * q2;.
Definition: Quat.h:381
Quat< T > operator*(S scalar, const Quat< T > &q)
Multiply each element of the given quaternion by scalar and return the result.
Definition: Quat.h:571
Quat(const Vec3< T > &axis, T angle)
Definition: Quat.h:110
Quat derivative(const Vec3< T > &omega) const
Definition: Quat.h:477
T & z()
Definition: Vec3.h:85
bool isApproxEqual(const Type &a, const Type &b)
Return true if a is equal to b to within the default floating-point comparison tolerance.
Definition: Math.h:351
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
Definition: Mat.h:169
Quat operator*(T scalar) const
Return (this*scalar), e.g. q = q1 * scalar;.
Definition: Quat.h:402
T & x()
Reference to the component, e.g. q.x() = 4.5f;.
Definition: Quat.h:201
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:82
Quat & mult(const Quat &q1, const Quat &q2)
Definition: Quat.h:443
void write(std::ostream &os) const
Definition: Quat.h:562
Vec3< typename MatType::value_type > eulerAngles(const MatType &mat, RotationOrder rotationOrder, typename MatType::value_type eps=static_cast< typename MatType::value_type >(1.0e-8))
Return the Euler angles composing the given rotation matrix.
Definition: Mat.h:338
Definition: Math.h:851
Quat()
Trivial constructor, the quaternion is NOT initialized.
Definition: Quat.h:86
Vec3< T0 > transform(const Vec3< T0 > &v) const
Definition: Mat3.h:526
RotationOrder
Definition: Math.h:856
Quat & operator=(const Quat &q)
Assignment operator.
Definition: Quat.h:309
T & operator()(int i)
Alternative indexed reference to the elements.
Definition: Quat.h:226
T & y()
Definition: Vec3.h:84
Quat & setAxisAngle(const Vec3< T > &axis, T angle)
Definition: Quat.h:275
T trace() const
Trace of matrix.
Definition: Mat3.h:509
Quat(const Quat &q)
Copy constructor.
Definition: Quat.h:191
Axis
Definition: Math.h:849
Quat(math::Axis axis, T angle)
Constructor given rotation as axis and angle.
Definition: Quat.h:125
Quat(const Mat3< T1 > &rot)
Constructor given a rotation matrix.
Definition: Quat.h:138
Quat & operator+=(const Quat &q)
Add quaternion q to "this" quaternion, e.g. q += q1;.
Definition: Quat.h:336
bool eq(const Quat &q, T eps=1.0e-7) const
Test if "this" is equivalent to q with tolerance of eps value.
Definition: Quat.h:329
Quat unit() const
this = normalized this
Definition: Quat.h:495
Definition: Math.h:850
T operator[](int i) const
Array style constant reference to the components, e.g. float f = q[1];.
Definition: Quat.h:219
T dot(const Quat &q) const
Dot product.
Definition: Quat.h:470
static unsigned numElements()
Definition: Quat.h:213
Quat(T x, T y, T z, T w)
Constructor with four arguments, e.g. Quatf q(1,2,3,4);.
Definition: Quat.h:89
bool operator==(const Quat &q) const
Equality operator, does exact floating point comparisons.
Definition: Quat.h:320
T value_type
Definition: Quat.h:81
T z() const
Definition: Quat.h:209
T mm[4]
Definition: Quat.h:566
Quat(T *a)
Constructor with array argument, e.g. float a[4]; Quatf q(a);.
Definition: Quat.h:99
bool isUnitary(const MatType &m)
Determine if a matrix is unitary (i.e., rotation or reflection).
Definition: Mat.h:894
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:102
T x() const
Get the component, e.g. float f = q.w();.
Definition: Quat.h:207
Vec3< T > rotateVector(const Vec3< T > &v) const
Return rotated vector by "this" quaternion.
Definition: Quat.h:525
static Quat identity()
Definition: Quat.h:533
T ValueType
Definition: Quat.h:82
T w() const
Definition: Quat.h:210
Quat & operator*=(T scalar)
Scale "this" quaternion by scalar, e.g. q *= scalar;.
Definition: Quat.h:358
Quat & setIdentity()
Set "this" vector to identity.
Definition: Quat.h:297
T & w()
Definition: Quat.h:204
static Quat zero()
Predefined constants, e.g. Quat q = Quat::identity();.
Definition: Quat.h:532
Definition: Exceptions.h:13
Quat & sub(const Quat &q1, const Quat &q2)
Definition: Quat.h:431
Definition: Exceptions.h:56
Mat3< T > slerp(const Mat3< T0 > &m1, const Mat3< T0 > &m2, T t)
Interpolate between m1 and m2. Converts to quaternion form and uses slerp m1 and m2 must be rotation ...
Definition: Quat.h:578
Vec3< T > axis() const
Return axis of rotation.
Definition: Quat.h:247
Quat & add(const Quat &q1, const Quat &q2)
Definition: Quat.h:419
T & y()
Definition: Quat.h:202
Quat operator/(T scalar) const
Return (this/scalar), e.g. q = q1 / scalar;.
Definition: Quat.h:408
T det() const
Determinant of matrix.
Definition: Mat3.h:500
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec3.h:83
Quat conjugate() const
Definition: Quat.h:519
T y() const
Definition: Quat.h:208
Quat operator*=(const Quat &q)
Assigns this to (this*q), e.g. q *= q1;.
Definition: Quat.h:395
Mat3< T > bezLerp(const Mat3< T0 > &m1, const Mat3< T0 > &m2, const Mat3< T0 > &m3, const Mat3< T0 > &m4, T t)
Definition: Quat.h:603
bool normalize(T eps=T(1.0e-8))
this = normalized this
Definition: Quat.h:486
Quat & init()
"this" quaternion gets initialized to identity, same as setIdentity()
Definition: Quat.h:271
Quat operator-() const
Negation operator, e.g. q = -q;.
Definition: Quat.h:414
Quat & setZero()
Set "this" vector to zero.
Definition: Quat.h:290
Quat operator-(const Quat &q) const
Return (this-q), e.g. q = q1 - q2;.
Definition: Quat.h:375
T & operator[](int i)
Array style reference to the components, e.g. q[3] = 1.34f;.
Definition: Quat.h:216
3x3 matrix class.
Definition: Mat3.h:28
Quat & init(T x, T y, T z, T w)
"this" quaternion gets initialized to [x, y, z, w]
Definition: Quat.h:264
Definition: Mat.h:170
Quat inverse(T tolerance=T(0))
returns inverse of this
Definition: Quat.h:505
T operator()(int i) const
Alternative indexed constant reference to the elements,.
Definition: Quat.h:229
T & z()
Definition: Quat.h:203
T angle(const Vec2< T > &v1, const Vec2< T > &v2)
Definition: Vec2.h:445
void read(std::istream &is)
Definition: Quat.h:563
T angle() const
Return angle of rotation.
Definition: Quat.h:232
Vec3< T > eulerAngles(RotationOrder rotationOrder) const
Returns vector of x,y,z rotational components.
Definition: Quat.h:305
Quat & operator-=(const Quat &q)
Subtract quaternion q from "this" quaternion, e.g. q -= q1;.
Definition: Quat.h:347
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:388
Quat & scale(T scale, const Quat &q)
Definition: Quat.h:459
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:154
Definition: Math.h:852
std::string str() const
Definition: Quat.h:536
MatType scale(const Vec3< typename MatType::value_type > &s)
Return a matrix that scales by s.
Definition: Mat.h:620
Quat operator+(const Quat &q) const
Return (this+q), e.g. q = q1 + q2;.
Definition: Quat.h:369