Skip to content

Shapes3D

Index · Français

Description

Create origin-centered triangle meshes for basic shapes. Use it to start a scene without manually specifying vertices.

gaspardos::graphics::Shapes3D — bindings/cpp/raster3d.hpp, C++98.

Simple program example

#include "raster3d.hpp"

int main()
{
    gaspardos::graphics::Mesh cube = gaspardos::graphics::Shapes3D::cube(2);
    return cube.vertices.size() == 8 && cube.triangles.size() == 12 ? 0 : 1;
}

Building from Windows

From the repository root, save the program as build/api-examples/Shapes3D.cpp.

New-Item -ItemType Directory -Force build/api-examples | Out-Null
& .\build-x64-install\bin\x86_64-gaspardos-g++.exe -std=c++98 -O2 -Ibindings/cpp build/api-examples/Shapes3D.cpp bindings/cpp/raster3d.cpp -o build/api-examples/Shapes3D.elf
if ($LASTEXITCODE -ne 0) { throw "C++ build failed" }

Executable for GaspardOS. Presentation requires WINDOW_BLIT=146 in the kernel; -38 means the extension is absent. Source files.

Dimensions must be finite, positive and at most 10000; rejected arguments produce an empty mesh.

Methods and public data

static Mesh cube(float size=2)

Cube with eight vertices and twelve triangles.

static Mesh box(float width, float height, float depth)

Box with six colored faces.

static Mesh pyramid(float base=2, float height=2)

Closed square-based pyramid, five vertices and six triangles.

static Mesh plane(float width=3, float depth=3)

XZ plane at y=0, four vertices and two triangles.

static Mesh sphere(float radius=1, unsigned slices=16, unsigned stacks=8)

Triangulated sphere; slices 3..64, stacks 2..32.

static Mesh cylinder(float radius=1, float height=2, unsigned slices=16)

Closed Y-axis cylinder; slices 3..64.