forked from ZEROWyt/Overwatch-2-TOPE-EXTERNAL-CHEAT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vector.hpp
231 lines (186 loc) · 6.13 KB
/
Vector.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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#pragma once
#include "includes.hpp"
#include "safecallez.h"
using namespace DirectX;
namespace OW {
class Vector2 {
public:
float X, Y;
Vector2() { X = 0; Y = 0; }
Vector2(float _X, float _Y)
{
X = _X;
Y = _Y;
}
inline float Distance(Vector2 v)
{
return float(sqrtf(powf(v.X - X, 2.0) + powf(v.Y - Y, 2.0)));
}
inline float get_length()
{
return float(sqrtf(powf(X, 2.0) + powf(Y, 2.0)));
}
inline Vector2 operator+(Vector2 v)
{
return { X + v.X, Y + v.Y };
}
inline Vector2 operator-(Vector2 v)
{
return { X - v.X, Y - v.Y };
}
};
#pragma pack(push, 1)
struct Vector3
{
public:
float X;
float Y;
float Z;
inline Vector3()
: X(0), Y(0), Z(0) {
}
inline Vector3(float x, float y, float z) : X(x), Y(y), Z(z) {}
__forceinline Vector3 operator-(const Vector3& V) {
return Vector3(X - V.X, Y - V.Y, Z - V.Z);
}
__forceinline Vector3 operator+(const Vector3& V) {
return Vector3(X + V.X, Y + V.Y, Z + V.Z);
}
__forceinline Vector3 operator*(float Scale) const {
return Vector3(X * Scale, Y * Scale, Z * Scale);
}
__forceinline Vector3 operator/(float Scale) const {
const float RScale = 1.f / Scale;
return Vector3(X * RScale, Y * RScale, Z * RScale);
}
__forceinline Vector3 operator+(float A) const {
return Vector3(X + A, Y + A, Z + A);
}
__forceinline Vector3 operator-(float A) const {
return Vector3(X - A, Y - A, Z - A);
}
__forceinline Vector3 operator*(const Vector3& V) const {
return Vector3(X * V.X, Y * V.Y, Z * V.Z);
}
__forceinline Vector3 operator/(const Vector3& V) const {
return Vector3(X / V.X, Y / V.Y, Z / V.Z);
}
__forceinline float operator|(const Vector3& V) const {
return X * V.X + Y * V.Y + Z * V.Z;
}
__forceinline float operator^(const Vector3& V) const {
return X * V.Y - Y * V.X - Z * V.Z;
}
__forceinline Vector3& operator+=(const Vector3& v) {
X += v.X;
Y += v.Y;
Z += v.Z;
return *this;
}
__forceinline Vector3& operator-=(const Vector3& v) {
X -= v.X;
Y -= v.Y;
Z -= v.Z;
return *this;
}
__forceinline Vector3& operator*=(const Vector3& v) {
X *= v.X;
Y *= v.Y;
Z *= v.Z;
return *this;
}
__forceinline Vector3& operator/=(const Vector3& v) {
X /= v.X;
Y /= v.Y;
Z /= v.Z;
return *this;
}
__forceinline bool operator==(const Vector3& src) const {
return (src.X == X) && (src.Y == Y) && (src.Z == Z);
}
__forceinline bool operator!=(const Vector3& src) const {
return (src.X != X) || (src.Y != Y) || (src.Z != Z);
}
__forceinline Vector3 Rotate(float angle)
{
return Vector3(X * cos(-angle) - Z * sin(-angle), Y, X * sin(-angle) + Z * cos(-angle));
}
__forceinline float Size() const {
return sqrt(X * X + Y * Y + Z * Z);
}
__forceinline float DistTo(Vector3 targetTo) const {
return (targetTo - *this).Size();
}
__forceinline Vector3 toRotator(Vector3 targetTo)
{
Vector3 Normalized = (targetTo - *this);
return Normalized * (1 / Normalized.Size());
}
};
class Matrix : public XMMATRIX
{
public:
float m11, m12, m13, m14,
m21, m22, m23, m24,
m31, m32, m33, m34,
m41, m42, m43, m44;
XMFLOAT3 get_location()
{
__try
{
XMMATRIX invView = XMMatrixInverse(NULL, (XMMATRIX)*this);
return XMFLOAT3(XMVectorGetX(invView.r[3]) / XMVectorGetW(invView.r[3]), XMVectorGetY(invView.r[3]) / XMVectorGetW(invView.r[3]), XMVectorGetZ(invView.r[3]) / XMVectorGetW(invView.r[3]));
}
__except (EXCEPTION_EXECUTE_HANDLER) {}
return XMFLOAT3(0, 0, 0);
}
XMFLOAT3 get_rotation()
{
__try {
return XMFLOAT3(XMVectorGetZ(r[0]), XMVectorGetZ(r[1]), XMVectorGetZ(r[2]));
}
__except (EXCEPTION_EXECUTE_HANDLER) {}
return XMFLOAT3(0, 0, 0);
}
Vector3 GetCameraVec()
{
float A = m22 * m33 - m32 * m23,
B = m32 * m13 - m12 * m33,
C = m12 * m23 - m22 * m13,
Z = m11 * A + m21 * B + m31 * C;
if (abs(Z) < 0.0001) return Vector3();
float D = m31 * m23 - m21 * m33,
E = m11 * m33 - m31 * m13,
F = m21 * m13 - m11 * m23,
G = m21 * m32 - m31 * m22,
H = m31 * m12 - m11 * m32,
K = m11 * m22 - m21 * m12;
return Vector3(-(A * m41 + D * m42 + G * m43) / Z, -(B * m41 + E * m42 + H * m43) / Z, -(C * m41 + F * m42 + K * m43) / Z);
}
bool WorldToScreen(Vector3 worldPos, Vector2* OutPos, bool ignoreret = false)
{
float screenX = (r[0].m128_f32[0] * worldPos.X) + (r[1].m128_f32[0] * worldPos.Y) + (r[2].m128_f32[0] * worldPos.Z) + r[3].m128_f32[0];
float screenY = (r[0].m128_f32[1] * worldPos.X) + (r[1].m128_f32[1] * worldPos.Y) + (r[2].m128_f32[1] * worldPos.Z) + r[3].m128_f32[1];
float screenW = (r[0].m128_f32[3] * worldPos.X) + (r[1].m128_f32[3] * worldPos.Y) + (r[2].m128_f32[3] * worldPos.Z) + r[3].m128_f32[3];
float camX = GetSystemMetrics(SM_CXSCREEN) / 2.0f;
float camY = GetSystemMetrics(SM_CYSCREEN) / 2.0f;
float x = camX + (camX * screenX / screenW);
float y = camY - (camY * screenY / screenW);
if (x < 0 || y < 0 || x >= GetSystemMetrics(SM_CXSCREEN) || y >= GetSystemMetrics(SM_CYSCREEN)) { return false; }
*OutPos = { x, y };
return (screenW > 0.001f) || ignoreret;
}
Vector2 WorldToScreen(Vector3 worldPos)
{
float screenX = (r[0].m128_f32[0] * worldPos.X) + (r[1].m128_f32[0] * worldPos.Y) + (r[2].m128_f32[0] * worldPos.Z) + r[3].m128_f32[0];
float screenY = (r[0].m128_f32[1] * worldPos.X) + (r[1].m128_f32[1] * worldPos.Y) + (r[2].m128_f32[1] * worldPos.Z) + r[3].m128_f32[1];
float screenW = (r[0].m128_f32[3] * worldPos.X) + (r[1].m128_f32[3] * worldPos.Y) + (r[2].m128_f32[3] * worldPos.Z) + r[3].m128_f32[3];
float camX = GetSystemMetrics(SM_CXSCREEN) / 2.0f;
float camY = GetSystemMetrics(SM_CYSCREEN) / 2.0f;
float x = camX + (camX * screenX / screenW);
float y = camY - (camY * screenY / screenW);
if (x < 0 || y < 0 || x >= GetSystemMetrics(SM_CXSCREEN) || y >= GetSystemMetrics(SM_CYSCREEN)) { return Vector2{}; }
return { x ,y };
}
};
}