Skip to main content

Ellipse Struct

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

Declaration

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

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

Ellipse ()

Creates a default ellipse (radiusX = 1.0, radiusY = 0.5, 64 segments). More...

Ellipse (float radiusX, float radiusY, unsigned int segments)

Creates an ellipse with specific radii and segment count. More...

Public Member Functions Index

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

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

Private Static Functions Index

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

Dynamically creates the vertex list for an ellipse. More...

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

Creates the index list for a Triangle Fan (for GL_TRIANGLES). More...

Description

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

Generates a 2D ellipse mesh, centered at the origin on the XY plane (Z=0). An ellipse is defined by two radii: one along the X-axis (semi-major or semi-minor) and one along the Y-axis. When both radii are equal, the ellipse degenerates to a circle.

The normals point in the positive Z direction. The indices are arranged as a Triangle Fan (for GL_TRIANGLES).

Definition at line 32 of file Ellipse.ixx.

Public Constructors

Ellipse()

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

Creates a default ellipse (radiusX = 1.0, radiusY = 0.5, 64 segments).

Definition at line 108 of file Ellipse.ixx.

108 Ellipse() : Ellipse(1.0f, 0.5f, 64) {}

Reference Ellipse.

Referenced by Ellipse.

Ellipse()

helios::rendering::asset::shape::basic::Ellipse::Ellipse (float radiusX, float radiusY, unsigned int segments)
inline explicit

Creates an ellipse with specific radii and segment count.

Parameters
radiusX

The semi-axis length along the X-axis.

radiusY

The semi-axis length along the Y-axis.

segments

The number of triangle segments that make up the ellipse. More segments result in a smoother curve.

Definition at line 118 of file Ellipse.ixx.

118 explicit Ellipse(float radiusX, float radiusY, unsigned int segments) :
119 Shape(
120 generateVertices(radiusX, radiusY, segments),
121 generateIndices(segments)
122 ) {}

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

Public Member Functions

primitiveType()

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

Returns the primitive type used for rendering.

Returns

PrimitiveType::Triangles for triangle-based rendering.

Definition at line 128 of file Ellipse.ixx.

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

Reference helios::rendering::mesh::Triangles.

Private Static Functions

generateIndices()

std::vector< unsigned int > helios::rendering::asset::shape::basic::Ellipse::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).

Parameters
segments

The number of segments used to build the ellipse.

Returns

A vector of indices defining the triangle fan.

Definition at line 88 of file Ellipse.ixx.

88 static std::vector<unsigned int> generateIndices(unsigned int segments) {
89 std::vector<unsigned int> indices;
90 indices.reserve(segments * 3); // 'segments' triangles, 3 indices per triangle
91
92 for (unsigned int i = 1; i <= segments; ++i) {
93 indices.push_back(0); // center vertex
94 indices.push_back(i); // current circumference vertex
95
96 // next circumference vertex
97 // for the last triangle (i == segments), connect back to Vertex 1
98 unsigned int next_i = (i == segments) ? 1 : (i + 1);
99 indices.push_back(next_i);
100 }
101 return indices;
102 }

generateVertices()

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

Dynamically creates the vertex list for an ellipse.

Generates one center vertex (Index 0) and 'segments' vertices on the circumference.

Parameters
radiusX

The semi-axis length along the X-axis.

radiusY

The semi-axis length along the Y-axis.

segments

The number of segments used to approximate the ellipse curve.

Returns

A vector of vertices defining the ellipse mesh.

Definition at line 45 of file Ellipse.ixx.

45 static std::vector<Vertex> generateVertices(float radiusX, float radiusY, unsigned int segments) {
46 std::vector<Vertex> vertices;
47 // 1 for the center vertex
48 vertices.reserve(segments + 1);
49
50 // center vertex (index 0)
51 vertices.push_back({
52 {0.0f, 0.0f, 0.0f}, // Position
53 {0.0f, 0.0f, 1.0f}, // Normal
54 {0.5f, 0.5f} // TexCoord (center of texture)
55 });
56
57 // circumference vertices (Indices 1 to segments)
58 for (unsigned int i = 0; i < segments; ++i) {
59 // calculate the angle for this segment
60 const float angle = (static_cast<float>(i) / static_cast<float>(segments)) * 2.0f * std::numbers::pi_v<float>;
61
62 float x = radiusX * std::cos(angle);
63 float y = radiusY * std::sin(angle);
64
65 // texture coordinates: map to [0, 1] range
66 // use the larger radius to normalize for consistent UV mapping
67 float maxRadius = std::max(radiusX, radiusY);
68 float u = (x / maxRadius) * 0.5f + 0.5f;
69 float v = (y / maxRadius) * 0.5f + 0.5f;
70
71 vertices.push_back({
72 {x, y, 0.0f},
73 {0.0f, 0.0f, 1.0f},
74 {u, v}
75 });
76 }
77 return vertices;
78 }

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.