HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_Quaternion.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT library (C++)
7  *
8  * COMMENTS: This class implements quaternions.
9  *
10  * WARNING:
11  * This class should NOT contain any virtual methods, nor should it
12  * define more member data. The size of UT_QuaternionF must always be
13  * 16 bytes (4 floats).
14  *
15  */
16 
17 #pragma once
18 
19 #ifndef __UT_Quaternion_h__
20 #define __UT_Quaternion_h__
21 
22 #include "UT_API.h"
23 #include "UT_FixedVectorTraits.h"
24 #include "UT_Vector3.h"
25 #include "UT_Vector4.h"
26 #include "UT_VectorTypes.h" // IWYU pragma: export
27 
28 #include <SYS/SYS_Inline.h>
29 #include <SYS/SYS_Math.h>
30 #include <SYS/SYS_Types.h>
31 #include <iosfwd>
32 #include <limits>
33 #include <stddef.h>
34 
35 class UT_IStream;
36 class UT_JSONParser;
37 class UT_JSONValue;
38 class UT_JSONWriter;
39 class UT_XformOrder;
40 
41 // Forward declaration
42 template <typename T> class UT_API UT_QuaternionT;
43 
44 /// Perform component-wise SYSlerp of two quaternions
45 template <typename T>
46 inline UT_QuaternionT<T>
47 SYSlerp(const UT_QuaternionT<T> &q1, const UT_QuaternionT<T> &q2, T t);
48 
49 /// Quaternion class
50 template <typename T>
52 {
53 public:
54 
55  typedef T value_type;
56  static constexpr int tuple_size = 4;
57 
58  /// q = qx(i) + qy(j) + qz(k) + qw.
59  UT_QuaternionT(T qx=0, T qy=0,
60  T qz=0, T qw=0)
61  {
62  vec[0] = qx; vec[1] = qy;
63  vec[2] = qz; vec[3] = qw;
64  }
65  UT_QuaternionT(const fpreal32 v[tuple_size])
66  {
67  vec[0] = v[0]; vec[1] = v[1];
68  vec[2] = v[2]; vec[3] = v[3];
69  }
70  UT_QuaternionT(const fpreal64 v[tuple_size])
71  {
72  vec[0] = v[0]; vec[1] = v[1];
73  vec[2] = v[2]; vec[3] = v[3];
74  }
76  {
77  vec[0] = v[0]; vec[1] = v[1];
78  vec[2] = v[2]; vec[3] = v[3];
79  }
80  inline UT_QuaternionT(T angle,
81  const UT_Vector3T<T> &axis,
82  int donormalize=1);
84  const UT_XformOrder &order)
85  {
86  updateFromEuler(rot, order);
87  }
88 
90 
91  SYS_FORCE_INLINE UT_QuaternionT(const ThisType &that) = default;
92  SYS_FORCE_INLINE UT_QuaternionT(ThisType &&that) = default;
93  SYS_FORCE_INLINE ThisType &operator=(const ThisType &that) = default;
94  SYS_FORCE_INLINE ThisType &operator=(ThisType &&that) = default;
95 
96  template <typename S>
98  { vec[0] = v.x(); vec[1] = v.y(); vec[2] = v.z(); vec[3] = v.w(); }
99  template <typename S>
101  { vec[0] = v.x(); vec[1] = v.y(); vec[2] = v.z(); vec[3] = v.w(); return *this; }
102 
104  inline UT_QuaternionT<T> &operator*=(T scalar);
105  inline UT_QuaternionT<T> &operator/=(const UT_QuaternionT<T> &quat);
106  inline UT_QuaternionT<T> &operator/=(T scalar);
107  inline UT_QuaternionT<T> &operator+=(const UT_QuaternionT<T> &quat);
108  inline bool operator==(const UT_QuaternionT<T> &quat) const;
109  inline bool operator!=(const UT_QuaternionT<T> &quat) const;
110  T operator()(int idx) const
111  { return vec[idx]; }
112  T &operator()(int idx)
113  { return vec[idx]; }
114  T operator[](int idx) const
115  { return vec[idx]; }
116  T &operator[](int idx)
117  { return vec[idx]; }
118 
119  /// Does a comparison with a tolerance. This also returns true if
120  /// quat.negated() is equal to us, unlike operator==().
121  inline bool isEqual(const UT_QuaternionT<T> &quat,
122  T tol = T(SYS_FTOLERANCE)) const;
123 
124  // The rotation this quaternion represents as a matrix
125  void getRotationMatrix(UT_Matrix3 &mat) const;
126  void getRotationMatrix(UT_DMatrix3 &mat) const;
127  void getInverseRotationMatrix(UT_Matrix3 &mat) const;
128  void getInverseRotationMatrix(UT_DMatrix3 &mat) const;
129 
130  void getTransformMatrix(UT_Matrix4 &mat) const;
131  void getTransformMatrix(UT_DMatrix4 &mat) const;
132 
133  /// Interpolates between this quat (t==0) and the target (t==1)
135  UT_QuaternionT<T> interpolate(const UT_QuaternionT<T> &target,
136  T t, T b = 0.0f) const;
137  /// Interpolates between the n quaternions in q, with weights w,
138  /// to within tolerance tol.
139  /// NOTE: The q's must be normalized, and the weights may need to sum to 1.
140  void interpolate(const UT_QuaternionT<T> *q, const T *w, exint n, T tol = T(1e-6));
141 
142  /// Do component-wise lerp between this quat (t=0) and the target (t=1).
144  {
145  vec[0] = SYSlerp(vec[0], target.vec[0], t);
146  vec[1] = SYSlerp(vec[1], target.vec[1], t);
147  vec[2] = SYSlerp(vec[2], target.vec[2], t);
148  vec[3] = SYSlerp(vec[3], target.vec[3], t);
149  }
150  /// Do component-wise lerp between this src (t=0) and dst (t=1).
152  const UT_QuaternionT<T> &dst,
153  T t)
154  {
155  vec[0] = SYSlerp(src.vec[0], dst.vec[0], t);
156  vec[1] = SYSlerp(src.vec[1], dst.vec[1], t);
157  vec[2] = SYSlerp(src.vec[2], dst.vec[2], t);
158  vec[3] = SYSlerp(src.vec[3], dst.vec[3], t);
159  }
160 
161  void assign(T qx, T qy,
162  T qz, T qw)
163  {
164  vec[0] = qx; vec[1] = qy;
165  vec[2] = qz; vec[3] = qw;
166  }
167  void identity()
168  {
169  vec[0] = vec[1] = vec[2] = 0.0f;
170  vec[3] = 1.0f;
171  }
172  void conjugate()
173  {
174  vec[0] = -vec[0];
175  vec[1] = -vec[1];
176  vec[2] = -vec[2];
177  }
178  void negate()
179  {
180  vec[0] = -vec[0];
181  vec[1] = -vec[1];
182  vec[2] = -vec[2];
183  vec[3] = -vec[3];
184  }
185  T normal() const
186  {
187  return vec[0] * vec[0] +
188  vec[1] * vec[1] +
189  vec[2] * vec[2] +
190  vec[3] * vec[3];
191  }
192  void normalize()
193  {
194  T dn = normal();
195  if (dn > std::numeric_limits<T>::min()
196  && dn != 1.0)
197  {
198  dn = SYSsqrt(dn);
199  *this /= dn;
200  }
201  }
202  T length() const
203  {
204  return SYSsqrt(normal());
205  }
206  void invert()
207  {
208  T n = normal();
209  if (n > std::numeric_limits<T>::min())
210  {
211  n = 1.0 / n;
212  conjugate();
213  vec[0] *= n;
214  vec[1] *= n;
215  vec[2] *= n;
216  vec[3] *= n;
217  }
218  }
219 
220  UT_QuaternionT<T> exp() const;
221  UT_QuaternionT<T> ln() const;
222  UT_QuaternionT<T> log() const { return ln(); }
223  UT_QuaternionT<T> pow(T exp) const;
224 
225  // Form the quaternion which takes v1 and rotates it to v2.
226  // v1 and v2 are assumed normalized
227  void updateFromVectors(const UT_Vector3T<T> &v1,
228  const UT_Vector3T<T> &v2);
229 
230  /// Form the quaternion from the rotation component of an
231  /// arbitrary 3x3 matrix.
232  void updateFromArbitraryMatrix(const UT_Matrix3 &);
233  void updateFromArbitraryMatrix(const UT_Matrix3D &);
234 
235  /// Form the quaternion from a rotation matrix
236  /// WARNING: This will produce incorrect results if given
237  /// a non-rotation matrix! Use updateFromArbitraryMatrix
238  /// if you may have a non-rotation matrix.
239  void updateFromRotationMatrix(const UT_Matrix3 &);
240  void updateFromRotationMatrix(const UT_Matrix3D &);
241 
242  // Form the quaternion from an angle/axis
243  void updateFromAngleAxis(T angle,
244  const UT_Vector3T<T> &axis,
245  int normalize=1);
246 
247  void getAngleAxis(T &angle,
248  UT_Vector3T<T> &axis) const;
249 
250  void updateFromLogMap(const UT_Vector3T<T> &v);
251  void getLogMap(UT_Vector3T<T> &v) const;
252 
253  // Form the quaternion from euler rotation angles (given in radians)
254  void updateFromEuler(const UT_Vector3T<T> &rot,
255  const UT_XformOrder &order);
256 
257  // Given the angular velocity omega, compute our derivative into q_prime
258  void computeDerivative(const UT_Vector3T<T> &omega,
259  UT_QuaternionT<T> &q_prime);
260 
261  // Returns the angular velocity required to move from the rotation of
262  // this quaternion to the destination quaternion in a given time.
263  UT_Vector3T<T> computeAngVel(const UT_QuaternionT<T> &dest,
264  T time) const;
265 
266  // Integrates this quaternion by the given angular velocity and time
267  // step. There are two appraoches to doing this. For small
268  // angular velocity/timesteps, one can compute the derivative
269  // implied by the angular velocity, apply linearly, and renormalize.
270  // Alternatively, one can construct the proper quaternion for the given
271  // angular velocity and rotate by that. Which method is controlled
272  // by the accurate flag.
273  void integrate(const UT_Vector3T<T> &angvel,
274  T timestep,
275  bool accurate = true);
276 
277  // Returns the rx/ry/rz euler rotation representation of the quaternion.
278  // The returned rotations are in radians.
279  UT_Vector3T<T> computeRotations(const UT_XformOrder &) const;
280 
281  /// Rotates a vector by this quaternion
282  /// Requires that this is normalized.
284  inline UT_Vector3T<T> rotate(const UT_Vector3T<T> &) const;
285 
286  /// rotates a vector by the inverse of this quaternion.
287  /// Requires that this is normalized.
289  inline UT_Vector3T<T> rotateInverse(const UT_Vector3T<T> &) const;
290 
291  // Multiply this quarternion's "real world" Euler angles by the given
292  // scalar s. That is, if this quaternion is
293  // [ cos(a), n1 sin(a), n2 sin(a), n3 sin(a) ] it is replaced by
294  // [ cos(a*s), n1 sin(a*s), n2 sin(a*s), n3 sin(a*s) ]
295  void multAngle( T s );
296 
297  // Decomposes this quaternion into a twist component along the axis and a swing component
298  // When reverse is false the decomposition is Q = Swing * Twist
299  void swingTwistDecompose(
300  const UT_Vector3T<T> &axis,
301  UT_QuaternionT<T> &swing,
303  const bool reverse = false) const;
304 
305  T &x() { return vec[0]; }
306  T &y() { return vec[1]; }
307  T &z() { return vec[2]; }
308  T &w() { return vec[3]; }
309 
310  T x() const { return vec[0]; }
311  T y() const { return vec[1]; }
312  T z() const { return vec[2]; }
313  T w() const { return vec[3]; }
314 
315  void save(std::ostream &os, int binary=0) const;
316  bool load(UT_IStream &is);
317 
318  /// @{
319  /// Methods to serialize to a JSON stream. The vector is stored as an
320  /// array of 4 reals.
321  bool save(UT_JSONWriter &w) const;
322  bool save(UT_JSONValue &v) const;
323  bool load(UT_JSONParser &p);
324  /// @}
325 
326  const T *data() const { return &vec[0]; }
327  T *data() { return &vec[0]; }
328 
329  T distance2(const UT_QuaternionT<T> &b) const noexcept
330  {
331  return UT::FA::Distance2<T, tuple_size>{}(vec, b.vec);
332  }
333  T distance(const UT_QuaternionT<T> &b) const noexcept
334  {
335  return SYSsqrt(distance2(b));
336  }
337 
338  static int entries() { return tuple_size; }
339 
340  /// Compute a hash
341  unsigned hash() const { return SYSvector_hash(data(), tuple_size); }
342 
343 protected:
344  void initialize(T qx = 0, T qy = 0,
345  T qz = 0, T qw = 0)
346  {
347  vec[0] = qx; vec[1] = qy;
348  vec[2] = qz; vec[3] = qw;
349  }
350 private:
351  // I/O friends:
352  friend std::ostream &operator<<(std::ostream &os, const UT_QuaternionT<T> &v)
353  {
354  v.save(os);
355  return os;
356  }
357  T vec[tuple_size];
358 };
359 
360 template <typename T>
361 UT_API size_t format(char *buf, size_t buf_size, const UT_QuaternionT<T> &q);
362 
363 template <typename T>
364 inline
366  int donormalize)
367 {
368  updateFromAngleAxis(angle, axis, donormalize);
369 }
370 
371 template <typename T>
372 inline bool
374 {
375  return (vec[0] == quat.vec[0] &&
376  vec[1] == quat.vec[1] &&
377  vec[2] == quat.vec[2] &&
378  vec[3] == quat.vec[3]);
379 }
380 
381 template <typename T>
382 inline bool
384 {
385  return !(*this == quat);
386 }
387 
388 template <typename T>
389 inline bool
391 {
392  // Two quaternions are equal if all values are equal, or if all values
393  // are equal magnitude but opposite sign. Both sets of values represent
394  // the same overall rotation.
395  return ((SYSisEqual(vec[0], quat.vec[0], tol) &&
396  SYSisEqual(vec[1], quat.vec[1], tol) &&
397  SYSisEqual(vec[2], quat.vec[2], tol) &&
398  SYSisEqual(vec[3], quat.vec[3], tol)) ||
399  (SYSisEqual(-vec[0], quat.vec[0], tol) &&
400  SYSisEqual(-vec[1], quat.vec[1], tol) &&
401  SYSisEqual(-vec[2], quat.vec[2], tol) &&
402  SYSisEqual(-vec[3], quat.vec[3], tol)));
403 }
404 
405 template <typename T>
406 inline UT_QuaternionT<T>
408 {
409  UT_QuaternionT<T> product = q1;
410 
411  product *= q2;
412 
413  return UT_QuaternionT<T>(product);
414 }
415 
416 template <typename T>
417 inline UT_QuaternionT<T>
419 {
420  return UT_QuaternionT<T>(q1.x() + q2.x(),
421  q1.y() + q2.y(),
422  q1.z() + q2.z(),
423  q1.w() + q2.w());
424 }
425 
426 template <typename T>
427 inline UT_QuaternionT<T> &
429 {
430  vec[0] += quat.vec[0];
431  vec[1] += quat.vec[1];
432  vec[2] += quat.vec[2];
433  vec[3] += quat.vec[3];
434 
435  return *this;
436 }
437 
438 template <typename T>
439 inline UT_QuaternionT<T>
441 {
442  return UT_QuaternionT<T>(q1.x() - q2.x(),
443  q1.y() - q2.y(),
444  q1.z() - q2.z(),
445  q1.w() - q2.w());
446 }
447 
448 template <typename T>
449 inline UT_QuaternionT<T>
451 {
452  return UT_QuaternionT<T>(-q.x(),
453  -q.y(),
454  -q.z(),
455  -q.w());
456 }
457 
458 template <typename T>
459 inline UT_QuaternionT<T>
460 operator*(const UT_QuaternionT<T> &q, T scalar)
461 {
462  return UT_QuaternionT<T>(q.x() * scalar,
463  q.y() * scalar,
464  q.z() * scalar,
465  q.w() * scalar);
466 }
467 
468 template <typename T>
469 inline UT_QuaternionT<T>
470 operator*(T scalar, const UT_QuaternionT<T> &q)
471 {
472  return UT_QuaternionT<T>(q.x() * scalar,
473  q.y() * scalar,
474  q.z() * scalar,
475  q.w() * scalar);
476 }
477 
478 template <typename T>
479 inline UT_QuaternionT<T> &
481 {
482  UT_Vector3T<T> v1(vec[0], vec[1], vec[2]);
483  UT_Vector3T<T> v2(q.vec[0], q.vec[1], q.vec[2]);
485  T s1 = vec[3], s2 = q.vec[3];
486 
487  vec[3] = s1*s2 - v1.dot(v2);
488  v3 = s1*v2 + s2*v1 + cross(v1, v2);
489  vec[0] = v3[0];
490  vec[1] = v3[1];
491  vec[2] = v3[2];
492 
493  return *this;
494 }
495 
496 template <typename T>
497 inline UT_QuaternionT<T> &
499 {
500  vec[0] *= scalar;
501  vec[1] *= scalar;
502  vec[2] *= scalar;
503  vec[3] *= scalar;
504 
505  return *this;
506 }
507 
508 template <typename T>
509 inline UT_QuaternionT<T>
511 {
512  UT_QuaternionT<T> a1 = a;
513  UT_QuaternionT<T> b1 = b;
514 
515  b1.invert();
516  a1 *= b1;
517 
518  return UT_QuaternionT<T>(a1);
519 }
520 
521 template <typename T>
522 inline UT_QuaternionT<T>
523 operator/(const UT_QuaternionT<T> &q, T scalar)
524 {
525  T d = 1.0/scalar;
526  return UT_QuaternionT<T>(q.x()*d, q.y()*d, q.z()*d, q.w()*d);
527 }
528 
529 template <typename T>
530 inline UT_QuaternionT<T> &
532 {
533  UT_QuaternionT<T> q = quat;
534 
535  q.invert();
536  operator*=(q);
537 
538  return *this;
539 }
540 
541 template <typename T>
542 inline UT_QuaternionT<T> &
544 {
545  T d = 1.0F/scalar;
546 
547  vec[0] *= d;
548  vec[1] *= d;
549  vec[2] *= d;
550  vec[3] *= d;
551 
552  return *this;
553 }
554 
555 template <typename T>
556 inline UT_Vector3T<T>
558 {
559  UT_QuaternionT<T> q = (*this) *
560  UT_QuaternionT<T>(v.x(), v.y(), v.z(), 0.0f) *
561  UT_QuaternionT<T>(-vec[0], -vec[1], -vec[2], vec[3]);
562  return UT_Vector3T<T>(q.x(), q.y(), q.z());
563 }
564 
565 template <typename T>
566 inline UT_Vector3T<T>
568 {
569  UT_QuaternionT<T> q = UT_QuaternionT<T>(-vec[0], -vec[1], -vec[2], vec[3]) *
570  UT_QuaternionT<T>(v.x(), v.y(), v.z(), 0.0f) *
571  (*this);
572  return UT_Vector3T<T>(q.x(), q.y(), q.z());
573 }
574 
575 template <typename T>
576 inline T
577 dot( const UT_QuaternionT<T> &q1, const UT_QuaternionT<T> &q2 )
578 {
579  return q1.x()*q2.x() + q1.y()*q2.y() + q1.z()*q2.z() + q1.w()*q2.w();
580 }
581 
582 template <typename T>
583 inline size_t
585 {
586  return val.hash();
587 }
588 
594 
595 template< typename T, exint D >
596 class UT_FixedVector;
597 
598 template<typename T>
600 {
602  typedef T DataType;
603  static const exint TupleSize = 4;
604  static const bool isVectorType = true;
605 };
606 
607 // UT_QuaternionTFromFixed<T> is a function object that
608 // creates a UT_QuaternionT<T> from a fixed array-like type TS,
609 // examples of which include T[4], UT_FixedVector<T,4> and UT_FixedArray<T,4> (AKA std::array<T,4>)
610 template <typename T>
612 {
613  template< typename TS >
614  constexpr SYS_FORCE_INLINE UT_QuaternionT<T> operator()(const TS& as) const noexcept
615  {
616  SYS_STATIC_ASSERT( SYS_IsFixedArrayOf_v< TS, T, 4 > );
617 
618  return UT_QuaternionT<T>{as[0], as[1], as[2], as[3]};
619  }
620 };
621 
622 // Convert a fixed array-like type TS into a UT_QuaternionT< T >.
623 // This allows conversion to UT_QuaternionT without fixing T.
624 // Instead, the element type of TS determines the type T.
625 template< typename TS >
627 UTmakeQuaternionT( const TS& as ) noexcept
628 {
630 
631  return UT_QuaternionTFromFixed< T >{}( as );
632 }
633 
634 // UT_FromFixed<V> creates a V from a flat, fixed array-like representation
635 
636 // Primary
637 template <typename V >
638 struct UT_FromFixed;
639 
640 // Partial specialization for UT_QuaternionT
641 template <typename T>
643 
644 ///////////////////////////////////////////////////////////////////////////////
645 //
646 // Implementations
647 //
648 
649 template <typename T>
650 inline UT_QuaternionT<T>
652 {
653  return UT_QuaternionT<T>( SYSlerp(q1.x(), q2.x(), t)
654  , SYSlerp(q1.y(), q2.y(), t)
655  , SYSlerp(q1.z(), q2.z(), t)
656  , SYSlerp(q1.w(), q2.w(), t)
657  );
658 }
659 
660 #endif
T & operator[](int idx)
Mat3< typename promote< S, T >::type > operator*(S scalar, const Mat3< T > &m)
Multiply each element of the given matrix by scalar and return the result.
Definition: Mat3.h:561
T length() const
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:2540
constexpr SYS_FORCE_INLINE T dot(const UT_Vector3T &b) const noexcept
Definition: UT_Vector3.h:529
UT_QuaternionT< T > & operator/=(const UT_QuaternionT< T > &quat)
UT_QuaternionT(const UT_Vector3T< T > &rot, const UT_XformOrder &order)
Definition: UT_Quaternion.h:83
#define SYS_STATIC_ASSERT(expr)
OIIO_FORCEINLINE const vint4 & operator/=(vint4 &a, const vint4 &b)
Definition: simd.h:4587
UT_QuaternionT< fpreal16 > UT_QuaternionH
UT_QuaternionT< T > & operator=(const UT_QuaternionT< S > &v)
T z() const
constexpr SYS_FORCE_INLINE UT_QuaternionT< T > operator()(const TS &as) const noexcept
SIM_API const UT_StringHolder angle
UT_QuaternionT< fpreal > UT_QuaternionR
GLboolean * data
Definition: glcorearb.h:131
GT_API const UT_StringHolder time
const GLdouble * v
Definition: glcorearb.h:837
Transformation order of scales, rotates, and translates.
Definition: UT_XformOrder.h:23
Mat3< typename promote< T0, T1 >::type > operator+(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Add corresponding elements of m0 and m1 and return the result.
Definition: Mat3.h:577
const GLuint GLenum const void * binary
Definition: glcorearb.h:1924
GA_API const UT_StringHolder rot
T & operator()(int idx)
typename SYS_FixedArrayElement< T >::type SYS_FixedArrayElement_t
GA_API const UT_StringHolder twist
fpreal64 distance2(const UT_VectorD &v1, const UT_VectorD &v2)
Distance squared (L2) aka quadrance.
Definition: UT_Vector.h:399
void assign(T qx, T qy, T qz, T qw)
constexpr SYS_FORCE_INLINE T & z() noexcept
Definition: UT_Vector3.h:667
int64 exint
Definition: SYS_Types.h:125
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
GLdouble s
Definition: glad.h:3009
PUGI__FN void reverse(I begin, I end)
Definition: pugixml.cpp:7458
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:87
#define UT_API
Definition: UT_API.h:14
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
static const exint TupleSize
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:818
GLdouble GLdouble GLdouble q
Definition: glad.h:2445
3D Vector class.
GLfloat GLfloat GLfloat GLfloat v3
Definition: glcorearb.h:819
4D Vector class.
Definition: UT_Vector4.h:174
static int entries()
float fpreal32
Definition: SYS_Types.h:200
size_t hash_value(const UT_QuaternionT< T > &val)
UT_QuaternionT< T > operator/(const UT_QuaternionT< T > &a, const UT_QuaternionT< T > &b)
double fpreal64
Definition: SYS_Types.h:201
ImageBuf OIIO_API pow(const ImageBuf &A, cspan< float > B, ROI roi={}, int nthreads=0)
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
UT_API size_t format(char *buf, size_t buf_size, const UT_QuaternionT< T > &q)
GLdouble n
Definition: glcorearb.h:2008
GLfloat f
Definition: glcorearb.h:1926
UT_QuaternionT< fpreal32 > UT_QuaternionF
Vec3< T > & operator*=(Vec3< T > &_v, const Mat3< MT > &_m)
Multiply _v by _m and replace _v with the resulting vector.
Definition: Mat3.h:633
UT_QuaternionT< T > ThisType
Definition: UT_Quaternion.h:89
SYS_NO_DISCARD_RESULT UT_Vector3T< T > rotateInverse(const UT_Vector3T< T > &) const
Mat3< typename promote< T0, T1 >::type > operator-(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Subtract corresponding elements of m0 and m1 and return the result.
Definition: Mat3.h:587
OIIO_FORCEINLINE const vint4 & operator+=(vint4 &a, const vint4 &b)
Definition: simd.h:4512
T x() const
UT_QuaternionT< fpreal64 > UT_QuaternionD
UT_QuaternionT(T qx=0, T qy=0, T qz=0, T qw=0)
q = qx(i) + qy(j) + qz(k) + qw.
Definition: UT_Quaternion.h:59
static const bool isVectorType
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
GLdouble GLdouble GLint GLint order
Definition: glad.h:2676
GLenum target
Definition: glcorearb.h:1667
UT_QuaternionT< T > & operator+=(const UT_QuaternionT< T > &quat)
#define SYS_NO_DISCARD_RESULT
Definition: SYS_Compiler.h:93
T operator()(int idx) const
const T * data() const
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
UT_QuaternionT(const UT_Vector4T< T > &v)
Definition: UT_Quaternion.h:75
void lerp(const UT_QuaternionT< T > &src, const UT_QuaternionT< T > &dst, T t)
Do component-wise lerp between this src (t=0) and dst (t=1).
T dot(const UT_QuaternionT< T > &q1, const UT_QuaternionT< T > &q2)
ImageBuf OIIO_API rotate(const ImageBuf &src, float angle, string_view filtername=string_view(), float filterwidth=0.0f, bool recompute_roi=false, ROI roi={}, int nthreads=0)
IMATH_HOSTDEVICE const Vec2< S > & operator*=(Vec2< S > &v, const Matrix22< T > &m) IMATH_NOEXCEPT
Vector-matrix multiplication: v *= m.
Definition: ImathMatrix.h:4660
char size_t buf_size
Definition: SYS_String.h:466
GLdouble t
Definition: glad.h:2397
UT_QuaternionT< T > SYSlerp(const UT_QuaternionT< T > &q1, const UT_QuaternionT< T > &q2, T t)
Perform component-wise SYSlerp of two quaternions.
UT_QuaternionT< T > & operator*=(const UT_QuaternionT< T > &q)
bool isEqual(const UT_QuaternionT< T > &quat, T tol=T(SYS_FTOLERANCE)) const
class UT_API UT_QuaternionT
Definition: UT_Quaternion.h:42
UT_QuaternionT< T > log() const
GLenum GLenum dst
Definition: glcorearb.h:1793
Quaternion class.
Definition: GEO_Detail.h:49
UT_QuaternionT(const fpreal64 v[tuple_size])
Definition: UT_Quaternion.h:70
T y() const
UT_QuaternionT< fpreal32 > UT_Quaternion
bool operator!=(const UT_QuaternionT< T > &quat) const
T distance2(const UT_QuaternionT< T > &b) const noexcept
T w() const
LeafData & operator=(const LeafData &)=delete
T distance(const UT_QuaternionT< T > &b) const noexcept
constexpr UT_QuaternionT< SYS_FixedArrayElement_t< TS > > UTmakeQuaternionT(const TS &as) noexcept
GLfloat GLfloat v1
Definition: glcorearb.h:817
GLuint GLfloat * val
Definition: glcorearb.h:1608
T operator[](int idx) const
FMT_CONSTEXPR basic_fp< F > normalize(basic_fp< F > value)
Definition: format.h:1701
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:99
UT_QuaternionT(const fpreal32 v[tuple_size])
Definition: UT_Quaternion.h:65
void lerp(const UT_QuaternionT< T > &target, T t)
Do component-wise lerp between this quat (t=0) and the target (t=1).
#define SYS_FTOLERANCE
Definition: SYS_Types.h:208
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
bool operator!=(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:165
T normal() const
bool operator==(const UT_QuaternionT< T > &quat) const
SYS_NO_DISCARD_RESULT UT_Vector3T< T > rotate(const UT_Vector3T< T > &) const
void initialize(T qx=0, T qy=0, T qz=0, T qw=0)
constexpr SYS_FORCE_INLINE T & y() noexcept
Definition: UT_Vector3.h:665
bool SYSisEqual(const UT_Vector2T< T > &a, const UT_Vector2T< T > &b, S tol=SYS_FTOLERANCE)
Componentwise equality.
Definition: UT_Vector2.h:674
unsigned hash() const
Compute a hash.
SIM_DerVector3 cross(const SIM_DerVector3 &lhs, const SIM_DerVector3 &rhs)
GLenum src
Definition: glcorearb.h:1793
constexpr SYS_FORCE_INLINE T & x() noexcept
Definition: UT_Vector3.h:663