source: flair-dev/trunk/include/FlairCore/Vector3D.h@ 79

Last change on this file since 79 was 50, checked in by Sanahuja Guillaume, 7 years ago

doc

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