19 #ifndef __UT_Quaternion_h__
20 #define __UT_Quaternion_h__
56 static constexpr
int tuple_size = 4;
61 vec[0] = qx; vec[1] = qy;
62 vec[2] = qz; vec[3] = qw;
66 vec[0] =
v[0]; vec[1] =
v[1];
67 vec[2] =
v[2]; vec[3] =
v[3];
71 vec[0] =
v[0]; vec[1] =
v[1];
72 vec[2] =
v[2]; vec[3] =
v[3];
76 vec[0] = v[0]; vec[1] = v[1];
77 vec[2] = v[2]; vec[3] = v[3];
85 updateFromEuler(rot, order);
97 { vec[0] =
v.
x(); vec[1] =
v.y(); vec[2] =
v.z(); vec[3] =
v.w(); }
100 { vec[0] = v.
x(); vec[1] = v.
y(); vec[2] = v.
z(); vec[3] = v.
w();
return *
this; }
124 void getRotationMatrix(
UT_Matrix3 &mat)
const;
126 void getInverseRotationMatrix(
UT_Matrix3 &mat)
const;
127 void getInverseRotationMatrix(
UT_DMatrix3 &mat)
const;
129 void getTransformMatrix(
UT_Matrix4 &mat)
const;
134 T t,
T b = 0.0
f)
const;
143 vec[0] =
SYSlerp(vec[0], target.vec[0], t);
144 vec[1] =
SYSlerp(vec[1], target.vec[1], t);
145 vec[2] =
SYSlerp(vec[2], target.vec[2], t);
146 vec[3] =
SYSlerp(vec[3], target.vec[3], t);
153 vec[0] =
SYSlerp(src.vec[0], dst.vec[0], t);
154 vec[1] =
SYSlerp(src.vec[1], dst.vec[1], t);
155 vec[2] =
SYSlerp(src.vec[2], dst.vec[2], t);
156 vec[3] =
SYSlerp(src.vec[3], dst.vec[3], t);
162 vec[0] = qx; vec[1] = qy;
163 vec[2] = qz; vec[3] = qw;
167 vec[0] = vec[1] = vec[2] = 0.0f;
185 return vec[0] * vec[0] +
202 return SYSsqrt(normal());
232 void updateFromArbitraryMatrix(
const UT_Matrix3 &);
233 void updateFromArbitraryMatrix(
const UT_Matrix3D &);
239 void updateFromRotationMatrix(
const UT_Matrix3 &);
240 void updateFromRotationMatrix(
const UT_Matrix3D &);
243 void updateFromAngleAxis(
T angle,
247 void getAngleAxis(
T &
angle,
275 bool accurate =
true);
293 void multAngle(
T s );
297 void swingTwistDecompose(
301 const bool reverse =
false)
const;
303 T &
x() {
return vec[0]; }
304 T &
y() {
return vec[1]; }
305 T &
z() {
return vec[2]; }
306 T &
w() {
return vec[3]; }
308 T x()
const {
return vec[0]; }
309 T y()
const {
return vec[1]; }
310 T z()
const {
return vec[2]; }
311 T w()
const {
return vec[3]; }
313 void save(std::ostream &os,
int binary=0)
const;
324 const T *
data()
const {
return &vec[0]; }
339 unsigned hash()
const {
return SYSvector_hash(
data(), tuple_size); }
345 vec[0] = qx; vec[1] = qy;
346 vec[2] = qz; vec[3] = qw;
350 friend std::ostream &operator<<(std::ostream &os, const UT_QuaternionT<T> &
v)
358 template <
typename T>
361 template <
typename T>
366 updateFromAngleAxis(angle, axis, donormalize);
369 template <
typename T>
373 return (vec[0] == quat.vec[0] &&
374 vec[1] == quat.vec[1] &&
375 vec[2] == quat.vec[2] &&
376 vec[3] == quat.vec[3]);
379 template <
typename T>
383 return !(*
this == quat);
386 template <
typename T>
393 return ((
SYSisEqual(vec[0], quat.vec[0], tol) &&
403 template <
typename T>
414 template <
typename T>
424 template <
typename T>
428 vec[0] += quat.vec[0];
429 vec[1] += quat.vec[1];
430 vec[2] += quat.vec[2];
431 vec[3] += quat.vec[3];
436 template <
typename T>
446 template <
typename T>
456 template <
typename T>
466 template <
typename T>
476 template <
typename T>
483 T s1 = vec[3], s2 = q.vec[3];
485 vec[3] = s1*s2 - v1.
dot(v2);
486 v3 = s1*v2 + s2*v1 +
cross(v1, v2);
494 template <
typename T>
506 template <
typename T>
519 template <
typename T>
527 template <
typename T>
539 template <
typename T>
553 template <
typename T>
563 template <
typename T>
573 template <
typename T>
577 return q1.
x()*q2.
x() + q1.
y()*q2.
y() + q1.
z()*q2.
z() + q1.
w()*q2.
w();
580 template <
typename T>
593 template<
typename T, ex
int D >
608 template <
typename T>
611 template<
typename TS >
623 template<
typename TS >
635 template <
typename V >
639 template <
typename T>
647 template <
typename T>
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.
GLenum GLuint GLenum GLsizei const GLchar * buf
constexpr SYS_FORCE_INLINE T dot(const UT_Vector3T &b) const noexcept
UT_QuaternionT< T > & operator/=(const UT_QuaternionT< T > &quat)
UT_QuaternionT(const UT_Vector3T< T > &rot, const UT_XformOrder &order)
#define SYS_STATIC_ASSERT(expr)
OIIO_FORCEINLINE const vint4 & operator/=(vint4 &a, const vint4 &b)
UT_QuaternionT< fpreal16 > UT_QuaternionH
UT_FixedVector< T, 4 > FixedVectorType
UT_QuaternionT< T > & operator=(const UT_QuaternionT< S > &v)
constexpr SYS_FORCE_INLINE UT_QuaternionT< T > operator()(const TS &as) const noexcept
SIM_API const UT_StringHolder angle
UT_QuaternionT< fpreal > UT_QuaternionR
GT_API const UT_StringHolder time
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.
const GLuint GLenum const void * binary
GA_API const UT_StringHolder rot
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.
void assign(T qx, T qy, T qz, T qw)
constexpr SYS_FORCE_INLINE T & z() noexcept
GLboolean GLboolean GLboolean GLboolean a
void reverse(I begin, I end)
JSON reader class which handles parsing of JSON or bJSON files.
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.
static const exint TupleSize
GLfloat GLfloat GLfloat v2
GLdouble GLdouble GLdouble q
GLfloat GLfloat GLfloat GLfloat v3
size_t hash_value(const UT_QuaternionT< T > &val)
UT_QuaternionT< T > operator/(const UT_QuaternionT< T > &a, const UT_QuaternionT< T > &b)
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
UT_API size_t format(char *buf, size_t buf_size, const UT_QuaternionT< T > &q)
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.
UT_QuaternionT< T > ThisType
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.
OIIO_FORCEINLINE const vint4 & operator+=(vint4 &a, const vint4 &b)
UT_QuaternionT< fpreal64 > UT_QuaternionD
UT_QuaternionT(T qx=0, T qy=0, T qz=0, T qw=0)
static const bool isVectorType
GLdouble GLdouble GLint GLint order
UT_QuaternionT< T > & operator+=(const UT_QuaternionT< T > &quat)
T operator()(int idx) const
GLboolean GLboolean GLboolean b
UT_QuaternionT(const UT_Vector4T< T > &v)
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.
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
UT_QuaternionT< T > log() const
UT_QuaternionT(const fpreal64 v[tuple_size])
UT_QuaternionT< fpreal32 > UT_Quaternion
bool operator!=(const UT_QuaternionT< T > &quat) const
T distance2(const UT_QuaternionT< T > &b) const noexcept
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
T operator[](int idx) const
Class to store JSON objects as C++ objects.
UT_QuaternionT(const fpreal32 v[tuple_size])
void lerp(const UT_QuaternionT< T > &target, T t)
Do component-wise lerp between this quat (t=0) and the target (t=1).
GLubyte GLubyte GLubyte GLubyte w
bool operator!=(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
bool operator==(const UT_QuaternionT< T > &quat) const
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
bool SYSisEqual(const UT_Vector2T< T > &a, const UT_Vector2T< T > &b, S tol=SYS_FTOLERANCE)
Componentwise equality.
unsigned hash() const
Compute a hash.
SIM_DerVector3 cross(const SIM_DerVector3 &lhs, const SIM_DerVector3 &rhs)
constexpr T normalize(UT_FixedVector< T, D > &a) noexcept
constexpr SYS_FORCE_INLINE T & x() noexcept