Tatooine
axis_aligned_bounding_box.h
Go to the documentation of this file.
1#ifndef TATOOINE_FLOWEXPLORER_NODES_AXIS_ALIGNED_BOUNDING_BOX_H
2#define TATOOINE_FLOWEXPLORER_NODES_AXIS_ALIGNED_BOUNDING_BOX_H
3//==============================================================================
5#include <tatooine/flowexplorer/line_shader.h>
7#include <tatooine/gl/imgui.h>
9//==============================================================================
11//==============================================================================
12template <size_t N>
15 renderable<axis_aligned_bounding_box<N>> {
20 using parent_type::max;
21 using parent_type::min;
22 //============================================================================
24 int m_line_width = 1;
25 std::array<GLfloat, 4> m_line_color{0.0f, 0.0f, 0.0f, 1.0f};
26 //============================================================================
29 tag::fill{-1}},
31 tag::fill{1}}},
32 renderable<axis_aligned_bounding_box>{"Axis Aligned Bounding Box", s,
33 *this} {
35 }
38 auto operator =(const axis_aligned_bounding_box&)
39 -> axis_aligned_bounding_box& = default;
40 auto operator =(axis_aligned_bounding_box&&) noexcept
41 -> axis_aligned_bounding_box& = default;
42 //============================================================================
43 auto render(mat4f const& P, mat4f const& V) -> void override {
45 auto& shader = line_shader::get();
46 shader.bind();
47 shader.set_color(m_line_color[0], m_line_color[1], m_line_color[2],
48 m_line_color[3]);
49 shader.set_projection_matrix(P);
50 shader.set_modelview_matrix(V);
52 m_gpu_data.draw_lines();
53 }
54 //============================================================================
55 auto set_vbo_data() -> void {
56 auto vbomap = m_gpu_data.vertexbuffer().map();
57 if constexpr (N == 3) {
58 vbomap[0] = gpu_vec{float(min(0)), float(min(1)), float(min(2))};
59 vbomap[1] = gpu_vec{float(max(0)), float(min(1)), float(min(2))};
60 vbomap[2] = gpu_vec{float(min(0)), float(max(1)), float(min(2))};
61 vbomap[3] = gpu_vec{float(max(0)), float(max(1)), float(min(2))};
62 vbomap[4] = gpu_vec{float(min(0)), float(min(1)), float(max(2))};
63 vbomap[5] = gpu_vec{float(max(0)), float(min(1)), float(max(2))};
64 vbomap[6] = gpu_vec{float(min(0)), float(max(1)), float(max(2))};
65 vbomap[7] = gpu_vec{float(max(0)), float(max(1)), float(max(2))};
66 } else if constexpr (N == 2) {
67 vbomap[0] = gpu_vec{float(min(0)), float(min(1))};
68 vbomap[1] = gpu_vec{float(max(0)), float(min(1))};
69 vbomap[2] = gpu_vec{float(min(0)), float(max(1))};
70 vbomap[3] = gpu_vec{float(max(0)), float(max(1))};
71 vbomap[4] = gpu_vec{float(min(0)), float(min(1))};
72 vbomap[5] = gpu_vec{float(max(0)), float(min(1))};
73 vbomap[6] = gpu_vec{float(min(0)), float(max(1))};
74 vbomap[7] = gpu_vec{float(max(0)), float(max(1))};
75 }
76 }
77 //----------------------------------------------------------------------------
78 auto create_indexed_data() -> void {
79 m_gpu_data.vertexbuffer().resize(8);
80 m_gpu_data.indexbuffer().resize(24);
82 m_gpu_data.indexbuffer() = {0, 1, 0, 2, 1, 3, 2, 3, 4, 5, 4, 6,
83 5, 7, 6, 7, 0, 4, 1, 5, 2, 6, 3, 7};
84 }
85 //----------------------------------------------------------------------------
86 auto is_transparent() const -> bool override { return m_line_color[3] < 1; }
87 //----------------------------------------------------------------------------
88 auto line_width() -> auto& { return m_line_width; }
89 auto line_width() const { return m_line_width; }
90 //----------------------------------------------------------------------------
91 auto line_color() -> auto& { return m_line_color; }
92 auto line_color() const -> auto const& { return m_line_color; }
93};
94//==============================================================================
97//==============================================================================
98} // namespace tatooine::flowexplorer::nodes
99//==============================================================================
102 TATOOINE_REFLECTION_INSERT_GETTER(min),
103 TATOOINE_REFLECTION_INSERT_GETTER(max),
104 TATOOINE_REFLECTION_INSERT_GETTER(line_width),
105 TATOOINE_REFLECTION_INSERT_GETTER(line_color));
108 TATOOINE_REFLECTION_INSERT_GETTER(min),
109 TATOOINE_REFLECTION_INSERT_GETTER(max),
110 TATOOINE_REFLECTION_INSERT_GETTER(line_width),
111 TATOOINE_REFLECTION_INSERT_GETTER(line_color));
112#endif
Definition: indexeddata.h:13
Definition: vertexbuffer.h:22
TATOOINE_FLOWEXPLORER_REGISTER_RENDERABLE(tatooine::flowexplorer::nodes::aabb2d, TATOOINE_REFLECTION_INSERT_GETTER(min), TATOOINE_REFLECTION_INSERT_GETTER(max), TATOOINE_REFLECTION_INSERT_GETTER(line_width), TATOOINE_REFLECTION_INSERT_GETTER(line_color))
Definition: abcflow.h:7
DLL_API auto line_width(GLfloat width) -> void
Definition: algorithm.h:6
Definition: axis_aligned_bounding_box.h:103
auto constexpr max() const -> auto const &
Definition: axis_aligned_bounding_box.h:156
auto constexpr min() const -> auto const &
Definition: axis_aligned_bounding_box.h:151
Definition: axis_aligned_bounding_box.h:15
auto line_width() const
Definition: axis_aligned_bounding_box.h:89
auto set_vbo_data() -> void
Definition: axis_aligned_bounding_box.h:55
auto is_transparent() const -> bool override
Definition: axis_aligned_bounding_box.h:86
axis_aligned_bounding_box(const axis_aligned_bounding_box &)=default
axis_aligned_bounding_box(flowexplorer::scene &s)
Definition: axis_aligned_bounding_box.h:27
axis_aligned_bounding_box(axis_aligned_bounding_box &&) noexcept=default
std::array< GLfloat, 4 > m_line_color
Definition: axis_aligned_bounding_box.h:25
int m_line_width
Definition: axis_aligned_bounding_box.h:24
auto line_color() const -> auto const &
Definition: axis_aligned_bounding_box.h:92
gl::indexeddata< vec< float, N > > m_gpu_data
Definition: axis_aligned_bounding_box.h:23
auto line_color() -> auto &
Definition: axis_aligned_bounding_box.h:91
auto create_indexed_data() -> void
Definition: axis_aligned_bounding_box.h:78
auto line_width() -> auto &
Definition: axis_aligned_bounding_box.h:88
auto render(mat4f const &P, mat4f const &V) -> void override
Definition: axis_aligned_bounding_box.h:43
Definition: renderable.h:42
Definition: scene.h:17
Definition: mat.h:14
Definition: tags.h:96
Definition: vec.h:12