-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUtils.cpp
49 lines (37 loc) · 1.13 KB
/
Utils.cpp
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
#include "Utils.h"
#include "Offsets.h"
#include "Sdk.h"
bool Utils::IsVisible(Vector3 from, Vector3 to) {
__asm
{
push to.z;
push to.y;
push to.x;
push from.z;
push from.y;
push from.x;
xor cl, cl;
xor eax, eax;
mov ebx, OFFSET_TRACELINE;
call ebx;
add esp, 0x18;
}
}
bool Utils::WorldToScreen(Vector3 pos, Vector2& screen) {
Screen* size = (Screen*)OFFSET_SCREENSIZE;
float* matrix = (float*)OFFSET_VIEWMATRIX;
Vector4 clipCoords;
clipCoords.x = pos.x * matrix[0] + pos.y * matrix[4] + pos.z * matrix[8] + matrix[12];
clipCoords.y = pos.x * matrix[1] + pos.y * matrix[5] + pos.z * matrix[9] + matrix[13];
clipCoords.z = pos.x * matrix[2] + pos.y * matrix[6] + pos.z * matrix[10] + matrix[14];
clipCoords.w = pos.x * matrix[3] + pos.y * matrix[7] + pos.z * matrix[11] + matrix[15];
if (clipCoords.w < 0.1f)
return false;
Vector3 NDC;
NDC.x = clipCoords.x / clipCoords.w;
NDC.y = clipCoords.y / clipCoords.w;
NDC.z = clipCoords.z / clipCoords.w;
screen.x = (size->width / 2 * NDC.x) + (NDC.x + size->width / 2);
screen.y = -(size->height / 2 * NDC.y) + (NDC.y + size->height / 2);
return true;
}