Loading...
Searching...
No Matches
quath.h
Go to the documentation of this file.
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
8// This file is generated by a script. Do not edit directly. Edit the
9// quat.template.h file to make changes.
10
11#ifndef PXR_BASE_GF_QUATH_H
12#define PXR_BASE_GF_QUATH_H
13
16
17#include "pxr/pxr.h"
18#include "pxr/base/gf/api.h"
19#include "pxr/base/gf/declare.h"
20#include "pxr/base/gf/vec3h.h"
21#include "pxr/base/gf/traits.h"
22#include "pxr/base/gf/half.h"
23#include "pxr/base/tf/hash.h"
24
25#include <iosfwd>
26
27PXR_NAMESPACE_OPEN_SCOPE
28
29template <>
30struct GfIsGfQuat<class GfQuath> { static const bool value = true; };
31
32
34GfHalf GfDot(const GfQuath& q1, const GfQuath& q2);
35
36
44{
45 public:
46 typedef GfHalf ScalarType;
47 typedef GfVec3h ImaginaryType;
48
51 GfQuath() = default;
52
60 explicit GfQuath (GfHalf realVal) : _imaginary(0), _real(realVal) {}
61
64 : _imaginary(i, j, k), _real(real)
65 {
66 }
67
69 GfQuath(GfHalf real, const GfVec3h &imaginary)
70 : _imaginary(imaginary), _real(real)
71 {
72 }
73
75 GF_API
76 explicit GfQuath(class GfQuatd const &other);
78 GF_API
79 explicit GfQuath(class GfQuatf const &other);
80
83 static GfQuath GetZero() { return GfQuath(0.0); }
84
87 static GfQuath GetIdentity() { return GfQuath(1.0); }
88
90 GfHalf GetReal() const { return _real; }
91
93 void SetReal(GfHalf real) { _real = real; }
94
96 const GfVec3h &GetImaginary() const { return _imaginary; }
97
99 void SetImaginary(const GfVec3h &imaginary) {
100 _imaginary = imaginary;
101 }
102
105 _imaginary.Set(i, j, k);
106 }
107
109 GfHalf GetLength() const { return GfSqrt(_GetLengthSquared()); }
110
113 GfQuath
115 GfQuath ret(*this);
116 ret.Normalize(eps);
117 return ret;
118 }
119
123 GF_API
125
129 return GfQuath(GetReal(), -GetImaginary());
130 }
131
135 return GetConjugate() / _GetLengthSquared();
136 }
137
145 GF_API
146 GfVec3h Transform(const GfVec3h& point) const;
147
149 friend inline size_t hash_value(const GfQuath &q) {
150 return TfHash::Combine(q.GetReal(), q.GetImaginary());
151 }
152
155 return GfQuath(-GetReal(), -GetImaginary());
156 }
157
160 bool operator==(const GfQuath &q) const {
161 return (GetReal() == q.GetReal() &&
162 GetImaginary() == q.GetImaginary());
163 }
164
167 bool operator!=(const GfQuath &q) const {
168 return !(*this == q);
169 }
170
172 GF_API
174
177 _real *= s;
178 _imaginary *= s;
179 return *this;
180 }
181
184 _real /= s;
185 _imaginary /= s;
186 return *this;
187 }
188
191 _real += q._real;
192 _imaginary += q._imaginary;
193 return *this;
194 }
195
198 _real -= q._real;
199 _imaginary -= q._imaginary;
200 return *this;
201 }
202
204 friend GfQuath
205 operator +(const GfQuath &q1, const GfQuath &q2) {
206 return GfQuath(q1) += q2;
207 }
208
210 friend GfQuath
211 operator -(const GfQuath &q1, const GfQuath &q2) {
212 return GfQuath(q1) -= q2;
213 }
214
216 friend GfQuath
217 operator *(const GfQuath &q1, const GfQuath &q2) {
218 return GfQuath(q1) *= q2;
219 }
220
222 friend GfQuath
223 operator *(const GfQuath &q, GfHalf s) {
224 return GfQuath(q) *= s;
225 }
226
228 friend GfQuath
229 operator *(GfHalf s, const GfQuath &q) {
230 return GfQuath(q) *= s;
231 }
232
234 friend GfQuath
235 operator /(const GfQuath &q, GfHalf s) {
236 return GfQuath(q) /= s;
237 }
238
239 private:
241 GfVec3h _imaginary;
242
244 GfHalf _real;
245
247 GfHalf
248 _GetLengthSquared() const {
249 return GfDot(*this, *this);
250 }
251};
252
257GF_API GfQuath
258GfSlerp(double alpha, const GfQuath& q0, const GfQuath& q1);
259
260GF_API GfQuath
261GfSlerp(const GfQuath& q0, const GfQuath& q1, double alpha);
262
263inline GfHalf
264GfDot(GfQuath const &q1, GfQuath const &q2) {
265 return GfDot(q1.GetImaginary(), q2.GetImaginary()) +
266 q1.GetReal()*q2.GetReal();
267}
268
271GF_API std::ostream& operator<<(std::ostream &, GfQuath const &);
272
273PXR_NAMESPACE_CLOSE_SCOPE
274
275#endif // PXR_BASE_GF_QUATH_H
Declares Gf types.
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients,...
Definition: quatd.h:43
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients,...
Definition: quatf.h:43
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients,...
Definition: quath.h:44
GfQuath(GfHalf real, GfHalf i, GfHalf j, GfHalf k)
Initialize the real and imaginary coefficients.
Definition: quath.h:63
GfQuath()=default
GfQuath value-initializes to zero and performs no default initialization, like float or double.
void SetImaginary(const GfVec3h &imaginary)
Set the imaginary coefficients.
Definition: quath.h:99
GfQuath operator-() const
Component-wise negation.
Definition: quath.h:154
friend size_t hash_value(const GfQuath &q)
Hash.
Definition: quath.h:149
GfHalf GetReal() const
Return the real coefficient.
Definition: quath.h:90
friend GfQuath operator/(const GfQuath &q, GfHalf s)
Returns the product of quaternion q and scalar 1 / s.
Definition: quath.h:235
GF_API GfHalf Normalize(GfHalf eps=GF_MIN_VECTOR_LENGTH)
Normalizes this quaternion in place to unit length, returning the length before normalization.
GfHalf GetLength() const
Return geometric length of this quaternion.
Definition: quath.h:109
GfQuath GetInverse() const
Return this quaternion's inverse, or reciprocal.
Definition: quath.h:134
friend GfQuath operator+(const GfQuath &q1, const GfQuath &q2)
Component-wise binary sum operator.
Definition: quath.h:205
GfQuath & operator+=(const GfQuath &q)
Add quaternion q to this quaternion.
Definition: quath.h:190
GfQuath GetConjugate() const
Return this quaternion's conjugate, which is the quaternion with the same real coefficient and negate...
Definition: quath.h:128
void SetReal(GfHalf real)
Set the real coefficient.
Definition: quath.h:93
friend GfQuath operator*(const GfQuath &q1, const GfQuath &q2)
Returns the product of quaternions q1 and q2.
Definition: quath.h:217
GF_API GfQuath & operator*=(const GfQuath &q)
Post-multiply quaternion q into this quaternion.
bool operator==(const GfQuath &q) const
Component-wise quaternion equality test.
Definition: quath.h:160
GfQuath & operator/=(GfHalf s)
Divide this quaternion's coefficients by s.
Definition: quath.h:183
GF_API GfQuath(class GfQuatd const &other)
Construct from GfQuatd.
const GfVec3h & GetImaginary() const
Return the imaginary coefficient.
Definition: quath.h:96
GfQuath GetNormalized(GfHalf eps=GF_MIN_VECTOR_LENGTH) const
length of this quaternion is smaller than eps, return the identity quaternion.
Definition: quath.h:114
bool operator!=(const GfQuath &q) const
Component-wise quaternion inequality test.
Definition: quath.h:167
GF_API GfVec3h Transform(const GfVec3h &point) const
Transform the GfVec3h point.
GF_API GfQuath(class GfQuatf const &other)
Construct from GfQuatf.
GfQuath(GfHalf real, const GfVec3h &imaginary)
Initialize the real and imaginary coefficients.
Definition: quath.h:69
void SetImaginary(GfHalf i, GfHalf j, GfHalf k)
Set the imaginary coefficients.
Definition: quath.h:104
static GfQuath GetZero()
Return the zero quaternion, with real coefficient 0 and an imaginary coefficients all zero.
Definition: quath.h:83
GfQuath(GfHalf realVal)
Initialize the real coefficient to realVal and the imaginary coefficients to zero.
Definition: quath.h:60
GfQuath & operator-=(const GfQuath &q)
Component-wise unary difference operator.
Definition: quath.h:197
static GfQuath GetIdentity()
Return the identity quaternion, with real coefficient 1 and an imaginary coefficients all zero.
Definition: quath.h:87
Basic type for a vector of 3 GfHalf components.
Definition: vec3h.h:47
GfVec3h & Set(GfHalf s0, GfHalf s1, GfHalf s2)
Set all elements with passed arguments.
Definition: vec3h.h:114
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:487
double GfSqrt(double f)
Return sqrt(f).
Definition: math.h:187
#define GF_MIN_VECTOR_LENGTH
This constant is used to determine whether the length of a vector is too small to handle accurately.
Definition: limits.h:17
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
This header serves to simply bring in the half float datatype and provide a hash_value function.
pxr_half::half GfHalf
A 16-bit floating point data type.
Definition: half.h:26
GfHalf GfDot(const GfQuath &q1, const GfQuath &q2)
Return the dot (inner) product of two quaternions.
Definition: quath.h:264
GF_API GfQuath GfSlerp(double alpha, const GfQuath &q0, const GfQuath &q1)
Spherically linearly interpolate between q0 and q1.
A metafunction with a static const bool member 'value' that is true for GfQuat types and false for al...
Definition: traits.h:30