forked from nb1027/Source
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathclasses.cpp
More file actions
67 lines (51 loc) · 1.96 KB
/
classes.cpp
File metadata and controls
67 lines (51 loc) · 1.96 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
60
61
62
63
64
65
66
67
#include "Classes.h"
Vector3 WorldToScreen(Vector3 world_location, Vector3 position, FRotator rotation, float fov)
{
Vector3 screen_location = Vector3(0, 0, 0);
D3DMATRIX tempMatrix = ToMatrix(rotation, world_location);
Vector3 vAxisX, vAxisY, vAxisZ;
vAxisX = Vector3(tempMatrix.m[0][0], tempMatrix.m[0][1], tempMatrix.m[0][2]);
vAxisY = Vector3(tempMatrix.m[1][0], tempMatrix.m[1][1], tempMatrix.m[1][2]);
vAxisZ = Vector3(tempMatrix.m[2][0], tempMatrix.m[2][1], tempMatrix.m[2][2]);
Vector3 vDelta = world_location - position;
Vector3 vTransformed = Vector3(vDelta.Dot(vAxisY), vDelta.Dot(vAxisZ), vDelta.Dot(vAxisX));
if (vTransformed.z < 1.f)
vTransformed.z = 1.f;
float FovAngle = fov;
double ScreenCenterX = 1920 / 2.0f;
double ScreenCenterY = 1080 / 2.0f;
screen_location.x = ScreenCenterX + vTransformed.x * (ScreenCenterX / tanf(FovAngle * (double)M_PI / 360.f)) / vTransformed.z;
screen_location.y = ScreenCenterY - vTransformed.y * (ScreenCenterX / tanf(FovAngle * (double)M_PI / 360.f)) / vTransformed.z;
screen_location.z = 0;
return screen_location;
}
D3DMATRIX ToMatrix(FRotator Rotation, Vector3 origin)
{
double Pitch = (Rotation.Pitch * double(UCONST_PI) / 180.f);
double Yaw = (Rotation.Yaw * double(UCONST_PI) / 180.f);
double Roll = (Rotation.Roll * double(UCONST_PI) / 180.f);
double SP = sinf(Pitch);
double CP = cosf(Pitch);
double SY = sinf(Yaw);
double CY = cosf(Yaw);
double SR = sinf(Roll);
double CR = cosf(Roll);
D3DMATRIX Matrix;
Matrix._11 = CP * CY;
Matrix._12 = CP * SY;
Matrix._13 = SP;
Matrix._14 = 0.f;
Matrix._21 = SR * SP * CY - CR * SY;
Matrix._22 = SR * SP * SY + CR * CY;
Matrix._23 = -SR * CP;
Matrix._24 = 0.f;
Matrix._31 = -(CR * SP * CY + SR * SY);
Matrix._32 = CY * SR - CR * SP * SY;
Matrix._33 = CR * CP;
Matrix._34 = 0.f;
Matrix._41 = origin.x;
Matrix._42 = origin.y;
Matrix._43 = origin.z;
Matrix._44 = 1.f;
return Matrix;
}