-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmath.hpp
More file actions
59 lines (40 loc) · 1.56 KB
/
Copy pathmath.hpp
File metadata and controls
59 lines (40 loc) · 1.56 KB
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
#ifndef MATH_HPP
#define MATH_HPP
#include <cmath>
#include "engine.hpp"
#include "memory.hpp"
//180/pi
#define radpi 57.295779513082f
//pi/180
#define pideg 0.017453293f
#define isNaN(n) n != n
inline static float distance_3d(float location_one[3], float location_two[2]) {
return sqrt(((location_one[1] - location_two[1])*(location_one[1] - location_two[1])) +
((location_one[0] - location_two[0])*(location_one[0] - location_two[0])) +
((location_one[2] - location_two[2])*(location_one[2] - location_two[2])));
}
inline static float vmatrix[4][4];
inline static bool world_to_screen(pid_t gamePid, const float vIn[3], float vOut[2], bool ignore_oof=true) {
Memory::read(gamePid, Engine::view_matrix, &vmatrix, sizeof(vmatrix));
float w = vmatrix[3][0] * vIn[0] + vmatrix[3][1] * vIn[1] + vmatrix[3][2] * vIn[2] + vmatrix[3][3];
if (w < 0.1f) return false;
float vOutTmp[2];
vOutTmp[0] = vmatrix[0][0] * vIn[0] + vmatrix[0][1] * vIn[1] + vmatrix[0][2] * vIn[2] + vmatrix[0][3];
vOutTmp[1] = vmatrix[1][0] * vIn[0] + vmatrix[1][1] * vIn[1] + vmatrix[1][2] * vIn[2] + vmatrix[1][3];
float invw = 1.0f / w;
vOutTmp[0] *= invw;
vOutTmp[1] *= invw;
int width = 1920;
int height = 1080;
float x = width / 2.0f;
float y = height / 2.0f;
x += 0.5f * vOutTmp[0] * width + 0.5f;
y -= 0.5f * vOutTmp[1] * height + 0.5f;
vOut[0] = x * 100.f / 100.f;
vOut[1] = y * 100.f / 100.f;
if (ignore_oof == true) {
if (vOut[0] > width+50 || vOut[1] > height+50 || vOut[0] < -50 || vOut[1] < -50) return false;
}
return true;
}
#endif