-
Notifications
You must be signed in to change notification settings - Fork 3
/
Level-Coord.cpp
235 lines (187 loc) · 5.27 KB
/
Level-Coord.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
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
#include "StdAfx.h"
#include ".\level.h"
// Coordinate utilities.
// Most of the code in this file has been taken from DEU, although it
// has been heavily rewritten and enhanced. However, the original copyright
// and license are still valid!
// Doom Editor Utility, by Brendon Wyber and Raphaël Quinet.
// You are allowed to use any parts of this code in another program, as
// long as you give credits to the authors in the documentation and in
// the program itself. Read the file README.1ST for more information.
// This program comes with absolutely no warranty.
// Changes to original code (c) 1995-2008 by Christoph Oelckers
//==========================================================================
//
//
//
//==========================================================================
int CLevel::SX(double x)
{
return int((x-m_CenterX)*10/m_ZoomFactor) + (m_ScreenCenterX);
}
int CLevel::SY(double y)
{
return -int((y-m_CenterY)*10/m_ZoomFactor) + (m_ScreenCenterY);
}
double CLevel::MX(int x)
{
return (x-(m_ScreenCenterX))*m_ZoomFactor/10+m_CenterX;
}
double CLevel::MY(int y)
{
return -(y-(m_ScreenCenterY))*m_ZoomFactor/10+m_CenterY;
}
//==========================================================================
//
//
//==========================================================================
bool CLevel::IsLineDefInside( int l, double x0, double y0, double x1, double y1)
{
CLine * cel=GetLine(l);
CVertex * v1 = StVt(cel);
CVertex * v2 = EnVt(cel);
double lx0 = v1->X();
double ly0 = v1->Y();
double lx1 = v2->X();
double ly1 = v2->Y();
double i;
/* do you like mathematics? */
if ((lx0 >= x0 && lx0 <= x1 && ly0 >= y0 && ly0 <= y1) ||
(lx1 >= x0 && lx1 <= x1 && ly1 >= y0 && ly1 <= y1)) return true;
if ((ly0 > y0) != (ly1 > y0))
{
i = lx0 + ((y0 - ly0) * (lx1 - lx0) / (ly1 - ly0));
if (i >= x0 && i <= x1) return true; /* the LineDef crosses the y0 side (left) */
}
if ((ly0 > y1) != (ly1 > y1))
{
i = lx0 + ((y1 - ly0) * (lx1 - lx0) / (ly1 - ly0));
if (i >= x0 && i <= x1) return true; /* the LineDef crosses the y1 side (right) */
}
if ((lx0 > x0) != (lx1 > x0))
{
i = ly0 + ((x0 - lx0) * (ly1 - ly0) / (lx1 - lx0));
if (i >= y0 && i <= y1) return true; /* the LineDef crosses the x0 side (down) */
}
if ((lx0 > x1) != (lx1 > x1))
{
i = ly0 + ((x1 - lx0) * (ly1 - ly0) / (lx1 - lx0));
if (i >= y0 && i <= y1) return true; /* the LineDef crosses the x1 side (up) */
}
return false;
}
//==========================================================================
//
//
//
//==========================================================================
bool CLevel::IsSectorInside(int cesno,double x0,double y0,double x1,double y1)
{
int n;
for(n=0;n<NumLines();n++)
{
if ((FrontSecNo(n)==cesno) || (BackSecNo(n)==cesno))
{
if (!IsLineDefInside(n,x0,y0,x1,y1)) return false;
}
}
return true;
}
//==========================================================================
//
//
//==========================================================================
int CLevel::GetThingFromPos(CRectFloat * lpr)
{
int i;
for(i=0;i<NumThings();i++)
{
if (lpr->PointInRect(*GetThing(i))) return i;
}
return -1;
}
//==========================================================================
//
//
//==========================================================================
int CLevel::GetVertexFromPos(CRectFloat * lpr)
{
int i;
for(i=0;i<NumVertices();i++)
{
if (lpr->PointInRect((wxRealPoint)*GetVertex(i))) return i;
}
return -1;
}
//==========================================================================
//
//
//==========================================================================
int CLevel::GetVertexFromPoint(wxPoint lpt)
{
int i;
for(i=0;i<NumVertices();i++)
{
CVertex * pth = GetVertex(i);
if (int(pth->X())==lpt.x && int(pth->Y())==lpt.y) return i;
}
return -1;
}
//==========================================================================
//
//
//==========================================================================
void CLevel::GetAttachedLines(int vt, TArray<int> & list)
{
for (int l = 0; l < NumLines(); l++)
{
if (StVtNo(l)==vt || EnVtNo(l)==vt) list.Push(l);
}
}
//==========================================================================
//
//
//==========================================================================
int CLevel::GetLineDefFromPos(CRectFloat * r)
{
int n;
for (n=0;n<NumLines();n++)
{
if (IsLineDefInside(n,r->left,r->top,r->right,r->bottom)) return n;
}
return -1;
}
//==========================================================================
//
//
//==========================================================================
int CLevel::GetSectorFromPos(wxRealPoint p)
{
int n;
CLine * curld=NULL;
double curx=m_Bounds.right+1;
for(n=0;n<NumLines();n++)
{
CLine * cel = GetLine(n);
if ((StVt(cel)->Y() > p.y) != (EnVt(cel)->Y() > p.y))
{
double lx0 = StVt(cel)->X();
double ly0 = StVt(cel)->Y();
double lx1 = EnVt(cel)->X();
double ly1 = EnVt(cel)->Y();
double m=lx0+((p.y-ly0)*(lx1-lx0)/(ly1-ly0));
if (m>=p.x && m<curx)
{
curx=m;
curld=cel;
}
}
}
/* now look if this LineDef has a SideDef bound to one sector */
if (curld)
{
int side = (StVt(curld)->Y() > EnVt(curld)->Y())? 0:1;
return curld->sides[side].sector;
}
return -1;
}