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

129 lines
4.4 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_TREADMILL_EXPERIMENT_STATE_HPP
  20. #define ANTKEEPER_TREADMILL_EXPERIMENT_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 <engine/animation/ik/ik-rig.hpp>
  34. #include "game/ant/ant-phenome.hpp"
  35. class treadmill_experiment_state: public game_state
  36. {
  37. public:
  38. explicit treadmill_experiment_state(::game& ctx);
  39. ~treadmill_experiment_state() override;
  40. private:
  41. void create_third_person_camera_rig();
  42. void destroy_third_person_camera_rig();
  43. void set_third_person_camera_zoom(double zoom);
  44. void set_third_person_camera_rotation(double yaw, double pitch);
  45. void zoom_third_person_camera(double zoom);
  46. void translate_third_person_camera(const math::dvec3& direction, double magnitude);
  47. void rotate_third_person_camera(const input::mouse_moved_event& event);
  48. void handle_mouse_motion(const input::mouse_moved_event& event);
  49. void update_third_person_camera();
  50. void load_camera_preset(std::uint8_t index);
  51. void save_camera_preset(std::uint8_t index);
  52. void load_or_save_camera_preset(std::uint8_t index);
  53. [[nodiscard]] geom::ray<float, 3> get_mouse_ray(const math::vec2<std::int32_t>& mouse_position) const;
  54. void setup_controls();
  55. std::vector<std::shared_ptr<::event::subscription>> action_subscriptions;
  56. std::shared_ptr<::event::subscription> mouse_motion_subscription;
  57. bool mouse_look{false};
  58. bool mouse_grip{false};
  59. bool mouse_zoom{false};
  60. geom::plane<float> mouse_grip_plane{{0.0, 1.0, 0.0}, 0.0};
  61. math::fvec3 mouse_grip_point{};
  62. bool moving{false};
  63. entity::id third_person_camera_rig_eid{entt::null};
  64. double third_person_camera_yaw{0.0};
  65. double third_person_camera_pitch{math::radians(45.0)};
  66. math::dvec3 third_person_camera_focal_point{0.0, 0.0, 0.0};
  67. double third_person_camera_zoom{0.25};
  68. std::uint32_t third_person_camera_zoom_step_count{6};
  69. double third_person_camera_near_focal_plane_height{1.0f};
  70. double third_person_camera_far_focal_plane_height{50.0f};
  71. double third_person_camera_near_hfov{math::radians(90.0)};
  72. double third_person_camera_far_hfov{math::radians(45.0)};
  73. /// In focal plane heights per second.
  74. double third_person_camera_speed{1.0f};
  75. double third_person_camera_hfov{};
  76. double third_person_camera_vfov{};
  77. double third_person_camera_focal_plane_width{};
  78. double third_person_camera_focal_plane_height{};
  79. double third_person_camera_focal_distance{};
  80. math::dquat third_person_camera_yaw_rotation{math::dquat::identity()};
  81. math::dquat third_person_camera_pitch_rotation{math::dquat::identity()};
  82. math::dquat third_person_camera_orientation{math::dquat::identity()};
  83. struct camera_preset
  84. {
  85. double yaw{};
  86. double pitch{};
  87. math::dvec3 focal_point{};
  88. double zoom{0.25};
  89. };
  90. std::vector<std::optional<camera_preset>> camera_presets{10};
  91. std::shared_ptr<render::matvar_fvec3> light_rectangle_emissive;
  92. std::shared_ptr<scene::light_probe> light_probe;
  93. std::shared_ptr<geom::brep_mesh> navmesh;
  94. std::unique_ptr<geom::bvh> navmesh_bvh;
  95. entity::id larva_eid;
  96. entity::id worker_eid;
  97. ant_phenome worker_phenome;
  98. geom::brep_face* navmesh_agent_face{};
  99. math::fvec3 navmesh_agent_position{};
  100. math::fvec3 navmesh_agent_normal{};
  101. std::shared_ptr<ik_rig> worker_ik_rig;
  102. std::shared_ptr<scene::light_probe> sky_probe;
  103. };
  104. #endif // ANTKEEPER_TREADMILL_EXPERIMENT_STATE_HPP