Antkeeper  0.0.1
astronomy-system.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_GAME_ASTRONOMY_SYSTEM_HPP
21 #define ANTKEEPER_GAME_ASTRONOMY_SYSTEM_HPP
22 
24 #include <engine/entity/id.hpp>
26 #include <engine/math/vector.hpp>
27 #include <engine/math/se3.hpp>
34 
35 
40  public updatable_system
41 {
42 public:
45 
52  virtual void update(float t, float dt);
53 
59  void set_time(double t);
60 
66  void set_time_scale(double scale);
67 
73  void set_observer(entity::id eid);
74 
80  void set_transmittance_samples(std::size_t samples);
81 
84  void set_starlight_illuminance(const math::dvec3& illuminance);
85  void set_sky_pass(::render::sky_pass* pass);
86 
87  [[nodiscard]] inline double get_time() const noexcept
88  {
89  return time_days;
90  }
91 
92 private:
93  void on_observer_modified(entity::registry& registry, entity::id entity_id);
94  void on_observer_destroyed(entity::registry& registry, entity::id entity_id);
95  void on_celestial_body_modified(entity::registry& registry, entity::id entity_id);
96  void on_celestial_body_destroyed(entity::registry& registry, entity::id entity_id);
97  void on_orbit_modified(entity::registry& registry, entity::id entity_id);
98  void on_orbit_destroyed(entity::registry& registry, entity::id entity_id);
99  void on_atmosphere_modified(entity::registry& registry, entity::id entity_id);
100  void on_atmosphere_destroyed(entity::registry& registry, entity::id entity_id);
101 
103  void observer_modified();
104 
106  void reference_body_modified();
107 
109  void reference_orbit_modified();
110 
112  void reference_atmosphere_modified();
113 
115  void update_bcbf_to_eus(const ::observer_component& observer, const ::celestial_body_component& body);
116 
118  void update_icrf_to_eus(const ::celestial_body_component& body, const ::orbit_component& orbit);
119 
128  math::dvec3 integrate_transmittance(const ::observer_component& observer, const ::celestial_body_component& body, const ::atmosphere_component& atmosphere, geom::ray<double, 3> ray) const;
129 
131  double time_days;
132 
134  double time_centuries;
135 
137  double time_scale;
138 
140  std::size_t transmittance_samples;
141 
143  entity::id observer_eid;
144 
146  entity::id reference_body_eid;
147 
149  math::se3<double> enu_to_eus;
150 
152  math::se3<double> bcbf_to_eus;
153 
155  math::se3<double> icrf_to_eus;
156 
157  scene::directional_light* sun_light;
158  scene::directional_light* moon_light;
159  ::render::sky_pass* sky_pass;
160  math::dvec3 starlight_illuminance;
161 };
162 
163 
164 #endif // ANTKEEPER_GAME_ASTRONOMY_SYSTEM_HPP
Calculates apparent properties of celestial bodies as seen by an observer.
void set_time(double t)
Sets the current time.
void set_moon_light(scene::directional_light *light)
virtual void update(float t, float dt)
Adds the timestep dt, scaled by set time scale, to the current time, then calculates apparent propert...
astronomy_system(entity::registry &registry)
void set_time_scale(double scale)
Sets the factor by which the timestep dt will be scaled before being added to the current time.
void set_sky_pass(::render::sky_pass *pass)
void set_observer(entity::id eid)
Sets the observer entity.
void set_starlight_illuminance(const math::dvec3 &illuminance)
void set_sun_light(scene::directional_light *light)
void set_transmittance_samples(std::size_t samples)
Sets the number of samples to take when integrating atmospheric transmittance.
double get_time() const noexcept
Light source with parallel rays and constant intensity.
Abstract base class for updatable systems.
entity::registry & registry
Registry on which the system operate.
entt::registry registry
Component registry type.
Definition: registry.hpp:28
entt::entity id
Entity ID type.
Definition: id.hpp:28
constexpr mat4< T > scale(const vec3< T > &v)
Constructs a scale matrix.
Half of a line proceeding from an initial point.
Definition: ray.hpp:38
n-dimensional vector.
Definition: vector.hpp:44