Program Listing for File Quaternion.hpp

Return to documentation for file (include/lvr2/geometry/Quaternion.hpp)

/*
 * Quatrnion.hpp
 *
 *  @date 29.08.2008
 *  @author Thomas Wiemann (twiemann@uos.de)
 */

//
//  Author: Thomas Wiemann
//  Date:   29.08.2008
//
//  Quaternion representation of rotations.
//
//  Based on: http://gpwiki.org/index.php/OpenGL:Tutorials:Using_Quaternions_to_represent_rotation
//


#ifndef __GLQUATERNION_H__
#define __GLQUATERNION_H__

#include "math.h"

#include "lvr2/geometry/BaseVector.hpp"
#include "lvr2/geometry/Matrix4.hpp"
#include "lvr2/geometry/Normal.hpp"

#include <iostream>

namespace lvr2
{

template<typename BaseVecT>
class Quaternion{

  using ValueType = typename BaseVecT::CoordType;

public:
  Quaternion();
  Quaternion(const Quaternion<BaseVecT> &o){ x = o.x; y = o.y; z = o.z; w = o.w;};
  Quaternion(BaseVecT vec, ValueType angle);
  Quaternion(ValueType pitch, ValueType yaw, ValueType roll);
  Quaternion(ValueType x, ValueType y, ValueType z, ValueType w);
  Quaternion(ValueType *vec, ValueType w);

  ~Quaternion();

  void normalize();
  void fromAxis(ValueType *vec, ValueType angle);
  void fromAxis(BaseVecT axis, ValueType angle);
  void fromEuler(ValueType pitch, ValueType yaw, ValueType roll);

  void getAxisAngle(BaseVecT *axis, ValueType *angle);
  void getMatrix(ValueType *m);

  void printMatrix();
  void printDebugInfo();

  BaseVecT toEuler();

  ValueType X() const {return x;};
  ValueType Y() const {return y;};
  ValueType Z() const {return z;};
  ValueType W() const {return w;};

  Quaternion<BaseVecT> getConjugate();
  Quaternion<BaseVecT> copy();

  Quaternion<BaseVecT> operator* (Quaternion<BaseVecT> rq);

  BaseVecT operator* (BaseVecT vec);
  BaseVecT operator* (BaseVecT *vec);

  Matrix4<BaseVecT> getMatrix();

private:
  ValueType w, x, y, z;

};

} // namespace lvr2

template<typename BaseVecT>
inline std::ostream& operator<<(std::ostream& os, const lvr2::Quaternion<BaseVecT> q){

    return os << "Quaternion: " << q.W() << " " << q.X() << " " << q.Y() << " " << q.Z() << "\n";

}

#include "Quaternion.tcc"

#endif