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 
40 #include <boost/functional/hash.hpp>
41 
42 #include <iosfwd>
43 
44 PXR_NAMESPACE_OPEN_SCOPE
45 
46 template <>
47 struct GfIsGfQuat<class GfQuatf> { static const bool value = true; };
48 
49 
51 float GfDot(const GfQuatf& q1, const GfQuatf& q2);
52 
53 
60 class GfQuatf
61 {
62  public:
63  typedef float ScalarType;
64  typedef GfVec3f ImaginaryType;
65 
67  GfQuatf() {}
68 
76  explicit GfQuatf (float realVal) : _imaginary(0), _real(realVal) {}
77 
79  GfQuatf(float real, float i, float j, float k)
80  : _imaginary(i, j, k), _real(real)
81  {
82  }
83 
85  GfQuatf(float real, const GfVec3f &imaginary)
86  : _imaginary(imaginary), _real(real)
87  {
88  }
89 
91  GF_API
92  explicit GfQuatf(class GfQuatd const &other);
94  GF_API
95  GfQuatf(class GfQuath const &other);
96 
99  static GfQuatf GetZero() { return GfQuatf(0.0); }
100 
103  static GfQuatf GetIdentity() { return GfQuatf(1.0); }
104 
106  float GetReal() const { return _real; }
107 
109  void SetReal(float real) { _real = real; }
110 
112  const GfVec3f &GetImaginary() const { return _imaginary; }
113 
115  void SetImaginary(const GfVec3f &imaginary) {
116  _imaginary = imaginary;
117  }
118 
120  void SetImaginary(float i, float j, float k) {
121  _imaginary.Set(i, j, k);
122  }
123 
125  float GetLength() const { return GfSqrt(_GetLengthSquared()); }
126 
129  GfQuatf
130  GetNormalized(float eps = GF_MIN_VECTOR_LENGTH) const {
131  GfQuatf ret(*this);
132  ret.Normalize(eps);
133  return ret;
134  }
135 
139  GF_API
140  float Normalize(float eps = GF_MIN_VECTOR_LENGTH);
141 
145  return GfQuatf(GetReal(), -GetImaginary());
146  }
147 
150  GfQuatf GetInverse() const {
151  return GetConjugate() / _GetLengthSquared();
152  }
153 
161  GF_API
162  GfVec3f Transform(const GfVec3f& point) const;
163 
165  friend inline size_t hash_value(const GfQuatf &q) {
166  size_t h = boost::hash<ScalarType>()(q.GetReal());
167  boost::hash_combine(h, q.GetImaginary());
168  return h;
169  }
170 
172  GfQuatf operator-() const {
173  return GfQuatf(-GetReal(), -GetImaginary());
174  }
175 
178  bool operator==(const GfQuatf &q) const {
179  return (GetReal() == q.GetReal() &&
180  GetImaginary() == q.GetImaginary());
181  }
182 
185  bool operator!=(const GfQuatf &q) const {
186  return !(*this == q);
187  }
188 
190  GF_API
191  GfQuatf &operator *=(const GfQuatf &q);
192 
194  GfQuatf &operator *=(float s) {
195  _real *= s;
196  _imaginary *= s;
197  return *this;
198  }
199 
201  GfQuatf &operator /=(float s) {
202  _real /= s;
203  _imaginary /= s;
204  return *this;
205  }
206 
209  _real += q._real;
210  _imaginary += q._imaginary;
211  return *this;
212  }
213 
216  _real -= q._real;
217  _imaginary -= q._imaginary;
218  return *this;
219  }
220 
222  friend GfQuatf
223  operator +(const GfQuatf &q1, const GfQuatf &q2) {
224  return GfQuatf(q1) += q2;
225  }
226 
228  friend GfQuatf
229  operator -(const GfQuatf &q1, const GfQuatf &q2) {
230  return GfQuatf(q1) -= q2;
231  }
232 
234  friend GfQuatf
235  operator *(const GfQuatf &q1, const GfQuatf &q2) {
236  return GfQuatf(q1) *= q2;
237  }
238 
240  friend GfQuatf
241  operator *(const GfQuatf &q, float s) {
242  return GfQuatf(q) *= s;
243  }
244 
246  friend GfQuatf
247  operator *(float s, const GfQuatf &q) {
248  return GfQuatf(q) *= s;
249  }
250 
252  friend GfQuatf
253  operator /(const GfQuatf &q, float s) {
254  return GfQuatf(q) /= s;
255  }
256 
257  private:
259  GfVec3f _imaginary;
260 
262  float _real;
263 
265  float
266  _GetLengthSquared() const {
267  return GfDot(*this, *this);
268  }
269 };
270 
275 GF_API GfQuatf
276 GfSlerp(double alpha, const GfQuatf& q0, const GfQuatf& q1);
277 
278 GF_API GfQuatf
279 GfSlerp(const GfQuatf& q0, const GfQuatf& q1, double alpha);
280 
281 inline float
282 GfDot(GfQuatf const &q1, GfQuatf const &q2) {
283  return GfDot(q1.GetImaginary(), q2.GetImaginary()) +
284  q1.GetReal()*q2.GetReal();
285 }
286 
289 GF_API std::ostream& operator<<(std::ostream &, GfQuatf const &);
290 
291 PXR_NAMESPACE_CLOSE_SCOPE
292 
293 #endif // PXR_BASE_GF_QUATF_H
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients,...
Definition: quath.h:61
GF_API GfQuatf & operator *=(const GfQuatf &q)
Post-multiply quaternion q into this quaternion.
GfQuatf operator-() const
Component-wise negation.
Definition: quatf.h:172
Basic type for a vector of 3 float components.
Definition: vec3f.h:63
friend GfQuatf operator *(const GfQuatf &q, float s)
Returns the product of quaternion q and scalar s.
Definition: quatf.h:241
Declares Gf types.
void SetImaginary(float i, float j, float k)
Set the imaginary coefficients.
Definition: quatf.h:120
bool operator==(const GfQuatf &q) const
Component-wise quaternion equality test.
Definition: quatf.h:178
GF_API GfQuatf GfSlerp(double alpha, const GfQuatf &q0, const GfQuatf &q1)
Spherically linearly interpolate between q0 and q1.
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients,...
Definition: quatf.h:60
static GfQuatf GetIdentity()
Return the identity quaternion, with real coefficient 1 and an imaginary coefficients all zero.
Definition: quatf.h:103
void SetReal(float real)
Set the real coefficient.
Definition: quatf.h:109
GfQuatf & operator -=(const GfQuatf &q)
Component-wise unary difference operator.
Definition: quatf.h:215
GfQuatf(float real, float i, float j, float k)
Initialize the real and imaginary coefficients.
Definition: quatf.h:79
GfQuatf & operator+=(const GfQuatf &q)
Add quaternion q to this quaternion.
Definition: quatf.h:208
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 GfVec3f Transform(const GfVec3f &point) const
Transform the GfVec3f point.
void SetImaginary(const GfVec3f &imaginary)
Set the imaginary coefficients.
Definition: quatf.h:115
bool operator!=(const GfQuatf &q) const
Component-wise quaternion inequality test.
Definition: quatf.h:185
GF_API std::ostream & operator<<(std::ostream &, GfQuatf const &)
Output a GfQuatd using the format (re, i, j, k)
GfQuatf()
Default constructor leaves the quaternion undefined.
Definition: quatf.h:67
GfVec3f & Set(float s0, float s1, float s2)
Set all elements with passed arguments.
Definition: vec3f.h:130
GfQuatf GetNormalized(float eps=GF_MIN_VECTOR_LENGTH) const
length of this quaternion is smaller than eps, return the identity quaternion.
Definition: quatf.h:130
float GetReal() const
Return the real coefficient.
Definition: quatf.h:106
float GfDot(const GfQuatf &q1, const GfQuatf &q2)
Return the dot (inner) product of two quaternions.
Definition: quatf.h:282
friend size_t hash_value(const GfQuatf &q)
Hash.
Definition: quatf.h:165
double GfSqrt(double f)
Return sqrt(f).
Definition: math.h:80
GfQuatf GetConjugate() const
Return this quaternion's conjugate, which is the quaternion with the same real coefficient and negate...
Definition: quatf.h:144
const GfVec3f & GetImaginary() const
Return the imaginary coefficient.
Definition: quatf.h:112
friend GfQuatf operator *(const GfQuatf &q1, const GfQuatf &q2)
Returns the product of quaternions q1 and q2.
Definition: quatf.h:235
GfQuatf & operator/=(float s)
Divide this quaternion's coefficients by s.
Definition: quatf.h:201
A metafunction with a static const bool member 'value' that is true for GfQuat types and false for al...
Definition: traits.h:47
float GetLength() const
Return geometric length of this quaternion.
Definition: quatf.h:125
GfQuatf & operator *=(float s)
Multiply this quaternion's coefficients by s.
Definition: quatf.h:194
friend GfQuatf operator *(float s, const GfQuatf &q)
Returns the product of quaternion q and scalar s.
Definition: quatf.h:247
GfQuatf GetInverse() const
Return this quaternion's inverse, or reciprocal.
Definition: quatf.h:150
friend GfQuatf operator+(const GfQuatf &q1, const GfQuatf &q2)
Component-wise binary sum operator.
Definition: quatf.h:223
static GfQuatf GetZero()
Return the zero quaternion, with real coefficient 0 and an imaginary coefficients all zero.
Definition: quatf.h:99
GfQuatf(float realVal)
Initialize the real coefficient to realVal and the imaginary coefficients to zero.
Definition: quatf.h:76
GfQuatf(float real, const GfVec3f &imaginary)
Initialize the real and imaginary coefficients.
Definition: quatf.h:85
friend GfQuatf operator -(const GfQuatf &q1, const GfQuatf &q2)
Component-wise binary difference operator.
Definition: quatf.h:229
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients,...
Definition: quatd.h:60
friend GfQuatf operator/(const GfQuatf &q, float s)
Returns the product of quaternion q and scalar 1 / s.
Definition: quatf.h:253
#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