Loading...
Searching...
No Matches
quatf.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_QUATF_H
12#define PXR_BASE_GF_QUATF_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/vec3f.h"
21#include "pxr/base/gf/traits.h"
22#include "pxr/base/tf/hash.h"
23
24#include <iosfwd>
25
26PXR_NAMESPACE_OPEN_SCOPE
27
28template <>
29struct GfIsGfQuat<class GfQuatf> { static const bool value = true; };
30
31
33float GfDot(const GfQuatf& q1, const GfQuatf& q2);
34
35
43{
44 public:
45 typedef float ScalarType;
46 typedef GfVec3f ImaginaryType;
47
50 GfQuatf() = default;
51
59 explicit GfQuatf (float realVal) : _imaginary(0), _real(realVal) {}
60
62 GfQuatf(float real, float i, float j, float k)
63 : _imaginary(i, j, k), _real(real)
64 {
65 }
66
68 GfQuatf(float real, const GfVec3f &imaginary)
69 : _imaginary(imaginary), _real(real)
70 {
71 }
72
74 GF_API
75 explicit GfQuatf(class GfQuatd const &other);
77 GF_API
78 GfQuatf(class GfQuath const &other);
79
82 static GfQuatf GetZero() { return GfQuatf(0.0); }
83
86 static GfQuatf GetIdentity() { return GfQuatf(1.0); }
87
89 float GetReal() const { return _real; }
90
92 void SetReal(float real) { _real = real; }
93
95 const GfVec3f &GetImaginary() const { return _imaginary; }
96
98 void SetImaginary(const GfVec3f &imaginary) {
99 _imaginary = imaginary;
100 }
101
103 void SetImaginary(float i, float j, float k) {
104 _imaginary.Set(i, j, k);
105 }
106
108 float GetLength() const { return GfSqrt(_GetLengthSquared()); }
109
112 GfQuatf
114 GfQuatf ret(*this);
115 ret.Normalize(eps);
116 return ret;
117 }
118
122 GF_API
123 float Normalize(float eps = GF_MIN_VECTOR_LENGTH);
124
128 return GfQuatf(GetReal(), -GetImaginary());
129 }
130
134 return GetConjugate() / _GetLengthSquared();
135 }
136
144 GF_API
145 GfVec3f Transform(const GfVec3f& point) const;
146
148 friend inline size_t hash_value(const GfQuatf &q) {
149 return TfHash::Combine(q.GetReal(), q.GetImaginary());
150 }
151
154 return GfQuatf(-GetReal(), -GetImaginary());
155 }
156
159 bool operator==(const GfQuatf &q) const {
160 return (GetReal() == q.GetReal() &&
161 GetImaginary() == q.GetImaginary());
162 }
163
166 bool operator!=(const GfQuatf &q) const {
167 return !(*this == q);
168 }
169
171 GF_API
173
176 _real *= s;
177 _imaginary *= s;
178 return *this;
179 }
180
183 _real /= s;
184 _imaginary /= s;
185 return *this;
186 }
187
190 _real += q._real;
191 _imaginary += q._imaginary;
192 return *this;
193 }
194
197 _real -= q._real;
198 _imaginary -= q._imaginary;
199 return *this;
200 }
201
203 friend GfQuatf
204 operator +(const GfQuatf &q1, const GfQuatf &q2) {
205 return GfQuatf(q1) += q2;
206 }
207
209 friend GfQuatf
210 operator -(const GfQuatf &q1, const GfQuatf &q2) {
211 return GfQuatf(q1) -= q2;
212 }
213
215 friend GfQuatf
216 operator *(const GfQuatf &q1, const GfQuatf &q2) {
217 return GfQuatf(q1) *= q2;
218 }
219
221 friend GfQuatf
222 operator *(const GfQuatf &q, float s) {
223 return GfQuatf(q) *= s;
224 }
225
227 friend GfQuatf
228 operator *(float s, const GfQuatf &q) {
229 return GfQuatf(q) *= s;
230 }
231
233 friend GfQuatf
234 operator /(const GfQuatf &q, float s) {
235 return GfQuatf(q) /= s;
236 }
237
238 private:
240 GfVec3f _imaginary;
241
243 float _real;
244
246 float
247 _GetLengthSquared() const {
248 return GfDot(*this, *this);
249 }
250};
251
256GF_API GfQuatf
257GfSlerp(double alpha, const GfQuatf& q0, const GfQuatf& q1);
258
259GF_API GfQuatf
260GfSlerp(const GfQuatf& q0, const GfQuatf& q1, double alpha);
261
262inline float
263GfDot(GfQuatf const &q1, GfQuatf const &q2) {
264 return GfDot(q1.GetImaginary(), q2.GetImaginary()) +
265 q1.GetReal()*q2.GetReal();
266}
267
270GF_API std::ostream& operator<<(std::ostream &, GfQuatf const &);
271
272PXR_NAMESPACE_CLOSE_SCOPE
273
274#endif // PXR_BASE_GF_QUATF_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
GF_API GfQuatf(class GfQuatd const &other)
Construct from GfQuatd.
friend size_t hash_value(const GfQuatf &q)
Hash.
Definition: quatf.h:148
bool operator==(const GfQuatf &q) const
Component-wise quaternion equality test.
Definition: quatf.h:159
GF_API float Normalize(float eps=GF_MIN_VECTOR_LENGTH)
Normalizes this quaternion in place to unit length, returning the length before normalization.
GF_API GfQuatf & operator*=(const GfQuatf &q)
Post-multiply quaternion q into this quaternion.
GfQuatf(float realVal)
Initialize the real coefficient to realVal and the imaginary coefficients to zero.
Definition: quatf.h:59
GfQuatf & operator/=(float s)
Divide this quaternion's coefficients by s.
Definition: quatf.h:182
void SetReal(float real)
Set the real coefficient.
Definition: quatf.h:92
void SetImaginary(float i, float j, float k)
Set the imaginary coefficients.
Definition: quatf.h:103
float GetLength() const
Return geometric length of this quaternion.
Definition: quatf.h:108
float GetReal() const
Return the real coefficient.
Definition: quatf.h:89
GfQuatf(float real, float i, float j, float k)
Initialize the real and imaginary coefficients.
Definition: quatf.h:62
GfQuatf & operator-=(const GfQuatf &q)
Component-wise unary difference operator.
Definition: quatf.h:196
GF_API GfVec3f Transform(const GfVec3f &point) const
Transform the GfVec3f point.
GfQuatf()=default
GfQuatf value-initializes to zero and performs no default initialization, like float or double.
static GfQuatf GetZero()
Return the zero quaternion, with real coefficient 0 and an imaginary coefficients all zero.
Definition: quatf.h:82
GfQuatf GetInverse() const
Return this quaternion's inverse, or reciprocal.
Definition: quatf.h:133
GF_API GfQuatf(class GfQuath const &other)
Implicitly convert from GfQuath.
GfQuatf GetConjugate() const
Return this quaternion's conjugate, which is the quaternion with the same real coefficient and negate...
Definition: quatf.h:127
GfQuatf GetNormalized(float eps=GF_MIN_VECTOR_LENGTH) const
length of this quaternion is smaller than eps, return the identity quaternion.
Definition: quatf.h:113
void SetImaginary(const GfVec3f &imaginary)
Set the imaginary coefficients.
Definition: quatf.h:98
friend GfQuatf operator/(const GfQuatf &q, float s)
Returns the product of quaternion q and scalar 1 / s.
Definition: quatf.h:234
friend GfQuatf operator+(const GfQuatf &q1, const GfQuatf &q2)
Component-wise binary sum operator.
Definition: quatf.h:204
friend GfQuatf operator*(const GfQuatf &q1, const GfQuatf &q2)
Returns the product of quaternions q1 and q2.
Definition: quatf.h:216
GfQuatf operator-() const
Component-wise negation.
Definition: quatf.h:153
GfQuatf & operator+=(const GfQuatf &q)
Add quaternion q to this quaternion.
Definition: quatf.h:189
bool operator!=(const GfQuatf &q) const
Component-wise quaternion inequality test.
Definition: quatf.h:166
static GfQuatf GetIdentity()
Return the identity quaternion, with real coefficient 1 and an imaginary coefficients all zero.
Definition: quatf.h:86
GfQuatf(float real, const GfVec3f &imaginary)
Initialize the real and imaginary coefficients.
Definition: quatf.h:68
const GfVec3f & GetImaginary() const
Return the imaginary coefficient.
Definition: quatf.h:95
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients,...
Definition: quath.h:44
Basic type for a vector of 3 float components.
Definition: vec3f.h:46
GfVec3f & Set(float s0, float s1, float s2)
Set all elements with passed arguments.
Definition: vec3f.h:113
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].
float GfDot(const GfQuatf &q1, const GfQuatf &q2)
Return the dot (inner) product of two quaternions.
Definition: quatf.h:263
GF_API GfQuatf GfSlerp(double alpha, const GfQuatf &q0, const GfQuatf &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