| 1 |
|
#ifndef _QUATERNION_H_ |
| 2 |
|
#define _QUATERNION_H_ |
| 3 |
|
#include <iostream> |
| 4 |
+ |
#include "Vector4d.hpp" |
| 5 |
|
using namespace std; |
| 6 |
|
|
| 7 |
|
class Mat3x3d; |
| 8 |
|
class Euler3; |
| 9 |
|
class Vector3d; |
| 10 |
|
|
| 11 |
< |
class Quaternion{ |
| 11 |
> |
class Quaternion : public Vector4d{ |
| 12 |
|
public: |
| 13 |
|
Quaternion(){ |
| 14 |
+ |
x = 1.0; |
| 15 |
+ |
y = 0.0; |
| 16 |
+ |
z = 0.0; |
| 17 |
+ |
w = 0.0; |
| 18 |
|
} |
| 19 |
|
|
| 15 |
– |
Quaternion(double x, double y, double z, double w){ |
| 16 |
– |
this->x = x; |
| 17 |
– |
this->y = y; |
| 18 |
– |
this->z = z; |
| 19 |
– |
this->w = w; |
| 20 |
– |
} |
| 21 |
– |
|
| 22 |
– |
Quaternion(const Quaternion& q){ |
| 23 |
– |
this->x = q.x; |
| 24 |
– |
this->y = q.y; |
| 25 |
– |
this->z = q.z; |
| 26 |
– |
this->w = q.w; |
| 27 |
– |
} |
| 28 |
– |
|
| 20 |
|
Quaternion(Mat3x3d& m); |
| 21 |
|
|
| 22 |
|
Quaternion(const Euler3& e); |
| 32 |
– |
|
| 33 |
– |
inline double& operator[](unsigned int i) { |
| 34 |
– |
switch (i){ |
| 35 |
– |
case 0: |
| 36 |
– |
return x; |
| 37 |
– |
case 1: |
| 38 |
– |
return y; |
| 39 |
– |
case 2: |
| 40 |
– |
return z; |
| 41 |
– |
case 3: |
| 42 |
– |
return w; |
| 43 |
– |
default: |
| 44 |
– |
cerr << "error in Quaternion::::operator[]" << endl |
| 45 |
– |
<< "The method has been called with an illegal index i=" << i << "." << endl; |
| 46 |
– |
exit(1); |
| 47 |
– |
} |
| 48 |
– |
} |
| 23 |
|
|
| 24 |
+ |
Quaternion& operator=( const Vector4d& v1 ){ |
| 25 |
+ |
if(this == & v1) |
| 26 |
+ |
return *this; |
| 27 |
+ |
|
| 28 |
+ |
this->x = v1.x; |
| 29 |
+ |
this->y = v1.y; |
| 30 |
+ |
this->z = v1.z; |
| 31 |
+ |
this->w = v1.w; |
| 32 |
+ |
|
| 33 |
+ |
return *this; |
| 34 |
+ |
} |
| 35 |
+ |
|
| 36 |
|
Mat3x3d toRotationMatrix(); |
| 37 |
|
Euler3 toEuler(); |
| 38 |
< |
|
| 53 |
< |
union{ |
| 54 |
< |
struct{ |
| 55 |
< |
double x; |
| 56 |
< |
double y; |
| 57 |
< |
double z; |
| 58 |
< |
double w; |
| 59 |
< |
}; |
| 60 |
< |
double quat[4]; |
| 61 |
< |
}; |
| 38 |
> |
|
| 39 |
|
}; |
| 40 |
|
|
| 41 |
|
#endif //end ifndef _QUATERNION_H_ |