HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HOM_Quaternion.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * COMMENTS:
7  */
8 
9 #ifndef __HOM_Quaternion_h__
10 #define __HOM_Quaternion_h__
11 
12 #include "HOM_API.h"
13 #include "HOM_Defines.h"
14 #include "HOM_Errors.h"
15 #include "HOM_Module.h"
16 #include "HOM_Vector3.h"
17 #include "HOM_PtrOrNull.h"
18 #include <UT/UT_Quaternion.h>
19 #include <vector>
20 #include <stdexcept>
21 
22 class HOM_Matrix3;
23 class HOM_Matrix4;
24 
25 SWIGOUT(%rename(Quaternion) HOM_Quaternion;)
26 
28 {
29 public:
31  : myQuaternion(0.0, 0.0, 0.0, 1.0)
32  { HOM_CONSTRUCT_OBJECT(this) }
33 
34  HOM_Quaternion(const std::vector<double> &sequence)
35  {
37  setTo(sequence);
38  }
39 
40  HOM_Quaternion(double x, double y, double z, double w)
41  : myQuaternion(x, y, z, w)
42  { HOM_CONSTRUCT_OBJECT(this) }
43 
44  HOM_Quaternion(double angle_in_deg, const std::vector<double> &axis)
45  {
46  setToAngleAxis(angle_in_deg, axis);
48  }
49 
50  HOM_Quaternion(HOM_Matrix3 &matrix3);
51  HOM_Quaternion(HOM_Matrix4 &matrix4);
52 
53  SWIGOUT(%ignore HOM_Quaternion(const UT_QuaternionD&);)
54  HOM_Quaternion(const UT_QuaternionD &quaternion)
55  : myQuaternion(quaternion)
56  { HOM_CONSTRUCT_OBJECT(this) }
57 
59  { HOM_DESTRUCT_OBJECT(this) }
60 
62  { return quaternion.myPointer &&
63  myQuaternion == quaternion.myPointer->myQuaternion; }
64 
66  { return !operator==(quaternion); }
67 
68  bool isAlmostEqual(HOM_Quaternion &quaternion, double tolerance=0.00001);
69 
70  // This method is deprecated.
71  bool almostEqual(HOM_Quaternion &quaternion, double tolerance=0.00001)
72  { return isAlmostEqual(quaternion, tolerance); }
73 
74  int __hash__();
77 
78  double __getitem__(int index);
79  void __setitem__(int index, double value);
80  int __len__()
81  { return 4; }
82 
83  void setTo(const std::vector<double> &tuple);
84 
85  void setToRotationMatrix(HOM_Matrix3 &matrix3);
86  void setToRotationMatrix(HOM_Matrix4 &matrix4);
87 
88  void setToAngleAxis(double angle_in_deg, const std::vector<double> &axis);
89 
90  void setToVectors(const HOM_Vector3 &v1, const HOM_Vector3 &v2);
91 
92  SWIGOUT(%kwargs setToEulerRotates;)
93  void setToEulerRotates(
94  const std::vector<double> &angles_in_deg,
95  const char *rotate_order="xyz");
96 
97  SWIGOUT(%ignore operator=;)
98  HOM_Quaternion &operator=(const HOM_Quaternion& quaternion)
99  {
100  myQuaternion = quaternion.myQuaternion;
101  return *this;
102  }
103 
104  HOM_Quaternion conjugate();
105  HOM_Quaternion inverse();
106  double dot(HOM_Quaternion &quaternion)
107  { return ::dot(myQuaternion, quaternion.myQuaternion); }
108 
110  { return HOM_Quaternion(myQuaternion + quaternion.myQuaternion); }
112  { return HOM_Quaternion(myQuaternion - quaternion.myQuaternion); }
113  HOM_Quaternion __mul__(double scalar)
114  { return HOM_Quaternion(myQuaternion * scalar); }
116 
117  HOM_Quaternion slerp(HOM_Quaternion &other, double fraction);
118 
119 
121 
122  double length()
123  { return myQuaternion.length(); }
124 
125 
126  SWIGOUT(%newobject extractRotationMatrix3;)
128 
129  std::pair<double, HOM_ElemPtr<HOM_Vector3> > extractAngleAxis();
130 
131  HOM_Vector3 extractEulerRotates(const char *rotate_order="xyz");
132 
133  HOM_Vector3 rotate(const HOM_Vector3 &v);
134 
136  { return &myQuaternion; }
137 
138 
139  SWIGOUT(%ignore myQuaternion;)
140  UT_QuaternionD myQuaternion;
141 };
142 
143 #endif
bool almostEqual(HOM_Quaternion &quaternion, double tolerance=0.00001)
bool operator==(HOM_PtrOrNull< HOM_Quaternion > quaternion)
HOM_Quaternion(double x, double y, double z, double w)
double dot(HOM_Quaternion &quaternion)
#define HOM_DESTRUCT_OBJECT(pointer)
Definition: HOM_Module.h:1056
HOM_Quaternion __sub__(HOM_Quaternion &quaternion)
const GLdouble * v
Definition: glcorearb.h:836
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:847
#define SWIGOUT(x)
Definition: HOM_Defines.h:24
string __repr__(VtArray< T > const &self)
Definition: wrapArray.h:344
GLint y
Definition: glcorearb.h:102
HOM_Quaternion(double angle_in_deg, const std::vector< double > &axis)
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:817
HOM_Quaternion(const std::vector< double > &sequence)
void * _asVoidPointer()
std::string __str__()
Quat< T > slerp(const Quat< T > &q1, const Quat< T > &q2, T t)
Definition: ImathQuat.h:495
#define HOM_API
Definition: HOM_API.h:13
fpreal64 dot(const CE_VectorT< T > &a, const CE_VectorT< T > &b)
Definition: CE_Vector.h:218
#define HOM_CONSTRUCT_OBJECT(pointer)
Definition: HOM_Module.h:1055
HOM_Quaternion __add__(HOM_Quaternion &quaternion)
int __hash__()
HOM_Matrix3 * extractRotationMatrix3()
GLint GLenum GLboolean normalized
Definition: glcorearb.h:871
HOM_Quaternion __mul__(double scalar)
void setTo(const std::vector< double > &sequence)
GLsizei const GLfloat * value
Definition: glcorearb.h:823
HOM_Matrix4 __mul__(HOM_Matrix4 &matrix4)
Definition: HOM_Matrix4.h:104
bool isAlmostEqual(HOM_Matrix4 &matrix4, double tolerance=0.00001)
HOM_Quaternion(const UT_QuaternionD &quaternion)
GLuint index
Definition: glcorearb.h:785
GLint GLenum GLint x
Definition: glcorearb.h:408
GLfloat GLfloat v1
Definition: glcorearb.h:816
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
UT_QuaternionD myQuaternion
bool operator!=(HOM_PtrOrNull< HOM_Quaternion > quaternion)
bool operator==(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Equality operator, does exact floating point comparisons.
Definition: Mat3.h:590