Skip to main content

Grid Struct

A configurable grid shape for rendering reference lines in 3D space. More...

Declaration

struct helios::rendering::asset::shape::basic::Grid { ... }

Base struct

structShape

Struct representing geometric primitives and indices for various shapes. provides immutable, shared access to vertices and indices of the represented geometric shape. More...

Public Constructors Index

Grid ()

Creates a default grid with 2 segments per coordinate axis. More...

Grid (unsigned int segmentsX, unsigned int segmentsY)

Creates a grid with a specified number of subdivisions. More...

Private Constructors Index

Grid (std::pair< std::vector< Vertex >, std::vector< unsigned int > > data)

Private constructor that takes pre-generated geometry data. More...

Public Member Functions Index

helios::rendering::mesh::PrimitiveTypeprimitiveType () const noexcept override

Returns the primitive type used for rendering this shape. More...

Private Static Functions Index

static std::pair< std::vector< Vertex >, std::vector< unsigned int > >generate (unsigned int segmentsX, unsigned int segmentsY)

Generates vertex and index data for the grid geometry. More...

Description

A configurable grid shape for rendering reference lines in 3D space.

The Grid class generates a planar grid mesh composed of line segments. The grid is centered at the origin and spans from -1 to +1 on both the X and Y axes. The number of subdivisions along each axis can be configured via constructor parameters.

The generated grid lies in the XY-plane with all vertices having a Z-coordinate of 0. All normals point in the positive Z direction (0, 0, 1).

Typical use cases include:

  • Scene orientation and scale reference
  • Debug visualization
  • Editor overlays

Example usage: ```cpp // Create a 10x10 grid auto grid = std::make_shared<Grid>(10, 10); scene->addRenderable(grid); ```

info

The grid uses `PrimitiveType::Lines` for rendering, not triangles.

See Also

Shape

Definition at line 48 of file Grid.ixx.

Public Constructors

Grid()

helios::rendering::asset::shape::basic::Grid::Grid ()
inline

Creates a default grid with 2 segments per coordinate axis.

Constructs a simple 2x2 grid, resulting in a cross-like pattern with one horizontal and one vertical subdivision.

Definition at line 137 of file Grid.ixx.

137 Grid() : Grid(2, 2) {}

Grid()

helios::rendering::asset::shape::basic::Grid::Grid (unsigned int segmentsX, unsigned int segmentsY)
inline explicit

Creates a grid with a specified number of subdivisions.

Constructs a grid with the given number of segments along each axis. Higher segment counts produce finer grids with more lines.

Parameters
segmentsX

Number of subdivisions along the X-axis. Must be at least 2.

segmentsY

Number of subdivisions along the Y-axis. Must be at least 2.

Exceptions
std::invalid_argument

If either segmentsX or segmentsY is less than 2.

Definition at line 150 of file Grid.ixx.

150 explicit Grid(unsigned int segmentsX, unsigned int segmentsY) :
151 Grid(generate(segmentsX, segmentsY))
152 { }

Private Constructors

Grid()

helios::rendering::asset::shape::basic::Grid::Grid (std::pair< std::vector< Vertex >, std::vector< unsigned int > > data)
inline explicit

Private constructor that takes pre-generated geometry data.

Used internally by the public constructors to initialize the base Shape class with vertex and index data.

Parameters
data

A pair containing vertex data and index data for the grid.

Definition at line 124 of file Grid.ixx.

124 explicit Grid(std::pair<std::vector<Vertex>, std::vector<unsigned int>> data) :
125 Shape(std::move(data.first), std::move(data.second))
126 {
127 }

Public Member Functions

primitiveType()

helios::rendering::mesh::PrimitiveType helios::rendering::asset::shape::basic::Grid::primitiveType ()
inline nodiscard noexcept virtual

Returns the primitive type used for rendering this shape.

Returns

`PrimitiveType::Lines` since the grid is rendered as line segments.

Definition at line 159 of file Grid.ixx.

159 [[nodiscard]] helios::rendering::mesh::PrimitiveType primitiveType() const noexcept override {
161 }

Reference helios::rendering::mesh::Lines.

Private Static Functions

generate()

std::pair< std::vector< Vertex >, std::vector< unsigned int > > helios::rendering::asset::shape::basic::Grid::generate (unsigned int segmentsX, unsigned int segmentsY)
inline static

Generates vertex and index data for the grid geometry.

Creates a grid of vertices in the XY-plane spanning from (-1, -1) to (1, 1). Vertices are generated row by row, and indices are created to form horizontal and vertical line segments connecting adjacent vertices.

Parameters
segmentsX

Number of subdivisions along the X-axis.

segmentsY

Number of subdivisions along the Y-axis.

Returns

A pair containing the vertex list and the index list for line rendering.

Exceptions
std::invalid_argument

If either segmentsX or segmentsY is less than 2.

Definition at line 68 of file Grid.ixx.

68 > generate(
69 unsigned int segmentsX, unsigned int segmentsY
70 ) {
71 if (segmentsY < 2 || segmentsX < 2) {
72 throw std::invalid_argument("Segments must at least be 2.");
73 }
74 std::vector<Vertex> vertices;
75 std::vector<unsigned int> indices;
76
77 vertices.reserve((segmentsX + 1) * (segmentsY + 1));
78
79 const float quotX = 2.0f/static_cast<float>(segmentsX);
80 const float quotY = 2.0f/static_cast<float>(segmentsY);
81
82 for (int i = 0; i < segmentsX+1; i++) {
83 float x = -1.0f + i * quotX;
84
85 for (int j = 0; j < segmentsY + 1; j++) {
86 float y = -1.0f + j * quotY;
87
88 vertices.push_back({
89 {x, y, 0.0f},
90 {0.0f, 0.0f, 1.0f},
91 {0.5f, 0.5f}
92 });
93
94 if (i >= segmentsX || j >= segmentsY) {
95 continue;
96 }
97
98 if (i > 0) {
99 unsigned int idx = (i) * (segmentsY + 1) + j;
100 indices.push_back(idx);
101 indices.push_back(idx +1);
102 }
103
104 if (j > 0) {
105 unsigned int idx = i * (segmentsY + 1) + j;
106 indices.push_back(idx);
107 indices.push_back(idx + 1 + segmentsY);
108 }
109 }
110
111 }
112
113 return std::pair(vertices, indices);
114 }

The documentation for this struct was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.