File: Brush.h

package info (click to toggle)
0ad 0.0.17-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 51,248 kB
  • ctags: 46,933
  • sloc: cpp: 223,208; ansic: 31,240; python: 16,343; perl: 4,083; sh: 1,011; makefile: 915; xml: 733; java: 621; ruby: 229; erlang: 53; sql: 40
file content (127 lines) | stat: -rw-r--r-- 3,673 bytes parent folder | download | duplicates (4)
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
/* Copyright (C) 2012 Wildfire Games.
 * This file is part of 0 A.D.
 *
 * 0 A.D. 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.
 *
 * 0 A.D. 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 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * CBrush, a class representing a convex object
 */

#ifndef maths_brush_h
#define maths_brush_h

#include "Vector3D.h"

#include "graphics/ShaderProgramPtr.h"

class CBoundingBoxAligned;
class CFrustum;
class CPlane;


/**
 * Class CBrush: Represents a convex object, supports some CSG operations.
 */
class CBrush
{
	friend class TestBrush;

public:
	CBrush() { }

	/**
	 * CBrush: Construct a brush from a bounds object.
	 *
	 * @param bounds the CBoundingBoxAligned object to construct the brush from.
	 */
	CBrush(const CBoundingBoxAligned& bounds);

	/**
	 * IsEmpty: Returns whether the brush is empty.
	 *
	 * @return @c true if the brush is empty, @c false otherwise
	 */
	bool IsEmpty() const { return m_Vertices.size() == 0; }

	/**
	 * Bounds: Calculate the axis-aligned bounding box for this brush.
	 *
	 * @param result the resulting bounding box is stored here
	 */
	void Bounds(CBoundingBoxAligned& result) const;

	/**
	 * Slice: Cut the object along the given plane, resulting in a smaller (or even empty) brush representing 
	 * the part of the object that lies in front of the plane (as defined by the positive direction of its 
	 * normal vector).
	 *
	 * @param plane the slicing plane
	 * @param result the resulting brush is stored here
	 */
	void Slice(const CPlane& plane, CBrush& result) const;

	/**
	 * Intersect: Intersect the brush with the given frustum.
	 *
	 * @param frustum the frustum to intersect with
	 * @param result the resulting brush is stored here
	 */
	void Intersect(const CFrustum& frustum, CBrush& result) const;

	/**
	 * Render the surfaces of the brush as triangles.
	 */
	void Render(CShaderProgramPtr& shader) const;

	/**
	 * Render the outline of the brush as lines.
	 */
	void RenderOutline(CShaderProgramPtr& shader) const;

private:
	
	/**
	 * Returns a copy of the vertices in this brush. Intended for testing purposes; you should not need to use
	 * this method directly.
	 */
	std::vector<CVector3D> GetVertices() const;

	/**
	 * Writes a vector of the faces in this brush to @p out. Each face is itself a vector, listing the vertex indices 
	 * that make up the face, starting and ending with the same index. Intended for testing purposes; you should not 
	 * need to use this method directly.
	 */
	void GetFaces(std::vector<std::vector<size_t> >& out) const;

private:
	static const size_t NO_VERTEX = ~0u;

	typedef std::vector<CVector3D> Vertices;
	typedef std::vector<size_t> FaceIndices;

	/// Collection of unique vertices that make up this shape.
	Vertices m_Vertices;

	/**
	 * Holds the face definitions of this brush. Each face is a sequence of indices into m_Vertices that starts and ends with 
	 * the same vertex index, completing a loop through all the vertices that make up the face. This vector holds all the face
	 * sequences back-to-back, thus looking something like 'x---xy--------yz--z' in the general case.
	 */
	FaceIndices m_Faces;

	struct Helper;
};

#endif // maths_brush_h