Shape

High-level shape handling utilities.

Overview

Typical use cases:

  • Handling 2D shape definitions and vertex data retrieval.

TODO:

  • Connect shape to GPU buffers for rendering.

Header

<RaeptorCogs/Shape.hpp>

Metadata

Author

Estorc

Version

v1.0

Copyright

Copyright (c) 2025 Estorc MIT License.

Classes

Classes

Class

Description

RaeptorCogs::Quad

Quad shape class.

RaeptorCogs::RegularPolygon

Regular polygon shape class.

RaeptorCogs::Shape

Base Shape class.

class Quad : public RaeptorCogs::Shape

Quad shape class.

Provides vertex and index data for a simple quad shape.

std::shared_ptr<Shape> quad = std::make_shared<Quad>();
size_t triangleCount;
const float* vertices = quad->getVertices();
const unsigned* indices = quad->getIndices(triangleCount);

Public Functions

~Quad() override = default

Destructor for Quad.

inline virtual const float *getVertices() const override

Get vertex data.

Returns:

Pointer to the vertex array.

inline virtual const unsigned *getIndices(size_t &count) const override

Get index data.

Parameters:

count – Output number of indices.

Returns:

Pointer to the index array.

Private Static Attributes

static float vertices[] = {0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f}

Vertex data for the quad.

Each vertex consists of position (x, y) and UV coordinates (u, v).

Note

The quad is defined in a 1x1 space from (0,0) to (1,1).

static unsigned indices[] = {0, 1, 2, 2, 3, 0}

Index data for the quad.

Defines two triangles that make up the quad.

class RegularPolygon : public RaeptorCogs::Shape

Regular polygon shape class.

Provides vertex and index data for a regular polygon shape with a specified number of sides.

Public Functions

~RegularPolygon() override = default

Destructor for RegularPolygon.

inline RegularPolygon(unsigned int sides)

Constructor for RegularPolygon.

Parameters:

sides – Number of sides of the polygon.

inline virtual const float *getVertices() const override

Get vertex data.

Returns:

Pointer to the vertex array.

inline virtual const unsigned *getIndices(size_t &count) const override

Get index data.

Parameters:

count – Output number of indices.

Returns:

Pointer to the index array.

Private Functions

inline void generateGeometry()

Generate geometry for the polygon.

Note

Called during construction to populate vertices and indices.

Private Members

unsigned int sides

Number of sides of the polygon.

Note

Minimum is 3.

std::vector<float> vertices

Vertex data.

Generated based on the number of sides.

std::vector<unsigned> indices

Index data.

Generated based on the number of sides.

class Shape

Base Shape class.

Provides an interface for 2D shapes to retrieve vertex and index data.

Subclassed by RaeptorCogs::Quad, RaeptorCogs::RegularPolygon

Public Functions

virtual ~Shape() = default

Virtual destructor.

virtual void getVertexData(std::vector<glm::mat3> *outTrianglesPos, std::vector<glm::mat3x2> *outTrianglesUV, size_t *triangleCount) const

Get vertex data as triangles.

Note

The default implementation converts the shape’s vertices and indices into triangles.

Parameters:
  • outTrianglesPos – Output vector for triangle positions.

  • outTrianglesUV – Output vector for triangle UV coordinates.

  • triangleCount – Output number of triangles.

virtual const float *getVertices() const = 0

Get raw vertex array.

Returns:

Pointer to the vertex array.

virtual const unsigned *getIndices(size_t &count) const = 0

Get raw index array.

Parameters:

count – Output number of indices.

Returns:

Pointer to the index array.