ADTF Display Toolbox
Loading...
Searching...
No Matches
vector3.h
Go to the documentation of this file.
1
7#pragma once
8
9#include <adtf_utils.h>
11
12#include <math.h>
13
14namespace adtf
15{
16
17namespace disptb
18{
19
20namespace graphicslib
21{
22
23namespace dengar
24{
25
31class cVector3 : public IVector3
32{
33private:
34 tFloat64 x;
35 tFloat64 y;
36 tFloat64 z;
37
38 static const tFloat64 nullScalar;
39 static const tFloat64 oneScalar;
40
41public:
42 static const cVector3 Null;
43 static const cVector3 One;
44
45public:
50 {
51 Zero();
52 }
53
59 cVector3(const IVector3* pVector3)
60 {
61 Set(pVector3->GetX(), pVector3->GetY(), pVector3->GetZ());
62 }
63
71 cVector3(const tFloat64 f64X, const tFloat64 f64Y, const tFloat64 f64Z)
72 {
73 Set(f64X, f64Y, f64Z);
74 }
75
79 tVoid Release()
80 {
81 delete this;
82 }
83
89 OPT_INLINE void Set(const cVector3& Vector)
90 {
91 x = Vector.x;
92 y = Vector.y;
93 z = Vector.z;
94 }
95
101 OPT_INLINE void Set(const tFloat64 Value)
102 {
103 x = y = z = Value;
104 }
105
113 OPT_INLINE void Set(const tFloat64 f64X, const tFloat64 f64Y, const tFloat64 f64Z)
114 {
115 x = f64X;
116 y = f64Y;
117 z = f64Z;
118 }
119
123 OPT_INLINE void Zero()
124 {
125 x = y = z = 0.0;
126 }
127
133 OPT_INLINE void Add(const cVector3& Vector)
134 {
135 x += Vector.x;
136 y += Vector.y;
137 z += Vector.z;
138 }
139
145 OPT_INLINE void Sub(const cVector3& Vector)
146 {
147 x -= Vector.x;
148 y -= Vector.y;
149 z -= Vector.z;
150 }
151
157 OPT_INLINE void Scale(const tFloat64 Value)
158 {
159 x *= Value;
160 y *= Value;
161 z *= Value;
162 }
163
169 OPT_INLINE void Scale(const cVector3& Vector)
170 {
171 x *= Vector.x;
172 y *= Vector.y;
173 z *= Vector.z;
174 }
175
176 // void Rotate(const cVector3& Vector);
177
186 OPT_INLINE cVector3 Scalar(const cVector3& Vector) const
187 {
188 return cVector3(x * Vector.x, y * Vector.y, z * Vector.z);
189 }
190
198 OPT_INLINE cVector3 Multiply(const cVector3& Vector) const
199 {
200 return *this * Vector;
201 }
202
203 // OPT_INLINE cVector3 Multiply(const cMatrix& Matrix) const;
204
210 tFloat Length() const
211 {
212 return (tFloat64) sqrt(x * x + y * y + z * z);
213 }
214
219 {
220 tFloat64 len = Length();
221
222 if (len > 0)
223 {
224 x /= len;
225 y /= len;
226 z /= len;
227 }
228 else
229 x = y = z = 0.0;
230 }
231
235 void Dump()
236 {
237 /*
238 * Using the largest available float type is compatible with all
239 * definitions of 'tScalar'.
240 */
241 printf("%05.2f\n", x);
242 printf("%05.2f\n", y);
243 printf("%05.2f\n", z);
244 }
245
251 tFloat64 GetX() const
252 {
253 return x;
254 }
255
262 tVoid SetX(tFloat64 f64XValue)
263 {
264 x = f64XValue;
265 }
266
272 tFloat64 GetY() const
273 {
274 return y;
275 }
276
283 tVoid SetY(tFloat64 f64YValue)
284 {
285 y = f64YValue;
286 }
287
293 tFloat64 GetZ() const
294 {
295 return z;
296 }
297
304 tVoid SetZ(tFloat64 f64ZValue)
305 {
306 z = f64ZValue;
307 }
308
317 {
318 Set(v.x, v.y, v.z);
319
320 return *this;
321 }
322
329 {
330 return cVector3(-x, -y, -z);
331 };
332
341 friend cVector3 operator+(const cVector3& v1, const cVector3& v2)
342 {
343 return cVector3(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
344 }
345
354 friend cVector3 operator-(const cVector3& v1, const cVector3& v2)
355 {
356 return cVector3(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
357 }
358
367 friend cVector3 operator*(const cVector3& v1, const cVector3& v2)
368 {
369 return cVector3(v1.y * v2.z - v1.z * v2.y, v1.z * v2.x - v1.x * v2.z, v1.x * v2.y - v1.y * v2.x);
370 }
371
380 friend cVector3 operator*(const tFloat64 s, const cVector3& v)
381 {
382 return cVector3(v.x * s, v.y * s, v.z * s);
383 }
384
393 friend cVector3 operator*(const cVector3& v, const tFloat64 s)
394 {
395 return cVector3(v.x * s, v.y * s, v.z * s);
396 }
397
406 friend cVector3 operator/(const cVector3& v, const tFloat64 s)
407 {
408 return cVector3(v.x / s, v.y / s, v.z / s);
409 }
410
417 friend void operator+=(cVector3& v1, const cVector3& v2)
418 {
419 v1.x += v2.x;
420 v1.y += v2.y;
421 v1.z += v2.z;
422 }
423
430 friend void operator-=(cVector3& v1, const cVector3& v2)
431 {
432 v1.x -= v2.x;
433 v1.y -= v2.y;
434 v1.z -= v2.z;
435 }
436
445 friend bool operator==(const cVector3& v1, const cVector3& v2)
446 {
447 if (v1.x == v2.x && v1.y == v2.y && v1.z == v2.z)
448 return true;
449 else
450 return false;
451 }
452
461 friend bool operator!=(const cVector3& v1, const cVector3& v2)
462 {
463 if (v1.x == v2.x && v1.y == v2.y && v1.z == v2.z)
464 return false;
465 else
466 return true;
467 }
468
474 explicit operator IVector3*()
475 {
476 return static_cast<IVector3*>(this);
477 }
478};
479
480inline const tFloat64 cVector3::nullScalar(0.0);
481inline const tFloat64 cVector3::oneScalar(1.0);
482inline const cVector3 cVector3::Null(nullScalar, nullScalar, nullScalar);
483inline const cVector3 cVector3::One(oneScalar, oneScalar, oneScalar);
484
485} // namespace dengar
486
487using dengar::cVector3;
488} // namespace graphicslib
489
490} // namespace disptb
491
492} // namespace adtf
OPT_INLINE void Sub(const cVector3 &Vector)
Subtract the given vector from the current one.
Definition vector3.h:145
OPT_INLINE void Zero()
Set vector to zero.
Definition vector3.h:123
OPT_INLINE void Set(const tFloat64 Value)
Set vector to the given value.
Definition vector3.h:101
tVoid Release()
Releases this vector.
Definition vector3.h:79
cVector3 operator-(void)
Negate the current vector.
Definition vector3.h:328
tVoid SetZ(tFloat64 f64ZValue)
Set the current z value to the given one.
Definition vector3.h:304
friend cVector3 operator*(const tFloat64 s, const cVector3 &v)
Scalar product of vector and scalar.
Definition vector3.h:380
OPT_INLINE void Scale(const tFloat64 Value)
Scale the current vector by the given value.
Definition vector3.h:157
static const tFloat64 oneScalar
scalar identity value
Definition vector3.h:39
friend bool operator==(const cVector3 &v1, const cVector3 &v2)
Comparison for equality of two vectors.
Definition vector3.h:445
OPT_INLINE void Set(const cVector3 &Vector)
Set vector to the given value.
Definition vector3.h:89
friend cVector3 operator+(const cVector3 &v1, const cVector3 &v2)
Add two vectors.
Definition vector3.h:341
friend cVector3 operator/(const cVector3 &v, const tFloat64 s)
Divide vector through scalar.
Definition vector3.h:406
cVector3 operator=(const cVector3 &v)
Set the current vector to the given one.
Definition vector3.h:316
tFloat64 GetY() const
gets the value of the y component
Definition vector3.h:272
cVector3(const IVector3 *pVector3)
constructor from IVector3
Definition vector3.h:59
OPT_INLINE cVector3 Multiply(const cVector3 &Vector) const
Cross product of the current vector and the given one.
Definition vector3.h:198
void Dump()
Dump the current vector to stdout.
Definition vector3.h:235
tFloat64 GetZ() const
gets the value of the z component
Definition vector3.h:293
friend void operator-=(cVector3 &v1, const cVector3 &v2)
Subtraction of two vectors.
Definition vector3.h:430
friend bool operator!=(const cVector3 &v1, const cVector3 &v2)
Comparison for inequality of two vectors.
Definition vector3.h:461
tFloat64 x
X coordinate of vector.
Definition vector3.h:34
friend void operator+=(cVector3 &v1, const cVector3 &v2)
Add two vectors.
Definition vector3.h:417
cVector3(const tFloat64 f64X, const tFloat64 f64Y, const tFloat64 f64Z)
Constructor.
Definition vector3.h:71
tFloat Length() const
Calculate the length of the current vector.
Definition vector3.h:210
friend cVector3 operator-(const cVector3 &v1, const cVector3 &v2)
Subtract two vectors.
Definition vector3.h:354
tVoid SetY(tFloat64 f64YValue)
Set the current y value to the given one.
Definition vector3.h:283
tFloat64 z
Z coordinate of vector.
Definition vector3.h:36
OPT_INLINE void Scale(const cVector3 &Vector)
Scale the current vector by the given one.
Definition vector3.h:169
friend cVector3 operator*(const cVector3 &v1, const cVector3 &v2)
Cross-product of two vectors.
Definition vector3.h:367
static const tFloat64 nullScalar
scalar null value
Definition vector3.h:38
tVoid SetX(tFloat64 f64XValue)
Set the current x value to the given one.
Definition vector3.h:262
OPT_INLINE void Add(const cVector3 &Vector)
Add the given vector to the current one.
Definition vector3.h:133
static const cVector3 One
Identity vector.
Definition vector3.h:43
OPT_INLINE cVector3 Scalar(const cVector3 &Vector) const
Multiply every coordinate of the current vector with the corresponding coordinate from the given one.
Definition vector3.h:186
tFloat64 y
Y coordinate of vector.
Definition vector3.h:35
friend cVector3 operator*(const cVector3 &v, const tFloat64 s)
Scalar product of vector and scalar.
Definition vector3.h:393
OPT_INLINE void Set(const tFloat64 f64X, const tFloat64 f64Y, const tFloat64 f64Z)
Set vector to the given value.
Definition vector3.h:113
tFloat64 GetX() const
gets the value of the x component
Definition vector3.h:251
static const cVector3 Null
Null vector.
Definition vector3.h:42
void Normalize()
Normalize the current vector so that the length becomes one.
Definition vector3.h:218
Namespace for functionality provided by the Display Toolbox.
Main namespace.
Copyright © Audi Electronics Venture GmbH.