/
hedge.h
454 lines (380 loc) · 12.7 KB
/
hedge.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
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
/** @file hedge.h Map Geometry Half-Edge.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/
#ifndef LIBDENG_MAP_HEDGE
#define LIBDENG_MAP_HEDGE
#include "MapElement"
#include "map/vertex.h"
#include "map/linedef.h"
#include "resource/r_data.h"
#include "p_dmu.h"
#include "sector.h"
#include "render/walldiv.h"
#include "render/rend_bias.h"
#include <de/Error>
// Helper macros for accessing hedge data elements.
#define FRONT 0
#define BACK 1
/**
* @defgroup hedgeFrameFlags Half-edge Frame Flags
* @ingroup map
*/
///@{
#define HEDGEINF_FACINGFRONT 0x0001
///@}
// Logical edge identifiers:
/// @addtogroup map
///@{
#define FROM 0
#define TO 1
/// Aliases:
#define START FROM
#define END TO
///@}
/**
* Map geometry half-edge.
*
* @em The twin of a half-edge is another HEdge, that which is on the other
* side. If a twin half-edge is linked, they must always be updated as one.
* (i.e., if one of the half-edges is split, the twin must be split also).
*
* @todo The design of this component presently means it cannot yet be rightly
* considered a half-edge (there are two vertex links and two adjacent edge
* links (among other discrepancies)). This component should be revised,
* simplifying it accordingly, as this will in turn lead to dependent logic
* improvements elsewhere. -ds
*
* @ingroup map
*/
class HEdge : public de::MapElement
{
public:
/// Required twin half-edge is missing. @ingroup errors
DENG2_ERROR(MissingTwinError);
/// Required line attribution is missing. @ingroup errors
DENG2_ERROR(MissingLineError);
/// Required sector attribution is missing. @ingroup errors
DENG2_ERROR(MissingSectorError);
/// The referenced geometry group does not exist. @ingroup errors
DENG2_ERROR(UnknownGeometryGroupError);
/// The referenced property does not exist. @ingroup errors
DENG2_ERROR(UnknownPropertyError);
/// The referenced property is not writeable. @ingroup errors
DENG2_ERROR(WritePropertyError);
public: /// @todo Make private:
/// [Start, End] of the segment.
Vertex *_v[2];
/// Next half-edge (clockwise) around the @em face.
HEdge *_next;
/// Previous half-edge (anticlockwise) around the @em face.
HEdge *_prev;
/// Linked @em twin half-edge (that on the other side of the half-edge).
HEdge *_twin;
/// The @em face of the half-edge (a BSP leaf).
BspLeaf *_bspLeaf;
/// Map line attributed to the half-edge.
LineDef *_line;
/// On which side of the attributed line (0=front, 1=back)?
int _lineSide;
/// Point along the attributed line at which v1 occurs; otherwise @c 0.
coord_t _lineOffset;
/// Map sector attributed to the half-edge.
Sector *_sector;
/// World angle.
angle_t _angle;
/// Accurate length of the segment (v1 -> v2).
coord_t _length;
/// For each @ref SideDefSection.
biassurface_t *_bsuf[3];
/// @ref hedgeFrameFlags
short _frameFlags;
/// Unique. Set when saving the BSP.
uint _origIndex;
public:
HEdge();
HEdge(HEdge const &other);
~HEdge();
/**
* Returns the specified edge vertex for the half-edge.
*
* @param to If not @c 0 return the To vertex; otherwise the From vertex.
*/
Vertex &vertex(int to);
/// @copydoc vertex()
Vertex const &vertex(int to) const;
/**
* Convenient accessor method for returning the origin of the specified
* edge vertex for the half-edge.
*
* @see vertex()
*/
inline const_pvec2d_t &vertexOrigin(int to) const
{
return vertex(to).origin();
}
/**
* Returns the From/Start vertex for the half-edge.
*/
inline Vertex &v1() { return vertex(FROM); }
/// @copydoc v1()
inline Vertex const &v1() const { return vertex(FROM); }
/// @copydoc v1()
/// An alias of v1().
inline Vertex &from() { return v1(); }
/// @copydoc from()
/// An alias of v1().
inline Vertex const &from() const { return v1(); }
/**
* Convenient accessor method for returning the origin of the From/Start
* vertex for the half-edge.
*
* @see v1()
*/
inline const_pvec2d_t &v1Origin() const { return v1().origin(); }
/// @copydoc v1Origin()
/// An alias of v1Origin()
inline const_pvec2d_t &fromOrigin() const { return v1Origin(); }
/**
* Returns the To/End vertex for the half-edge.
*/
inline Vertex &v2() { return vertex(TO); }
/// @copydoc v2()
inline Vertex const &v2() const { return vertex(TO); }
/// @copydoc v2()
/// An alias of v2().
inline Vertex &to() { return v2(); }
/// @copydoc to()
/// An alias of v2().
inline Vertex const &to() const { return v2(); }
/**
* Convenient accessor method for returning the origin of the To/End
* vertex for the half-edge.
*
* @see v2()
*/
inline const_pvec2d_t &v2Origin() const { return v2().origin(); }
/// @copydoc v2Origin()
/// An alias of v2Origin()
inline const_pvec2d_t &toOrigin() const { return v2Origin(); }
/**
* Returns the linked @em next half-edge (clockwise) around the face of
* the half-edge (which might be *this* half-edge).
*
* @see nextIsThis()
*/
HEdge &next() const;
/**
* Returns @c true iff the @em next half-edge (clockwise) around the face
* of the half-edge is *this*.
*
* @see next()
*/
inline bool nextIsThis() const { return &next() == this; }
/**
* Returns the linked @em previous half-edge (anticlockwise) around the
* face of the half-edge (which might be *this* half-edge).
*
* @see prevIsThis()
*/
HEdge &prev() const;
/**
* Returns @c true iff the @em previous half-edge (anticlockwise) around
* the face of the half-edge is *this*.
*
* @see prev()
*/
inline bool prevIsThis() const { return &prev() == this; }
/**
* Returns @c true iff a @em twin is linked to the half-edge.
*/
bool hasTwin() const;
/**
* Returns the linked @em twin of the half-edge.
*/
HEdge &twin() const;
/**
* Returns a pointer to the linked @em twin of the half-edge; otherwise @c 0.
*
* @see hasTwin()
*/
inline HEdge *twinPtr() const { return hasTwin()? &twin() : 0; }
/**
* Returns @c true iff a BspLeaf is linked to the half-edge.
*/
bool hasBspLeaf() const;
/**
* Returns the BSP leaf for the half-edge.
*/
BspLeaf &bspLeaf() const;
/**
* Returns @c true iff a line is attributed to the half-edge.
*/
bool hasLine() const;
/**
* Returns the line attributed to the half-edge.
*
* @see hasLine()
*/
LineDef &line() const;
/**
* Returns a pointer to the line attributed to the half-edge; otherwise @c 0.
*
* @see hasLine()
*/
inline LineDef *linePtr() const { return hasLine()? &line() : 0; }
/**
* Convenient accessor method for returning the Side of the line attributed
* to the half-edge.
*
* @see hasLine(), line()
*/
inline LineDef::Side &lineSide() const { return line().side(lineSideId()); }
/**
* Convenient method for determining if the Side of the line attributed to
* the half-edge has a sidedef.
*
* @see hasLine(), lineSide(), LineDef::Side::hasSideDef()
*/
inline bool hasLineSideDef() const {
return hasLine() && lineSide().hasSideDef();
}
/**
* Convenient accessor method for returning the SideDef of the Side of the
* line attributed to the half-edge.
*
* @see hasLineSideDef()
*/
inline SideDef &lineSideDef() const { return lineSide().sideDef(); }
/**
* Returns the logical side of the line attributed to the half-edge.
*/
int lineSideId() const;
/**
* Returns the offset point at which v1 occurs from the attributed line for
* the half-edge.
*/
coord_t lineOffset() const;
/**
* Returns @c true iff a sector is attributed to the half-edge.
*/
bool hasSector() const;
/**
* Returns the sector attributed to the half-edge.
*
* @see hasSector()
*/
Sector §or() const;
/**
* Returns a pointer to the sector attributed to the half-edge; otherwise @c 0.
*
* @see hasSector()
*/
inline Sector *sectorPtr() const { return hasSector()? §or() : 0; }
/**
* Returns the world angle of the half-edge.
*/
angle_t angle() const;
/**
* Returns the accurate length of the half-edge from v1 to v2.
*/
coord_t length() const;
/**
* Returns the original index of the half-edge.
* @deprecated No longer needed.
*/
uint origIndex() const;
/**
* Returns the distance from @a point to the nearest point along the HEdge [0..1].
*
* @param point Point to measure the distance to in the map coordinate space.
*/
coord_t pointDistance(const_pvec2d_t point, coord_t *offset) const;
/**
* Returns the distance from @a point to the nearest point along the HEdge [0..1].
*
* @param x X axis point to measure the distance to in the map coordinate space.
* @param y Y axis point to measure the distance to in the map coordinate space.
*/
inline coord_t pointDistance(coord_t x, coord_t y, coord_t *offset) const
{
coord_t point[2] = { x, y };
return pointDistance(point, offset);
}
/**
* On which side of the HEdge does the specified @a point lie?
*
* @param point Point to test in the map coordinate space.
*
* @return @c <0 Point is to the left/back of the hedge.
* @c =0 Point lies directly on the hedge.
* @c >0 Point is to the right/front of the hedge.
*/
coord_t pointOnSide(const_pvec2d_t point) const;
/**
* On which side of the HEdge does the specified @a point lie?
*
* @param x X axis point to test in the map coordinate space.
* @param y Y axis point to test in the map coordinate space.
*
* @return @c <0 Point is to the left/back of the hedge.
* @c =0 Point lies directly on the hedge.
* @c >0 Point is to the right/front of the hedge.
*/
inline coord_t pointOnSide(coord_t x, coord_t y) const
{
coord_t point[2] = { x, y };
return pointOnSide(point);
}
/**
* Prepare wall division data for a section of the HEdge.
*
* @param section Section to prepare divisions for.
* @param frontSector Sector to use for the front side.
* @param backSector Sector to use for the back side.
* @param leftWallDivs Division data for the left edge is written here.
* @param rightWallDivs Division data for the right edge is written here.
* @param matOffset Material offset data is written here.
*
* @return @c true if divisions were prepared (the specified @a section has a
* non-zero Z axis height).
*/
bool prepareWallDivs(SideDefSection section, Sector *frontSector, Sector *backSector,
walldivs_t *leftWallDivs, walldivs_t *rightWallDivs, pvec2f_t matOffset) const;
/**
* Retrieve the bias surface for specified geometry @a groupId
*
* @param groupId Geometry group identifier for the bias surface.
*/
biassurface_t &biasSurfaceForGeometryGroup(uint groupId);
/**
* Get a property value, selected by DMU_* name.
*
* @param args Property arguments.
* @return Always @c 0 (can be used as an iterator).
*/
int property(setargs_t &args) const;
/**
* Update a property value, selected by DMU_* name.
*
* @param args Property arguments.
* @return Always @c 0 (can be used as an iterator).
*/
int setProperty(setargs_t const &args);
};
#endif // LIBDENG_MAP_HEDGE