Skip to main content

Circle Struct

Basic Circle Shape (2D, in XY plane). More...

Declaration

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

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

Circle ()

Creates a default circle (radius 1.0, 64 segments). More...

Circle (float radius, unsigned int segments)

Creates a circle with a specific radius and segment count. More...

Public Member Functions Index

helios::rendering::model::config::PrimitiveTypeprimitiveType () const noexcept override

Returns the intended PrimitiveType for this Shape. More...

Private Static Functions Index

static std::vector< Vertex >generateVertices (float radius, unsigned int segments)

Dynamically creates the vertex list for a circle. Generates one center vertex (Index 0) and 'segments' vertices on the circumference. More...

static std::vector< unsigned int >generateIndices (unsigned int segments)

Creates the index list for a `Triangle Fan` (for GL_TRIANGLES). Each triangle consists of (center, point_i, point_i+1). More...

Description

Basic Circle Shape (2D, in XY plane).

Generates a 2D circle mesh, centered at the origin on the XY plane (Z=0). The normals point in the positive Z direction. The indices are arranged as a Triangle Fan (for GL_TRIANGLES).

Definition at line 29 of file Circle.ixx.

Public Constructors

Circle()

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

Creates a default circle (radius 1.0, 64 segments).

Definition at line 94 of file Circle.ixx.

94 Circle() : Circle(1.0f, 64) {}

Reference Circle.

Referenced by Circle.

Circle()

helios::rendering::asset::shape::basic::Circle::Circle (float radius, unsigned int segments)
inline explicit

Creates a circle with a specific radius and segment count.

Parameters
radius

The radius of the circle (from center to circumference).

segments

The number of triangle segments that make up the circle. (More segments = smoother circle).

Definition at line 103 of file Circle.ixx.

103 explicit Circle(float radius, unsigned int segments) :
104 Shape(
105 generateVertices(radius, segments),
106 generateIndices(segments)
107 ) {}

Reference helios::rendering::asset::shape::Shape::Shape.

Public Member Functions

primitiveType()

helios::rendering::model::config::PrimitiveType helios::rendering::asset::shape::basic::Circle::primitiveType ()
inline nodiscard noexcept virtual

Returns the intended PrimitiveType for this Shape.

This method returns the intended PrimitiveType for the Shape represented by this instance. This information can be used to properly set up the MeshConfig wrapping this Shape.

Returns

The intended PrimitiveType of this Shape.

Definition at line 109 of file Circle.ixx.

Reference helios::rendering::model::config::Triangles.

Private Static Functions

generateIndices()

std::vector< unsigned int > helios::rendering::asset::shape::basic::Circle::generateIndices (unsigned int segments)
inline static

Creates the index list for a `Triangle Fan` (for GL_TRIANGLES). Each triangle consists of (center, point_i, point_i+1).

Definition at line 73 of file Circle.ixx.

73 static std::vector<unsigned int> generateIndices(unsigned int segments) {
74 std::vector<unsigned int> indices;
75 indices.reserve(segments * 3); // 'segments' triangles, 3 indices per triangle
76
77 for (unsigned int i = 1; i <= segments; ++i) {
78 indices.push_back(0); // center vertex
79 indices.push_back(i); // current circumference vertex
80
81 // next circumference vertex
82 // for the last triangle (i == segments),
83 // connect back to Vertex 1
84 unsigned int next_i = (i == segments) ? 1 : (i + 1);
85 indices.push_back(next_i);
86 }
87 return indices;
88 }

generateVertices()

std::vector< Vertex > helios::rendering::asset::shape::basic::Circle::generateVertices (float radius, unsigned int segments)
inline static

Dynamically creates the vertex list for a circle. Generates one center vertex (Index 0) and 'segments' vertices on the circumference.

Definition at line 36 of file Circle.ixx.

36 static std::vector<Vertex> generateVertices(float radius, unsigned int segments) {
37 std::vector<Vertex> vertices;
38 // 1 for the center vertex
39 vertices.reserve(segments + 1);
40
41 // center vertex (index 0)
42 vertices.push_back({
43 {0.0f, 0.0f, 0.0f}, // Position
44 {0.0f, 0.0f, 1.0f}, // Normal
45 {0.5f, 0.5f} // TexCoord
46 });
47
48 // circumference vertices (Indices 1 to segments)
49 for (unsigned int i = 0; i < segments; ++i) {
50 // calculate the angle for this segment
51 const float angle = (static_cast<float>(i) / static_cast<float>(segments)) * 2.0f * std::numbers::pi_v<float>;
52
53 float x = radius * std::cos(angle);
54 float y = radius * std::sin(angle);
55
56 // texture coordinates: map [-radius, +radius] to [0, 1]
57 float u = (x / radius) * 0.5f + 0.5f;
58 float v = (y / radius) * 0.5f + 0.5f;
59
60 vertices.push_back({
61 {x, y, 0.0f},
62 {0.0f, 0.0f, 1.0f},
63 {u, v}
64 });
65 }
66 return vertices;
67 }

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.