forked from mscv/ErectusExperimental
-
Notifications
You must be signed in to change notification settings - Fork 5
/
utils.h
144 lines (110 loc) · 2.87 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#pragma once
#include <cmath>
#include <cstdint>
#include <random>
class Vector2
{
public:
Vector2() = default;
Vector2(const float _x, const float _y) : x(_x), y(_y) {}
float operator[] (const size_t idx) const { return (&x)[idx]; }
float& operator[] (const size_t idx) { return (&x)[idx]; }
Vector2& operator=(const Vector2& other) = default;
Vector2 operator*(const float multiplier) const
{
return Vector2(x * multiplier, y * multiplier);
}
Vector2 operator/(const float divisor) const
{
return *this * (1.f / divisor);
}
Vector2 operator+(const Vector2& other) const
{
return Vector2(x + other.x, y + other.y);
}
Vector2& operator+=(const Vector2 other)
{
x += other.x;
y += other.y;
return *this;
}
Vector2 operator-(const Vector2& other) const
{
return Vector2(x - other.x, y - other.y);
}
Vector2& operator-=(const Vector2 other)
{
x -= other.x;
y -= other.y;
return *this;
}
[[nodiscard]] float Length() const
{
return sqrt(x * x + y * y);
}
[[nodiscard]] float DistanceTo(const Vector2& other) const
{
return (*this - other).Length();
}
float x, y;
};
class Vector3
{
public:
Vector3() = default;
Vector3(const float _x, const float _y, const float _z) : x(_x), y(_y), z(_z) {}
float operator[] (const size_t idx) const { return (&x)[idx]; }
float& operator[] (const size_t idx) { return (&x)[idx]; }
Vector3& operator=(const Vector3& other) = default;
Vector3 operator*(const float multiplier) const
{
return Vector3(x * multiplier, y * multiplier, z * multiplier);
}
Vector3 operator/(const float divisor) const
{
return *this * (1.f / divisor);
}
Vector3 operator+(const Vector3& other) const
{
return Vector3(x + other.x, y + other.y, z + other.z);
}
Vector3& operator+=(const Vector3 other)
{
x += other.x;
y += other.y;
z += other.z;
return *this;
}
Vector3 operator-(const Vector3& other) const
{
return Vector3(x - other.x, y - other.y, z - other.z);
}
Vector3& operator-=(const Vector3 other)
{
x -= other.x;
y -= other.y;
z -= other.z;
return *this;
}
[[nodiscard]] float Length() const
{
return sqrt(x * x + y * y + z * z);
}
[[nodiscard]] float DistanceTo(const Vector3& other) const
{
return (*this - other).Length();
}
float x, y, z;
};
class Utils final {
public:
static void ValidateRgb(float* value);
static int GetRangedInt(int min, int max);
static bool Valid(std::uintptr_t ptr);
static float GetDegrees(const Vector3& src, const Vector3& forward, const Vector3& origin);
static Vector3 ProjectView(const Vector3& forward, const Vector3& origin, float distance);
static std::string RandomString(std::size_t length);
private:
static float RadiansToDegrees(float radians);
virtual void Dummy() = 0;
};