Loading...
Searching...
No Matches
quatf.h
Go to the documentation of this file.
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the Apache License, Version 2.0 (the "Apache License")
5// with the following modification; you may not use this file except in
6// compliance with the Apache License and the following modification to it:
7// Section 6. Trademarks. is deleted and replaced with:
8//
9// 6. Trademarks. This License does not grant permission to use the trade
10// names, trademarks, service marks, or product names of the Licensor
11// and its affiliates, except as required to comply with Section 4(c) of
12// the License and to reproduce the content of the NOTICE file.
13//
14// You may obtain a copy of the Apache License at
15//
16// http://www.apache.org/licenses/LICENSE-2.0
17//
18// Unless required by applicable law or agreed to in writing, software
19// distributed under the Apache License with the above modification is
20// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21// KIND, either express or implied. See the Apache License for the specific
22// language governing permissions and limitations under the Apache License.
23//
25// This file is generated by a script. Do not edit directly. Edit the
26// quat.template.h file to make changes.
27
28#ifndef PXR_BASE_GF_QUATF_H
29#define PXR_BASE_GF_QUATF_H
30
33
34#include "pxr/pxr.h"
35#include "pxr/base/gf/api.h"
36#include "pxr/base/gf/declare.h"
37#include "pxr/base/gf/vec3f.h"
38#include "pxr/base/gf/traits.h"
39#include "pxr/base/tf/hash.h"
40
41#include <iosfwd>
42
43PXR_NAMESPACE_OPEN_SCOPE
44
45template <>
46struct GfIsGfQuat<class GfQuatf> { static const bool value = true; };
47
48
50float GfDot(const GfQuatf& q1, const GfQuatf& q2);
51
52
60{
61 public:
62 typedef float ScalarType;
63 typedef GfVec3f ImaginaryType;
64
67
75 explicit GfQuatf (float realVal) : _imaginary(0), _real(realVal) {}
76
78 GfQuatf(float real, float i, float j, float k)
79 : _imaginary(i, j, k), _real(real)
80 {
81 }
82
84 GfQuatf(float real, const GfVec3f &imaginary)
85 : _imaginary(imaginary), _real(real)
86 {
87 }
88
90 GF_API
91 explicit GfQuatf(class GfQuatd const &other);
93 GF_API
94 GfQuatf(class GfQuath const &other);
95
98 static GfQuatf GetZero() { return GfQuatf(0.0); }
99
102 static GfQuatf GetIdentity() { return GfQuatf(1.0); }
103
105 float GetReal() const { return _real; }
106
108 void SetReal(float real) { _real = real; }
109
111 const GfVec3f &GetImaginary() const { return _imaginary; }
112
114 void SetImaginary(const GfVec3f &imaginary) {
115 _imaginary = imaginary;
116 }
117
119 void SetImaginary(float i, float j, float k) {
120 _imaginary.Set(i, j, k);
121 }
122
124 float GetLength() const { return GfSqrt(_GetLengthSquared()); }
125
128 GfQuatf
130 GfQuatf ret(*this);
131 ret.Normalize(eps);
132 return ret;
133 }
134
138 GF_API
139 float Normalize(float eps = GF_MIN_VECTOR_LENGTH);
140
144 return GfQuatf(GetReal(), -GetImaginary());
145 }
146
150 return GetConjugate() / _GetLengthSquared();
151 }
152
160 GF_API
161 GfVec3f Transform(const GfVec3f& point) const;
162
164 friend inline size_t hash_value(const GfQuatf &q) {
165 return TfHash::Combine(q.GetReal(), q.GetImaginary());
166 }
167
170 return GfQuatf(-GetReal(), -GetImaginary());
171 }
172
175 bool operator==(const GfQuatf &q) const {
176 return (GetReal() == q.GetReal() &&
177 GetImaginary() == q.GetImaginary());
178 }
179
182 bool operator!=(const GfQuatf &q) const {
183 return !(*this == q);
184 }
185
187 GF_API
189
192 _real *= s;
193 _imaginary *= s;
194 return *this;
195 }
196
199 _real /= s;
200 _imaginary /= s;
201 return *this;
202 }
203
206 _real += q._real;
207 _imaginary += q._imaginary;
208 return *this;
209 }
210
213 _real -= q._real;
214 _imaginary -= q._imaginary;
215 return *this;
216 }
217
219 friend GfQuatf
220 operator +(const GfQuatf &q1, const GfQuatf &q2) {
221 return GfQuatf(q1) += q2;
222 }
223
225 friend GfQuatf
226 operator -(const GfQuatf &q1, const GfQuatf &q2) {
227 return GfQuatf(q1) -= q2;
228 }
229
231 friend GfQuatf
232 operator *(const GfQuatf &q1, const GfQuatf &q2) {
233 return GfQuatf(q1) *= q2;
234 }
235
237 friend GfQuatf
238 operator *(const GfQuatf &q, float s) {
239 return GfQuatf(q) *= s;
240 }
241
243 friend GfQuatf
244 operator *(float s, const GfQuatf &q) {
245 return GfQuatf(q) *= s;
246 }
247
249 friend GfQuatf
250 operator /(const GfQuatf &q, float s) {
251 return GfQuatf(q) /= s;
252 }
253
254 private:
256 GfVec3f _imaginary;
257
259 float _real;
260
262 float
263 _GetLengthSquared() const {
264 return GfDot(*this, *this);
265 }
266};
267
272GF_API GfQuatf
273GfSlerp(double alpha, const GfQuatf& q0, const GfQuatf& q1);
274
275GF_API GfQuatf
276GfSlerp(const GfQuatf& q0, const GfQuatf& q1, double alpha);
277
278inline float
279GfDot(GfQuatf const &q1, GfQuatf const &q2) {
280 return GfDot(q1.GetImaginary(), q2.GetImaginary()) +
281 q1.GetReal()*q2.GetReal();
282}
283
286GF_API std::ostream& operator<<(std::ostream &, GfQuatf const &);
287
288PXR_NAMESPACE_CLOSE_SCOPE
289
290#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:60
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients,...
Definition: quatf.h:60
GF_API GfQuatf(class GfQuatd const &other)
Construct from GfQuatd.
friend size_t hash_value(const GfQuatf &q)
Hash.
Definition: quatf.h:164
bool operator==(const GfQuatf &q) const
Component-wise quaternion equality test.
Definition: quatf.h:175
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:75
GfQuatf & operator/=(float s)
Divide this quaternion's coefficients by s.
Definition: quatf.h:198
void SetReal(float real)
Set the real coefficient.
Definition: quatf.h:108
void SetImaginary(float i, float j, float k)
Set the imaginary coefficients.
Definition: quatf.h:119
float GetLength() const
Return geometric length of this quaternion.
Definition: quatf.h:124
float GetReal() const
Return the real coefficient.
Definition: quatf.h:105
GfQuatf(float real, float i, float j, float k)
Initialize the real and imaginary coefficients.
Definition: quatf.h:78
GfQuatf & operator-=(const GfQuatf &q)
Component-wise unary difference operator.
Definition: quatf.h:212
GF_API GfVec3f Transform(const GfVec3f &point) const
Transform the GfVec3f point.
static GfQuatf GetZero()
Return the zero quaternion, with real coefficient 0 and an imaginary coefficients all zero.
Definition: quatf.h:98
GfQuatf()
Default constructor leaves the quaternion undefined.
Definition: quatf.h:66
GfQuatf GetInverse() const
Return this quaternion's inverse, or reciprocal.
Definition: quatf.h:149
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:143
GfQuatf GetNormalized(float eps=GF_MIN_VECTOR_LENGTH) const
length of this quaternion is smaller than eps, return the identity quaternion.
Definition: quatf.h:129
void SetImaginary(const GfVec3f &imaginary)
Set the imaginary coefficients.
Definition: quatf.h:114
friend GfQuatf operator/(const GfQuatf &q, float s)
Returns the product of quaternion q and scalar 1 / s.
Definition: quatf.h:250
friend GfQuatf operator+(const GfQuatf &q1, const GfQuatf &q2)
Component-wise binary sum operator.
Definition: quatf.h:220
friend GfQuatf operator*(const GfQuatf &q1, const GfQuatf &q2)
Returns the product of quaternions q1 and q2.
Definition: quatf.h:232
GfQuatf operator-() const
Component-wise negation.
Definition: quatf.h:169
GfQuatf & operator+=(const GfQuatf &q)
Add quaternion q to this quaternion.
Definition: quatf.h:205
bool operator!=(const GfQuatf &q) const
Component-wise quaternion inequality test.
Definition: quatf.h:182
static GfQuatf GetIdentity()
Return the identity quaternion, with real coefficient 1 and an imaginary coefficients all zero.
Definition: quatf.h:102
GfQuatf(float real, const GfVec3f &imaginary)
Initialize the real and imaginary coefficients.
Definition: quatf.h:84
const GfVec3f & GetImaginary() const
Return the imaginary coefficient.
Definition: quatf.h:111
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients,...
Definition: quath.h:61
Basic type for a vector of 3 float components.
Definition: vec3f.h:63
GfVec3f & Set(float s0, float s1, float s2)
Set all elements with passed arguments.
Definition: vec3f.h:129
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:492
double GfSqrt(double f)
Return sqrt(f).
Definition: math.h:80
#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:34
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:279
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:47