opynsim
Unofficial C++ Documentation
Loading...
Searching...
No Matches
liboscar
graphics
geometries
polyhedron_geometry.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <
liboscar/graphics/mesh.h
>
4
#include <
liboscar/maths/vector.h
>
5
#include <
liboscar/utilities/c_string_view.h
>
6
7
#include <cstddef>
8
#include <cstdint>
9
#include <span>
10
#include <vector>
11
12
namespace
osc
13
{
14
// parameters to construct `PolyhedronGeometry`
15
//
16
// defaults to a tetrahedron for demonstration purposes, callers should
17
// overwrite `vertices` and `indices` as appropriate
18
struct
PolyhedronGeometryParams
final {
19
friend
bool
operator==
(
const
PolyhedronGeometryParams
&,
const
PolyhedronGeometryParams
&);
20
21
std::vector<Vector3>
vertices
= {
22
{1.0f, 1.0f, 1.0f}, {-1.0f, -1.0f, 1.0f}, {-1.0f, 1.0f, -1.0f}, {1.0f, -1.0f, -1.0f},
23
};
24
std::vector<uint32_t>
indices
= {
25
2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1,
26
};
27
float
radius
= 1.0f;
28
size_t
detail_level
= 0;
29
};
30
31
// generates a 3D solid with flat faces by projecting triangle faces (`indices`
32
// indexes into `vertices` for each triangle) onto a sphere of `radius`, followed
33
// by dividing them up to the desired `detail_level`
34
class
PolyhedronGeometry
final {
35
public
:
36
using
Params
=
PolyhedronGeometryParams
;
37
38
static
constexpr
CStringView
name
() {
return
"Polyhedron"
; }
39
40
explicit
PolyhedronGeometry
(
const
Params
& =
Params
{});
41
42
// constructs a `PolyhedronGeometry` from existing vertex + index data (rather
43
// than requiring `std::vector`s)
44
explicit
PolyhedronGeometry
(
45
std::span<const Vector3> vertices,
46
std::span<const uint32_t> indices,
47
float
radius = 1.0f,
48
size_t
detail_level = 0
49
);
50
51
const
Mesh
&
mesh
()
const
{
return
mesh_; }
52
operator
const
Mesh
& ()
const
{
return
mesh_; }
53
private
:
54
Mesh
mesh_;
55
};
56
}
c_string_view.h
osc::CStringView
Definition
c_string_view.h:13
osc::Mesh
Definition
mesh.h:33
osc::PolyhedronGeometry
Definition
polyhedron_geometry.h:34
osc::PolyhedronGeometry::PolyhedronGeometry
PolyhedronGeometry(const Params &=Params{})
osc::PolyhedronGeometry::name
static constexpr CStringView name()
Definition
polyhedron_geometry.h:38
osc::PolyhedronGeometry::mesh
const Mesh & mesh() const
Definition
polyhedron_geometry.h:51
osc::PolyhedronGeometry::PolyhedronGeometry
PolyhedronGeometry(std::span< const Vector3 > vertices, std::span< const uint32_t > indices, float radius=1.0f, size_t detail_level=0)
mesh.h
osc
Definition
custom_decoration_generator.h:5
osc::PolyhedronGeometryParams
Definition
polyhedron_geometry.h:18
osc::PolyhedronGeometryParams::detail_level
size_t detail_level
Definition
polyhedron_geometry.h:28
osc::PolyhedronGeometryParams::radius
float radius
Definition
polyhedron_geometry.h:27
osc::PolyhedronGeometryParams::operator==
friend bool operator==(const PolyhedronGeometryParams &, const PolyhedronGeometryParams &)
osc::PolyhedronGeometryParams::vertices
std::vector< Vector3 > vertices
Definition
polyhedron_geometry.h:21
osc::PolyhedronGeometryParams::indices
std::vector< uint32_t > indices
Definition
polyhedron_geometry.h:24
vector.h
Generated by
1.9.8