QuaternionT.h
Go to the documentation of this file.
1 #pragma once
2 
5 
6 namespace CD_Matrix
7 {
9 template<typename T>
10 class QuaternionT : private Vector4T<T>
11 {
12 public:
14 
15  explicit QuaternionT<T>(const T & x, const T & y, const T & z, const T & w) : Vector4T<T>(x, y, z, w) {}
16 
17  template<bool b>
18  explicit QuaternionT<T>(const Vector3T<T, b> & axis, const T & angle)
19  {
20  T d = axis.norm();
21  T s = sin(angle * 0.5) / d;
22  this->m_x = axis[0] * s;
23  this->m_y = axis[1] * s;
24  this->m_z = axis[2] * s;
25  this->m_w = cos(angle * T(0.5));
26  }
27 
28  using Vector4T<T>::operator[];
29  using Vector4T<T>::operator+;
30  using Vector4T<T>::operator+=;
31  using Vector4T<T>::operator-;
32  using Vector4T<T>::operator-=;
33 
35  {
36  this->m_w = A.m_w;
37  this->m_x = A.m_x;
38  this->m_y = A.m_y;
39  this->m_z = A.m_z;
40  return *this;
41  }
42 
44  {
45  return QuaternionD(-(this->m_x), -(this->m_y), -(this->m_y), this->m_t);
46  }
47 
48  void ConjugateIt()
49  {
50  this->m_x = -this->m_x;
51  this->m_y = -this->m_y;
52  this->m_z = -this->m_z;
53  }
54 
56  {
57  return QuaternionD(this->m_w * q[0] + this->m_x * q[3] + this->m_y * q[2] - this->m_z * q[1],
58  this->m_w * q[1] + this->m_y * q[3] + this->m_z * q[0] - this->m_x * q[2],
59  this->m_w * q[2] + this->m_z * q[3] + this->m_x * q[1] - this->m_y * q[0],
60  this->m_w * q[3] - this->m_x * q[0] - this->m_y * q[1] - this->m_z * q[2]);
61  }
62 
64  {
65  T x = this->m_w * q[0] + this->m_x * q[3] + this->m_y * q[2] - this->m_z * q[1],
66  y = this->m_w * q[0] + this->m_x * q[3] + this->m_y * q[2] - this->m_z * q[1],
67  z = this->m_w * q[0] + this->m_x * q[3] + this->m_y * q[2] - this->m_z * q[1],
68  w = this->m_w * q[0] + this->m_x * q[3] + this->m_y * q[2] - this->m_z * q[1];
69 
70  this->m_x = x;
71  this->m_y = y;
72  this->m_z = z;
73  this->m_w = w;
74 
75  return *this;
76  }
77 
78  virtual ~QuaternionT(void) {}
79 };
80 } // namespace CD_Matrix
CD_Matrix::QuaternionT::operator*=
QuaternionT< T > & operator*=(const QuaternionT< T > &q)
Definition: QuaternionT.h:63
SmallVector4T.h
CD_Matrix::Vector4T::m_z
T m_z
Definition: SmallVector4T.h:22
CD_Matrix::Vector3T::norm
T norm() const
Definition: SmallVector3T.h:290
CD_Matrix::Vector4T::m_y
T m_y
Definition: SmallVector4T.h:22
CD_Matrix::Vector4T
Template to handle 3 dimensional vector.
Definition: SmallVector4T.h:19
CD_Matrix::QuaternionT::~QuaternionT
virtual ~QuaternionT(void)
Definition: QuaternionT.h:78
SmallVector3T.h
CD_Matrix::QuaternionT::ConjugateIt
void ConjugateIt()
Definition: QuaternionT.h:48
CD_Matrix::Vector4T::m_w
T m_w
Definition: SmallVector4T.h:22
CD_Matrix::QuaternionT::operator=
const QuaternionT< T > & operator=(const QuaternionT< T > &A)
Definition: QuaternionT.h:34
CD_Matrix::QuaternionT
Definition: QuaternionT.h:10
CD_Matrix::Vector4T::m_x
T m_x
Definition: SmallVector4T.h:22
CD_Matrix
Definition: QuaternionT.h:6
CD_Matrix::Vector3T
Definition: SmallMatrix3x3T.h:14
CD_Matrix::QuaternionT::operator*
QuaternionT< T > operator*(const QuaternionT< T > &q)
Definition: QuaternionT.h:55
CD_Matrix::QuaternionT::Conjugate
QuaternionT< T > Conjugate() const
Definition: QuaternionT.h:43