Thanks to visit codestin.com
Credit goes to canreader.github.io

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