Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Refactor: Separated Face from Polygon
All components and map geometry model abstractions for the half-edge
data structure are now implemented.

Todo: Generalize the components and clean up.
Todo: Rename Polygon as Mesh
Todo: BspLeaf should not own multiple polygons/meshes. GameMap should
own the meshes and BspLeaf should reference one or more Faces.
  • Loading branch information
danij-deng committed Jun 5, 2013
1 parent 41a82fa commit 066a9f3
Show file tree
Hide file tree
Showing 24 changed files with 452 additions and 322 deletions.
3 changes: 3 additions & 0 deletions doomsday/client/client.pro
Expand Up @@ -113,6 +113,7 @@ DENG_HEADERS += \
include/BspLeaf \
include/BspNode \
include/EntityDatabase \
include/Face \
include/Game \
include/Games \
include/HEdge \
Expand Down Expand Up @@ -244,6 +245,7 @@ DENG_HEADERS += \
include/map/bspnode.h \
include/map/dam_file.h \
include/map/entitydatabase.h \
include/map/face.h \
include/map/gamemap.h \
include/map/generators.h \
include/map/hedge.h \
Expand Down Expand Up @@ -522,6 +524,7 @@ SOURCES += \
src/map/bspnode.cpp \
src/map/dam_file.cpp \
src/map/entitydatabase.cpp \
src/map/face.cpp \
src/map/gamemap.cpp \
src/map/generators.cpp \
src/map/hedge.cpp \
Expand Down
1 change: 1 addition & 0 deletions doomsday/client/include/Face
@@ -0,0 +1 @@
#include "map/face.h"
1 change: 1 addition & 0 deletions doomsday/client/include/map/bspleaf.h
Expand Up @@ -27,6 +27,7 @@
#include <de/Vector>

#include "MapElement"
#include "HEdge"
#include "Line"
#include "Polygon"

Expand Down
128 changes: 128 additions & 0 deletions doomsday/client/include/map/face.h
@@ -0,0 +1,128 @@
/** @file map/face.h World Map Face Geometry.
*
* @authors Copyright © 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 DENG_WORLD_MAP_FACE
#define DENG_WORLD_MAP_FACE

#include <de/aabox.h>

#include <de/Vector>

#include "MapElement"

namespace de {

class HEdge;
class Polygon;

/**
* Face geometry.
*
* @ingroup map
*/
class Face
{
DENG2_NO_COPY (Face)
DENG2_NO_ASSIGN(Face)

public:
explicit Face(Polygon &poly);

/**
* Returns the Polygon mesh the face is a part of.
*/
Polygon &poly() const;

/**
* Returns a pointer to the first half-edge in the face geometry (note that
* half-edges are sorted in a clockwise order). May return @c 0 if there is
* no half-edge linked to the face.
*/
HEdge *hedge() const;

/**
* Change the first half-edge in the face geometry.
*/
void setHEdge(HEdge *newHEdge);

/**
* Returns the axis-aligned bounding box which encompases all the vertexes
* which define the face geometry.
*/
AABoxd const &aaBox() const;

/**
* Update the face geometry's axis-aligned bounding box to encompass all vertexes.
*/
void updateAABox();

/**
* Returns the point described by the average origin coordinates of all the
* vertexes which define the geometry.
*/
Vector2d const &center() const;

/**
* Update the center point of the geometry.
*
* @pre Axis-aligned bounding box must have been initialized.
*/
void updateCenter();

/**
* Determines whether the face geometry is currently convex.
*
* @note Due to the potential computational complexity of determining convexity
* this should be called sparingly/only when necessary.
*
* @todo Cache this result.
*/
bool isConvex() const;

/**
* Returns a pointer to the map element attributed to the face. May return @c 0
* if not attributed.
*/
MapElement *mapElement() const;

/**
* Change the MapElement to which the face is attributed.
*
* @param newMapElement New MapElement to attribute to the face. Ownership is
* unaffected. Can be @c 0 (to clear the attribution).
*
* @see mapElement()
*/
void setMapElement(MapElement *newMapElement);

#ifdef DENG_DEBUG
/**
* Output a textual, human-readable description/representation of the face to
* the application's output log.
*/
void print() const;
#endif

private:
DENG2_PRIVATE(d)
};

} // namespace de

#endif // DENG_WORLD_MAP_FACE
26 changes: 13 additions & 13 deletions doomsday/client/include/map/hedge.h
Expand Up @@ -28,7 +28,7 @@

