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