1 | /**********************************************************************
|
---|
2 | *<
|
---|
3 | FILE: quat.h
|
---|
4 |
|
---|
5 | DESCRIPTION: Class definitions for Quat
|
---|
6 |
|
---|
7 | CREATED BY: Dan Silva
|
---|
8 |
|
---|
9 | HISTORY:
|
---|
10 |
|
---|
11 | *> Copyright (c) 1994, All Rights Reserved.
|
---|
12 | **********************************************************************/
|
---|
13 | #ifndef _QUAT_H
|
---|
14 |
|
---|
15 | #define _QUAT_H
|
---|
16 |
|
---|
17 | #include "matrix3.h"
|
---|
18 |
|
---|
19 | class ostream;
|
---|
20 | class Quat;
|
---|
21 |
|
---|
22 | class AngAxis {
|
---|
23 | public:
|
---|
24 | Point3 axis;
|
---|
25 | float angle;
|
---|
26 |
|
---|
27 | AngAxis() {}
|
---|
28 | AngAxis(const Point3& axis,float angle) {this->axis=axis;this->angle=angle;}
|
---|
29 | DllExport AngAxis(const Quat &q);
|
---|
30 | DllExport int GetNumRevs();
|
---|
31 | DllExport void SetNumRevs(int num);
|
---|
32 | };
|
---|
33 |
|
---|
34 | class Quat {
|
---|
35 | public:
|
---|
36 | float x,y,z,w;
|
---|
37 |
|
---|
38 | // Constructors
|
---|
39 | Quat(){}
|
---|
40 | Quat(float X, float Y, float Z, float W) { x = X; y = Y; z = Z; w = W; }
|
---|
41 | Quat(double X, double Y, double Z, double W) {
|
---|
42 | x = (float)X; y = (float)Y; z = (float)Z; w = (float)W;
|
---|
43 | }
|
---|
44 | Quat(const Quat& a) { x = a.x; y = a.y; z = a.z; w = a.w; }
|
---|
45 | Quat(float af[4]) { x = af[0]; y = af[1]; z = af[2]; w = af[3]; }
|
---|
46 | DllExport Quat(const Matrix3& mat);
|
---|
47 | DllExport Quat(const AngAxis& aa);
|
---|
48 |
|
---|
49 | // Access operators
|
---|
50 | float& operator[](int i) { return (&x)[i]; }
|
---|
51 | const float& operator[](int i) const { return (&x)[i]; }
|
---|
52 |
|
---|
53 | // Conversion function
|
---|
54 | operator float*() { return(&x); }
|
---|
55 |
|
---|
56 | // Unary operators
|
---|
57 | Quat operator-() const { return(Quat(-x,-y,-z,-w)); }
|
---|
58 | Quat operator+() const { return *this; }
|
---|
59 |
|
---|
60 | // Assignment operators
|
---|
61 | DllExport Quat& operator-=(const Quat&);
|
---|
62 | DllExport Quat& operator+=(const Quat&);
|
---|
63 | DllExport Quat& operator*=(const Quat&);
|
---|
64 | DllExport Quat& operator*=(float);
|
---|
65 | DllExport Quat& operator/=(float);
|
---|
66 |
|
---|
67 | DllExport Quat& MakeClosest(const Quat& qto);
|
---|
68 |
|
---|
69 | // Comparison
|
---|
70 | DllExport int operator==(const Quat& a) const;
|
---|
71 |
|
---|
72 | void Identity() { x = y = z = (float)0.0; w = (float) 1.0; }
|
---|
73 | DllExport int IsIdentity() const;
|
---|
74 | DllExport void Normalize(); // normalize
|
---|
75 | DllExport void MakeMatrix(Matrix3 &mat) const;
|
---|
76 |
|
---|
77 | // Binary operators
|
---|
78 | DllExport Quat operator-(const Quat&) const; //RB: Changed these to // difference of two quaternions
|
---|
79 | DllExport Quat operator+(const Quat&) const; // duplicate * and / // sum of two quaternions
|
---|
80 | DllExport Quat operator*(const Quat&) const; // product of two quaternions
|
---|
81 | DllExport Quat operator/(const Quat&) const; // ratio of two quaternions
|
---|
82 | };
|
---|
83 |
|
---|
84 | Quat DllExport operator*(float, const Quat&); // multiply by scalar
|
---|
85 | Quat DllExport operator*(const Quat&, float); // multiply by scalar
|
---|
86 | Quat DllExport operator/(const Quat&, float); // divide by scalar
|
---|
87 | Quat DllExport Inverse(const Quat& q); // Inverse of quaternion (1/q)
|
---|
88 | Quat DllExport Conjugate(const Quat& q);
|
---|
89 | Quat DllExport LogN(const Quat& q);
|
---|
90 | Quat DllExport Exp(const Quat& q);
|
---|
91 | Quat DllExport Slerp(const Quat& p, const Quat& q, float t);
|
---|
92 | Quat DllExport LnDif(const Quat& p, const Quat& q);
|
---|
93 | Quat DllExport QCompA(const Quat& qprev,const Quat& q, const Quat& qnext);
|
---|
94 | Quat DllExport Squad(const Quat& p, const Quat& a, const Quat &b, const Quat& q, float t);
|
---|
95 | Quat DllExport qorthog(const Quat& p, const Point3& axis);
|
---|
96 | Quat DllExport squadrev(
|
---|
97 | float angle, // angle of rotation
|
---|
98 | const Point3& axis, // the axis of rotation
|
---|
99 | const Quat& p, // start quaternion
|
---|
100 | const Quat& a, // start tangent quaternion
|
---|
101 | const Quat& b, // end tangent quaternion
|
---|
102 | const Quat& q, // end quaternion
|
---|
103 | float t // parameter, in range [0.0,1.0]
|
---|
104 | );
|
---|
105 |
|
---|
106 | void DllExport RotateMatrix(Matrix3& mat, const Quat& q);
|
---|
107 | void DllExport PreRotateMatrix(Matrix3& mat, const Quat& q);
|
---|
108 | Quat DllExport QFromAngAxis(float ang, const Point3& axis);
|
---|
109 | void DllExport AngAxisFromQ(const Quat& q, float *ang, Point3& axis);
|
---|
110 | float DllExport QangAxis(const Quat& p, const Quat& q, Point3& axis);
|
---|
111 | void DllExport DecomposeMatrix(const Matrix3& mat, Point3& p, Quat& q, Point3& s);
|
---|
112 | Quat DllExport TransformQuat(const Matrix3 &m, const Quat&q );
|
---|
113 | inline Quat IdentQuat() { return(Quat(0.0,0.0,0.0,1.0)); }
|
---|
114 |
|
---|
115 | // Assumes Euler angles are of the form:
|
---|
116 | // RotateX(ang[0])
|
---|
117 | // RotateY(ang[1])
|
---|
118 | // RotateZ(ang[2])
|
---|
119 | //
|
---|
120 | void DllExport QuatToEuler(Quat &q, float *ang);
|
---|
121 | void DllExport EulerToQuat(float *ang, Quat &q);
|
---|
122 |
|
---|
123 | ostream DllExport &operator<<(ostream&, const Quat&);
|
---|
124 |
|
---|
125 | #endif _QUAT_H
|
---|