123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- /*!
- * \file include/Quaternion.h
- * \brief Quaternion
- *
- * \author Mongoose
- */
-
- #ifndef _QUATERNION_H_
- #define _QUATERNION_H_
-
- #include "MatMath.h"
-
- /*!
- * \brief Quaternion
- */
- class Quaternion {
- public:
-
- /*!
- * \brief Constructs an object of Quaternion
- */
- Quaternion();
-
- /*!
- * \brief Constructs an object of Quaternion
- * \param w W part of new Quaternion
- * \param x X part of new Quaternion
- * \param y Y part of new Quaternion
- * \param z Z part of new Quaternion
- */
- Quaternion(vec_t w, vec_t x, vec_t y, vec_t z);
-
- /*!
- * \brief Constructs an object of Quaternion
- * \param v contents of new Quaternion
- */
- Quaternion(vec4_t v);
-
- /*!
- * \brief Deconstructs an object of Quaternion
- */
- ~Quaternion();
-
- /*!
- * \brief Get column order matrix equivalent of this quaternion
- * \param m where matrix will be stored
- */
- void getMatrix(matrix_t m);
-
- /*!
- * \brief Assign q to this quaternion
- * \param q what to assign this quaternion to
- * \returns this quaternion
- */
- Quaternion &operator =(const Quaternion &q);
-
- /*!
- * \brief Multiplies this quaternion.
- *
- * Use normalize() call for unit quaternion.
- *
- * \param q what to multiply this quaternion with
- * \returns resultant quaternion
- * \sa Quaternion::normalize()
- */
- Quaternion operator *(const Quaternion &q);
-
- /*!
- * \brief Divide from this quaternion
- * \param q what to divide from this quaternion
- * \returns resultant quaternion
- */
- Quaternion operator /(const Quaternion &q);
-
- /*!
- * \brief Add to this quaternion
- * \param q what to add to this quaternion
- * \returns resultant quaternion
- */
- Quaternion operator +(const Quaternion &q);
-
- /*!
- * \brief Subtract from this quaternion
- * \param q what to subtract from this quaternion
- * \returns resultant quaternion
- */
- Quaternion operator -(const Quaternion &q);
-
- /*!
- * \brief Compares q to this quaternion
- * \param q what to compare this quaternion to
- * \returns true if equal, false otherwise
- */
- bool operator ==(const Quaternion &q);
-
- /*!
- * \brief Conjugate this quaternion
- * \returns Conjugate of this quaternion
- */
- Quaternion conjugate();
-
- /*!
- * \brief Scale this quaternion
- * \param s scaling factor
- * \returns Scaled result of this quaternion
- */
- Quaternion scale(vec_t s);
-
- /*!
- * \brief Inverse this quaternion
- * \returns inverse of this quaternion
- */
- Quaternion inverse();
-
- /*!
- * \brief Dot Product of quaternions
- * \param a first argument to dot product
- * \param b second argument to dot product
- * \returns dot product between a and b quaternions
- */
- static vec_t dot(Quaternion a, Quaternion b);
-
- /*!
- * \brief Magnitude of this quaternion
- * \returns Magnitude of this quaternion
- */
- vec_t magnitude();
-
- /*!
- * \brief Interpolates between a and b rotations.
- *
- * Using spherical linear interpolation:
- * `I = (((B . A)^-1)^Time)A`
- *
- * \param a first argument for slerp
- * \param b second argument for slerp
- * \param time time argument for slerp
- * \returns resultant quaternion
- */
- static Quaternion slerp(Quaternion a, Quaternion b, vec_t time);
-
- /*!
- * \brief Sets this quaternion to identity
- */
- void setIdentity();
-
- /*!
- * \brief Sets this quaternion
- * \param angle new angle
- * \param x new X coordinate
- * \param y new Y coordinate
- * \param z new Z coordinate
- */
- void set(vec_t angle, vec_t x, vec_t y, vec_t z);
-
- /*!
- * \brief Normalize this quaternion
- */
- void normalize();
-
- /*!
- * \brief Set this quaternion
- * \param q will be copied into this quaternion
- */
- void copy(Quaternion q);
-
- /*!
- * \brief Sets matrix equivalent of this quaternion
- * \param m matrix in valid column order
- */
- void setByMatrix(matrix_t m);
-
- private:
-
- /*!
- * \brief Multiplies two quaternions
- * \param a first argument to multiplication
- * \param b second argument to multiplication
- * \returns resultant quaternion
- */
- static Quaternion multiply(Quaternion a, Quaternion b);
-
- /*!
- * \brief Divides B from A quaternion
- * \param a first argument to division
- * \param b second argument to division
- * \returns quotient quaternion
- */
- static Quaternion divide(Quaternion a, Quaternion b);
-
- /*!
- * \brief Adds A and B quaternions
- * \param a first argument to addition
- * \param b second argument to addition
- * \returns resultant quaternion
- */
- static Quaternion add(Quaternion a, Quaternion b);
-
- /*!
- * \brief Subtracts B from A quaternion
- * \param a first argument to subtraction
- * \param b second argument to subtraction
- * \returns resultant quaternion
- */
- static Quaternion subtract(Quaternion a, Quaternion b);
-
- vec_t mW; //!< Quaternion, W part
- vec_t mX; //!< Quaternion, X part
- vec_t mY; //!< Quaternion, Y part
- vec_t mZ; //!< Quaternion, Z part
- };
-
- #endif
|