💿🐜 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.

112 lines
3.9 KiB

  1. /*
  2. * Copyright (C) 2023 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_NEST_VIEW_STATE_HPP
  20. #define ANTKEEPER_NEST_VIEW_STATE_HPP
  21. #include "game/states/game-state.hpp"
  22. #include <engine/entity/id.hpp>
  23. #include <engine/math/vector.hpp>
  24. #include <engine/render/model.hpp>
  25. #include <engine/event/subscription.hpp>
  26. #include <engine/input/mouse-events.hpp>
  27. #include <engine/geom/primitives/ray.hpp>
  28. #include <engine/geom/primitives/plane.hpp>
  29. #include <engine/math/angles.hpp>
  30. #include <engine/scene/light-probe.hpp>
  31. #include <engine/geom/bvh/bvh.hpp>
  32. #include <engine/geom/brep/brep-mesh.hpp>
  33. #include "game/ant/ant-phenome.hpp"
  34. class nest_view_state: public game_state
  35. {
  36. public:
  37. explicit nest_view_state(::game& ctx);
  38. virtual ~nest_view_state();
  39. private:
  40. void create_third_person_camera_rig();
  41. void destroy_third_person_camera_rig();
  42. void set_third_person_camera_zoom(double zoom);
  43. void set_third_person_camera_rotation(double yaw, double pitch);
  44. void zoom_third_person_camera(double zoom);
  45. void translate_third_person_camera(const math::dvec3& direction, double magnitude);
  46. void rotate_third_person_camera(const input::mouse_moved_event& event);
  47. void handle_mouse_motion(const input::mouse_moved_event& event);
  48. void update_third_person_camera();
  49. [[nodiscard]] geom::ray<float, 3> get_mouse_ray(const math::vec2<std::int32_t>& mouse_position) const;
  50. void setup_controls();
  51. std::vector<std::shared_ptr<::event::subscription>> action_subscriptions;
  52. std::shared_ptr<::event::subscription> mouse_motion_subscription;
  53. bool mouse_look{false};
  54. bool mouse_grip{false};
  55. bool mouse_zoom{false};
  56. geom::plane<float> mouse_grip_plane{{0.0, 1.0, 0.0}, 0.0};
  57. math::fvec3 mouse_grip_point{};
  58. bool moving{false};
  59. entity::id third_person_camera_rig_eid{entt::null};
  60. double third_person_camera_yaw{0.0};
  61. double third_person_camera_pitch{math::radians(45.0)};
  62. math::dvec3 third_person_camera_focal_point{0.0, 0.0, 0.0};
  63. double third_person_camera_zoom{0.25};
  64. std::uint32_t third_person_camera_zoom_step_count{6};
  65. double third_person_camera_near_focal_plane_height{2.0f};
  66. double third_person_camera_far_focal_plane_height{50.0f};
  67. double third_person_camera_near_hfov{math::radians(90.0)};
  68. double third_person_camera_far_hfov{math::radians(45.0)};
  69. /// In focal plane heights per second.
  70. double third_person_camera_speed{1.0f};
  71. double third_person_camera_hfov{};
  72. double third_person_camera_vfov{};
  73. double third_person_camera_focal_plane_width{};
  74. double third_person_camera_focal_plane_height{};
  75. double third_person_camera_focal_distance{};
  76. math::dquat third_person_camera_yaw_rotation{math::dquat::identity()};
  77. math::dquat third_person_camera_pitch_rotation{math::dquat::identity()};
  78. math::dquat third_person_camera_orientation{math::dquat::identity()};
  79. std::shared_ptr<render::matvar_fvec3> light_rectangle_emissive;
  80. std::shared_ptr<scene::light_probe> light_probe;
  81. std::shared_ptr<geom::brep_mesh> navmesh;
  82. std::unique_ptr<geom::bvh> navmesh_bvh;
  83. entity::id larva_eid;
  84. entity::id worker_eid;
  85. ant_phenome worker_phenome;
  86. geom::brep_face* navmesh_agent_face{};
  87. math::fvec3 navmesh_agent_position{};
  88. math::fvec3 navmesh_agent_normal{};
  89. };
  90. #endif // ANTKEEPER_NEST_VIEW_STATE_HPP