117 double a_z) :
w(a_w),
x(a_x),
y(a_y),
z(a_z) {}
130 inline operator double*() {
return &
w;}
133 inline operator double const*()
const {
return &
w;}
138 double neww =
w*a_quaternion.
w -
x*a_quaternion.
x -
y*a_quaternion.
y -
z*a_quaternion.
z;
139 double newx =
w*a_quaternion.
x +
x*a_quaternion.
w +
y*a_quaternion.
z -
z*a_quaternion.
y;
140 double newy =
w*a_quaternion.
y -
x*a_quaternion.
z +
y*a_quaternion.
w +
z*a_quaternion.
x;
141 double newz =
w*a_quaternion.
z +
x*a_quaternion.
y -
y*a_quaternion.
x +
z*a_quaternion.
w;
183 return ( (
w==a_quaternion.
w) &&
184 (
x==a_quaternion.
x) &&
185 (
y==a_quaternion.
y) &&
186 (
z==a_quaternion.
z) );
209 inline double mag()
const {
return sqrt(
magsq()); }
250 a_matrix(0,0) = 1.0 - y2 - z2;
251 a_matrix(0,1) = xy - wz;
252 a_matrix(0,2) = xz + wy;
253 a_matrix(1,0) = xy + wz;
254 a_matrix(1,1) = 1.0 - x2 - z2;
255 a_matrix(1,2) = yz - wx;
256 a_matrix(2,0) = xz - wy;
257 a_matrix(2,1) = yz + wx;
258 a_matrix(2,2) = 1.0 - x2 - y2;
276 double trace = 1.0 + a_matrix(0,0) + a_matrix(1,1) + a_matrix(2,2);
280 double s = 2.0*sqrt(trace);
281 x = (a_matrix(2,1) - a_matrix(1,2))/s;
282 y = (a_matrix(0,2) - a_matrix(2,0))/s;
283 z = (a_matrix(1,0) - a_matrix(0,1))/s;
286 else if ((a_matrix(0,0) > a_matrix(1,1)) && (a_matrix(0,0) > a_matrix(2,2)))
289 double s = 2.0*sqrt(1.0+a_matrix(0,0)-a_matrix(1,1)-a_matrix(2,2));
291 y = (a_matrix(1,0) + a_matrix(0,1))/s;
292 z = (a_matrix(0,2) + a_matrix(2,0))/s;
293 w = (a_matrix(2,1) - a_matrix(1,2))/s;
295 else if (a_matrix(1,1) > a_matrix(2,2))
298 double s = 2.0*sqrt(1.0+a_matrix(1,1)-a_matrix(0,0)-a_matrix(2,2));
299 x = (a_matrix(1,0) + a_matrix(0,1))/s;
301 z = (a_matrix(2,1) + a_matrix(1,2))/s;
302 w = (a_matrix(0,2) - a_matrix(2,0))/s;
307 double s = 2.0*sqrt(1.0+a_matrix(2,2)-a_matrix(0,0)-a_matrix(1,1));
308 x = (a_matrix(0,2) + a_matrix(2,0))/s;
309 y = (a_matrix(2,1) + a_matrix(1,2))/s;
311 w = (a_matrix(1,0) - a_matrix(0,1))/s;
334 double sina = sin(a_angleRad / 2.0);
335 double cosa = cos(a_angleRad / 2.0);
337 x = a_axis(0) * sina;
338 y = a_axis(1) * sina;
339 z = a_axis(2) * sina;
361 double cosa =
w /
mag();
362 a_angleRad = acos(cosa);
424 double neww =
w*a_quaternion.
w -
x*a_quaternion.
x -
y*a_quaternion.
y -
z*a_quaternion.
z;
425 double newx =
w*a_quaternion.
x +
x*a_quaternion.
w +
y*a_quaternion.
z -
z*a_quaternion.
y;
426 double newy =
w*a_quaternion.
y -
x*a_quaternion.
z +
y*a_quaternion.
w +
z*a_quaternion.
x;
427 double newz =
w*a_quaternion.
z +
x*a_quaternion.
y -
y*a_quaternion.
x +
z*a_quaternion.
w;
449 inline void mul(
double a_scale)
476 return (
w*a_quaternion.
w +
x*a_quaternion.
x +
y*a_quaternion.
y +
z*a_quaternion.
z);
551 double costheta = a_quaternion0.
dot(a_quaternion1);
552 if ((costheta-1.0) < 1e-4 && (costheta-1.0) > -1e-4)
556 *
this = a_quaternion0;
557 this->
mul(1.0-a_level);
558 a_quaternion1.
mul(a_level);
564 double ratio1, ratio2;
565 if ((costheta+1.0) > -1e-4 && (costheta+1.0) < 1e-4)
569 a_quaternion1.
w = a_quaternion0.
z;
570 a_quaternion1.
x = -a_quaternion0.
y;
571 a_quaternion1.
y = a_quaternion0.
x;
572 a_quaternion1.
z = -a_quaternion0.
w;
573 ratio1 = sin(
C_PI*(0.5-a_level));
574 ratio2 = sin(
C_PI*a_level);
580 costheta = -costheta;
583 double theta = acos(costheta);
584 double sintheta = sin(theta);
586 ratio1 = sin(theta*(1.0-a_level))/sintheta;
587 ratio2 = sin(theta*a_level)/sintheta;
589 *
this = a_quaternion0;
591 a_quaternion1.
mul(ratio2);
611 inline std::string
str(
const unsigned int a_precision = 2)
const
615 cStr(
w, a_precision) +
"| " +
616 cStr(
x, a_precision) +
", " +
617 cStr(
y, a_precision) +
", " +
618 cStr(
z, a_precision) +
652 result.
mul(a_quaternion1);
661 result.
add(a_quaternion1);
670 result.
sub(a_quaternion1);
676static inline std::ostream &operator << (std::ostream &a_os, cQuaternion
const& a_quaternion)
678 a_os << a_quaternion.str(3);
Definition CAudioBuffer.cpp:57
cMatrix3d operator-(const cMatrix3d &a_matrix1, const cMatrix3d &a_matrix2)
An overloaded - operator for matrix/matrix addition.
Definition CMatrix3d.h:2593
std::string cStr(const bool a_value)
This function converts a boolean into a string.
Definition CString.cpp:189
const double C_SMALL
Small value near zero.
Definition CConstants.h:103
const double C_PI
PI constant.
Definition CConstants.h:88
cMatrix3d operator+(const cMatrix3d &a_matrix1, const cMatrix3d &a_matrix2)
An overloaded + operator for matrix/matrix addition.
Definition CMatrix3d.h:2583
cVector3d operator*(const cMatrix3d &a_matrix, const cVector3d &a_vector)
An overloaded * operator for matrix/vector multiplication.
Definition CMatrix3d.h:2554
This class implements a 3D matrix.
Definition CMatrix3d.h:98
This class implements a quaternion.
Definition CQuaternion.h:84
void normalize()
This method normalizes this quaternion.
Definition CQuaternion.h:215
double mag() const
This method returns the quaternion magnitude.
Definition CQuaternion.h:209
bool operator==(cQuaternion const &a_quaternion) const
== operator.
Definition CQuaternion.h:181
double length() const
This method returns the quaternion magnitude.
Definition CQuaternion.h:212
cQuaternion()
Constructor of cQuaternion.
Definition CQuaternion.h:111
double lengthsq() const
This method returns the squared value of the quaternion magnitude.
Definition CQuaternion.h:206
void toAxisAngle(cVector3d &a_axis, double &a_angleRad) const
This method converts a quaternion representation into an axis-angle representation.
Definition CQuaternion.h:359
void invert()
This method inverts this quaternion.
Definition CQuaternion.h:398
std::string str(const unsigned int a_precision=2) const
This method converts this quaternion into a string.
Definition CQuaternion.h:611
void toRotMat(cMatrix3d &a_matrix) const
This method convert this quaternion into a rotation matrix.
Definition CQuaternion.h:238
void add(cQuaternion const &a_quaternion)
This method computes the addition between this quaternion and another passed as argument.
Definition CQuaternion.h:494
cQuaternion & operator+=(cQuaternion const &a_quaternion)
+= operator.
Definition CQuaternion.h:161
double z
Component z of quaternion.
Definition CQuaternion.h:101
double x
Component x of quaternion.
Definition CQuaternion.h:95
cQuaternion & operator*=(cQuaternion const &a_quaternion)
*= operator (Grassman product).
Definition CQuaternion.h:136
cQuaternion(double a_w, double a_x, double a_y, double a_z)
Constructor of cQuaternion.
Definition CQuaternion.h:114
void negate()
This method negates this quaternion.
Definition CQuaternion.h:200
double y
Component y of quaternion.
Definition CQuaternion.h:98
void fromRotMat(cMatrix3d const &a_matrix)
This method converts a rotation matrix into a quaternion.
Definition CQuaternion.h:274
void zero()
This method clears this quaternion with zeros.
Definition CQuaternion.h:197
double magsq() const
This method returns the squared value of the quaternion magnitude.
Definition CQuaternion.h:203
void conj()
This method computes the conjugate of this quaternion.
Definition CQuaternion.h:379
cQuaternion & operator-=(cQuaternion const &a_quaternion)
-= operator.
Definition CQuaternion.h:171
double dot(cQuaternion const &a_quaternion) const
This method computes the dot product between this quaternion and another quaternion.
Definition CQuaternion.h:474
double w
Component w of quaternion.
Definition CQuaternion.h:92
void fromAxisAngle(cVector3d a_axis, double a_angleRad)
This method converts an axis-angle representation into a quaternion.
Definition CQuaternion.h:329
void sub(cQuaternion const &a_quaternion)
This method computes the subtraction between this quaternion and another passed as argument.
Definition CQuaternion.h:517
void slerp(double a_level, cQuaternion const &a_quaternion0, cQuaternion a_quaternion1)
This method computes a spherical linear interpolation between two quaternions (SLERP).
Definition CQuaternion.h:545
void mul(double a_scale)
This method multiplies this quaternion by a scalar.
Definition CQuaternion.h:449
void mul(cQuaternion const &a_quaternion)
This method computes the multiplication of this quaternion with another quaternion.
Definition CQuaternion.h:422
cQuaternion(double const *in)
Constructor of cQuaternion.
Definition CQuaternion.h:120
This class implements a 3D vector.
Definition CVector3d.h:89
void normalize()
This method normalizes this vector to length 1.
Definition CVector3d.h:1034