-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathImpl.as
75 lines (64 loc) · 1.47 KB
/
Impl.as
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
namespace Camera
{
vec3 ToScreen(const vec3 &in pos)
{
if (g_currentCamera is null) {
return vec3(0, 0, 1);
}
auto ret = g_projection * pos;
if (ret.w == 0.0f) {
return vec3(0, 0, ret.w);
}
vec2 screenPos = g_displayPos + (ret.xy / ret.w + 1) / 2 * g_displaySize;
return vec3(screenPos, ret.w);
}
vec2 ToScreenSpace(const vec3 &in pos)
{
return ToScreen(pos).xy;
}
bool IsBehind(const vec3 &in pos)
{
if (g_currentCamera is null) {
return true;
}
return (g_projection * pos).w > 0;
}
CHmsCamera@ GetCurrent()
{
return g_currentCamera;
}
mat4 GetProjectionMatrix()
{
return g_projection;
}
vec3 GetCurrentPosition()
{
return g_position;
}
void SetEditorOrbitalTarget(const vec3 &in pos)
{
auto editor = cast<CGameCtnEditorCommon>(GetApp().Editor);
if (editor is null) {
throw("Not in editor");
return;
}
auto orbital = editor.OrbitalCameraControl;
if (orbital is null) {
throw("No orbital camera");
return;
}
float h = (orbital.m_CurrentHAngle + Math::PI / 2) * -1;
float v = orbital.m_CurrentVAngle;
vec4 axis(1, 0, 0, 0);
axis = axis * mat4::Rotate(v, vec3(0, 0, -1));
axis = axis * mat4::Rotate(h, vec3(0, 1, 0));
orbital.m_TargetedPosition = pos;
vec3 newCameraPos = pos + axis.xyz * orbital.m_CameraToTargetDistance;
#if TMNEXT
orbital.Pos = newCameraPos;
#else
//TODO: This is correct for Maniaplanet, but probably not for Turbo
Dev::SetOffset(orbital, 0x44, newCameraPos);
#endif
}
}