1 | // %flair:license{
|
---|
2 | // This file is part of the Flair framework distributed under the
|
---|
3 | // CECILL-C 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 |
|
---|
18 | namespace flair { namespace core {
|
---|
19 | class Vector2D;
|
---|
20 | class RotationMatrix;
|
---|
21 | class Quaternion;
|
---|
22 |
|
---|
23 | /*! \class Vector3D
|
---|
24 | *
|
---|
25 | * \brief Class defining a 3D vector
|
---|
26 | */
|
---|
27 | class Vector3D {
|
---|
28 | public:
|
---|
29 | /*!
|
---|
30 | * \brief Constructor
|
---|
31 | *
|
---|
32 | * Construct a Vector3D using specified values.
|
---|
33 | *
|
---|
34 | * \param x
|
---|
35 | * \param y
|
---|
36 | * \param z
|
---|
37 | */
|
---|
38 | Vector3D(float x=0,float y=0,float z=0);
|
---|
39 |
|
---|
40 | /*!
|
---|
41 | * \brief Destructor
|
---|
42 | *
|
---|
43 | */
|
---|
44 | ~Vector3D();
|
---|
45 |
|
---|
46 | /*!
|
---|
47 | * \brief x
|
---|
48 | */
|
---|
49 | float x;
|
---|
50 |
|
---|
51 | /*!
|
---|
52 | * \brief y
|
---|
53 | */
|
---|
54 | float y;
|
---|
55 |
|
---|
56 | /*!
|
---|
57 | * \brief z
|
---|
58 | */
|
---|
59 | float z;
|
---|
60 |
|
---|
61 | /*!
|
---|
62 | * \brief x axis rotation
|
---|
63 | *
|
---|
64 | * \param value rotation value in radians
|
---|
65 | */
|
---|
66 | void RotateX(float value);
|
---|
67 |
|
---|
68 | /*!
|
---|
69 | * \brief x axis rotation
|
---|
70 | *
|
---|
71 | * \param value rotation value in degrees
|
---|
72 | */
|
---|
73 | void RotateXDeg(float value);
|
---|
74 |
|
---|
75 | /*!
|
---|
76 | * \brief y axis rotation
|
---|
77 | *
|
---|
78 | * \param value rotation value in radians
|
---|
79 | */
|
---|
80 | void RotateY(float value);
|
---|
81 |
|
---|
82 | /*!
|
---|
83 | * \brief y axis rotation
|
---|
84 | *
|
---|
85 | * \param value rotation value in degrees
|
---|
86 | */
|
---|
87 | void RotateYDeg(float value);
|
---|
88 |
|
---|
89 | /*!
|
---|
90 | * \brief z axis rotation
|
---|
91 | *
|
---|
92 | * \param value rotation value in radians
|
---|
93 | */
|
---|
94 | void RotateZ(float value);
|
---|
95 |
|
---|
96 | /*!
|
---|
97 | * \brief z axis rotation
|
---|
98 | *
|
---|
99 | * \param value rotation value in degrees
|
---|
100 | */
|
---|
101 | void RotateZDeg(float value);
|
---|
102 |
|
---|
103 | /*!
|
---|
104 | * \brief rotation
|
---|
105 | *
|
---|
106 | * \param matrix rotation matrix
|
---|
107 | */
|
---|
108 | void Rotate(const RotationMatrix &matrix);
|
---|
109 |
|
---|
110 | /*!
|
---|
111 | * \brief rotation
|
---|
112 | *
|
---|
113 | * Compute a rotation from a quaternion. This method uses a rotation matrix
|
---|
114 | * internaly.
|
---|
115 | *
|
---|
116 | * \param quaternion quaternion
|
---|
117 | */
|
---|
118 | void Rotate(const Quaternion &quaternion);
|
---|
119 |
|
---|
120 | /*!
|
---|
121 | * \brief Convert to a Vector2D
|
---|
122 | *
|
---|
123 | * Uses x and y coordinates.
|
---|
124 | *
|
---|
125 | * \param vector destination
|
---|
126 | */
|
---|
127 | void To2Dxy(Vector2D &vector) const;
|
---|
128 |
|
---|
129 | /*!
|
---|
130 | * \brief Convert to a Vector2D
|
---|
131 | *
|
---|
132 | * Uses x and y coordinates.
|
---|
133 | *
|
---|
134 | * \return destination
|
---|
135 | */
|
---|
136 | Vector2D To2Dxy(void) const;
|
---|
137 |
|
---|
138 | /*!
|
---|
139 | * \brief Norm
|
---|
140 | *
|
---|
141 | * \return value
|
---|
142 | */
|
---|
143 | float GetNorm(void) const;
|
---|
144 |
|
---|
145 | /*!
|
---|
146 | * \brief Normalize
|
---|
147 | */
|
---|
148 | void Normalize(void);
|
---|
149 |
|
---|
150 | /*!
|
---|
151 | * \brief Saturate
|
---|
152 | *
|
---|
153 | * Saturate between min and max
|
---|
154 | *
|
---|
155 | * \param min minimum value
|
---|
156 | * \param max maximum value
|
---|
157 | */
|
---|
158 | void Saturate(const Vector3D &min,const Vector3D &max);
|
---|
159 |
|
---|
160 | /*!
|
---|
161 | * \brief Saturate
|
---|
162 | *
|
---|
163 | * Saturate between min and max
|
---|
164 | *
|
---|
165 | * \param min minimum Vector3D(min,min,min) value
|
---|
166 | * \param max maximum Vector3D(max,max,max) value
|
---|
167 | */
|
---|
168 | void Saturate(float min,float max);
|
---|
169 |
|
---|
170 | /*!
|
---|
171 | * \brief Saturate
|
---|
172 | *
|
---|
173 | * Saturate between -abs(value) and abs(value)
|
---|
174 | *
|
---|
175 | * \param value saturation Vector3D value
|
---|
176 | */
|
---|
177 | void Saturate(const Vector3D &value);
|
---|
178 |
|
---|
179 | /*!
|
---|
180 | * \brief Saturate
|
---|
181 | *
|
---|
182 | * Saturate between -abs(Vector3D(value,value,value)) and abs(Vector3D(value,value,value))
|
---|
183 | *
|
---|
184 | * \param value saturation Vector3D(value,value,value)
|
---|
185 | */
|
---|
186 | void Saturate(float value);
|
---|
187 |
|
---|
188 | float &operator[](size_t idx);
|
---|
189 | const float &operator[](size_t idx) const;
|
---|
190 | Vector3D &operator=(const Vector3D& vector);
|
---|
191 | Vector3D &operator+=(const Vector3D& vector);
|
---|
192 | Vector3D &operator-=(const Vector3D& vector);
|
---|
193 |
|
---|
194 | private:
|
---|
195 |
|
---|
196 | };
|
---|
197 |
|
---|
198 | /*! Add
|
---|
199 | *
|
---|
200 | * \brief Add
|
---|
201 | *
|
---|
202 | * \param vectorA vector
|
---|
203 | * \param vectorB vector
|
---|
204 | *
|
---|
205 | * \return vectorA+vectorB
|
---|
206 | */
|
---|
207 | Vector3D operator + (const Vector3D &vectorA,const Vector3D &vectorB);
|
---|
208 |
|
---|
209 | /*! Substract
|
---|
210 | *
|
---|
211 | * \brief Substract
|
---|
212 | *
|
---|
213 | * \param vectorA vector
|
---|
214 | * \param vectorB vector
|
---|
215 | *
|
---|
216 | * \return vectorA-vectorB
|
---|
217 | */
|
---|
218 | Vector3D operator - (const Vector3D &vectorA,const Vector3D &vectorB);
|
---|
219 |
|
---|
220 | /*! Minus
|
---|
221 | *
|
---|
222 | * \brief Minus
|
---|
223 | *
|
---|
224 | * \param vector vector
|
---|
225 | *
|
---|
226 | * \return -vector
|
---|
227 | */
|
---|
228 | Vector3D operator-(const Vector3D &vector);
|
---|
229 |
|
---|
230 | /*! Divid
|
---|
231 | *
|
---|
232 | * \brief Divid
|
---|
233 | *
|
---|
234 | * \param vector vector
|
---|
235 | * \param coeff coefficent
|
---|
236 | *
|
---|
237 | * \return vector/coefficient
|
---|
238 | */
|
---|
239 | Vector3D operator / (const Vector3D &vector, float coeff);
|
---|
240 |
|
---|
241 | /*! Hadamard product
|
---|
242 | *
|
---|
243 | * \brief Hadamard product
|
---|
244 | *
|
---|
245 | * \param vectorA vector
|
---|
246 | * \param vectorBA vector
|
---|
247 | *
|
---|
248 | * \return Hadamard product
|
---|
249 | */
|
---|
250 | Vector3D operator * (const Vector3D &vectorA, const Vector3D &vectorB);
|
---|
251 |
|
---|
252 | /*! Multiply
|
---|
253 | *
|
---|
254 | * \brief Multiply
|
---|
255 | *
|
---|
256 | * \param vector vector
|
---|
257 | * \param coeff coefficent
|
---|
258 | *
|
---|
259 | * \return coefficient*vector
|
---|
260 | */
|
---|
261 | Vector3D operator * (const Vector3D &vector, float coeff);
|
---|
262 |
|
---|
263 | /*! Multiply
|
---|
264 | *
|
---|
265 | * \brief Multiply
|
---|
266 | *
|
---|
267 | * \param coeff coefficent
|
---|
268 | * \param vector vector
|
---|
269 | *
|
---|
270 | * \return coefficient*vector
|
---|
271 | */
|
---|
272 | Vector3D operator * (float coeff, const Vector3D &vector);
|
---|
273 |
|
---|
274 | /*! Cross product
|
---|
275 | *
|
---|
276 | * \brief Cross product
|
---|
277 | *
|
---|
278 | * \param vectorA first vector
|
---|
279 | * \param vectorB second vector
|
---|
280 | *
|
---|
281 | * \return cross product
|
---|
282 | */
|
---|
283 | Vector3D CrossProduct(const Vector3D &vectorA, const Vector3D &vectorB);
|
---|
284 |
|
---|
285 | /*! Dot product
|
---|
286 | *
|
---|
287 | * \brief Dot product
|
---|
288 | *
|
---|
289 | * \param vectorA first vector
|
---|
290 | * \param vectorB second vector
|
---|
291 | *
|
---|
292 | * \return dot product
|
---|
293 | */
|
---|
294 | float DotProduct(const Vector3D &vectorA, const Vector3D &vectorB);
|
---|
295 |
|
---|
296 | } // end namespace core
|
---|
297 | } // end namespace flair
|
---|
298 |
|
---|
299 | #endif // VECTOR3D_H
|
---|