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