💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.6 KiB

  1. /*
  2. * Copyright (C) 2021 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef ANTKEEPER_ECS_PAINTING_SYSTEM_HPP
  20. #define ANTKEEPER_ECS_PAINTING_SYSTEM_HPP
  21. #include "entity-system.hpp"
  22. #include "ecs/entity.hpp"
  23. #include "event/event-handler.hpp"
  24. #include "game/events/tool-events.hpp"
  25. #include "utility/fundamental-types.hpp"
  26. #include "scene/collection.hpp"
  27. #include "scene/model-instance.hpp"
  28. #include "gl/vertex-buffer.hpp"
  29. #include <vector>
  30. #include <optional>
  31. class material;
  32. class event_dispatcher;
  33. class resource_manager;
  34. class model;
  35. class model_group;
  36. namespace ecs {
  37. class painting_system: public entity_system,
  38. public event_handler<tool_pressed_event>,
  39. public event_handler<tool_released_event>
  40. {
  41. public:
  42. painting_system(ecs::registry& registry, event_dispatcher* event_dispatcher, resource_manager* resource_manager);
  43. virtual ~painting_system();
  44. virtual void update(double t, double dt);
  45. void set_scene(scene::collection* collection);
  46. private:
  47. virtual void handle_event(const tool_pressed_event& event);
  48. virtual void handle_event(const tool_released_event& event);
  49. std::optional<std::tuple<float3, float3>> cast_ray(const float3& position) const;
  50. event_dispatcher* event_dispatcher;
  51. resource_manager* resource_manager;
  52. scene::collection* scene_collection;
  53. bool painting;
  54. entity brush_entity;
  55. float3 stroke_start;
  56. float3 stroke_end;
  57. float min_stroke_length;
  58. float min_stroke_length_squared;
  59. float stroke_width;
  60. int max_stroke_segments;
  61. int current_stroke_segment;
  62. float max_miter_angle;
  63. float decal_offset;
  64. float3 stroke_bounds_min;
  65. float3 stroke_bounds_max;
  66. float3 p0;
  67. float3 p0a;
  68. float3 p0b;
  69. std::size_t vertex_size;
  70. std::size_t vertex_stride;
  71. std::size_t vertex_count;
  72. model* stroke_model;
  73. model_group* stroke_model_group;
  74. gl::vertex_buffer* stroke_vbo;
  75. bool midstroke;
  76. scene::model_instance* stroke_model_instance;
  77. };
  78. } // namespace ecs
  79. #endif // ANTKEEPER_ECS_PAINTING_SYSTEM_HPP