SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
Vector.hpp
Go to the documentation of this file.
1#ifndef _Vector_HPP_
2#define _Vector_HPP_
3
4#include <string>
5#include <sstream>
6#include <cmath>
7#include <stdexcept>
8#include <array>
9#include <algorithm>
10#include <cassert>
11#include <iomanip>
12
13#define VECTOR_Up Vector3D(0, 1, 0)
14#define VECTOR_Down Vector3D(0, -1, 0)
15#define VECTOR_Right Vector3D(1, 0, 0)
16#define VECTOR_Left Vector3D(-1, 0, 0)
17#define VECTOR_Forward Vector3D(0, 0, 1)
18#define VECTOR_Backward Vector3D(0, 0, -1)
19
20#define EPSILON 1e-5f
21
22namespace Sleak
23{
24 namespace Math
25 {
26 /// Fixed-size numeric vector with the standard component-wise algebra.
27 /// Vector2D/3D/4D wrap this for the common dimensions used engine-wide.
28 /// @ingroup math
29 template <typename T, size_t N>
30 class Vector {
31 public:
32 // Constructors
33 constexpr Vector() noexcept { data.fill(static_cast<T>(0)); }
34
35 constexpr Vector(std::initializer_list<T> list) {
36 if (list.size() != N) {
37 throw std::invalid_argument(
38 "Initializer list size does not match vector "
39 "dimension");
40 }
41 std::copy_n(list.begin(), N, data.begin());
42 }
43
44 // Access elements (read/write)
45 [[nodiscard]] T& operator[](size_t index) {
46 assert(index < N && "Vector index out of range");
47 return data[index];
48 }
49
50 // Read-only access
51 [[nodiscard]] const T& operator[](size_t index) const {
52 assert(index < N && "Vector index out of range");
53 return data[index];
54 }
55
56 // Basic operations
57 Vector<T, N> operator+(const Vector<T, N>& other) const {
58 Vector<T, N> result;
59 std::transform(data.begin(), data.end(), other.data.begin(),
60 result.data.begin(), std::plus<T>());
61 return result;
62 }
63
64 Vector<T, N> operator-(const Vector<T, N>& other) const {
65 Vector<T, N> result;
66 std::transform(data.begin(), data.end(), other.data.begin(),
67 result.data.begin(), std::minus<T>());
68 return result;
69 }
70
72 std::transform(data.begin(), data.end(), other.data.begin(),
73 data.begin(), std::plus<T>());
74 return *this;
75 }
76
78 std::transform(data.begin(), data.end(), other.data.begin(),
79 data.begin(), std::minus<T>());
80 return *this;
81 }
82
83 Vector<T, N> operator*(T scalar) const {
84 Vector<T, N> result;
85 std::transform(
86 data.begin(), data.end(), result.data.begin(),
87 [scalar](const T& val) { return val * scalar; });
88 return result;
89 }
90
91 Vector<T, N> operator/(T scalar) const {
92 if (scalar == 0) {
93 throw std::invalid_argument("Division by zero");
94 }
95 Vector<T, N> result;
96 for (size_t i = 0; i < N; ++i) {
97 result[i] = data[i] / scalar;
98 }
99 return result;
100 }
101
102 // Dot product
103 T Dot(const Vector<T, N>& other) const {
104 T result = 0;
105 for (size_t i = 0; i < N; ++i) {
106 result += data[i] * other[i];
107 }
108 return result;
109 }
110
111 // Cross product (only for 3D vectors)
112 template <size_t M = N>
113 typename std::enable_if<M == 3, Vector<T, N>>::type
114 Cross(const Vector<T, N>& other) const {
115 static_assert(N == 3, "Cross product is only defined for 3D vectors");
116 return {
117 data[1] * other[2] - data[2] * other[1],
118 data[2] * other[0] - data[0] * other[2],
119 data[0] * other[1] - data[1] * other[0]
120 };
121 }
122
123 // Magnitude (length)
124 T Magnitude() const {
125 T sum = 0;
126 for (size_t i = 0; i < N; ++i) {
127 sum += data[i] * data[i];
128 }
129 return std::sqrt(sum);
130 }
131
132 // Normalize the vector (in-place)
133 void Normalize() {
134 T mag = Magnitude();
135 if (mag == 0) {
136 data[0] = 0.0f; data[1] = 0.0f; data[2] = 0.0f;
137 return;
138 // TODO: throw std::runtime_error("Cannot normalize a zero vector");
139 }
140 *this = *this / mag;
141 }
142
143 // Return a normalized copy of the vector
145 Vector<T, N> result = *this;
146 result.Normalize();
147 return result;
148 }
149
150 // Equality comparison
151 bool operator==(const Vector<T, N>& other) const {
152 for (size_t i = 0; i < N; ++i) {
153 if (std::abs(data[i] - other[i]) >= EPSILON) {
154 return false;
155 }
156 }
157 return true;
158 }
159
160 // Inequality comparison
161 bool operator!=(const Vector<T, N>& other) const {
162 return !(*this == other);
163 }
164
165 // Convert to string
166 std::string ToString() const {
167 std::ostringstream ss;
168 ss << "Vector<" << N << ">(";
169 for (size_t i = 0; i < N; ++i) {
170 ss << data[i];
171 if (i < N - 1) ss << ", ";
172 }
173 ss << ")\n";
174 return ss.str();
175 }
176
177 /// Raw pointer to the backing N-element array.
179 return data.data();
180 }
181
182 friend std::ostream& operator<<(
183 std::ostream& os, const Vector<T, N>& v) {
184 os << v.ToString();
185 return os;
186 }
187
188 private:
189 std::array<T, N> data;
190 };
191
192 /// Two-component float vector, used for UVs, screen positions, and
193 /// min/max ranges such as a camera controller's pitch limits.
194 ///
195 /// Wraps Vector<float, 2> with named accessors and the usual
196 /// operators. Components are read with GetX()/GetY(), written with
197 /// SetX()/SetY() or Set(), and accumulated with AddX()/AddY().
198 ///
199 /// @code{.cpp}
200 /// Sleak::Math::Vector2D tiling(2.0f, 2.0f);
201 /// material->SetTiling(tiling);
202 ///
203 /// // Pitch clamp expressed as a min/max pair
204 /// controller->SetPitchRange(Sleak::Math::Vector2D(-89.0f, 89.0f));
205 /// @endcode
206 ///
207 /// @see Vector3D, Vector4D, Vector
208 /// @ingroup math
209 class Vector2D {
210 public:
211 // Constructors
212 Vector2D() : vec({0.0f, 0.0f}) {}
213 Vector2D(float x, float y) : vec({x, y}) {}
214
215 // Accessors
216 float GetX() const { return vec[0]; }
217 float GetY() const { return vec[1]; }
218
219 // Mutators
220 void SetX(float val) { vec[0] = val; }
221 void SetY(float val) { vec[1] = val; }
222 void Set(float x, float y) { vec[0] = x; vec[1] = y; }
223
224 void AddX(float val) { vec[0] += val; }
225 void AddY(float val) { vec[1] += val; }
226 void Add(float x, float y) { vec[0] += x; vec[1] += y; }
227
228 // Basic operations
229 Vector2D operator+(const Vector2D& other) const {
230 return Vector2D(vec[0] + other.vec[0], vec[1] + other.vec[1]);
231 }
232
233 Vector2D operator-(const Vector2D& other) const {
234 return Vector2D(vec[0] - other.vec[0], vec[1] - other.vec[1]);
235 }
236
237 Vector2D& operator+=(const Vector2D& other) {
238 vec[0] += other.vec[0];
239 vec[1] += other.vec[1];
240 return *this;
241 }
242
243 Vector2D& operator-=(const Vector2D& other) {
244 vec[0] -= other.vec[0];
245 vec[1] -= other.vec[1];
246 return *this;
247 }
248
249 // Scalar operations
250 Vector2D operator*(float scalar) const {
251 return Vector2D(vec[0] * scalar, vec[1] * scalar);
252 }
253
254 Vector2D operator/(float scalar) const {
255 if (scalar == 0) throw std::invalid_argument("Division by zero");
256 return Vector2D(vec[0] / scalar, vec[1] / scalar);
257 }
258
259 // Vector operations
260 float Dot(const Vector2D& other) const {
261 return vec[0] * other.vec[0] + vec[1] * other.vec[1];
262 }
263
264 float Cross(const Vector2D& other) const {
265 return vec[0] * other.vec[1] - vec[1] * other.vec[0];
266 }
267
268 // Magnitude and normalization
269 float Magnitude() const {
270 return std::hypot(vec[0], vec[1]);
271 }
272
273 void Normalize() {
274 float mag = Magnitude();
275 if (mag == 0) throw std::runtime_error("Cannot normalize a zero vector");
276 vec[0] /= mag;
277 vec[1] /= mag;
278 }
279
281 Vector2D result = *this;
282 result.Normalize();
283 return result;
284 }
285
286 // Equality comparison
287 bool operator==(const Vector2D& other) const {
288 return std::abs(vec[0] - other.vec[0]) < EPSILON &&
289 std::abs(vec[1] - other.vec[1]) < EPSILON;
290 }
291
292 bool operator!=(const Vector2D& other) const {
293 return !(*this == other);
294 }
295
296 friend std::ostream& operator<< (std::ostream& os, const Vector2D& vec) {
297 os << vec.ToString();
298 return os;
299 }
300
301 std::string ToString() const {
302 return ToString(2);
303 }
304
305 std::string ToString(uint8_t precision) const {
306 std::ostringstream ss;
307 ss << std::fixed << std::setprecision(precision);
308 ss << "Vector2D(" << vec[0] << ", " << vec[1] << ")";
309 return ss.str();
310 }
311
312 float* ToArray() {
313 return vec.ToRawArray();
314 }
315
316 private:
318 };
319
320 /// Three-component float vector: the workhorse type for positions,
321 /// directions, scales, normals, and velocities across the engine.
322 ///
323 /// Wraps Vector<float, 3> with named accessors, full arithmetic,
324 /// and the geometric operations you need day to day: Dot(),
325 /// Cross(), Magnitude(), Normalize() (in place) and Normalized()
326 /// (returns a copy). Note that `operator*` with another Vector3D is
327 /// componentwise, not a dot or cross product.
328 ///
329 /// Named constants cover the axis directions: Zero(), Identity(),
330 /// Up(), Down(), Left(), Right(), Forward(), and Backward().
331 ///
332 /// @code{.cpp}
333 /// using Sleak::Math::Vector3D;
334 ///
335 /// Vector3D camPos(-5.0f, 3.0f, -5.0f);
336 /// Vector3D target(0.0f, 0.0f, 0.0f);
337 ///
338 /// Vector3D forward = (target - camPos).Normalized();
339 /// float distance = (target - camPos).Magnitude();
340 ///
341 /// // Build a right vector from forward and world up
342 /// Vector3D right = forward.Cross(Vector3D::Up()).Normalized();
343 ///
344 /// // Facing test: positive means the target is in front
345 /// bool inFront = forward.Dot(target - camPos) > 0.0f;
346 ///
347 /// // Move along a direction
348 /// camPos += forward * (speed * deltaTime);
349 /// @endcode
350 ///
351 /// @see Vector2D, Vector4D, Vector, Quaternion
352 /// @ingroup math
353 class Vector3D {
354 public:
355 // Constructors
356 Vector3D() : vec({0.0f, 0.0f, 0.0f}) {}
357 Vector3D(float x, float y, float z) : vec({x, y, z}) {}
358
359 // Accessors
360 float GetX() const { return vec[0]; }
361 float GetY() const { return vec[1]; }
362 float GetZ() const { return vec[2]; }
363
364 // Mutators
365 void SetX(float val) { vec[0] = val; }
366 void SetY(float val) { vec[1] = val; }
367 void SetZ(float val) { vec[2] = val; }
368 void Set(float x, float y, float z) {
369 vec[0] = x; vec[1] = y; vec[2] = z;
370 }
371
372 void AddX(float val) { vec[0] += val; }
373 void AddY(float val) { vec[1] += val; }
374 void AddZ(float val) { vec[2] += val; }
375 void Add(float x, float y, float z) {
376 vec[0] += x; vec[1] += y; vec[2] += z;
377 }
378
379 // Basic operations
380 Vector3D operator+(const Vector3D& other) const {
381 return Vector3D(vec[0] + other.vec[0], vec[1] + other.vec[1], vec[2] + other.vec[2]);
382 }
383
384 Vector3D operator-(const Vector3D& other) const {
385 return Vector3D(vec[0] - other.vec[0], vec[1] - other.vec[1], vec[2] - other.vec[2]);
386 }
387
388 Vector3D& operator+=(const Vector3D& other) {
389 vec[0] += other.vec[0];
390 vec[1] += other.vec[1];
391 vec[2] += other.vec[2];
392 return *this;
393 }
394
395 Vector3D& operator-=(const Vector3D& other) {
396 vec[0] -= other.vec[0];
397 vec[1] -= other.vec[1];
398 vec[2] -= other.vec[2];
399 return *this;
400 }
401
402 // Scalar operations
403 Vector3D operator*(float scalar) const {
404 return Vector3D(vec[0] * scalar, vec[1] * scalar, vec[2] * scalar);
405 }
406
407 Vector3D operator*(const Vector3D& other) const {
408 return Vector3D(vec[0] * other.GetX(), vec[1] * other.GetY(), vec[2] * other.GetZ());
409 }
410
411 Vector3D operator/(float scalar) const {
412 if (scalar == 0) throw std::invalid_argument("Division by zero");
413 return Vector3D(vec[0] / scalar, vec[1] / scalar, vec[2] / scalar);
414 }
415
416 // Vector operations
417 float Dot(const Vector3D& other) const {
418 return vec[0] * other.vec[0] + vec[1] * other.vec[1] + vec[2] * other.vec[2];
419 }
420
421 Vector3D Cross(const Vector3D& other) const {
422 return Vector3D(
423 vec[1] * other.vec[2] - vec[2] * other.vec[1],
424 vec[2] * other.vec[0] - vec[0] * other.vec[2],
425 vec[0] * other.vec[1] - vec[1] * other.vec[0]
426 );
427 }
428
429 // Magnitude and normalization
430 float Magnitude() const {
431 return std::sqrt(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]);
432 }
433
434 // Normalizes the current vector
436 float mag = Magnitude();
437
438 if(mag == 0) {
439 vec[0] = 0;
440 vec[1] = 0;
441 vec[2] = 0;
442 }
443 else
444 {
445 vec[0] /= mag;
446 vec[1] /= mag;
447 vec[2] /= mag;
448 }
449
450 return *this;
451 }
452
453 // Makes another instance of this vector and noröalizes it
455 Vector3D result = *this;
456 result.Normalize();
457 return result;
458 }
459
460 // Equality comparison
461 bool operator==(const Vector3D& other) const {
462 return std::abs(vec[0] - other.vec[0]) < EPSILON &&
463 std::abs(vec[1] - other.vec[1]) < EPSILON &&
464 std::abs(vec[2] - other.vec[2]) < EPSILON;
465 }
466
467 bool operator!=(const Vector3D& other) const {
468 return !(*this == other);
469 }
470
471 friend std::ostream& operator<< (std::ostream& os, const Vector3D& vec) {
472 os << vec.ToString();
473 return os;
474 }
475
477 return vec;
478 }
479
480 std::string ToString() const {
481 return ToString(2);
482 }
483
484 std::string ToString(uint8_t precision) const {
485 std::ostringstream ss;
486 ss << std::fixed << std::setprecision(precision);
487 ss << "Vector3D(" << vec[0] << ", " << vec[1] << ", " << vec[2] << ")";
488 return ss.str();
489 }
490
491 float* ToArray() {
492 return vec.ToRawArray();
493 }
494
495 static Vector3D Zero() { return Vector3D(0,0,0);}
496 static Vector3D Identity() { return Vector3D(1,1,1);}
497 static Vector3D Up() { return VECTOR_Up; }
498 static Vector3D Down() { return VECTOR_Down; }
499 static Vector3D Right() { return VECTOR_Right; }
500 static Vector3D Left() { return VECTOR_Left; }
501 static Vector3D Forward() { return VECTOR_Forward; }
502 static Vector3D Backward() { return VECTOR_Backward; }
503
504 private:
506 };
507
508 /// Four-component float vector for homogeneous coordinates, RGBA
509 /// values, and shader constant payloads.
510 ///
511 /// Wraps Vector<float, 4> with the same accessor pattern as
512 /// Vector2D and Vector3D, adding a W component. Reach for it when a
513 /// value has to survive a Matrix4 transform with its translation
514 /// intact (`w = 1` for points, `w = 0` for directions), or when you
515 /// are packing four floats for the GPU.
516 ///
517 /// @code{.cpp}
518 /// using Sleak::Math::Vector4D;
519 ///
520 /// Vector4D point(1.0f, 2.0f, 3.0f, 1.0f); // a position
521 /// Vector4D direction(0.0f, 1.0f, 0.0f, 0.0f); // a direction
522 /// Vector4D tint(1.0f, 0.95f, 0.85f, 1.0f); // RGBA
523 ///
524 /// float alpha = tint.GetW();
525 /// @endcode
526 ///
527 /// @see Vector2D, Vector3D, Vector, Matrix4, Color
528 /// @ingroup math
529 class Vector4D {
530 public:
531 // Constructors
532 Vector4D() : vec({0.0f, 0.0f, 0.0f, 0.0f}) {}
533 Vector4D(float x, float y, float z, float w) : vec({x, y, z, w}) {}
534
535 // Accessors
536 float GetX() const { return vec[0]; }
537 float GetY() const { return vec[1]; }
538 float GetZ() const { return vec[2]; }
539 float GetW() const { return vec[3]; }
540
541 // Mutators
542 void SetX(float val) { vec[0] = val; }
543 void SetY(float val) { vec[1] = val; }
544 void SetZ(float val) { vec[2] = val; }
545 void SetW(float val) { vec[3] = val; }
546 void Set(float x, float y, float z, float w) {
547 vec[0] = x; vec[1] = y; vec[2] = z; vec[3] = w;
548 }
549
550 // Basic operations
551 Vector4D operator+(const Vector4D& other) const {
552 return Vector4D(vec[0] + other.vec[0], vec[1] + other.vec[1], vec[2] + other.vec[2], vec[3] + other.vec[3]);
553 }
554
555 Vector4D operator-(const Vector4D& other) const {
556 return Vector4D(vec[0] - other.vec[0], vec[1] - other.vec[1], vec[2] - other.vec[2], vec[3] - other.vec[3]);
557 }
558
559 Vector4D& operator+=(const Vector4D& other) {
560 vec[0] += other.vec[0];
561 vec[1] += other.vec[1];
562 vec[2] += other.vec[2];
563 vec[3] += other.vec[3];
564 return *this;
565 }
566
567 Vector4D& operator-=(const Vector4D& other) {
568 vec[0] -= other.vec[0];
569 vec[1] -= other.vec[1];
570 vec[2] -= other.vec[2];
571 vec[3] -= other.vec[3];
572 return *this;
573 }
574
575 // Scalar operations
576 Vector4D operator*(float scalar) const {
577 return Vector4D(vec[0] * scalar, vec[1] * scalar, vec[2] * scalar, vec[3] * scalar);
578 }
579
580 Vector4D operator/(float scalar) const {
581 if (scalar == 0) throw std::invalid_argument("Division by zero");
582 return Vector4D(vec[0] / scalar, vec[1] / scalar, vec[2] / scalar, vec[3] / scalar);
583 }
584
585 // Vector operations
586 float Dot(const Vector4D& other) const {
587 return vec[0] * other.vec[0] + vec[1] * other.vec[1] + vec[2] * other.vec[2] + vec[3] * other.vec[3];
588 }
589
590 // Magnitude and normalization
591 float Magnitude() const {
592 return std::sqrt(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2] + vec[3] * vec[3]);
593 }
594
595 void Normalize() {
596 float mag = Magnitude();
597 if (mag == 0) throw std::runtime_error("Cannot normalize a zero vector");
598 vec[0] /= mag;
599 vec[1] /= mag;
600 vec[2] /= mag;
601 vec[3] /= mag;
602 }
603
605 Vector4D result = *this;
606 result.Normalize();
607 return result;
608 }
609
610 // Equality comparison
611 bool operator==(const Vector4D& other) const {
612 return std::abs(vec[0] - other.vec[0]) < EPSILON &&
613 std::abs(vec[1] - other.vec[1]) < EPSILON &&
614 std::abs(vec[2] - other.vec[2]) < EPSILON &&
615 std::abs(vec[3] - other.vec[3]) < EPSILON;
616 }
617
618 bool operator!=(const Vector4D& other) const {
619 return !(*this == other);
620 }
621
622 friend std::ostream& operator<< (std::ostream& os, const Vector4D& vec) {
623 os << vec.ToString();
624 return os;
625 }
626
627 std::string ToString() const {
628 return ToString(2);
629 }
630
631 std::string ToString(uint8_t precision) const {
632 std::ostringstream ss;
633 ss << std::fixed << std::setprecision(precision);
634 ss << "Vector4D(" << vec[0] << ", " << vec[1] << ", " << vec[2] << ", " << vec[3] << ")";
635 return ss.str();
636 }
637
638 float* ToArray() {
639 return vec.ToRawArray();
640 }
641
642 private:
644 };
645
646 // Free functions for scalar multiplication (commutative)
647 template <typename T, size_t N>
648 Vector<T, N> operator*(T scalar, const Vector<T, N>& vec) {
649 return vec * scalar;
650 }
651
652 }
653} // namespace Sleak
654
655
656#endif
#define EPSILON
Definition Vector.hpp:20
#define VECTOR_Down
Definition Vector.hpp:14
#define VECTOR_Backward
Definition Vector.hpp:18
#define VECTOR_Left
Definition Vector.hpp:16
#define VECTOR_Forward
Definition Vector.hpp:17
#define VECTOR_Up
Definition Vector.hpp:13
#define VECTOR_Right
Definition Vector.hpp:15
std::string ToString() const
Definition Vector.hpp:301
bool operator!=(const Vector2D &other) const
Definition Vector.hpp:292
Vector2D operator*(float scalar) const
Definition Vector.hpp:250
void SetY(float val)
Definition Vector.hpp:221
void Set(float x, float y)
Definition Vector.hpp:222
friend std::ostream & operator<<(std::ostream &os, const Vector2D &vec)
Definition Vector.hpp:296
Vector2D Normalized() const
Definition Vector.hpp:280
float Magnitude() const
Definition Vector.hpp:269
void AddX(float val)
Definition Vector.hpp:224
void AddY(float val)
Definition Vector.hpp:225
void Add(float x, float y)
Definition Vector.hpp:226
float Cross(const Vector2D &other) const
Definition Vector.hpp:264
Vector2D operator+(const Vector2D &other) const
Definition Vector.hpp:229
bool operator==(const Vector2D &other) const
Definition Vector.hpp:287
Vector2D operator/(float scalar) const
Definition Vector.hpp:254
std::string ToString(uint8_t precision) const
Definition Vector.hpp:305
Vector2D & operator+=(const Vector2D &other)
Definition Vector.hpp:237
float GetX() const
Definition Vector.hpp:216
Vector2D(float x, float y)
Definition Vector.hpp:213
Vector2D & operator-=(const Vector2D &other)
Definition Vector.hpp:243
void SetX(float val)
Definition Vector.hpp:220
float Dot(const Vector2D &other) const
Definition Vector.hpp:260
float GetY() const
Definition Vector.hpp:217
Vector2D operator-(const Vector2D &other) const
Definition Vector.hpp:233
Vector3D & operator-=(const Vector3D &other)
Definition Vector.hpp:395
bool operator!=(const Vector3D &other) const
Definition Vector.hpp:467
static Vector3D Right()
Definition Vector.hpp:499
void Add(float x, float y, float z)
Definition Vector.hpp:375
void AddY(float val)
Definition Vector.hpp:373
float GetY() const
Definition Vector.hpp:361
void Set(float x, float y, float z)
Definition Vector.hpp:368
float Dot(const Vector3D &other) const
Definition Vector.hpp:417
Vector3D(float x, float y, float z)
Definition Vector.hpp:357
Vector3D operator-(const Vector3D &other) const
Definition Vector.hpp:384
void SetY(float val)
Definition Vector.hpp:366
float GetX() const
Definition Vector.hpp:360
Vector3D & Normalize()
Definition Vector.hpp:435
Vector3D & operator+=(const Vector3D &other)
Definition Vector.hpp:388
void AddX(float val)
Definition Vector.hpp:372
static Vector3D Backward()
Definition Vector.hpp:502
static Vector3D Left()
Definition Vector.hpp:500
Vector3D Normalized() const
Definition Vector.hpp:454
std::string ToString(uint8_t precision) const
Definition Vector.hpp:484
float GetZ() const
Definition Vector.hpp:362
static Vector3D Identity()
Definition Vector.hpp:496
void AddZ(float val)
Definition Vector.hpp:374
static Vector3D Forward()
Definition Vector.hpp:501
Vector3D operator+(const Vector3D &other) const
Definition Vector.hpp:380
void SetX(float val)
Definition Vector.hpp:365
static Vector3D Zero()
Definition Vector.hpp:495
bool operator==(const Vector3D &other) const
Definition Vector.hpp:461
Vector3D Cross(const Vector3D &other) const
Definition Vector.hpp:421
Vector3D operator*(const Vector3D &other) const
Definition Vector.hpp:407
float Magnitude() const
Definition Vector.hpp:430
void SetZ(float val)
Definition Vector.hpp:367
Vector3D operator/(float scalar) const
Definition Vector.hpp:411
static Vector3D Down()
Definition Vector.hpp:498
friend std::ostream & operator<<(std::ostream &os, const Vector3D &vec)
Definition Vector.hpp:471
Vector< float, 3 > BaseVector()
Definition Vector.hpp:476
std::string ToString() const
Definition Vector.hpp:480
Vector3D operator*(float scalar) const
Definition Vector.hpp:403
static Vector3D Up()
Definition Vector.hpp:497
float GetW() const
Definition Vector.hpp:539
void SetZ(float val)
Definition Vector.hpp:544
Vector4D(float x, float y, float z, float w)
Definition Vector.hpp:533
Vector4D & operator+=(const Vector4D &other)
Definition Vector.hpp:559
void SetX(float val)
Definition Vector.hpp:542
bool operator==(const Vector4D &other) const
Definition Vector.hpp:611
void SetY(float val)
Definition Vector.hpp:543
Vector4D operator+(const Vector4D &other) const
Definition Vector.hpp:551
float GetX() const
Definition Vector.hpp:536
void Set(float x, float y, float z, float w)
Definition Vector.hpp:546
Vector4D & operator-=(const Vector4D &other)
Definition Vector.hpp:567
Vector4D operator/(float scalar) const
Definition Vector.hpp:580
Vector4D operator*(float scalar) const
Definition Vector.hpp:576
friend std::ostream & operator<<(std::ostream &os, const Vector4D &vec)
Definition Vector.hpp:622
Vector4D Normalized() const
Definition Vector.hpp:604
float Dot(const Vector4D &other) const
Definition Vector.hpp:586
std::string ToString(uint8_t precision) const
Definition Vector.hpp:631
float GetZ() const
Definition Vector.hpp:538
std::string ToString() const
Definition Vector.hpp:627
float GetY() const
Definition Vector.hpp:537
Vector4D operator-(const Vector4D &other) const
Definition Vector.hpp:555
float Magnitude() const
Definition Vector.hpp:591
void SetW(float val)
Definition Vector.hpp:545
bool operator!=(const Vector4D &other) const
Definition Vector.hpp:618
T Dot(const Vector< T, N > &other) const
Definition Vector.hpp:103
Vector< T, N > operator+(const Vector< T, N > &other) const
Definition Vector.hpp:57
bool operator==(const Vector< T, N > &other) const
Definition Vector.hpp:151
Vector< T, N > operator/(T scalar) const
Definition Vector.hpp:91
Vector< T, N > operator-(const Vector< T, N > &other) const
Definition Vector.hpp:64
T * ToRawArray()
Raw pointer to the backing N-element array.
Definition Vector.hpp:178
std::enable_if< M==3, Vector< T, N > >::type Cross(const Vector< T, N > &other) const
Definition Vector.hpp:114
Vector< T, N > & operator-=(const Vector< T, N > &other)
Definition Vector.hpp:77
Vector< T, N > & operator+=(const Vector< T, N > &other)
Definition Vector.hpp:71
constexpr Vector(std::initializer_list< T > list)
Definition Vector.hpp:35
Vector< T, N > operator*(T scalar) const
Definition Vector.hpp:83
const T & operator[](size_t index) const
Definition Vector.hpp:51
bool operator!=(const Vector< T, N > &other) const
Definition Vector.hpp:161
T Magnitude() const
Definition Vector.hpp:124
T & operator[](size_t index)
Definition Vector.hpp:45
constexpr Vector() noexcept
Definition Vector.hpp:33
std::string ToString() const
Definition Vector.hpp:166
friend std::ostream & operator<<(std::ostream &os, const Vector< T, N > &v)
Definition Vector.hpp:182
Vector< T, N > Normalized() const
Definition Vector.hpp:144
Vector3D operator*(const Quaternion &quat, const Vector3D &vec)
Root namespace for everything the engine exposes.
Definition Camera.hpp:10