Algebra3D
Algebra for 3D transformations
 All Classes Namespaces Files Functions Variables Typedefs Macros
Quaternion.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015 Jaroslaw Glowacki
3  * jarek (dot) glowacki (at) gmail (dot) com
4  *
5  * This file is part of algebra3d.
6  *
7  * algebra3d is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * algebra3d is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with algebra3d. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
27 #ifndef _QUATERNION_H_
28 #define _QUATERNION_H_
29 
30 #include<algebra3d/global.h>
31 
32 namespace algebra3d {
33 
34 /* Forward declarations */
35 template<class fpType>
36 class Matrix3;
37 template<class fpType>
38 class Vector3;
39 
48 template<class fpType>
49 class Quaternion {
50  // Friendship declarations
51  template<class fpT>
52  friend std::istream& operator>>(std::istream &stream,
53  Quaternion<fpT> &quat);
54 
55 protected:
57  fpType data[4];
58 
59 public:
61  fpType &x;
63  fpType &y;
65  fpType &z;
67  fpType &w;
68 
69 public:
73  Quaternion();
74 
81  Quaternion(const fpType(&data)[4]);
82 
91  Quaternion(fpType x, fpType y, fpType z, fpType w);
92 
98  Quaternion(const Quaternion<fpType> &quat);
99 
105  Quaternion(const Vector3<fpType> &vec);
106 
113  Quaternion(Vector3<fpType> axis, fpType angle);
114 
120  Quaternion(const Matrix3<fpType> &mat);
121 
125  virtual ~Quaternion();
126 
133  virtual void set(const fpType *data);
134 
140  virtual void set(const Matrix3<fpType> &mat);
141 
148  virtual void get(fpType *storage) const;
149 
156  virtual fpType getAngle() const;
157 
164  virtual Vector3<fpType> getAxis() const;
165 
171  virtual fpType getNorm() const;
172 
176  virtual void normalize();
177 
185  virtual bool isUnit() const;
186 
194  virtual Quaternion<fpType> getSqrtRotation() const;
195 
212  const Quaternion<fpType> &quat) const;
213 
219  virtual void operator=(const Quaternion<fpType> &quat);
220 
229  virtual const fpType &operator[](int ind) const;
230 
239  virtual fpType &operator[](int ind);
240 
252  virtual bool compareRotations(const Quaternion<fpType> &quat,
253  fpType precision = PRECISION) const;
254 
267  virtual bool compare(const Quaternion<fpType> &quat,
268  const fpType &precision = PRECISION) const;
269 
278  virtual bool operator==(const Quaternion<fpType> &quat) const;
279 
288  virtual bool operator!=(const Quaternion<fpType> &quat) const;
289 
298  virtual Quaternion<fpType> inv() const;
299 
305  virtual void operator*=(const Quaternion<fpType> &quat);
306 
313  virtual Quaternion<fpType> operator*(const Quaternion<fpType> &quat) const;
314 
321  virtual void scaleAngle(const fpType &mult);
322 
329  virtual Quaternion<fpType> getScaledAngleRotation(const fpType &mult) const;
330 
338  virtual Vector3<fpType> operator*(const Vector3<fpType> &vec) const;
339 };
340 
348 template<class fpType>
349 std::ostream& operator<<(std::ostream &stream, const Quaternion<fpType> &quat);
350 
358 template<class fpType>
359 std::istream& operator>>(std::istream &stream, Quaternion<fpType> &quat);
360 
367 
374 
375 } /* namespace algebra3d */
376 
377 #endif // _QUATERNION_H_
virtual void operator*=(const Quaternion< fpType > &quat)
virtual void set(const fpType *data)
virtual bool compare(const Quaternion< fpType > &quat, const fpType &precision=PRECISION) const
virtual void normalize()
virtual bool compareRotations(const Quaternion< fpType > &quat, fpType precision=PRECISION) const
virtual Vector3< fpType > getAxis() const
A class to store vectors of 3 elements.
Definition: Matrix3.h:35
virtual Quaternion< fpType > operator*(const Quaternion< fpType > &quat) const
std::istream & operator>>(std::istream &stream, Matrix3< fpType > &mat)
fpType & x
Definition: Quaternion.h:61
fpType & w
Definition: Quaternion.h:67
fpType & z
Definition: Quaternion.h:65
virtual void operator=(const Quaternion< fpType > &quat)
virtual fpType getNorm() const
virtual bool operator==(const Quaternion< fpType > &quat) const
A class to store 3x3 rotation matrices.
Definition: Matrix3.h:48
fpType data[4]
Definition: Quaternion.h:57
fpType & y
Definition: Quaternion.h:63
virtual Quaternion< fpType > getSqrtRotation() const
Quaternion< float > QuaternionF
Definition: Quaternion.h:373
#define PRECISION
Definition: global.h:51
virtual fpType getAngle() const
virtual Quaternion< fpType > getSqrtRotationTowards(const Quaternion< fpType > &quat) const
Quaternion< double > QuaternionD
Definition: Quaternion.h:366
virtual bool operator!=(const Quaternion< fpType > &quat) const
A class to store quaternions.
Definition: Matrix3.h:37
virtual Quaternion< fpType > getScaledAngleRotation(const fpType &mult) const
virtual const fpType & operator[](int ind) const
virtual void scaleAngle(const fpType &mult)
virtual bool isUnit() const
virtual Quaternion< fpType > inv() const