Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
Render.h
Go to the documentation of this file.
1/* Copyright (C) 2025 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_HELPER_RENDER
19#define INCLUDED_HELPER_RENDER
20
21#include "maths/Vector2D.h"
22
23#include <cstddef>
24#include <vector>
25
28class CFixedVector3D;
29class CMatrix3D;
30class CSimContext;
31class CVector3D;
32struct SOverlayLine;
34
36{
37 /// Packed array of consecutive dashes' points. Use m_StartIndices to navigate it.
38 std::vector<CVector2D> m_Points;
39
40 /**
41 * Start indices in m_Points of each dash. Dash n starts at point m_StartIndices[n] and ends at the point with index
42 * m_StartIndices[n+1] - 1, or at the end of the m_Points vector. Use the GetEndIndex(n) convenience method to abstract away the
43 * difference and get the (exclusive) end index of dash n.
44 */
45 std::vector<size_t> m_StartIndices;
46
47 /// Returns the (exclusive) end point index (i.e. index within m_Points) of dash n.
48 size_t GetEndIndex(size_t i)
49 {
50 // for the last dash, there is no next starting index, so we need to use the end index of the m_Points array instead
51 return (i < m_StartIndices.size() - 1 ? m_StartIndices[i+1] : m_Points.size());
52 }
53};
54
55namespace SimRender
56{
57
58/**
59 * Constructs overlay line from given points, conforming to terrain.
60 *
61 * @param[in] xz List of x,z coordinate pairs representing the line.
62 * @param[in,out] overlay Updated overlay line now conforming to terrain.
63 * @param[in] floating If true, the line conforms to water as well.
64 * @param[in] heightOffset Height above terrain to offset the line.
65 */
67 const CSimContext& context, const std::vector<float>& xz,
68 SOverlayLine& overlay,
69 bool floating, float heightOffset = 0.25f);
70
71/**
72 * Constructs overlay line as a circle with given center and radius, conforming to terrain.
73 *
74 * @param[in] x,z Coordinates of center of circle.
75 * @param[in] radius Radius of circle to construct.
76 * @param[in,out] overlay Updated overlay line representing this circle.
77 * @param[in] floating If true, the circle conforms to water as well.
78 * @param[in] heightOffset Height above terrain to offset the circle.
79 * @param heightOffset The vertical offset to apply to points, to raise the line off the terrain a bit.
80 */
82 const CSimContext& context, float x, float z, float radius,
83 SOverlayLine& overlay,
84 bool floating, float heightOffset = 0.25f);
85
86/**
87 * Constructs overlay line as an outlined circle sector (an arc with straight lines between the
88 * endpoints and the circle's center), conforming to terrain.
89 */
91 const CSimContext& context, float x, float z, float radius,
92 float start, float end,
93 SOverlayLine& overlay,
94 bool floating, float heightOffset = 0.25f);
95
96/**
97 * Constructs overlay line as rectangle with given center and dimensions, conforming to terrain.
98 *
99 * @param[in] x,z Coordinates of center of rectangle.
100 * @param[in] w,h Width/height dimensions of the rectangle.
101 * @param[in] a Clockwise angle to orient the rectangle.
102 * @param[in,out] overlay Updated overlay line representing this rectangle.
103 * @param[in] floating If true, the rectangle conforms to water as well.
104 * @param[in] heightOffset Height above terrain to offset the rectangle.
105 */
107 const CSimContext& context, float x, float z, float w, float h, float a,
108 SOverlayLine& overlay,
109 bool floating, float heightOffset = 0.25f);
110
111/**
112 * Constructs a solid outline of an arbitrarily-aligned bounding @p box.
113 *
114 * @param[in] box
115 * @param[in,out] overlayLine Updated overlay line representing the oriented box.
116 */
117void ConstructBoxOutline(const CBoundingBoxOriented& box, SOverlayLine& overlayLine);
118
119/**
120 * Constructs a solid outline of an axis-aligned bounding @p box.
121 *
122 * @param[in] bound
123 * @param[in,out] overlayLine Updated overlay line representing the AABB.
124 */
125void ConstructBoxOutline(const CBoundingBoxAligned& box, SOverlayLine& overlayLine);
126
127/**
128 * Constructs a simple gimbal outline with the given radius and center.
129 *
130 * @param[in] center
131 * @param[in] radius
132 * @param[in,out] out Updated overlay line representing the gimbal.
133 * @param[in] numSteps The amount of steps to trace a circle's complete outline. Must be a (strictly) positive multiple of four.
134 * For small radii, you can get away with small values; setting this to 4 will create a diamond shape.
135 */
136void ConstructGimbal(const CVector3D& center, float radius, SOverlayLine& out, size_t numSteps = 16);
137
138/**
139 * Constructs 3D axis marker overlay lines for the given coordinate system.
140 * The XYZ axes are colored RGB, respectively.
141 *
142 * @param[in] coordSystem Specifies the coordinate system.
143 * @param[out] outX,outY,outZ Constructed overlay lines for each axes.
144 */
145void ConstructAxesMarker(const CMatrix3D& coordSystem, SOverlayLine& outX, SOverlayLine& outY, SOverlayLine& outZ);
146
147/**
148 * Updates the given points so each point is averaged with its neighbours, resulting in
149 * a somewhat smoother curve, assuming the points are roughly equally spaced.
150 *
151 * @param[in,out] points List of points to smooth.
152 * @param[in] closed if true, then the points are treated as a closed path (the last is connected
153 * to the first).
154 */
155void SmoothPointsAverage(std::vector<CVector2D>& points, bool closed);
156
157/**
158 * Updates the given points to include intermediate points interpolating between the original
159 * control points, using a rounded nonuniform spline.
160 *
161 * @param[in,out] points List of points to interpolate.
162 * @param[in] closed if true, then the points are treated as a closed path (the last is connected
163 * to the first).
164 * @param[in] offset The points are shifted by this distance in a direction 90 degrees clockwise from
165 * the direction of the curve.
166 * @param[in] segmentSamples Amount of intermediate points to sample between every two control points.
167 */
168void InterpolatePointsRNS(std::vector<CVector2D>& points, bool closed, float offset, int segmentSamples = 4);
169
170/**
171 * Creates a dashed line from the given line, dash length, and blank space between.
172 *
173 * @param[in] linePoints List of points specifying the input line.
174 * @param[out] dashedLineOut The dashed line returned as a list of smaller lines
175 * @param[in] dashLength Length of a single dash. Must be strictly positive.
176 * @param[in] blankLength Length of a single blank between dashes. Must be strictly positive.
177 */
178void ConstructDashedLine(const std::vector<CVector2D>& linePoints, SDashedLine& dashedLineOut,
179 const float dashLength, const float blankLength);
180
181/**
182 * Subdivides a list of @p points into segments of maximum length @p maxSegmentLength that are of equal size between every two
183 * control points. The resulting subdivided list of points is written back to @p points.
184 *
185 * @param points The list of intermediate points to subdivide.
186 * @param maxSegmentLength The maximum length of a single segment after subdivision. Must be strictly positive.
187 * @param closed Should the provided list of points be treated as a closed shape? If true, the resulting list of points will include
188 * extra subdivided points between the last and the first point.
189 */
190void SubdividePoints(std::vector<CVector2D>& points, float maxSegmentLength, bool closed);
191
192/**
193 * Sets the coordinates of a rectangular textured overlay, for example used by selection rings of structures.
194 */
195void ConstructTexturedLineBox(SOverlayTexturedLine& overlay, const CVector2D& origin, const CFixedVector3D& rotation, const float sizeX, const float sizeZ);
196
197/**
198 * Sets the coordinates of a circular textured overlay, for example by selection rings of units or attack range visualization.
199 */
200void ConstructTexturedLineCircle(SOverlayTexturedLine& overlay, const CVector2D& origin, const float overlay_radius);
201
202} // namespace
203
204#endif // INCLUDED_HELPER_RENDER
Definition: BoundingBoxAligned.h:35
Definition: BoundingBoxOriented.h:31
Definition: FixedVector3D.h:25
Definition: Matrix3D.h:36
Contains pointers to various 'global' objects that are needed by the simulation code,...
Definition: SimContext.h:34
Definition: Vector2D.h:32
Definition: Vector3D.h:32
Definition: Render.h:56
void ConstructBoxOutline(const CBoundingBoxOriented &box, SOverlayLine &overlayLine)
Constructs a solid outline of an arbitrarily-aligned bounding box.
Definition: Render.cpp:227
void ConstructSquareOnGround(const CSimContext &context, float x, float z, float w, float h, float a, SOverlayLine &overlay, bool floating, float heightOffset=0.25f)
Constructs overlay line as rectangle with given center and dimensions, conforming to terrain.
Definition: Render.cpp:160
void ConstructTexturedLineBox(SOverlayTexturedLine &overlay, const CVector2D &origin, const CFixedVector3D &rotation, const float sizeX, const float sizeZ)
Sets the coordinates of a rectangular textured overlay, for example used by selection rings of struct...
Definition: Render.cpp:602
void ConstructCircleOnGround(const CSimContext &context, float x, float z, float radius, SOverlayLine &overlay, bool floating, float heightOffset=0.25f)
Constructs overlay line as a circle with given center and radius, conforming to terrain.
Definition: Render.cpp:128
void InterpolatePointsRNS(std::vector< CVector2D > &points, bool closed, float offset, int segmentSamples=4)
Updates the given points to include intermediate points interpolating between the original control po...
Definition: Render.cpp:384
void SubdividePoints(std::vector< CVector2D > &points, float maxSegmentLength, bool closed)
Subdivides a list of points into segments of maximum length maxSegmentLength that are of equal size b...
Definition: Render.cpp:564
void ConstructTexturedLineCircle(SOverlayTexturedLine &overlay, const CVector2D &origin, const float overlay_radius)
Sets the coordinates of a circular textured overlay, for example by selection rings of units or attac...
Definition: Render.cpp:625
void ConstructLineOnGround(const CSimContext &context, const std::vector< float > &xz, SOverlayLine &overlay, bool floating, float heightOffset=0.25f)
Constructs overlay line from given points, conforming to terrain.
Definition: Render.cpp:45
void ConstructGimbal(const CVector3D &center, float radius, SOverlayLine &out, size_t numSteps=16)
Constructs a simple gimbal outline with the given radius and center.
Definition: Render.cpp:257
void ConstructClosedArcOnGround(const CSimContext &context, float x, float z, float radius, float start, float end, SOverlayLine &overlay, bool floating, float heightOffset=0.25f)
Constructs overlay line as an outlined circle sector (an arc with straight lines between the endpoint...
Definition: Render.cpp:135
void ConstructDashedLine(const std::vector< CVector2D > &linePoints, SDashedLine &dashedLineOut, const float dashLength, const float blankLength)
Creates a dashed line from the given line, dash length, and blank space between.
Definition: Render.cpp:475
void ConstructAxesMarker(const CMatrix3D &coordSystem, SOverlayLine &outX, SOverlayLine &outY, SOverlayLine &outZ)
Constructs 3D axis marker overlay lines for the given coordinate system.
Definition: Render.cpp:318
void SmoothPointsAverage(std::vector< CVector2D > &points, bool closed)
Updates the given points so each point is averaged with its neighbours, resulting in a somewhat smoot...
Definition: Render.cpp:342
Definition: Render.h:36
size_t GetEndIndex(size_t i)
Returns the (exclusive) end point index (i.e. index within m_Points) of dash n.
Definition: Render.h:48
std::vector< size_t > m_StartIndices
Start indices in m_Points of each dash.
Definition: Render.h:45
std::vector< CVector2D > m_Points
Packed array of consecutive dashes' points. Use m_StartIndices to navigate it.
Definition: Render.h:38
Line-based overlay, with world-space coordinates, rendered in the world potentially behind other obje...
Definition: Overlay.h:42
Textured line overlay, with world-space coordinates, rendered in the world onto the terrain.
Definition: Overlay.h:69
static void out(const wchar_t *fmt,...)
Definition: wdbg_sym.cpp:407