ESyS-Particle
4.0.1
|
00001 00002 // // 00003 // Copyright (c) 2003-2011 by The University of Queensland // 00004 // Earth Systems Science Computational Centre (ESSCC) // 00005 // http://www.uq.edu.au/esscc // 00006 // // 00007 // Primary Business: Brisbane, Queensland, Australia // 00008 // Licensed under the Open Software License version 3.0 // 00009 // http://www.opensource.org/licenses/osl-3.0.php // 00010 // // 00012 00013 #ifndef _QUATERNION_H 00014 #define _QUATERNION_H 00015 00016 #define DO_INLINE_QUATERNION 1 00017 00018 #if DO_INLINE_QUATERNION >= 1 00019 #define QUATERNION_INLINE inline 00020 #else 00021 #define QUATERNION_INLINE 00022 #endif 00023 00024 #include <math.h> 00025 #include "Foundation/vec3.h" 00026 00027 class Matrix3; 00028 00029 class Quaternion 00030 { 00031 private: 00032 Vec3 vector; 00033 double scalar; 00034 00035 public: 00036 // Constructors 00037 QUATERNION_INLINE Quaternion(); 00038 QUATERNION_INLINE Quaternion(double, const Vec3 &); 00039 00040 // Copy Constructor 00041 QUATERNION_INLINE Quaternion(const Quaternion &); 00042 00043 // Destructor 00044 QUATERNION_INLINE ~Quaternion() {}; 00045 00046 // Assignment 00047 QUATERNION_INLINE Quaternion& operator=(const Quaternion&); 00048 00049 // Output 00050 QUATERNION_INLINE std::ostream& output(std::ostream&) const; 00051 QUATERNION_INLINE std::istream& input(std::istream& ci); 00052 00053 // Math 00054 QUATERNION_INLINE bool operator==(const Quaternion&) const; 00055 QUATERNION_INLINE bool operator!=(const Quaternion&) const; 00056 00057 QUATERNION_INLINE Quaternion operator+(const Quaternion&) const; 00058 QUATERNION_INLINE Quaternion operator-(const Quaternion&) const; 00059 QUATERNION_INLINE Quaternion operator-() const; 00060 QUATERNION_INLINE friend Quaternion operator*(double, const Quaternion&); 00061 QUATERNION_INLINE Quaternion operator*(double) const; 00062 QUATERNION_INLINE Quaternion operator*(const Quaternion&) const; 00063 QUATERNION_INLINE Quaternion operator/(const Quaternion&) const; 00064 00065 QUATERNION_INLINE Quaternion& operator+=(const Quaternion&); 00066 QUATERNION_INLINE Quaternion& operator-=(const Quaternion&); 00067 QUATERNION_INLINE Quaternion& operator*=(double); 00068 QUATERNION_INLINE Quaternion& operator*=(const Quaternion&); 00069 QUATERNION_INLINE Quaternion& operator/=(const Quaternion&); 00070 00071 QUATERNION_INLINE Quaternion inverse() const; 00072 00073 QUATERNION_INLINE void normalize(); 00074 00075 QUATERNION_INLINE double length() const; 00076 00077 QUATERNION_INLINE Matrix3 to_matrix() const; 00078 00079 // Access Functions 00080 QUATERNION_INLINE Vec3 return_vec() const { return vector; }; 00081 QUATERNION_INLINE double return_sca() const { return scalar; }; 00082 00083 QUATERNION_INLINE void set_vector(const Vec3 &v) { vector = v; } 00084 QUATERNION_INLINE void set_scalar(double d) { scalar = d; } 00085 00091 QUATERNION_INLINE Vec3 asAngleAxis() const; 00092 00096 typedef std::pair<double,Vec3> AngleAxisPair; 00102 QUATERNION_INLINE AngleAxisPair asAngleAxisPair() const; 00103 }; 00104 00105 QUATERNION_INLINE std::ostream& operator<<(std::ostream&, const Quaternion &); 00106 QUATERNION_INLINE std::istream& operator>>(std::istream&, Quaternion &); 00107 00108 #if DO_INLINE_QUATERNION >= 1 00109 #include "Foundation/Quaternion.hpp" 00110 #endif 00111 00112 #endif