Antkeeper  0.0.1
treadmill-experiment-state.hpp
Go to the documentation of this file.
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 
20 #ifndef ANTKEEPER_TREADMILL_EXPERIMENT_STATE_HPP
21 #define ANTKEEPER_TREADMILL_EXPERIMENT_STATE_HPP
22 
24 #include <engine/entity/id.hpp>
25 #include <engine/math/vector.hpp>
26 #include <engine/render/model.hpp>
31 #include <engine/math/angles.hpp>
34 #include <engine/geom/bvh/bvh.hpp>
37 #include "game/ant/ant-phenome.hpp"
38 
40 {
41 public:
42  explicit treadmill_experiment_state(::game& ctx);
43  ~treadmill_experiment_state() override;
44 
45 private:
46  void create_third_person_camera_rig();
47  void destroy_third_person_camera_rig();
48 
49  void set_third_person_camera_zoom(double zoom);
50  void set_third_person_camera_rotation(double yaw, double pitch);
51 
52  void zoom_third_person_camera(double zoom);
53  void translate_third_person_camera(const math::dvec3& direction, double magnitude);
54  void rotate_third_person_camera(const input::mouse_moved_event& event);
55 
56  void handle_mouse_motion(const input::mouse_moved_event& event);
57 
58  void update_third_person_camera();
59  void load_camera_preset(std::uint8_t index);
60  void save_camera_preset(std::uint8_t index);
61  void load_or_save_camera_preset(std::uint8_t index);
62 
63  [[nodiscard]] geom::ray<float, 3> get_mouse_ray(const math::vec2<std::int32_t>& mouse_position) const;
64 
65  void setup_controls();
66 
67  std::vector<std::shared_ptr<::event::subscription>> action_subscriptions;
68  std::shared_ptr<::event::subscription> mouse_motion_subscription;
69 
70  bool mouse_look{false};
71  bool mouse_grip{false};
72  bool mouse_zoom{false};
73  geom::plane<float> mouse_grip_plane{{0.0, 1.0, 0.0}, 0.0};
74  math::fvec3 mouse_grip_point{};
75 
76  bool moving{false};
77 
78  entity::id third_person_camera_rig_eid{entt::null};
79  double third_person_camera_yaw{0.0};
80  double third_person_camera_pitch{math::radians(45.0)};
81  math::dvec3 third_person_camera_focal_point{0.0, 0.0, 0.0};
82  double third_person_camera_zoom{0.25};
83  std::uint32_t third_person_camera_zoom_step_count{6};
84 
85  double third_person_camera_near_focal_plane_height{1.0f};
86  double third_person_camera_far_focal_plane_height{50.0f};
87 
88  double third_person_camera_near_hfov{math::radians(90.0)};
89  double third_person_camera_far_hfov{math::radians(45.0)};
90 
92  double third_person_camera_speed{1.0f};
93 
94  double third_person_camera_hfov{};
95  double third_person_camera_vfov{};
96  double third_person_camera_focal_plane_width{};
97  double third_person_camera_focal_plane_height{};
98  double third_person_camera_focal_distance{};
99  math::dquat third_person_camera_yaw_rotation{math::dquat::identity()};
100  math::dquat third_person_camera_pitch_rotation{math::dquat::identity()};
101  math::dquat third_person_camera_orientation{math::dquat::identity()};
102 
103  struct camera_preset
104  {
105  double yaw{};
106  double pitch{};
107  math::dvec3 focal_point{};
108  double zoom{0.25};
109  };
110 
111  std::vector<std::optional<camera_preset>> camera_presets{10};
112 
113  std::shared_ptr<render::matvar_fvec3> light_rectangle_emissive;
114  std::shared_ptr<scene::light_probe> light_probe;
115 
116  entity::id larva_eid;
117  entity::id worker_eid;
118 
119  std::shared_ptr<ant_phenome> worker_phenome;
120  std::shared_ptr<ik_rig> worker_ik_rig;
121 
122  std::shared_ptr<scene::light_probe> sky_probe;
123  std::shared_ptr<scene::rectangle_light> area_light;
124 };
125 
126 #endif // ANTKEEPER_TREADMILL_EXPERIMENT_STATE_HPP
Abstract base class for game states.
Definition: game-state.hpp:29
::game & ctx
Definition: game-state.hpp:44
Definition: game.hpp:121
entt::entity id
Entity ID type.
Definition: id.hpp:28
Publish-subscribe messaging.
Definition: channel.hpp:32
constexpr T radians(T degrees) noexcept
Converts an angle given in degrees to radians.
Definition: angles.hpp:48
n-dimensional plane.
Definition: hyperplane.hpp:36
Half of a line proceeding from an initial point.
Definition: ray.hpp:38
Event generated when a mouse has been moved.
Quaternion composed of a real scalar part and imaginary vector part.
Definition: quaternion.hpp:39
static constexpr quaternion identity() noexcept
Returns a rotation identity quaternion.
Definition: quaternion.hpp:200
n-dimensional vector.
Definition: vector.hpp:44