1  // %flair:license{


2  // This file is part of the Flair framework distributed under the


3  // CECILLC License, Version 1.0.


4  // %flair:license}


5 


6  /*!


7  * \file Vector3D.h


8  * \brief Class defining a 3D vector


9  * \author Guillaume Sanahuja, Copyright Heudiasyc UMR UTC/CNRS 7253


10  * \date 2013/05/02


11  * \version 4.0


12  */


13  #ifndef VECTOR3D_H


14  #define VECTOR3D_H


15 


16  #include <stddef.h>


17  #include <Vector2D.h>


18 


19  namespace flair {


20  namespace core {


21  class RotationMatrix;


22  class Quaternion;


23 


24  /*! \class Vector3D


25  *


26  * \brief Class defining a 3D vector


27  */


28  template <typename T>


29  class Vector3D {


30  public:


31  /*!


32  * \brief Constructor


33  *


34  * Construct a Vector3D using specified values.


35  *


36  * \param x


37  * \param y


38  * \param z


39  */


40  Vector3D(T x = 0, T y = 0, T z = 0);


41 


42  /*!


43  * \brief Destructor


44  *


45  */


46  ~Vector3D();


47 


48  /*!


49  * \brief x


50  */


51  T x;


52 


53  /*!


54  * \brief y


55  */


56  T y;


57 


58  /*!


59  * \brief z


60  */


61  T z;


62 


63  /*!


64  * \brief x axis rotation


65  *


66  * \param value rotation value in radians


67  */


68  void RotateX(float value);


69 


70  /*!


71  * \brief x axis rotation


72  *


73  * \param value rotation value in degrees


74  */


75  void RotateXDeg(float value);


76 


77  /*!


78  * \brief y axis rotation


79  *


80  * \param value rotation value in radians


81  */


82  void RotateY(float value);


83 


84  /*!


85  * \brief y axis rotation


86  *


87  * \param value rotation value in degrees


88  */


89  void RotateYDeg(float value);


90 


91  /*!


92  * \brief z axis rotation


93  *


94  * \param value rotation value in radians


95  */


96  void RotateZ(float value);


97 


98  /*!


99  * \brief z axis rotation


100  *


101  * \param value rotation value in degrees


102  */


103  void RotateZDeg(float value);


104 


105  /*!


106  * \brief rotation


107  *


108  * \param matrix rotation matrix


109  */


110  void Rotate(const RotationMatrix &matrix);


111 


112  /*!


113  * \brief rotation


114  *


115  * Compute a rotation from a quaternion. This method uses a rotation matrix


116  * internaly.


117  *


118  * \param quaternion quaternion


119  */


120  void Rotate(const Quaternion &quaternion);


121 


122  /*!


123  * \brief Convert to a Vector2D


124  *


125  * Uses x and y coordinates.


126  *


127  * \param vector destination


128  */


129  void To2Dxy(Vector2D<T> &vector) const;


130 


131  /*!


132  * \brief Convert to a Vector2D


133  *


134  * Uses x and y coordinates.


135  *


136  * \return destination


137  */


138  Vector2D<T> To2Dxy(void) const;


139 


140  /*!


141  * \brief Norm


142  *


143  * \return value


144  */


145  float GetNorm(void) const;


146 


147  /*!


148  * \brief Normalize


149  */


150  void Normalize(void);


151 


152  /*!


153  * \brief Saturate


154  *


155  * Saturate between min and max


156  *


157  * \param min minimum value


158  * \param max maximum value


159  */


160  void Saturate(const Vector3D<T> &min, const Vector3D<T> &max);


161 


162  /*!


163  * \brief Saturate


164  *


165  * Saturate between min and max


166  *


167  * \param min minimum Vector3D(min,min,min) value


168  * \param max maximum Vector3D(max,max,max) value


169  */


170  void Saturate(float min, float max);


171 


172  /*!


173  * \brief Saturate


174  *


175  * Saturate between abs(value) and abs(value)


176  *


177  * \param value saturation Vector3D value


178  */


179  void Saturate(const Vector3D<T> &value);


180 


181  /*!


182  * \brief Saturate


183  *


184  * Saturate between abs(Vector3D(value,value,value)) and


185  *abs(Vector3D(value,value,value))


186  *


187  * \param value saturation Vector3D(value,value,value)


188  */


189  void Saturate(float value);


190 


191  T &operator[](size_t idx);


192  const T &operator[](size_t idx) const;


193  //Vector3D<T> &operator=(const Vector3D<T> &vector);


194  template<typename S> Vector3D<T> &operator=(const Vector3D<S> &vector) {


195  x = vector.x;


196  y = vector.y;


197  z = vector.z;


198  return (*this);


199  }


200  Vector3D<T> &operator+=(const Vector3D<T> &vector);


201  Vector3D<T> &operator=(const Vector3D<T> &vector);


202 


203  private:


204  };


205 


206  typedef Vector3D<float> Vector3Df;


207 


208  /*! Add


209  *


210  * \brief Add


211  *


212  * \param vectorA vector


213  * \param vectorB vector


214  *


215  * \return vectorA+vectorB


216  */


217  template<typename T> Vector3D<T> operator+(const Vector3D<T> &vectorA, const Vector3D<T> &vectorB);


218 


219  /*! Substract


220  *


221  * \brief Substract


222  *


223  * \param vectorA vector


224  * \param vectorB vector


225  *


226  * \return vectorAvectorB


227  */


228  template<typename T> Vector3D<T> operator(const Vector3D<T> &vectorA, const Vector3D<T> &vectorB);


229 


230  /*! Minus


231  *


232  * \brief Minus


233  *


234  * \param vector vector


235  *


236  * \return vector


237  */


238  template<typename T> Vector3D<T> operator(const Vector3D<T> &vector);


239 


240  /*! Divid


241  *


242  * \brief Divid


243  *


244  * \param vector vector


245  * \param coeff coefficent


246  *


247  * \return vector/coefficient


248  */


249  template<typename T> Vector3D<T> operator/(const Vector3D<T> &vector, float coeff);


250 


251  /*! Hadamard product


252  *


253  * \brief Hadamard product


254  *


255  * \param vectorA vector


256  * \param vectorBA vector


257  *


258  * \return Hadamard product


259  */


260  template<typename T> Vector3D<T> operator*(const Vector3D<T> &vectorA, const Vector3D<T> &vectorB);


261 


262  /*! Multiply


263  *


264  * \brief Multiply


265  *


266  * \param vector vector


267  * \param coeff coefficent


268  *


269  * \return coefficient*vector


270  */


271  template<typename T> Vector3D<T> operator*(const Vector3D<T> &vector, float coeff);


272 


273  /*! Multiply


274  *


275  * \brief Multiply


276  *


277  * \param coeff coefficent


278  * \param vector vector


279  *


280  * \return coefficient*vector


281  */


282  template<typename T> Vector3D<T> operator*(float coeff, const Vector3D<T> &vector);


283 


284  /*! Cross product


285  *


286  * \brief Cross product


287  *


288  * \param vectorA first vector


289  * \param vectorB second vector


290  *


291  * \return cross product


292  */


293  template<typename T> Vector3D<T> CrossProduct(const Vector3D<T> &vectorA, const Vector3D<T> &vectorB);


294 


295  /*! Dot product


296  *


297  * \brief Dot product


298  *


299  * \param vectorA first vector


300  * \param vectorB second vector


301  *


302  * \return dot product


303  */


304  template<typename T> float DotProduct(const Vector3D<T> &vectorA, const Vector3D<T> &vectorB);


305 


306  } // end namespace core


307  } // end namespace flair


308 


309  #endif // VECTOR3D_H

