ESyS-Particle  4.0.1
Quaternion.h
1 
2 // //
3 // Copyright (c) 2003-2011 by The University of Queensland //
4 // Earth Systems Science Computational Centre (ESSCC) //
5 // http://www.uq.edu.au/esscc //
6 // //
7 // Primary Business: Brisbane, Queensland, Australia //
8 // Licensed under the Open Software License version 3.0 //
9 // http://www.opensource.org/licenses/osl-3.0.php //
10 // //
12 
13 #ifndef _QUATERNION_H
14 #define _QUATERNION_H
15 
16 #define DO_INLINE_QUATERNION 1
17 
18 #if DO_INLINE_QUATERNION >= 1
19 #define QUATERNION_INLINE inline
20 #else
21 #define QUATERNION_INLINE
22 #endif
23 
24 #include <math.h>
25 #include "Foundation/vec3.h"
26 
27 class Matrix3;
28 
30 {
31 private:
32  Vec3 vector;
33  double scalar;
34 
35 public:
36  // Constructors
37  QUATERNION_INLINE Quaternion();
38  QUATERNION_INLINE Quaternion(double, const Vec3 &);
39 
40  // Copy Constructor
41  QUATERNION_INLINE Quaternion(const Quaternion &);
42 
43  // Destructor
44  QUATERNION_INLINE ~Quaternion() {};
45 
46  // Assignment
47  QUATERNION_INLINE Quaternion& operator=(const Quaternion&);
48 
49  // Output
50  QUATERNION_INLINE std::ostream& output(std::ostream&) const;
51  QUATERNION_INLINE std::istream& input(std::istream& ci);
52 
53  // Math
54  QUATERNION_INLINE bool operator==(const Quaternion&) const;
55  QUATERNION_INLINE bool operator!=(const Quaternion&) const;
56 
57  QUATERNION_INLINE Quaternion operator+(const Quaternion&) const;
58  QUATERNION_INLINE Quaternion operator-(const Quaternion&) const;
59  QUATERNION_INLINE Quaternion operator-() const;
60  QUATERNION_INLINE friend Quaternion operator*(double, const Quaternion&);
61  QUATERNION_INLINE Quaternion operator*(double) const;
62  QUATERNION_INLINE Quaternion operator*(const Quaternion&) const;
63  QUATERNION_INLINE Quaternion operator/(const Quaternion&) const;
64 
65  QUATERNION_INLINE Quaternion& operator+=(const Quaternion&);
66  QUATERNION_INLINE Quaternion& operator-=(const Quaternion&);
67  QUATERNION_INLINE Quaternion& operator*=(double);
68  QUATERNION_INLINE Quaternion& operator*=(const Quaternion&);
69  QUATERNION_INLINE Quaternion& operator/=(const Quaternion&);
70 
71  QUATERNION_INLINE Quaternion inverse() const;
72 
73  QUATERNION_INLINE void normalize();
74 
75  QUATERNION_INLINE double length() const;
76 
77  QUATERNION_INLINE Matrix3 to_matrix() const;
78 
79  // Access Functions
80  QUATERNION_INLINE Vec3 return_vec() const { return vector; };
81  QUATERNION_INLINE double return_sca() const { return scalar; };
82 
83  QUATERNION_INLINE void set_vector(const Vec3 &v) { vector = v; }
84  QUATERNION_INLINE void set_scalar(double d) { scalar = d; }
85 
91  QUATERNION_INLINE Vec3 asAngleAxis() const;
92 
96  typedef std::pair<double,Vec3> AngleAxisPair;
102  QUATERNION_INLINE AngleAxisPair asAngleAxisPair() const;
103 };
104 
105 QUATERNION_INLINE std::ostream& operator<<(std::ostream&, const Quaternion &);
106 QUATERNION_INLINE std::istream& operator>>(std::istream&, Quaternion &);
107 
108 #if DO_INLINE_QUATERNION >= 1
109 #include "Foundation/Quaternion.hpp"
110 #endif
111 
112 #endif