Pyrogenesis  trunk
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 
30 class CFrustum;
31 class CPlane;
32 
33 
34 /**
35  * Class CBrush: Represents a convex object, supports some CSG operations.
36  */
37 class CBrush
38 {
39  friend class TestBrush;
40 
41 public:
42  CBrush() { }
43 
44  /**
45  * CBrush: Construct a brush from a bounds object.
46  *
47  * @param bounds the CBoundingBoxAligned object to construct the brush from.
48  */
49  CBrush(const CBoundingBoxAligned& bounds);
50 
51  /**
52  * IsEmpty: Returns whether the brush is empty.
53  *
54  * @return @c true if the brush is empty, @c false otherwise
55  */
56  bool IsEmpty() const { return m_Vertices.size() == 0; }
57 
58  /**
59  * Bounds: Calculate the axis-aligned bounding box for this brush.
60  *
61  * @param result the resulting bounding box is stored here
62  */
63  void Bounds(CBoundingBoxAligned& result) const;
64 
65  /**
66  * Slice: Cut the object along the given plane, resulting in a smaller (or even empty) brush representing
67  * the part of the object that lies in front of the plane (as defined by the positive direction of its
68  * normal vector).
69  *
70  * @param plane the slicing plane
71  * @param result the resulting brush is stored here
72  */
73  void Slice(const CPlane& plane, CBrush& result) const;
74 
75  /**
76  * Intersect: Intersect the brush with the given frustum.
77  *
78  * @param frustum the frustum to intersect with
79  * @param result the resulting brush is stored here
80  */
81  void Intersect(const CFrustum& frustum, CBrush& result) const;
82 
83  /**
84  * Render the surfaces of the brush as triangles.
85  */
86  void Render(CShaderProgramPtr& shader) const;
87 
88  /**
89  * Render the outline of the brush as lines.
90  */
91  void RenderOutline(CShaderProgramPtr& shader) const;
92 
93 private:
94 
95  /**
96  * Returns a copy of the vertices in this brush. Intended for testing purposes; you should not need to use
97  * this method directly.
98  */
99  std::vector<CVector3D> GetVertices() const;
100 
101  /**
102  * Writes a vector of the faces in this brush to @p out. Each face is itself a vector, listing the vertex indices
103  * that make up the face, starting and ending with the same index. Intended for testing purposes; you should not
104  * need to use this method directly.
105  */
106  void GetFaces(std::vector<std::vector<size_t> >& out) const;
107 
108 private:
109  static const size_t NO_VERTEX = ~0u;
110 
111  typedef std::vector<CVector3D> Vertices;
112  typedef std::vector<size_t> FaceIndices;
113 
114  /// Collection of unique vertices that make up this shape.
115  Vertices m_Vertices;
116 
117  /**
118  * Holds the face definitions of this brush. Each face is a sequence of indices into m_Vertices that starts and ends with
119  * the same vertex index, completing a loop through all the vertices that make up the face. This vector holds all the face
120  * sequences back-to-back, thus looking something like 'x---xy--------yz--z' in the general case.
121  */
122  FaceIndices m_Faces;
123 
124  struct Helper;
125 };
126 
127 #endif // maths_brush_h
CBrush()
Definition: Brush.h:42
void GetFaces(std::vector< std::vector< size_t > > &out) const
Writes a vector of the faces in this brush to out.
Definition: Brush.cpp:388
void Intersect(const CFrustum &frustum, CBrush &result) const
Intersect: Intersect the brush with the given frustum.
Definition: Brush.cpp:349
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:383
void RenderOutline(CShaderProgramPtr &shader) const
Render the outline of the brush as lines.
Definition: Brush.cpp:457
Definition: Frustum.h:39
std::vector< CVector3D > Vertices
Definition: Brush.h:111
friend class TestBrush
Definition: Brush.h:39
bool IsEmpty() const
IsEmpty: Returns whether the brush is empty.
Definition: Brush.h:56
static const size_t NO_VERTEX
Definition: Brush.h:109
Definition: Brush.cpp:122
Class CBrush: Represents a convex object, supports some CSG operations.
Definition: Brush.h:37
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:193
Vertices m_Vertices
Collection of unique vertices that make up this shape.
Definition: Brush.h:115
FaceIndices m_Faces
Holds the face definitions of this brush.
Definition: Brush.h:122
void Bounds(CBoundingBoxAligned &result) const
Bounds: Calculate the axis-aligned bounding box for this brush.
Definition: Brush.cpp:64
Definition: BoundingBoxAligned.h:35
void Render(CShaderProgramPtr &shader) const
Render the surfaces of the brush as triangles.
Definition: Brush.cpp:419
Definition: Plane.h:38
std::vector< size_t > FaceIndices
Definition: Brush.h:112
std::shared_ptr< CShaderProgram > CShaderProgramPtr
Definition: ShaderProgramPtr.h:25