[2] | 1 | // %flair:license{
|
---|
[15] | 2 | // This file is part of the Flair framework distributed under the
|
---|
| 3 | // CECILL-C License, Version 1.0.
|
---|
[2] | 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>
|
---|
[167] | 17 | #include <Vector2D.h>
|
---|
[2] | 18 |
|
---|
[15] | 19 | namespace flair {
|
---|
| 20 | namespace core {
|
---|
| 21 | class RotationMatrix;
|
---|
| 22 | class Quaternion;
|
---|
[2] | 23 |
|
---|
[15] | 24 | /*! \class Vector3D
|
---|
| 25 | *
|
---|
| 26 | * \brief Class defining a 3D vector
|
---|
| 27 | */
|
---|
[167] | 28 | template <typename T>
|
---|
[15] | 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 | */
|
---|
[167] | 40 | Vector3D(T x = 0, T y = 0, T z = 0);
|
---|
[2] | 41 |
|
---|
[15] | 42 | /*!
|
---|
| 43 | * \brief Destructor
|
---|
| 44 | *
|
---|
| 45 | */
|
---|
| 46 | ~Vector3D();
|
---|
[2] | 47 |
|
---|
[15] | 48 | /*!
|
---|
| 49 | * \brief x
|
---|
| 50 | */
|
---|
[167] | 51 | T x;
|
---|
[2] | 52 |
|
---|
[15] | 53 | /*!
|
---|
| 54 | * \brief y
|
---|
| 55 | */
|
---|
[167] | 56 | T y;
|
---|
[2] | 57 |
|
---|
[15] | 58 | /*!
|
---|
| 59 | * \brief z
|
---|
| 60 | */
|
---|
[167] | 61 | T z;
|
---|
[2] | 62 |
|
---|
[15] | 63 | /*!
|
---|
| 64 | * \brief x axis rotation
|
---|
| 65 | *
|
---|
| 66 | * \param value rotation value in radians
|
---|
| 67 | */
|
---|
| 68 | void RotateX(float value);
|
---|
[2] | 69 |
|
---|
[15] | 70 | /*!
|
---|
| 71 | * \brief x axis rotation
|
---|
| 72 | *
|
---|
| 73 | * \param value rotation value in degrees
|
---|
| 74 | */
|
---|
| 75 | void RotateXDeg(float value);
|
---|
[2] | 76 |
|
---|
[15] | 77 | /*!
|
---|
| 78 | * \brief y axis rotation
|
---|
| 79 | *
|
---|
| 80 | * \param value rotation value in radians
|
---|
| 81 | */
|
---|
| 82 | void RotateY(float value);
|
---|
[2] | 83 |
|
---|
[15] | 84 | /*!
|
---|
| 85 | * \brief y axis rotation
|
---|
| 86 | *
|
---|
| 87 | * \param value rotation value in degrees
|
---|
| 88 | */
|
---|
| 89 | void RotateYDeg(float value);
|
---|
[2] | 90 |
|
---|
[15] | 91 | /*!
|
---|
| 92 | * \brief z axis rotation
|
---|
| 93 | *
|
---|
| 94 | * \param value rotation value in radians
|
---|
| 95 | */
|
---|
| 96 | void RotateZ(float value);
|
---|
[2] | 97 |
|
---|
[15] | 98 | /*!
|
---|
| 99 | * \brief z axis rotation
|
---|
| 100 | *
|
---|
| 101 | * \param value rotation value in degrees
|
---|
| 102 | */
|
---|
| 103 | void RotateZDeg(float value);
|
---|
[2] | 104 |
|
---|
[15] | 105 | /*!
|
---|
| 106 | * \brief rotation
|
---|
| 107 | *
|
---|
| 108 | * \param matrix rotation matrix
|
---|
| 109 | */
|
---|
| 110 | void Rotate(const RotationMatrix &matrix);
|
---|
[2] | 111 |
|
---|
[15] | 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);
|
---|
[2] | 121 |
|
---|
[15] | 122 | /*!
|
---|
| 123 | * \brief Convert to a Vector2D
|
---|
| 124 | *
|
---|
| 125 | * Uses x and y coordinates.
|
---|
| 126 | *
|
---|
| 127 | * \param vector destination
|
---|
| 128 | */
|
---|
[167] | 129 | void To2Dxy(Vector2D<T> &vector) const;
|
---|
[2] | 130 |
|
---|
[15] | 131 | /*!
|
---|
| 132 | * \brief Convert to a Vector2D
|
---|
| 133 | *
|
---|
| 134 | * Uses x and y coordinates.
|
---|
| 135 | *
|
---|
| 136 | * \return destination
|
---|
| 137 | */
|
---|
[167] | 138 | Vector2D<T> To2Dxy(void) const;
|
---|
[2] | 139 |
|
---|
[15] | 140 | /*!
|
---|
| 141 | * \brief Norm
|
---|
| 142 | *
|
---|
| 143 | * \return value
|
---|
| 144 | */
|
---|
| 145 | float GetNorm(void) const;
|
---|
[2] | 146 |
|
---|
[15] | 147 | /*!
|
---|
| 148 | * \brief Normalize
|
---|
| 149 | */
|
---|
| 150 | void Normalize(void);
|
---|
[2] | 151 |
|
---|
[15] | 152 | /*!
|
---|
| 153 | * \brief Saturate
|
---|
| 154 | *
|
---|
| 155 | * Saturate between min and max
|
---|
| 156 | *
|
---|
| 157 | * \param min minimum value
|
---|
| 158 | * \param max maximum value
|
---|
| 159 | */
|
---|
[167] | 160 | void Saturate(const Vector3D<T> &min, const Vector3D<T> &max);
|
---|
[2] | 161 |
|
---|
[15] | 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);
|
---|
[2] | 171 |
|
---|
[15] | 172 | /*!
|
---|
| 173 | * \brief Saturate
|
---|
| 174 | *
|
---|
| 175 | * Saturate between -abs(value) and abs(value)
|
---|
| 176 | *
|
---|
| 177 | * \param value saturation Vector3D value
|
---|
| 178 | */
|
---|
[167] | 179 | void Saturate(const Vector3D<T> &value);
|
---|
[2] | 180 |
|
---|
[15] | 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);
|
---|
[2] | 190 |
|
---|
[167] | 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);
|
---|
[2] | 202 |
|
---|
[15] | 203 | private:
|
---|
| 204 | };
|
---|
[2] | 205 |
|
---|
[167] | 206 | typedef Vector3D<float> Vector3Df;
|
---|
| 207 |
|
---|
[15] | 208 | /*! Add
|
---|
| 209 | *
|
---|
| 210 | * \brief Add
|
---|
| 211 | *
|
---|
| 212 | * \param vectorA vector
|
---|
| 213 | * \param vectorB vector
|
---|
| 214 | *
|
---|
| 215 | * \return vectorA+vectorB
|
---|
| 216 | */
|
---|
[167] | 217 | template<typename T> Vector3D<T> operator+(const Vector3D<T> &vectorA, const Vector3D<T> &vectorB);
|
---|
[2] | 218 |
|
---|
[15] | 219 | /*! Substract
|
---|
| 220 | *
|
---|
| 221 | * \brief Substract
|
---|
| 222 | *
|
---|
| 223 | * \param vectorA vector
|
---|
| 224 | * \param vectorB vector
|
---|
| 225 | *
|
---|
| 226 | * \return vectorA-vectorB
|
---|
| 227 | */
|
---|
[167] | 228 | template<typename T> Vector3D<T> operator-(const Vector3D<T> &vectorA, const Vector3D<T> &vectorB);
|
---|
[2] | 229 |
|
---|
[15] | 230 | /*! Minus
|
---|
| 231 | *
|
---|
| 232 | * \brief Minus
|
---|
| 233 | *
|
---|
| 234 | * \param vector vector
|
---|
| 235 | *
|
---|
| 236 | * \return -vector
|
---|
| 237 | */
|
---|
[167] | 238 | template<typename T> Vector3D<T> operator-(const Vector3D<T> &vector);
|
---|
[2] | 239 |
|
---|
[15] | 240 | /*! Divid
|
---|
| 241 | *
|
---|
| 242 | * \brief Divid
|
---|
| 243 | *
|
---|
| 244 | * \param vector vector
|
---|
| 245 | * \param coeff coefficent
|
---|
| 246 | *
|
---|
| 247 | * \return vector/coefficient
|
---|
| 248 | */
|
---|
[167] | 249 | template<typename T> Vector3D<T> operator/(const Vector3D<T> &vector, float coeff);
|
---|
[2] | 250 |
|
---|
[15] | 251 | /*! Hadamard product
|
---|
| 252 | *
|
---|
| 253 | * \brief Hadamard product
|
---|
| 254 | *
|
---|
| 255 | * \param vectorA vector
|
---|
| 256 | * \param vectorBA vector
|
---|
| 257 | *
|
---|
| 258 | * \return Hadamard product
|
---|
| 259 | */
|
---|
[167] | 260 | template<typename T> Vector3D<T> operator*(const Vector3D<T> &vectorA, const Vector3D<T> &vectorB);
|
---|
[2] | 261 |
|
---|
[15] | 262 | /*! Multiply
|
---|
| 263 | *
|
---|
| 264 | * \brief Multiply
|
---|
| 265 | *
|
---|
| 266 | * \param vector vector
|
---|
| 267 | * \param coeff coefficent
|
---|
| 268 | *
|
---|
| 269 | * \return coefficient*vector
|
---|
| 270 | */
|
---|
[167] | 271 | template<typename T> Vector3D<T> operator*(const Vector3D<T> &vector, float coeff);
|
---|
[2] | 272 |
|
---|
[15] | 273 | /*! Multiply
|
---|
| 274 | *
|
---|
| 275 | * \brief Multiply
|
---|
| 276 | *
|
---|
| 277 | * \param coeff coefficent
|
---|
| 278 | * \param vector vector
|
---|
| 279 | *
|
---|
| 280 | * \return coefficient*vector
|
---|
| 281 | */
|
---|
[167] | 282 | template<typename T> Vector3D<T> operator*(float coeff, const Vector3D<T> &vector);
|
---|
[2] | 283 |
|
---|
[15] | 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 | */
|
---|
[167] | 293 | template<typename T> Vector3D<T> CrossProduct(const Vector3D<T> &vectorA, const Vector3D<T> &vectorB);
|
---|
[2] | 294 |
|
---|
[15] | 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 | */
|
---|
[167] | 304 | template<typename T> float DotProduct(const Vector3D<T> &vectorA, const Vector3D<T> &vectorB);
|
---|
[2] | 305 |
|
---|
| 306 | } // end namespace core
|
---|
| 307 | } // end namespace flair
|
---|
| 308 |
|
---|
| 309 | #endif // VECTOR3D_H
|
---|