This repository was archived by the owner on Feb 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathPrediction.h
199 lines (149 loc) · 3.99 KB
/
Prediction.h
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
#pragma once
#include "LSRender.h"
#include "Logging.hpp"
class LinePrediction
{
public:
static struct LineInfo_t
{
SpellData*data;
};
LinePrediction()
{
}
float Length(RVector3&vec)
{
return (float)sqrt((vec.x * vec.x) + (vec.y * vec.y) + (vec.z * vec.z));
}
void Normalize(RVector3&vec)
{
float length = Length(vec);
if (length != 0)
{
float inv = 1.0f / length;
vec.x *= inv;
vec.y *= inv;
vec.z *= inv;
}
}
RVector3 Calculate(Obj_AI_Base * target, float range, float missilespeed, float casttime);
~LinePrediction()
{
}
private:
};
class CirclePrediction
{
public:
float Length(RVector3&vec)
{
return (float)sqrt((vec.x * vec.x) + (vec.y * vec.y) + (vec.z * vec.z));
}
void Normalize(RVector3&vec)
{
float length = Length(vec);
if (length != 0)
{
float inv = 1.0f / length;
vec.x *= inv;
vec.y *= inv;
vec.z *= inv;
}
}
RVector3 Calculate(Obj_AI_Base * target, float range, float missilespeed, float radius, float casttime);
CirclePrediction()
{
}
~CirclePrediction()
{
}
private:
};
class Prediction
{
public:
Prediction();
~Prediction();
Prediction(LinePrediction* pred)
{
LinePred = pred;
}
Prediction(CirclePrediction* pred)
{
CircPred = pred;
}
enum CollisionType
{
Minion
};
bool BoundBox(D3DXVECTOR2 cursorPos, D3DXVECTOR2 Pos, D3DXVECTOR2 Size)
{
return Pos.x >= cursorPos.x - Size.x && Pos.x <= cursorPos.x + Size.x && Pos.y >= cursorPos.y - Size.y && Pos.y <= cursorPos.y + Size.y /*sol*/ && cursorPos.x >= Pos.x /*üst*/ && cursorPos.y >= Pos.y;
}
bool PointInLineSegment(D3DXVECTOR2 segmentStart, D3DXVECTOR2 segmentEnd, D3DXVECTOR2 point)
{
auto crossproduct = (point.y - segmentStart.y) * (segmentEnd.x - segmentStart.x) - (point.x - segmentStart.x) * (segmentEnd.y - segmentStart.y);
if (abs(crossproduct) > 2)
{
return false;
}
auto dotproduct = (point.x - segmentStart.x) * (segmentEnd.x - segmentStart.x) + (point.y - segmentStart.y) * (segmentEnd.y - segmentStart.y);
if (dotproduct < 0)
{
return false;
}
auto squaredlengthba = (segmentEnd.x - segmentStart.x) * (segmentEnd.x - segmentStart.x) + (segmentEnd.y - segmentStart.y) * (segmentEnd.y - segmentStart.y);
if (dotproduct > squaredlengthba)
{
return false;
}
return true;
}
bool PointOnLineSegment(D3DXVECTOR2 pt1, D3DXVECTOR2 pt2, D3DXVECTOR2 pt, double epsilon = 0.001)
{
if (pt.x - std::fmax(pt1.x, pt2.x) > epsilon ||
std::fmin(pt1.x, pt2.x) - pt.x > epsilon ||
pt.y - std::fmax(pt1.y, pt2.y) > epsilon ||
std::fmin(pt1.y, pt2.y) - pt.y > epsilon)
return false;
if (abs(pt2.x - pt1.x) < epsilon)
return abs(pt1.x - pt.x) < epsilon || abs(pt2.x - pt.x) < epsilon;
if (abs(pt2.y - pt1.y) < epsilon)
return abs(pt1.y - pt.y) < epsilon || abs(pt2.y - pt.y) < epsilon;
double x = pt1.x + (pt.y - pt1.y) * (pt2.x - pt1.x) / (pt2.y - pt1.y);
double y = pt1.y + (pt.x - pt1.x) * (pt2.y - pt1.y) / (pt2.x - pt1.x);
return abs(pt.x - x) < epsilon || abs(pt.y - y) < epsilon;
}
bool IsCollisioned(CollisionType type ,RVector3 vec,float radius)
{
auto local = ObjectManager::GetPlayer();
switch (type)
{
case Minion:
{
for (GameObject*minion : ObjectManager::GetMinions(ObjectManager::ObjectTeam::Enemies))
{
auto base = (Obj_AI_Base*)minion;
auto basecord = base->GetPosition();//LinePred->Calculate(base);
RVector3 pt1,pt2,pt;
if (!render.r3dWorldToScreen(&basecord, &pt))
continue;
render.r3dWorldToScreen(&local->GetPosition(), &pt1);
render.r3dWorldToScreen(&vec, &pt2);
#ifdef linepred
render.DrawLine(pt.x, pt.y, pt2.x, pt2.y, 10, D3DCOLOR_ARGB(255, 255, 20, 147));
render.DrawLine(pt2.x, pt2.y, pt1.x, pt1.y, 10, D3DCOLOR_ARGB(255, 255, 165, 0));
#endif
if (PointOnLineSegment(D3DXVECTOR2(pt1.x,pt1.y), D3DXVECTOR2(pt2.x,pt2.y), D3DXVECTOR2(pt.x,pt.y),radius))
{
return true;
}
}
break;
}
}
return false;
}
LinePrediction* LinePred;
CirclePrediction* CircPred;
};