Tatooine
axis_aligned_bounding_box2.h
Go to the documentation of this file.
1#ifndef TATOOINE_RENDERING_INTERACTIVE_AXIS_ALIGNED_BOUNDING_BOX2_H
2#define TATOOINE_RENDERING_INTERACTIVE_AXIS_ALIGNED_BOUNDING_BOX2_H
3//==============================================================================
11//==============================================================================
13//==============================================================================
14template <floating_point Real>
17 //============================================================================
18 struct geometry : gl::indexeddata<Vec2<GLfloat>> {
19 static auto get() -> auto& {
20 static auto instance = geometry{};
21 return instance;
22 }
24 vertexbuffer().resize(4);
25 {
26 auto vb_map = vertexbuffer().wmap();
27 vb_map[0] = Vec2<GLfloat>{0, 0};
28 vb_map[1] = Vec2<GLfloat>{1, 0};
29 vb_map[2] = Vec2<GLfloat>{1, 1};
30 vb_map[3] = Vec2<GLfloat>{0, 1};
31 }
32 indexbuffer().resize(4);
33 {
34 auto data = indexbuffer().wmap();
35 data[0] = 0;
36 data[1] = 1;
37 data[2] = 2;
38 data[3] = 3;
39 }
40 }
41 };
42 //============================================================================
44 //============================================================================
45 private:
46 int line_width = 1;
47 Vec4<GLfloat> color = {0, 0, 0, 1};
48
49 public:
50 //============================================================================
51 renderer(renderable_type const& /*aabb*/) {}
52 //----------------------------------------------------------------------------
53 auto properties(renderable_type const& /*aabb*/) {
54 ImGui::Text("Axis Aligned Bounding Box");
55 ImGui::DragInt("Line width", &line_width, 1, 1, 20);
56 ImGui::ColorEdit4("Color", color.data());
57 }
58 //============================================================================
59 auto render() {
62
63 line_shader.set_color(color(0), color(1), color(2), color(3));
64 gl::line_width(line_width);
65 geometry::get().draw_line_loop();
66 }
67 //----------------------------------------------------------------------------
68 auto update(auto const /*dt*/, renderable_type const& aabb,
69 camera auto const& cam) {
70 using CamReal = typename std::decay_t<decltype(cam)>::real_type;
71 static auto constexpr cam_is_float = is_same<GLfloat, CamReal>;
72 if constexpr (cam_is_float) {
73 line_shader::get().set_projection_matrix(cam.projection_matrix());
74 } else {
75 line_shader::get().set_projection_matrix(
76 Mat4<GLfloat>{cam.projection_matrix()});
77 }
78
79 if constexpr (cam_is_float) {
80 line_shader::get().set_model_view_matrix(
81 cam.view_matrix() *
82 translation_matrix<GLfloat>(aabb.min(0), aabb.min(1), 0) *
83 scale_matrix<GLfloat>(aabb.max(0) - aabb.min(0),
84 aabb.max(1) - aabb.min(1), 1));
85 } else {
86 line_shader::get().set_model_view_matrix(
87 Mat4<GLfloat>{cam.view_matrix()} *
88 translation_matrix<GLfloat>(aabb.min(0), aabb.min(1), 0) *
89 scale_matrix<GLfloat>(aabb.max(0) - aabb.min(0),
90 aabb.max(1) - aabb.min(1), 1));
91 }
92 }
93};
94//==============================================================================
95} // namespace tatooine::rendering::interactive
96//==============================================================================
97#endif
Definition: indexeddata.h:13
DLL_API void bind() const
constexpr auto data() -> ValueType *
Definition: static_multidim_array.h:260
Definition: camera.h:312
DLL_API auto line_width(GLfloat width) -> void
Definition: interactive.h:15
Definition: algorithm.h:6
typename get_impl< Container, I >::type get
Definition: get.h:11
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: mat.h:14
renderer(renderable_type const &)
Definition: axis_aligned_bounding_box2.h:51
auto update(auto const, renderable_type const &aabb, camera auto const &cam)
Definition: axis_aligned_bounding_box2.h:68
auto properties(renderable_type const &)
Definition: axis_aligned_bounding_box2.h:53
auto set_color(GLfloat r, GLfloat g, GLfloat b, GLfloat a=1) -> void
Definition: shaders.h:85
Definition: vec.h:12