Changeset 167 in flair-src for trunk/lib/FlairCore/src/Vector3D.h


Ignore:
Timestamp:
Apr 12, 2017, 1:59:38 PM (5 years ago)
Author:
Sanahuja Guillaume
Message:

modifs pour template vectors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairCore/src/Vector3D.h

    r15 r167  
    1515
    1616#include <stddef.h>
     17#include <Vector2D.h>
    1718
    1819namespace flair {
    1920namespace core {
    20 class Vector2D;
    2121class RotationMatrix;
    2222class Quaternion;
     
    2626* \brief Class defining a 3D vector
    2727*/
     28template <typename T>
    2829class Vector3D {
    2930public:
     
    3738  * \param z
    3839  */
    39   Vector3D(float x = 0, float y = 0, float z = 0);
     40  Vector3D(T x = 0, T y = 0, T z = 0);
    4041
    4142  /*!
     
    4849  * \brief x
    4950  */
    50   float x;
     51  T x;
    5152
    5253  /*!
    5354  * \brief y
    5455  */
    55   float y;
     56  T y;
    5657
    5758  /*!
    5859  * \brief z
    5960  */
    60   float z;
     61  T z;
    6162
    6263  /*!
     
    126127  * \param vector destination
    127128  */
    128   void To2Dxy(Vector2D &vector) const;
     129  void To2Dxy(Vector2D<T> &vector) const;
    129130
    130131  /*!
     
    135136  * \return destination
    136137  */
    137   Vector2D To2Dxy(void) const;
     138  Vector2D<T> To2Dxy(void) const;
    138139
    139140  /*!
     
    157158  * \param max maximum value
    158159  */
    159   void Saturate(const Vector3D &min, const Vector3D &max);
     160  void Saturate(const Vector3D<T> &min, const Vector3D<T> &max);
    160161
    161162  /*!
     
    176177  * \param value saturation Vector3D value
    177178  */
    178   void Saturate(const Vector3D &value);
     179  void Saturate(const Vector3D<T> &value);
    179180
    180181  /*!
     
    188189  void Saturate(float value);
    189190
    190   float &operator[](size_t idx);
    191   const float &operator[](size_t idx) const;
    192   Vector3D &operator=(const Vector3D &vector);
    193   Vector3D &operator+=(const Vector3D &vector);
    194   Vector3D &operator-=(const Vector3D &vector);
     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);
    195202
    196203private:
    197204};
    198205
     206typedef Vector3D<float> Vector3Df;
     207
    199208/*! Add
    200209*
     
    206215* \return vectorA+vectorB
    207216*/
    208 Vector3D operator+(const Vector3D &vectorA, const Vector3D &vectorB);
     217template<typename T> Vector3D<T> operator+(const Vector3D<T> &vectorA, const Vector3D<T> &vectorB);
    209218
    210219/*! Substract
     
    217226* \return vectorA-vectorB
    218227*/
    219 Vector3D operator-(const Vector3D &vectorA, const Vector3D &vectorB);
     228template<typename T> Vector3D<T> operator-(const Vector3D<T> &vectorA, const Vector3D<T> &vectorB);
    220229
    221230/*! Minus
     
    227236* \return -vector
    228237*/
    229 Vector3D operator-(const Vector3D &vector);
     238template<typename T> Vector3D<T> operator-(const Vector3D<T> &vector);
    230239
    231240/*! Divid
     
    238247* \return vector/coefficient
    239248*/
    240 Vector3D operator/(const Vector3D &vector, float coeff);
     249template<typename T> Vector3D<T> operator/(const Vector3D<T> &vector, float coeff);
    241250
    242251/*! Hadamard product
     
    249258* \return Hadamard product
    250259*/
    251 Vector3D operator*(const Vector3D &vectorA, const Vector3D &vectorB);
     260template<typename T> Vector3D<T> operator*(const Vector3D<T> &vectorA, const Vector3D<T> &vectorB);
    252261
    253262/*! Multiply
     
    260269* \return coefficient*vector
    261270*/
    262 Vector3D operator*(const Vector3D &vector, float coeff);
     271template<typename T> Vector3D<T> operator*(const Vector3D<T> &vector, float coeff);
    263272
    264273/*! Multiply
     
    271280* \return coefficient*vector
    272281*/
    273 Vector3D operator*(float coeff, const Vector3D &vector);
     282template<typename T> Vector3D<T> operator*(float coeff, const Vector3D<T> &vector);
    274283
    275284/*! Cross product
     
    282291* \return cross product
    283292*/
    284 Vector3D CrossProduct(const Vector3D &vectorA, const Vector3D &vectorB);
     293template<typename T> Vector3D<T> CrossProduct(const Vector3D<T> &vectorA, const Vector3D<T> &vectorB);
    285294
    286295/*! Dot product
     
    293302* \return dot product
    294303*/
    295 float DotProduct(const Vector3D &vectorA, const Vector3D &vectorB);
     304template<typename T> float DotProduct(const Vector3D<T> &vectorA, const Vector3D<T> &vectorB);
    296305
    297306} // end namespace core
Note: See TracChangeset for help on using the changeset viewer.