forked from PixarAnimationStudios/OpenUSD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquatd.h
279 lines (228 loc) · 8.28 KB
/
quatd.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
////////////////////////////////////////////////////////////////////////
// This file is generated by a script. Do not edit directly. Edit the
// quat.template.h file to make changes.
#ifndef GF_QUATD_H
#define GF_QUATD_H
/// \file gf/quatd.h
/// \ingroup group_gf_LinearAlgebra
#include "pxr/pxr.h"
#include "pxr/base/gf/api.h"
#include "pxr/base/gf/declare.h"
#include "pxr/base/gf/vec3d.h"
#include "pxr/base/gf/traits.h"
#include <boost/functional/hash.hpp>
#include <iosfwd>
PXR_NAMESPACE_OPEN_SCOPE
template <>
struct GfIsGfQuat<class GfQuatd> { static const bool value = true; };
/// Return the dot (inner) product of two quaternions.
double GfDot(const GfQuatd& q1, const GfQuatd& q2);
/// \class GfQuatd
/// \ingroup group_gf_LinearAlgebra
///
/// Basic type: a quaternion, a complex number with a real coefficient and
/// three imaginary coefficients, stored as a 3-vector.
///
class GfQuatd
{
public:
typedef double ScalarType;
typedef GfVec3d ImaginaryType;
/// Default constructor leaves the quaternion undefined.
GfQuatd() {}
/// Initialize the real coefficient to \p realVal and the imaginary
/// coefficients to zero.
///
/// Since quaternions typically must be normalized, reasonable values for
/// \p realVal are -1, 0, or 1. Other values are legal but are likely to
/// be meaningless.
///
explicit GfQuatd (double realVal) : _imaginary(0), _real(realVal) {}
/// Initialize the real and imaginary coefficients.
GfQuatd(double real, double i, double j, double k)
: _imaginary(i, j, k), _real(real)
{
}
/// Initialize the real and imaginary coefficients.
GfQuatd(double real, const GfVec3d &imaginary)
: _imaginary(imaginary), _real(real)
{
}
/// Implicitly convert from GfQuatf.
GF_API
GfQuatd(class GfQuatf const &other);
/// Implicitly convert from GfQuath.
GF_API
GfQuatd(class GfQuath const &other);
/// Return the identity quaternion, with real coefficient 1 and an
/// imaginary coefficients all zero.
static GfQuatd GetIdentity() { return GfQuatd(1.0); }
/// Return the real coefficient.
double GetReal() const { return _real; }
/// Set the real coefficient.
void SetReal(double real) { _real = real; }
/// Return the imaginary coefficient.
const GfVec3d &GetImaginary() const { return _imaginary; }
/// Set the imaginary coefficients.
void SetImaginary(const GfVec3d &imaginary) {
_imaginary = imaginary;
}
/// Set the imaginary coefficients.
void SetImaginary(double i, double j, double k) {
_imaginary.Set(i, j, k);
}
/// Return geometric length of this quaternion.
double GetLength() const { return GfSqrt(_GetLengthSquared()); }
/// length of this quaternion is smaller than \p eps, return the identity
/// quaternion.
GfQuatd
GetNormalized(double eps = GF_MIN_VECTOR_LENGTH) const {
GfQuatd ret(*this);
ret.Normalize(eps);
return ret;
}
/// Normalizes this quaternion in place to unit length, returning the
/// length before normalization. If the length of this quaternion is
/// smaller than \p eps, this sets the quaternion to identity.
GF_API
double Normalize(double eps = GF_MIN_VECTOR_LENGTH);
/// Return this quaternion's conjugate, which is the quaternion with the
/// same real coefficient and negated imaginary coefficients.
GfQuatd GetConjugate() const {
return GfQuatd(GetReal(), -GetImaginary());
}
/// Return this quaternion's inverse, or reciprocal. This is the
/// quaternion's conjugate divided by it's squared length.
GfQuatd GetInverse() const {
return GetConjugate() / _GetLengthSquared();
}
/// Hash.
friend inline size_t hash_value(const GfQuatd &q) {
size_t h = boost::hash<ScalarType>()(q.GetReal());
boost::hash_combine(h, q.GetImaginary());
return h;
}
/// Component-wise negation.
GfQuatd operator-() const {
return GfQuatd(-GetReal(), -GetImaginary());
}
/// Component-wise quaternion equality test. The real and imaginary parts
/// must match exactly for quaternions to be considered equal.
bool operator==(const GfQuatd &q) const {
return (GetReal() == q.GetReal() &&
GetImaginary() == q.GetImaginary());
}
/// Component-wise quaternion inequality test. The real and imaginary
/// parts must match exactly for quaternions to be considered equal.
bool operator!=(const GfQuatd &q) const {
return !(*this == q);
}
/// Post-multiply quaternion \p q into this quaternion.
GF_API
GfQuatd &operator *=(const GfQuatd &q);
/// Multiply this quaternion's coefficients by \p s.
GfQuatd &operator *=(double s) {
_real *= s;
_imaginary *= s;
return *this;
}
/// Divide this quaternion's coefficients by \p s.
GfQuatd &operator /=(double s) {
_real /= s;
_imaginary /= s;
return *this;
}
/// Add quaternion \p q to this quaternion.
GfQuatd &operator +=(const GfQuatd &q) {
_real += q._real;
_imaginary += q._imaginary;
return *this;
}
/// Component-wise unary difference operator.
GfQuatd &operator -=(const GfQuatd &q) {
_real -= q._real;
_imaginary -= q._imaginary;
return *this;
}
/// Component-wise binary sum operator.
friend GfQuatd
operator +(const GfQuatd &q1, const GfQuatd &q2) {
return GfQuatd(q1) += q2;
}
/// Component-wise binary difference operator.
friend GfQuatd
operator -(const GfQuatd &q1, const GfQuatd &q2) {
return GfQuatd(q1) -= q2;
}
/// Returns the product of quaternions \p q1 and \p q2.
friend GfQuatd
operator *(const GfQuatd &q1, const GfQuatd &q2) {
return GfQuatd(q1) *= q2;
}
/// Returns the product of quaternion \p q and scalar \p s.
friend GfQuatd
operator *(const GfQuatd &q, double s) {
return GfQuatd(q) *= s;
}
/// Returns the product of quaternion \p q and scalar \p s.
friend GfQuatd
operator *(double s, const GfQuatd &q) {
return GfQuatd(q) *= s;
}
/// Returns the product of quaternion \p q and scalar 1 / \p s.
friend GfQuatd
operator /(const GfQuatd &q, double s) {
return GfQuatd(q) /= s;
}
private:
/// Imaginary part
GfVec3d _imaginary;
/// Real part
double _real;
/// Returns the square of the length
double
_GetLengthSquared() const {
return GfDot(*this, *this);
}
};
/// Spherically linearly interpolate between \p q0 and \p q1.
///
/// If the interpolant \p alpha is zero, then the result is \p q0, while
/// \p alpha of one yields \p q1.
GF_API GfQuatd
GfSlerp(double alpha, const GfQuatd& q0, const GfQuatd& q1);
GF_API GfQuatd
GfSlerp(const GfQuatd& q0, const GfQuatd& q1, double alpha);
inline double
GfDot(GfQuatd const &q1, GfQuatd const &q2) {
return GfDot(q1.GetImaginary(), q2.GetImaginary()) +
q1.GetReal()*q2.GetReal();
}
/// Output a GfQuatd using the format (re, i, j, k)
/// \ingroup group_gf_DebuggingOutput
GF_API std::ostream& operator<<(std::ostream &, GfQuatd const &);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // GF_QUATD_H