-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRender.cpp
More file actions
238 lines (187 loc) · 6.73 KB
/
Render.cpp
File metadata and controls
238 lines (187 loc) · 6.73 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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#include "Render.h"
Render::Render(AActor* LocalPlayer, AActor* Actor)
{
this->Actor = Actor;
this->LocalPlayer = LocalPlayer;
for (int32_t i = 0; i < BoneFNames::Max; i++)
{
Vector2 Screen{ 0 };
BonePos[i] = GetBoneLocation(Actor->Mesh, i);
BoneIs[i] = WorldToScreen(BonePos[i], Screen);
BonePoint[i].X = (float)(Screen.X);
BonePoint[i].Y = (float)(Screen.Y);
}
}
void Render::DrawBone(ImColor Color)
{
DrawPartBone(0, 6, Color);
DrawPartBone(6, 8, Color);
DrawPartBone(14, 8, Color);
}
void Render::DrawPartBone(int32_t start, int32_t end, ImColor Color)
{
BoneIdx Id;
int32_t* Bone = (int32_t*)&Id;
// Vector2f Point, oPoint;
Vector2f Point, oPoint;
for (int32_t i = start; i < start + end; i++)
{
Point = BonePoint[Bone[i]];
if (i != start)
{
ImGui::GetForegroundDrawList()->AddLine({ (float)oPoint.X, (float)oPoint.Y }, { (float)Point.X, (float)Point.Y }, Color);
}
oPoint = Point;
}
}
void Render::DrawBox2D(ImColor Color)
{
int LeftIndex = FindLeftPoint();
int RightIndex = FindRightPoint();
int LowestIndex = FindLowestPoint();
int HighesIndex = FindHighestPoint();
Vector3 head = GetBoneLocation(Actor->Mesh, BoneFNames::Head);
Vector2 headpoint{};
head.Z += 30;
if (WorldToScreen(head, headpoint) && BoneIs[LeftIndex] && BoneIs[RightIndex]
&& BoneIs[LowestIndex] && BoneIs[HighesIndex])
{
ImGui::GetForegroundDrawList()->AddRect({ (float)BonePoint[LeftIndex].X,(float)headpoint.Y }, { (float)BonePoint[RightIndex].X,(float)BonePoint[LowestIndex].Y }, Color);
}
}
void Render::DrawBox3D(ImColor Color)
{
Vector3 Pos = BonePos[BoneFNames::Root];//取得底部坐标
double Height = BonePos[BoneFNames::Head].Z;//取得高度
Vector3 Top_Pos[4], Bottom_Pos[4];
Vector2 Top_Point[4], Bottom_Point[4];
Vector2f Top_Pointf[4], Bottom_Pointf[4];
for (int i = 0; i < 4; i++)
{
int offset = 45 + i * 90;
Bottom_Pos[i].X = Pos.X + cos((Actor->RootComponent->ModelYaw + offset) * 3.1415926 / 180.f) * 55.f;
Bottom_Pos[i].Y = Pos.Y + sin((Actor->RootComponent->ModelYaw + offset) * 3.1415926 / 180.f) * 55.f;
Bottom_Pos[i].Z = Pos.Z;
Top_Pos[i] = Bottom_Pos[i];
Top_Pos[i].Z = Height;
if (!WorldToScreen(Bottom_Pos[i], Bottom_Point[i])
|| !WorldToScreen(Top_Pos[i], Top_Point[i]))
{
break;
}
Top_Pointf[i].X = (float)Top_Point[i].X;
Top_Pointf[i].Y = (float)Top_Point[i].Y;
Bottom_Pointf[i].X = (float)Bottom_Point[i].X;
Bottom_Pointf[i].Y = (float)Bottom_Point[i].Y;
//画直线高
ImGui::GetForegroundDrawList()->AddLine({ Bottom_Pointf[i].X,Bottom_Pointf[i].Y }, { Top_Pointf[i].X,Top_Pointf[i].Y }, Color);
if (i)
{
//画上面跟下面的长方形
ImGui::GetForegroundDrawList()->AddLine({ Bottom_Pointf[i - 1].X,Bottom_Pointf[i - 1].Y }, { Bottom_Pointf[i].X,Bottom_Pointf[i].Y }, Color);
ImGui::GetForegroundDrawList()->AddLine({ Top_Pointf[i - 1].X,Top_Pointf[i - 1].Y }, { Top_Pointf[i].X,Top_Pointf[i].Y }, Color);
if (i == 3)
{
ImGui::GetForegroundDrawList()->AddLine({ Bottom_Pointf[0].X,Bottom_Pointf[0].Y }, { Bottom_Pointf[i].X,Bottom_Pointf[i].Y }, Color);
ImGui::GetForegroundDrawList()->AddLine({ Top_Pointf[0].X,Top_Pointf[0].Y }, { Top_Pointf[i].X,Top_Pointf[i].Y }, Color);
}
}
}
}
void Render::DrawRadar(ImColor Color)
{
Vector3 Pos = BonePos[BoneFNames::Root];
Vector3 CameraPos = LocalPlayer->Controller->PlayerCameraManager->Pos;
Pos.X = (Pos.X - CameraPos.X) / 150; // 150 缩放比例
Pos.Y = (Pos.Y - CameraPos.Y) / 150;
double R = sqrt(pow(Pos.X, 2) + pow(Pos.Y, 2));
double Angle = atan2(Pos.Y, Pos.X) * 180 / 3.1415926f;
Angle = LocalPlayer->ControllerYawRotation - Angle;
Angle = Angle * 3.1415926f / 180;
Vector2f Point;
Point.X = Width + (float)(-(R * sin(Angle)));
Point.Y = Height + (float)(-(R * cos(Angle)));//求出绘制的点
ImGui::GetForegroundDrawList()->AddRectFilled({ Point.X - 2,Point.Y - 2 }, { Point.X + 2,Point.Y + 2 }, Color);
ImGui::GetForegroundDrawList()->AddRect({ Point.X - 3,Point.Y - 3 }, { Point.X + 3,Point.Y + 3 }, ImColor(0, 0, 0));
ImGui::GetForegroundDrawList()->AddLine({ Width - 70,Height }, { Width + 70,Height }, ImColor(0, 0, 0));
ImGui::GetForegroundDrawList()->AddLine({ Width,Height - 70 }, { Width,Height + 70 }, ImColor(0, 0, 0));
ImGui::GetForegroundDrawList()->AddRectFilled({ Width - 2,Height - 2 }, { Width + 2,Height + 2 }, ImColor(255, 255, 255));
ImGui::GetForegroundDrawList()->AddRect({ Width - 3,Height - 3 }, { Width + 3,Height + 3 }, ImColor(0, 0, 0));//绘制出自己的方块
}
void Render::DrawBlood(ImColor Color)
{
int LeftIndex = FindLeftPoint();
int LowestIndex = FindLowestPoint();
int HighesIndex = FindHighestPoint();
if (BoneIs[LeftIndex]
&& BoneIs[LowestIndex]
&& BoneIs[HighesIndex])
{
if (Actor->HealthStatsComponent->Health < 50)
Color = ImColor(255, 0, 0);
float FilledW = (float)(Actor->HealthStatsComponent->Health) / 100.f * (BonePoint[HighesIndex].Y - BonePoint[LowestIndex].Y);
ImGui::GetForegroundDrawList()->AddRect({ BonePoint[LeftIndex].X - 5,BonePoint[LowestIndex].Y }, { BonePoint[LeftIndex].X - 2,BonePoint[HighesIndex].Y }, ImColor(0, 0, 0));
ImGui::GetForegroundDrawList()->AddRectFilled({ BonePoint[LeftIndex].X - 4,BonePoint[LowestIndex].Y }, { BonePoint[LeftIndex].X - 3,BonePoint[LowestIndex].Y + FilledW }, Color);
}
}
void Render::DrawLosLine(ImColor Color)
{
Vector2 StartPoint, EndPoint;
Vector3 StartPos, EndPos;
StartPos = BonePos[BoneFNames::Head];
EndPos.X = StartPos.X + cos(Actor->RootComponent->ModelYaw * 3.1415926f / 180.f) * 700;
EndPos.Y = StartPos.Y + sin(Actor->RootComponent->ModelYaw * 3.1415926f / 180.f) * 700;
EndPos.Z = StartPos.Z + sin(0 * 3.1415926f / 180.f) * 700;
if (WorldToScreen(StartPos, StartPoint) && WorldToScreen(EndPos, EndPoint))
{
ImGui::GetForegroundDrawList()->AddCircleFilled({ (float)StartPoint.X,(float)StartPoint.Y }, 2, Color);
ImGui::GetForegroundDrawList()->AddLine({ (float)StartPoint.X,(float)StartPoint.Y }, { (float)EndPoint.X,(float)EndPoint.Y }, Color);
}
}
void Render::DrawSnapLine(ImColor Color)
{
if (BoneIs[BoneFNames::Root])
{
ImGui::GetForegroundDrawList()->AddLine({ Width, Height * 2 }, { BonePoint[BoneFNames::Root].X,BonePoint[BoneFNames::Root].Y}, Color);
}
}
int Render::FindLeftPoint()
{
int ret = 0;
for (int i = 0; i < BoneFNames::Max; i++)
{
if (BonePoint[i].X < BonePoint[ret].X)
ret = i;
}
return ret;
}
int Render::FindRightPoint()
{
int ret = 0;
for (int i = 0; i < BoneFNames::Max; i++)
{
if (BonePoint[i].X > BonePoint[ret].X)
ret = i;
}
return ret;
}
int Render::FindHighestPoint()
{
int ret = 0;
for (int i = 0; i < BoneFNames::Max; i++)
{
if (BonePoint[i].Y < BonePoint[ret].Y)
ret = i;
}
return ret;
}
int Render::FindLowestPoint()
{
int ret = 0;
for (int i = 0; i < BoneFNames::Max; i++)
{
if (BonePoint[i].Y > BonePoint[ret].Y)
ret = i;
}
return ret;
}