OGLplus  (0.59.0) a C++ wrapper for rendering APIs

torus.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_SHAPES_TORUS_HPP
10 #define EAGINE_SHAPES_TORUS_HPP
11 
12 #include "../callable_ref.hpp"
13 #include "../config/basic.hpp"
14 #include "../valid_if/ge0_lt1.hpp"
15 #include "../valid_if/greater_than.hpp"
16 #include "gen_base.hpp"
17 #include <array>
18 #include <cassert>
19 #include <memory>
20 
21 namespace eagine {
22 namespace shapes {
23 
28 public:
30  vertex_attrib_bits attr_bits,
33  valid_if_ge0_lt1<float> radius_ratio) noexcept;
34 
36  vertex_attrib_bits attr_bits,
38  valid_if_greater_than<int, 3> sections) noexcept
39  : unit_torus_gen(attr_bits, std::move(rings), std::move(sections), 0.5F) {
40  }
41 
42  unit_torus_gen(vertex_attrib_bits attr_bits) noexcept
43  : unit_torus_gen(attr_bits, 24, 36) {}
44 
45  using offset_getter =
47 
48  auto vertex_count() -> span_size_t override;
49 
50  void vertex_pivots(span<float> dest) noexcept;
51 
52  void positions(span<float> dest, offset_getter) noexcept;
53 
54  void normals(span<float> dest, offset_getter) noexcept;
55 
56  void tangentials(span<float> dest, offset_getter) noexcept;
57 
58  void bitangentials(span<float> dest, offset_getter) noexcept;
59 
60  void wrap_coords(span<float> dest) noexcept;
61 
62  auto attribute_variants(vertex_attrib_kind attrib) -> span_size_t override;
63 
65 
66  auto special_variant_name(span_size_t index) -> string_view;
67  void make_special_attrib_values(
68  void (
69  unit_torus_gen::*function)(span<float>, unit_torus_gen::offset_getter),
71  span<float>);
72 
73  void attrib_values(vertex_attrib_variant, span<float>) override;
74 
75  auto draw_variant_count() -> span_size_t override;
76 
77  auto index_type(drawing_variant) -> index_data_type override;
78 
79  auto index_count(drawing_variant) -> span_size_t override;
80 
81  void indices(drawing_variant, span<std::uint8_t> dest) override;
82 
83  void indices(drawing_variant, span<std::uint16_t> dest) override;
84 
85  void indices(drawing_variant, span<std::uint32_t> dest) override;
86 
88 
89  void instructions(drawing_variant, span<draw_operation> ops) override;
90 
91  auto bounding_sphere() -> math::sphere<float, true> override;
92 
93 private:
95 
96  const std::size_t _r_seed{1234};
97  const std::size_t _s_seed{2345};
98  span_size_t _rings;
99  span_size_t _sections;
100  float _radius_ratio;
101 
102  static auto _attr_mask() noexcept -> vertex_attrib_bits;
103 
104  template <typename T>
105  void _indices(drawing_variant, span<T> dest) noexcept;
106 };
107 //------------------------------------------------------------------------------
110 static inline auto unit_torus(
111  vertex_attrib_bits attr_bits,
114  valid_if_ge0_lt1<float> radius_ratio) {
115  return std::make_unique<unit_torus_gen>(
116  attr_bits, std::move(rings), std::move(sections), std::move(radius_ratio));
117 }
118 //------------------------------------------------------------------------------
128 static inline auto unit_torus(vertex_attrib_bits attr_bits) {
129  return unit_torus(attr_bits, 18, 36, 0.5F);
130 }
131 //------------------------------------------------------------------------------
132 } // namespace shapes
133 } // namespace eagine
134 
135 #if !EAGINE_LINK_LIBRARY || defined(EAGINE_IMPLEMENTING_LIBRARY)
136 #include <eagine/shapes/torus.inl>
137 #include <utility>
138 #endif
139 
140 #endif // EAGINE_SHAPES_TORUS_HPP
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
Declaration of class template storing a reference to a callable object.
Definition: callable_ref.hpp:24
basic_string_span< const char > string_view
Alias for const string views.
Definition: string_span.hpp:116
static auto unit_torus(vertex_attrib_bits attr_bits, valid_if_greater_than< int, 4 > rings, valid_if_greater_than< int, 3 > sections, valid_if_ge0_lt1< float > radius_ratio)
Constructs instances of unit_torus_gen.
Definition: torus.hpp:110
bitfield< vertex_attrib_kind > vertex_attrib_bits
Alias for vertex_attrib_kind bitfield type.
Definition: vertex_attrib.hpp:85
Basic template for spheres in N-dimensional space.
Definition: primitives.hpp:122
Common code is placed in this namespace.
Definition: eagine.hpp:21
void instructions(drawing_variant, span< draw_operation > ops) override
Fetches the drawing operations for the specified drawing variant.
auto operation_count()
Returns the number of drawing instructions for the default variant.
Definition: gen_base.hpp:179
Primary template for conditionally valid values.
Definition: decl.hpp:49
Class designating an vertex attribute variant in a shape generator.
Definition: vertex_attrib.hpp:104
span_size_t drawing_variant
Alias for shape drawing variant index type.
Definition: gen_base.hpp:31
auto variant_name(vertex_attrib_variant) -> string_view override
Returns the name of the specified attribute variant.
Base class for shape generators re-calculating the center.
Definition: gen_base.hpp:320
void attrib_values(vertex_attrib_variant, span< float >) override
Fetches the vertex attribute data for the specified variant as floats.
auto index_type() -> index_data_type
Returns the index data type for the default draw variant.
Definition: gen_base.hpp:139
auto attribute_variants(vertex_attrib_kind attrib) -> span_size_t override
Returns the count of shape attribute variants.
auto vertex_count() -> span_size_t override
Returns the shaped vertex count.
vertex_attrib_kind
Shape vertex attribute kind enumeration.
Definition: vertex_attrib.hpp:25
auto bounding_sphere() -> math::sphere< float, true > override
Returns the bounding sphere for the generated shape.
Generator of centered torus shape with unit diameter.
Definition: torus.hpp:27
auto draw_variant_count() -> span_size_t override
Returns the count of possible shape draw variants.
index_data_type
Shape element index type enumeration.
Definition: drawing.hpp:111
auto index_count()
Returns the index count for the default drawing variant.
Definition: gen_base.hpp:147
void indices(drawing_variant, span< std::uint8_t > dest) override
Fetches the index data for the specified drawing variant.

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).