28 #ifndef BERSERK_TVECN_H
29 #define BERSERK_TVECN_H
37 #include <initializer_list>
54 template<
typename T, u
int32 N>
57 static_assert(
N > 0,
"Vector size must be more than 0");
64 static_assert(
N >= 1,
"Out of bounds index assignment");
69 static_assert(
N >= 2,
"Out of bounds index assignment");
75 static_assert(
N >= 3,
"Out of bounds index assignment");
82 static_assert(
N >= 4,
"Out of bounds index assignment");
91 static_assert(
N >=
M + 1,
"Out of bounds index assignment");
98 for (
const auto &a : list) {
108 for (
uint32 i = 0; i <
N; i++) {
109 values[i] = other.values[i];
114 for (
uint32 i = 0; i <
N; i++) {
115 values[i] = other.values[i];
122 while (i <
N && i <
M) {
123 values[i] = other.values[i];
143 for (
uint32 i = 0; i <
N; i++) {
153 for (
uint32 i = 0; i <
N; i++) {
163 for (
uint32 i = 0; i <
N; i++) {
173 for (
uint32 i = 0; i <
N; i++) {
183 for (
uint32 i = 0; i <
N; i++) {
193 for (
uint32 i = 0; i <
N; i++) {
203 for (
uint32 i = 0; i <
N; i++) {
213 for (
uint32 i = 0; i <
N; i++) {
221 for (
uint32 i = 0; i <
N; i++) {
229 for (
uint32 i = 0; i <
N; i++) {
237 for (
uint32 i = 0; i <
N; i++) {
245 for (
uint32 i = 0; i <
N; i++) {
253 for (
uint32 i = 0; i <
N; i++) {
261 for (
uint32 i = 0; i <
N; i++) {
269 for (
uint32 i = 0; i <
N; i++) {
277 for (
uint32 i = 0; i <
N; i++) {
291 for (
uint32 i = 0; i <
N; i++) {
300 for (
uint32 i = 0; i <
N; i++) {
309 for (
uint32 i = 0; i <
N; i++) {
318 for (
uint32 i = 0; i <
N; i++) {
327 for (
uint32 i = 0; i <
N; i++) {
337 for (
uint32 i = 0; i <
N; i++) {
357 for (
uint32 i = 0; i <
N; i++) {
376 static_assert(
N == 3,
"Cross product only defined for 3-dim vectors");
384 result[0] = a.
y() * b.
z() - a.
z() * b.
y();
385 result[1] = a.
z() * b.
x() - a.
x() * b.
z();
386 result[2] = a.
x() * b.
y() - a.
y() * b.
x();
400 static_assert(
N == 3,
"Triple product only defined for 3-dim vectors");
412 for (
uint32 i = 0; i <
N; i++) {
423 return Lerp(t, a, b);
431 for (
uint32 i = 0; i <
N; i++) {
440 return Lerp(t, a, b);
448 for (
uint32 i = 0; i <
N; i++) {
458 for (
uint32 i = 0; i <
N; i++) {
468 for (
uint32 i = 0; i <
N; i++) {
478 for (
uint32 i = 0; i <
N; i++) {
488 for (
uint32 i = 0; i <
N; i++) {
498 for (
uint32 i = 0; i <
N; i++) {
508 for (
uint32 i = 0; i <
N; i++) {
549 for (
const auto &v :
values) {
550 builder.
Hash(&v,
sizeof(
T));
557 static_assert(
N >= 1,
"No component");
562 static_assert(
N >= 2,
"No component");
567 static_assert(
N >= 3,
"No component");
572 static_assert(
N >= 4,
"No component");
630 template<
typename T, BRK_NS::u
int32 N>
640 template<
typename T, BRK_NS::u
int32 N>
641 inline std::ostream &
operator<<(std::ostream &ostream,
const BRK_NS::TVecN<T, N> &vec) {
645 ostream <<
"," << vec[i];
#define BRK_NS_END
Definition: Config.hpp:48
#define BRK_NS
Definition: Config.hpp:50
std::ostream & operator<<(std::ostream &ostream, const BRK_NS::TVecN< T, N > &vec)
Definition: TVecN.hpp:641
std::size_t size_t
Definition: Typedefs.hpp:49
std::uint32_t uint32
Definition: Typedefs.hpp:44
Crc32 hash builder.
Definition: Crc32.hpp:68
Crc32Hash GetHash() const
Definition: Crc32.hpp:86
Crc32Builder & Hash(const void *buffer, size_t size)
Definition: Crc32.hpp:78
static float Lerp(float t, float left, float right)
Definition: MathUtils.hpp:156
static float Min(float a, float b)
Definition: MathUtils.hpp:82
static T Clamp(T t, T left, T right)
Definition: MathUtils.hpp:188
static float Pow(float a, float p)
Definition: MathUtils.hpp:112
static float Sqrt(float a)
Definition: MathUtils.hpp:106
static float Acos(float a)
Definition: MathUtils.hpp:100
static BRK_API const float THRESH_FLOAT32
Definition: MathUtils.hpp:53
static BRK_API const float THRESH_ZERO_NORM_SQUARED
Definition: MathUtils.hpp:56
static float Max(float a, float b)
Definition: MathUtils.hpp:85
static float Abs(float a)
Definition: MathUtils.hpp:124
static float Sin(float a)
Definition: MathUtils.hpp:88
static void Copy(void *destination, const void *source, size_t sizeInBytes)
Definition: Memory.hpp:58
Generic vector class for an N dimensional space base on type T.
Definition: TVecN.hpp:55
TVecN & operator/=(const TVecN &other)
Definition: TVecN.hpp:244
T * GetData()
Definition: TVecN.hpp:579
static TVecN Slerp(T t, const TVecN &a, const TVecN &b)
Definition: TVecN.hpp:419
bool operator>(const TVecN &other) const
Definition: TVecN.hpp:315
T Length2() const
Definition: TVecN.hpp:505
TVecN(const std::initializer_list< T > &list) noexcept
Definition: TVecN.hpp:96
TVecN & operator/=(T a)
Definition: TVecN.hpp:276
static TVecN Min(const TVecN &a, const TVecN &b)
Definition: TVecN.hpp:455
TVecN & Zero()
Definition: TVecN.hpp:538
bool operator>=(const TVecN &other) const
Definition: TVecN.hpp:297
TVecN(const TVecN< T, M > &v, T a)
Definition: TVecN.hpp:90
bool operator!=(const TVecN &other) const
Definition: TVecN.hpp:334
TVecN(T x, T y)
Definition: TVecN.hpp:68
T z() const
Definition: TVecN.hpp:566
const T * GetData() const
Definition: TVecN.hpp:580
static T Distance(const TVecN &a, const TVecN &b)
Definition: TVecN.hpp:349
T x() const
Definition: TVecN.hpp:556
TVecN & operator-=(T a)
Definition: TVecN.hpp:260
static TVecN Slerp(T t, T ang, const TVecN &a, const TVecN &b)
Definition: TVecN.hpp:438
TVecN(T x, T y, T z, T w)
Definition: TVecN.hpp:81
static TVecN Cross(const TVecN &a, const TVecN &b)
Definition: TVecN.hpp:375
const T & operator[](uint32 index) const
Definition: TVecN.hpp:577
T & operator[](uint32 index)
Definition: TVecN.hpp:576
static TVecN Max(const TVecN &a, const TVecN &b)
Definition: TVecN.hpp:465
static TVecN AxisZ()
Definition: TVecN.hpp:590
TVecN operator-() const
Definition: TVecN.hpp:284
TVecN & operator+=(T a)
Definition: TVecN.hpp:252
TVecN(TVecN &&other) noexcept
Definition: TVecN.hpp:113
TVecN(T x, T y, T z)
Definition: TVecN.hpp:74
static TVecN AxisX()
Definition: TVecN.hpp:582
TVecN operator/(T a) const
Definition: TVecN.hpp:210
TVecN operator/(const TVecN &other) const
Definition: TVecN.hpp:170
TVecN(const TVecN< T, M > &other) noexcept
Definition: TVecN.hpp:120
TVecN operator*(T a) const
Definition: TVecN.hpp:200
TVecN & operator=(const TVecN &other)
Definition: TVecN.hpp:128
static TVecN AxisY()
Definition: TVecN.hpp:586
static TVecN Clamp(const TVecN &t, const TVecN &left, const TVecN &right)
Definition: TVecN.hpp:475
TVecN & operator*=(const TVecN &other)
Definition: TVecN.hpp:236
TVecN operator*(const TVecN &other) const
Definition: TVecN.hpp:160
bool operator==(const TVecN &other) const
Definition: TVecN.hpp:324
TVecN Abs() const
Definition: TVecN.hpp:485
TVecN & operator+=(const TVecN &other)
Definition: TVecN.hpp:220
TVecN Normalized() const
Definition: TVecN.hpp:520
TVecN & operator*=(T a)
Definition: TVecN.hpp:268
TVecN operator+(const TVecN &other) const
Definition: TVecN.hpp:140
TVecN & operator=(TVecN &&other) noexcept
Definition: TVecN.hpp:134
T w() const
Definition: TVecN.hpp:571
TVecN operator-(const TVecN &other) const
Definition: TVecN.hpp:150
T y() const
Definition: TVecN.hpp:561
TVecN() noexcept
Definition: TVecN.hpp:59
static T Angle(const TVecN &a, const TVecN &b)
Definition: TVecN.hpp:364
static T Distance2(const TVecN &a, const TVecN &b)
Definition: TVecN.hpp:344
TVecN operator+(T a) const
Definition: TVecN.hpp:180
TVecN(const TVecN &other) noexcept
Definition: TVecN.hpp:107
bool operator<(const TVecN &other) const
Definition: TVecN.hpp:306
TVecN & operator-=(const TVecN &other)
Definition: TVecN.hpp:228
static T Triple(const TVecN &a, const TVecN &b, const TVecN &c)
Definition: TVecN.hpp:399
T values[N]
Definition: TVecN.hpp:595
static T Dot(const TVecN &a, const TVecN &b)
Definition: TVecN.hpp:354
TVecN & NormalizeThis()
Definition: TVecN.hpp:525
TVecN Pow(T factor) const
Definition: TVecN.hpp:495
T Length() const
Definition: TVecN.hpp:515
bool operator<=(const TVecN &other) const
Definition: TVecN.hpp:288
Crc32Hash Hash() const
Definition: TVecN.hpp:546
TVecN operator-(T a) const
Definition: TVecN.hpp:190
TVecN(T x)
Definition: TVecN.hpp:63
static TVecN Lerp(float t, const TVecN &a, const TVecN &b)
Definition: TVecN.hpp:409
Definition: GLDevice.cpp:46
Definition: TQuat.hpp:431
std::size_t operator()(const BRK_NS::TVecN< T, N > &vec) const
Definition: TVecN.hpp:633