cursor_guide_impl.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #ifndef DEPTHGUIDE_CURSOR_GUIDE_IMPL_H
  2. #define DEPTHGUIDE_CURSOR_GUIDE_IMPL_H
  3. #include "module/guidance/cursor_guide.h"
  4. #include "core/math_helper.hpp"
  5. namespace cursor_guide_impl {
  6. struct point_set {
  7. struct point_type {
  8. glm::vec3 position;
  9. float radius;
  10. bool is_picked = false;
  11. };
  12. using container_type =
  13. std::list<point_type>;
  14. using iterator_type =
  15. container_type::iterator;
  16. container_type c;
  17. // object observed in world
  18. glm::mat4 transform = glm::mat4(1.0f);
  19. // p: in world coordinate
  20. void emplace(const glm::vec3 &p, float r);
  21. // tp: point in world coordinate
  22. // return true if some point is picked.
  23. bool try_picking(const glm::vec3 &tp);
  24. void remove_picked();
  25. };
  26. using mesh_cache_type =
  27. std::unordered_map<float, mesh_ptr>;
  28. extern mesh_cache_type mesh_cache;
  29. mesh_ptr get_mesh(float radius);
  30. }
  31. using namespace cursor_guide_impl;
  32. struct cursor_guide::impl {
  33. static constexpr auto amb_factor = 0.9f;
  34. static constexpr auto color_free = glm::vec3(0, 1, 0);
  35. static constexpr auto color_picked = glm::vec3(1, 0, 0);
  36. static constexpr auto color_fixed = glm::vec3(0, 0, 1);
  37. sophiar_conn_type *sophiar_conn = nullptr;
  38. float current_radius = 5.f;
  39. std::optional<glm::vec3> free_pos; // in world coordinate
  40. using binding_store_base_type
  41. = create_config::item_type;
  42. struct binding_store_type
  43. : public binding_store_base_type {
  44. using base_type = binding_store_base_type;
  45. impl *pimpl = nullptr;
  46. point_set points;
  47. explicit binding_store_type(impl *_pimpl, const base_type &base)
  48. : binding_store_base_type(base) {
  49. pimpl = _pimpl;
  50. }
  51. void update_transform();
  52. };
  53. using binding_list_type =
  54. std::vector<binding_store_type>;
  55. binding_list_type binding_list;
  56. size_t current_binding = 0;
  57. explicit impl(const create_config &conf);
  58. void update(const guide_info &info);
  59. void show();
  60. void pre_render_slot(const scene_ptr &info);
  61. };
  62. #endif //DEPTHGUIDE_CURSOR_GUIDE_IMPL_H