-
Notifications
You must be signed in to change notification settings - Fork 7
/
Camera.cpp
158 lines (136 loc) · 3.41 KB
/
Camera.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
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
#include "Camera.h"
#include "skse64/NiNodes.h"
namespace Tralala
{
uintptr_t g_playerCameraAddr = 0;
void PlayerCameraGetAddress()
{
const std::array<BYTE, 9> pattern = { 0x8B, 0x4D, 0xC7, 0x0F, 0xB6, 0xC9, 0x83, 0xF8, 0x04 };
g_playerCameraAddr = (uintptr_t)scan_memory_data(pattern, 0x21, true, 0x3, 0x7);
}
float ThirdPersonState::GetDistanceWithinTargetHead(Tralala::Actor * target)
{
if (!target || !target->processManager || !target->processManager->middleProcess)
return FLT_MAX;
NiNode* headNode = (NiNode*)target->processManager->middleProcess->unk158;
if (!headNode)
return FLT_MAX;
NiPoint3 dist;
dist.x = camPos.x - headNode->m_worldTransform.pos.x;
dist.y = camPos.y - headNode->m_worldTransform.pos.y;
dist.z = camPos.z - headNode->m_worldTransform.pos.z;
return (dist.x*dist.x + dist.y*dist.y + dist.z*dist.z);
}
void ThirdPersonState::SetFirstPersonSmooth(float minZoom, bool overShoulder)
{
if (unkDD[0] == 0)
{
savedZoom = curPosY;
dstPosY = minZoom;
unkDD[0] = 1;
}
else
{
curPosY = dstPosY;
}
if (!overShoulder)
fOverShoulderPosX = fOverShoulderCombatAddY = fOverShoulderPosZ = 0;
}
PlayerCamera * PlayerCamera::GetSingleton()
{
return *(PlayerCamera**)g_playerCameraAddr;
}
bool PlayerCamera::IsCameraFirstPerson()
{
return cameraState == cameraStates[kCameraState_FirstPerson];
}
bool PlayerCamera::IsCameraThirdPerson()
{
return cameraState == cameraStates[kCameraState_ThirdPerson2];
}
bool PlayerCamera::IsCameraFree()
{
return cameraState == cameraStates[kCameraState_Free];
}
void PlayerCamera::GetFirstCamPos(NiPoint3* pos)
{
Tralala::PlayerCharacter * player = Tralala::PlayerCharacter::GetSingleton();
pos->x = player->pos.x;
pos->y = player->pos.y;
FirstPersonState * fps = GetFirstPersonCamera();
if (fps->cameraNode)
{
pos->z = player->pos.z + fps->cameraNode->m_localTransform.pos.z;
}
else
{
player->GetMarkerPosition(pos);
}
}
void PlayerCamera::GetThirdCamPos(NiPoint3* pos)
{
ThirdPersonState * tps = GetThirdPersonCamera();
tps->GetCameraPosition(pos);
}
void PlayerCamera::GetCameraPos(NiPoint3* pos)
{
PlayerCharacter* player = PlayerCharacter::GetSingleton();
float x, y, z;
if (IsCameraFirstPerson())
{
NiNode* node = cameraNode;
if (node)
{
x = node->m_worldTransform.pos.x;
y = node->m_worldTransform.pos.y;
z = node->m_worldTransform.pos.z;
}
else
{
return GetFirstCamPos(pos);
}
}
else if (IsCameraThirdPerson())
{
return GetThirdCamPos(pos);
}
else
{
NiPoint3 playerPos;
player->GetMarkerPosition(&playerPos);
z = playerPos.z;
x = player->pos.x;
y = player->pos.y;
}
pos->x = x;
pos->y = y;
pos->z = z;
}
void PlayerCamera::GetCameraAngle(NiPoint3* pos)
{
PlayerCharacter* player = PlayerCharacter::GetSingleton();
if (IsCameraFirstPerson())
{
FirstPersonState* fps = GetFirstPersonCamera();
NiPoint3 angle;
ComputeAnglesFromMatrix(&fps->cameraNode->m_worldTransform.rot, &angle);
pos->z = NormalAbsoluteAngle(-angle.z);
pos->x = player->rot.x - angle.x;
pos->y = angle.y;
}
else if (IsCameraThirdPerson())
{
ThirdPersonState* tps = GetThirdPersonCamera();
NiPoint3 angle;
pos->z = player->rot.z + tps->diffRotZ;
pos->x = player->rot.x + tps->diffRotX;
pos->y = 0;
}
else
{
pos->x = player->rot.x;
pos->y = player->rot.y;
pos->z = player->rot.z;
}
}
}