Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Brush.h
Go to the documentation of this file.
1 /* Copyright (C) 2012 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 /*
19  * CBrush, a class representing a convex object
20  */
21 
22 #ifndef maths_brush_h
23 #define maths_brush_h
24 
25 #include "Vector3D.h"
26 
28 class CFrustum;
29 class CPlane;
30 
31 
32 /**
33  * Class CBrush: Represents a convex object, supports some CSG operations.
34  */
35 class CBrush
36 {
37  friend class TestBrush;
38 
39 public:
40  CBrush() { }
41 
42  /**
43  * CBrush: Construct a brush from a bounds object.
44  *
45  * @param bounds the CBoundingBoxAligned object to construct the brush from.
46  */
47  CBrush(const CBoundingBoxAligned& bounds);
48 
49  /**
50  * IsEmpty: Returns whether the brush is empty.
51  *
52  * @return @c true if the brush is empty, @c false otherwise
53  */
54  bool IsEmpty() const { return m_Vertices.size() == 0; }
55 
56  /**
57  * Bounds: Calculate the axis-aligned bounding box for this brush.
58  *
59  * @param result the resulting bounding box is stored here
60  */
61  void Bounds(CBoundingBoxAligned& result) const;
62 
63  /**
64  * Slice: Cut the object along the given plane, resulting in a smaller (or even empty) brush representing
65  * the part of the object that lies in front of the plane (as defined by the positive direction of its
66  * normal vector).
67  *
68  * @param plane the slicing plane
69  * @param result the resulting brush is stored here
70  */
71  void Slice(const CPlane& plane, CBrush& result) const;
72 
73  /**
74  * Intersect: Intersect the brush with the given frustum.
75  *
76  * @param frustum the frustum to intersect with
77  * @param result the resulting brush is stored here
78  */
79  void Intersect(const CFrustum& frustum, CBrush& result) const;
80 
81 private:
82 
83  /**
84  * Returns a copy of the vertices in this brush. Intended for testing purposes; you should not need to use
85  * this method directly.
86  */
87  std::vector<CVector3D> GetVertices() const;
88 
89  /**
90  * Writes a vector of the faces in this brush to @p out. Each face is itself a vector, listing the vertex indices
91  * that make up the face, starting and ending with the same index. Intended for testing purposes; you should not
92  * need to use this method directly.
93  */
94  void GetFaces(std::vector<std::vector<size_t> >& out) const;
95 
96 private:
97  static const size_t NO_VERTEX = ~0u;
98 
99  typedef std::vector<CVector3D> Vertices;
100  typedef std::vector<size_t> FaceIndices;
101 
102  /// Collection of unique vertices that make up this shape.
104 
105  /**
106  * Holds the face definitions of this brush. Each face is a sequence of indices into m_Vertices that starts and ends with
107  * the same vertex index, completing a loop through all the vertices that make up the face. This vector holds all the face
108  * sequences back-to-back, thus looking something like 'x---xy--------yz--z' in the general case.
109  */
111 
112  struct Helper;
113 };
114 
115 #endif // maths_brush_h
CBrush()
Definition: Brush.h:40
void GetFaces(std::vector< std::vector< size_t > > &out) const
Writes a vector of the faces in this brush to out.
Definition: Brush.cpp:387
void Intersect(const CFrustum &frustum, CBrush &result) const
Intersect: Intersect the brush with the given frustum.
Definition: Brush.cpp:348
static void out(const wchar_t *fmt,...)
Definition: wdbg_sym.cpp:419
std::vector< CVector3D > GetVertices() const
Returns a copy of the vertices in this brush.
Definition: Brush.cpp:382
std::vector< CVector3D > Vertices
Definition: Brush.h:99
friend class TestBrush
Definition: Brush.h:37
bool IsEmpty() const
IsEmpty: Returns whether the brush is empty.
Definition: Brush.h:54
static const size_t NO_VERTEX
Definition: Brush.h:97
Class CBrush: Represents a convex object, supports some CSG operations.
Definition: Brush.h:35
void Slice(const CPlane &plane, CBrush &result) const
Slice: Cut the object along the given plane, resulting in a smaller (or even empty) brush representin...
Definition: Brush.cpp:192
Vertices m_Vertices
Collection of unique vertices that make up this shape.
Definition: Brush.h:103
FaceIndices m_Faces
Holds the face definitions of this brush.
Definition: Brush.h:110
void Bounds(CBoundingBoxAligned &result) const
Bounds: Calculate the axis-aligned bounding box for this brush.
Definition: Brush.cpp:63
Definition: Plane.h:38
std::vector< size_t > FaceIndices
Definition: Brush.h:100