forked from boowampp/ApexDmaCheatUpdated
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vector3D.hpp
97 lines (77 loc) · 2.24 KB
/
Vector3D.hpp
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
#pragma once
#include "Vector2D.hpp"
struct Vector3D {
float x, y, z;
Vector3D() : x(0), y(0), z(0) {}
Vector3D(float x_val, float y_val, float z_val) : x(x_val), y(y_val), z(z_val) {}
Vector3D Subtract(const Vector3D& other) const {
return Vector3D(x - other.x, y - other.y, z - other.z);
}
Vector3D Add(const Vector3D& other) const {
return Vector3D(x + other.x, y + other.y, z + other.z);
}
float DotProduct(const Vector3D& other) const {
return x * other.x + y * other.y + z * other.z;
}
float Magnitude() const {
return std::sqrt(x * x + y * y + z * z);
}
float Magnitude2D() const {
return std::sqrt(x * x + y * y);
}
float Distance(const Vector3D& other) const {
Vector3D diff = Subtract(other);
return diff.Magnitude();
}
bool IsZeroVector() {
return x == 0 && y == 0 && z == 0;
}
bool IsValid() {
if(std::isnan(x) || std::isinf(x) || std::isnan(y) || std::isinf(y) || std::isnan(z) || std::isinf(z)) {
return false;
}
return true;
}
Vector3D& Normalize() {
float len = Magnitude();
if (len > 0) {
x /= len;
y /= len;
z /= len;
}
return *this;
}
Vector3D Multiply(float scalar) const {
return Vector3D(x * scalar, y * scalar, z * scalar);
}
Vector2D To2D() const {
return Vector2D(x, y);
}
float Distance2D(const Vector3D& other) const {
return (other.Subtract(*this)).Magnitude2D();
};
Vector3D& operator+=(const Vector3D& other) {
x += other.x;
y += other.y;
z += other.z;
return *this;
}
Vector3D& operator-=(const Vector3D& other) {
x -= other.x;
y -= other.y;
z -= other.z;
return *this;
}
bool operator==(const Vector3D& other) const {
float epsilon = 1e-5;
return (std::abs(x - other.x) < epsilon)
&& (std::abs(y - other.y) < epsilon)
&& (std::abs(z - other.z) < epsilon);
}
bool operator!=(const Vector3D& other) const {
return !(*this == other);
}
Vector3D ModifyZ(float zOffset) {
return Vector3D{ x, y, z + zOffset };
}
};