namespace de {

class Polygon;
class Face;

/**
* Half-edge geometry.
Expand All @@ -47,8 +47,8 @@ class HEdge
/// Required neighbor half-edge is missing. @ingroup errors
DENG2_ERROR(MissingNeighborError);

/// Required polygon is missing. @ingroup errors
DENG2_ERROR(MissingPolygonError);
/// Required face is missing. @ingroup errors
DENG2_ERROR(MissingFaceError);

public:
HEdge(Vertex &vertex);
Expand Down Expand Up @@ -175,26 +175,26 @@ class HEdge
void setTwin(HEdge const *newTwin);

/**
* Returns @c true iff the half-edge is part of some Polygon.
* Returns @c true iff the half-edge is part of some Face geometry.
*/
bool hasPoly() const;
bool hasFace() const;

/**
* Returns the Polygon the half-edge is a part of.
* Returns the Face geometry the half-edge is a part of.
*
* @see hasPoly()
* @see hasFace()
*/
Polygon &poly() const;
Face &face() const;

/**
* Change the Polygon to which the half-edge is attributed.
* Change the Face to which the half-edge is attributed.
*
* @param newPolygon New Polygon to attribute to the half-edge. Ownership is
* unaffected. Can be @c 0 (to clear the attribution).
* @param newFace New Face to attribute to the half-edge. Ownership is
* unaffected. Can be @c 0 (to clear the attribution).
*
* @see hasPoly(), poly()
* @see hasFace(), face()
*/
void setPoly(Polygon const *newPolygon);
void setFace(Face const *newFace);

/**
* Returns a pointer to the map element attributed to the half-edge. May return
Expand Down
103 changes: 12 additions & 91 deletions doomsday/client/include/map/polygon.h
@@ -1,4 +1,4 @@
/** @file map/polygon.h World Map Polygon Geometry.
/** @file data/polygon.h Polygon Mesh Geometry.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
Expand All @@ -18,122 +18,43 @@
* 02110-1301 USA</small>
*/

#ifndef DENG_WORLD_MAP_POLYGON
#define DENG_WORLD_MAP_POLYGON
#ifndef DENG_DATA_POLYGON
#define DENG_DATA_POLYGON

#include <de/aabox.h>

#include <de/Error>
#include <de/Vector>

class BspLeaf;
#include <de/libdeng2.h>

namespace de {

class HEdge;
class Face;

/**
* Polygon geometry.
* Polygon mesh geometry.
*
* @ingroup map
* @ingroup data
*/
class Polygon
{
public:
/// No BSP leaf is attributed. @ingroup errors
DENG2_ERROR(MissingBspLeafError);

public: /// @todo Make private:
/// First half-edge in the face geometry. Ordered by angle, clockwise starting
/// from the smallest angle.
HEdge *_hedge;

/// Number of half-edge's in the face.
public: /// @todo make private:
/// Total number of half-edge's in the polygon.
int _hedgeCount;

public:
Polygon();

/**
* Returns @c true iff a BSP leaf is attributed to the polygon.
*/
bool hasBspLeaf() const;

/**
* Returns the BSP leaf attributed to the polygon.
*
* @see hasBspLeaf()
* Returns a pointer to the first Face of the polygon.
*/
BspLeaf &bspLeaf() const;

/**
* Change the BSP leaf attributed to the polygon.
*
* @param newBspLeaf New BSP leaf to attribute the polygon. Ownership is
* unaffected. Can be @c 0 (to clear the attribution).
*
* @see hasBspLeaf(), bspLeaf()
*/
void setBspLeaf(BspLeaf *newBspLeaf);

/**
* Returns a pointer to the first half-edge of the Face of the polygon (note
* that half-edges are sorted in a clockwise order). May return @c 0 if there
* is no half-edge linked to the face.
*/
HEdge *firstHEdge() const;
Face *firstFace() const;

/**
* Total number of half-edges in the polygon.
*/
int hedgeCount() const;

/**
* Returns the axis-aligned bounding box which encompases all the vertexes
* which define the geometry.
*/
AABoxd const &aaBox() const;

/**
* Update the geometry's axis-aligned bounding box to encompass all vertexes.
*/
void updateAABox();

/**
* Returns the point described by the average origin coordinates of all the
* vertexes which define the geometry.
*/
Vector2d const &center() const;

/**
* Update the center point of the geometry.
*
* @pre Axis-aligned bounding box must have been initialized.
*/
void updateCenter();

/**
* Determines whether the geometry of the polygon is currently convex.
*
* @note Due to the potential computational complexity of determining convexity
* this should be called sparingly/only when necessary.
*
* @todo Cache this result.
*/
bool isConvex() const;

#ifdef DENG_DEBUG
/**
* Output a textual, human-readable description/representation of the polygon
* to the application's output log.
*/
void print() const;
#endif

private:
DENG2_PRIVATE(d)
};

} // namespace de

#endif // DENG_WORLD_MAP_POLYGON
#endif // DENG_DATA_POLYGON
10 changes: 6 additions & 4 deletions doomsday/client/include/map/segment.h
Expand Up @@ -24,16 +24,16 @@
#include <de/Error>

#include "MapElement"
#include "BspLeaf"
#include "Face"
#include "HEdge"
#include "Line"
#include "Polygon"
#include "Vertex"

#ifdef __CLIENT__
struct BiasSurface;
#endif

class BspLeaf;
class Sector;

/**
Expand Down Expand Up @@ -89,7 +89,7 @@ class Segment : public de::MapElement
* @see HEdge::hasPoly(), Polygon::hasBspLeaf()
*/
inline bool hasBspLeaf() const {
return hedge().hasPoly() && hedge().poly().hasBspLeaf();
return hedge().hasFace() && hedge().face().mapElement() != 0;
}

/**
Expand All @@ -98,7 +98,9 @@ class Segment : public de::MapElement
*
* @see hasBspLeaf(), Polygon::bspLeaf()
*/
inline BspLeaf &bspLeaf() const { return hedge().poly().bspLeaf(); }
inline BspLeaf &bspLeaf() const {
return *hedge().face().mapElement()->castTo<BspLeaf>();
}

/**
* Convenience accessor which returns the Sector attributed to the BspLeaf
Expand Down

0 comments on commit 066a9f3

Please sign in to comment.