Pyrogenesis  trunk
Overlay.h
Go to the documentation of this file.
1 /* Copyright (C) 2015 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 #ifndef INCLUDED_GRAPHICS_OVERLAY
19 #define INCLUDED_GRAPHICS_OVERLAY
20 
21 #include "graphics/Texture.h"
22 #include "maths/Vector2D.h"
23 #include "maths/Vector3D.h"
24 #include "maths/FixedVector3D.h"
25 #include "ps/Shapes.h"
26 
27 class CTerrain;
28 class CSimContext;
29 class CTexturedLineRData;
30 
31 /**
32  * Line-based overlay, with world-space coordinates, rendered in the world
33  * potentially behind other objects. Designed for selection circles and debug info.
34  */
36 {
38 
40  std::vector<float> m_Coords; // (x, y, z) vertex coordinate triples; shape is not automatically closed
41  u8 m_Thickness; // in pixels
42 
43  void PushCoords(const CVector3D& v) { PushCoords(v.X, v.Y, v.Z); }
44  void PushCoords(const float x, const float y, const float z)
45  {
46  m_Coords.push_back(x);
47  m_Coords.push_back(y);
48  m_Coords.push_back(z);
49  }
50 };
51 
52 /**
53  * Textured line overlay, with world-space coordinates, rendered in the world onto the terrain.
54  * Designed for relatively static textured lines, i.e. territory borders, originally.
55  *
56  * Once submitted for rendering, instances must not be copied afterwards. The reason is that they
57  * are assigned rendering data that is unique to the submitted instance, and non-transferable to
58  * any copies that would otherwise be made. Amongst others, this restraint includes that they must
59  * not be submitted by their address inside a std::vector storing them by value.
60  */
62 {
64  {
65  LINECAP_FLAT, ///< no line ending; abrupt stop of the line (aka. butt ending)
66 
67  /**
68  * Semi-circular line ending. The texture is mapped by curving the left vertical edge
69  * around the semi-circle's rim. That is, the center point has UV coordinates (0.5;0.5),
70  * and the rim vertices all have U coordinate 0 and a V coordinate that ranges from 0 to
71  * 1 as the rim is traversed.
72  */
74  LINECAP_SHARP, ///< sharp point ending
75  LINECAP_SQUARE, ///< square end that extends half the line width beyond the line end
76  };
77 
79  : m_Thickness(1.0f), m_Closed(false), m_AlwaysVisible(false),
80  m_StartCapType(LINECAP_FLAT), m_EndCapType(LINECAP_FLAT), m_SimContext(NULL)
81  { }
82 
85 
86  /// Color to apply to the line texture, where indicated by the mask.
88  /// (x, z) vertex coordinate pairs; y is computed automatically.
89  std::vector<float> m_Coords;
90  /// Half-width of the line, in world-space units.
91  float m_Thickness;
92  /// Should this line be treated as a closed loop? If set, any end cap settings are ignored.
93  bool m_Closed;
94  /// Should this line be rendered fully visible at all times, even under the SoD?
96 
99 
100  /**
101  * Simulation context applicable for this overlay line; used to obtain terrain information
102  * during automatic computation of Y coordinates.
103  */
105 
106  /**
107  * Cached renderer data, because expensive to compute. Allocated by the renderer when necessary
108  * for rendering purposes.
109  *
110  * Note: the rendering data may be shared between copies of this object to prevent having to
111  * recompute it, while at the same time maintaining copyability of this object (see also docs on
112  * CTexturedLineRData).
113  */
114  shared_ptr<CTexturedLineRData> m_RenderData;
115 
116  /**
117  * Converts a string line cap type into its corresponding LineCap enum value, and returns
118  * the resulting value. If the input string is unrecognized, a warning is issued and a
119  * default value is returned.
120  */
121  static LineCapType StrToLineCapType(const std::wstring& str);
122 
123  void PushCoords(const float x, const float z) { m_Coords.push_back(x); m_Coords.push_back(z); }
124  void PushCoords(const CVector2D& v) { PushCoords(v.X, v.Y); }
125  void PushCoords(const std::vector<CVector2D>& points)
126  {
127  for (size_t i = 0; i < points.size(); ++i)
128  PushCoords(points[i]);
129  }
130 };
131 
132 /**
133  * Billboard sprite overlay, with world-space coordinates, rendered on top
134  * of all other objects. Designed for health bars and rank icons.
135  */
137 {
140  CVector3D m_Position; // base position
141  float m_X0, m_Y0, m_X1, m_Y1; // billboard corner coordinates, relative to base position
142 };
143 
144 /**
145  * Rectangular single-quad terrain overlay, in world space coordinates. The vertices of the quad
146  * are not required to be coplanar; the quad is arbitrarily triangulated with no effort being made
147  * to find a best fit to the underlying terrain.
148  */
150 {
153  CVector3D m_Corners[4];
155 };
156 
158 {
159  SOverlaySphere() : m_Radius(0) { }
160 
162  float m_Radius;
164 };
165 
166 // TODO: OverlayText
167 
168 #endif // INCLUDED_GRAPHICS_OVERLAY
CTexturePtr m_TextureBase
Definition: Overlay.h:83
Line-based overlay, with world-space coordinates, rendered in the world potentially behind other obje...
Definition: Overlay.h:35
sharp point ending
Definition: Overlay.h:74
float X
Definition: Vector2D.h:157
void PushCoords(const float x, const float y, const float z)
Definition: Overlay.h:44
CColor m_Color
Definition: Overlay.h:163
Definition: Shapes.h:36
void PushCoords(const float x, const float z)
Definition: Overlay.h:123
Definition: Vector3D.h:28
bool m_AlwaysVisible
Should this line be rendered fully visible at all times, even under the SoD?
Definition: Overlay.h:95
Definition: Terrain.h:51
CColor m_Color
Definition: Overlay.h:154
Billboard sprite overlay, with world-space coordinates, rendered on top of all other objects...
Definition: Overlay.h:136
SOverlayTexturedLine()
Definition: Overlay.h:78
LineCapType m_EndCapType
Definition: Overlay.h:98
Contains pointers to various &#39;global&#39; objects that are needed by the simulation code, to allow easy access without using real (evil) global variables.
Definition: SimContext.h:32
square end that extends half the line width beyond the line end
Definition: Overlay.h:75
uint8_t u8
Definition: types.h:37
CVector3D m_Position
Definition: Overlay.h:140
void PushCoords(const std::vector< CVector2D > &points)
Definition: Overlay.h:125
std::vector< float > m_Coords
Definition: Overlay.h:40
float m_Y1
Definition: Overlay.h:141
CTexturePtr m_Texture
Definition: Overlay.h:151
Textured line overlay, with world-space coordinates, rendered in the world onto the terrain...
Definition: Overlay.h:61
bool m_Closed
Should this line be treated as a closed loop? If set, any end cap settings are ignored.
Definition: Overlay.h:93
float X
Definition: Vector3D.h:31
Semi-circular line ending.
Definition: Overlay.h:73
void PushCoords(const CVector3D &v)
Definition: Overlay.h:43
float Y
Definition: Vector3D.h:31
SOverlaySphere()
Definition: Overlay.h:159
CColor m_Color
Color to apply to the line texture, where indicated by the mask.
Definition: Overlay.h:87
Rendering data for an STexturedOverlayLine.
Definition: TexturedLineRData.h:39
std::vector< float > m_Coords
(x, z) vertex coordinate pairs; y is computed automatically.
Definition: Overlay.h:89
CTexturePtr m_TextureMask
Definition: Overlay.h:84
CVector3D m_Center
Definition: Overlay.h:161
float Y
Definition: Vector2D.h:157
Definition: Vector2D.h:31
Rectangular single-quad terrain overlay, in world space coordinates.
Definition: Overlay.h:149
std::shared_ptr< CTexture > CTexturePtr
Definition: Texture.h:22
float m_Radius
Definition: Overlay.h:162
u8 m_Thickness
Definition: Overlay.h:41
no line ending; abrupt stop of the line (aka. butt ending)
Definition: Overlay.h:65
float Z
Definition: Vector3D.h:31
SOverlayLine()
Definition: Overlay.h:37
const CSimContext * m_SimContext
Simulation context applicable for this overlay line; used to obtain terrain information during automa...
Definition: Overlay.h:104
CTexturePtr m_Texture
Definition: Overlay.h:138
LineCapType m_StartCapType
Definition: Overlay.h:97
float m_Thickness
Half-width of the line, in world-space units.
Definition: Overlay.h:91
CColor m_Color
Definition: Overlay.h:39
void PushCoords(const CVector2D &v)
Definition: Overlay.h:124
LineCapType
Definition: Overlay.h:63
shared_ptr< CTexturedLineRData > m_RenderData
Cached renderer data, because expensive to compute.
Definition: Overlay.h:114
Definition: Overlay.h:157
CTexturePtr m_TextureMask
Definition: Overlay.h:152
CColor m_Color
Definition: Overlay.h:139