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

119 lines
3.7 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_ASTRONOMY_SYSTEM_HPP
  20. #define ANTKEEPER_ECS_ASTRONOMY_SYSTEM_HPP
  21. #include "entity-system.hpp"
  22. #include "ecs/entity.hpp"
  23. #include "scene/directional-light.hpp"
  24. #include "utility/fundamental-types.hpp"
  25. #include "physics/frame.hpp"
  26. #include "renderer/passes/sky-pass.hpp"
  27. #include "ecs/components/blackbody-component.hpp"
  28. #include "ecs/components/atmosphere-component.hpp"
  29. namespace ecs {
  30. /**
  31. * Calculates apparent properties of celestial bodies relative to an observer.
  32. */
  33. class astronomy_system:
  34. public entity_system
  35. {
  36. public:
  37. astronomy_system(ecs::registry& registry);
  38. /**
  39. * Scales then adds the timestep `dt` to the current time, then recalculates the positions of celestial bodies.
  40. *
  41. * @param t Time, in seconds.
  42. * @param dt Delta time, in seconds.
  43. */
  44. virtual void update(double t, double dt);
  45. /**
  46. * Sets the current universal time.
  47. *
  48. * @param time Universal time, in days.
  49. */
  50. void set_universal_time(double time);
  51. /**
  52. * Sets the factor by which the timestep `dt` will be scaled before being added to the current universal time.
  53. *
  54. * @param scale Factor by which to scale the timestep.
  55. */
  56. void set_time_scale(double scale);
  57. /**
  58. * Sets the reference body, from which observations are taking place.
  59. *
  60. * @param entity Entity of the reference body.
  61. */
  62. void set_reference_body(ecs::entity entity);
  63. /**
  64. * Sets the axial tilt of the reference body.
  65. *
  66. * @param angle Angle between the reference body's rotational axis and its orbital axis, in radians.
  67. */
  68. void set_reference_body_axial_tilt(double angle);
  69. /**
  70. * Sets the location of the observer using spherical coordinates in BCBF space.
  71. *
  72. * @param location Spherical coordinates of the observer, in reference body BCBF space, in the ISO order of radial distance, polar angle (radians), and azimuthal angle (radians).
  73. */
  74. void set_observer_location(const double3& location);
  75. void set_sun_light(scene::directional_light* light);
  76. void set_sky_pass(sky_pass* pass);
  77. private:
  78. void on_blackbody_construct(ecs::registry& registry, ecs::entity entity, ecs::blackbody_component& blackbody);
  79. void on_blackbody_replace(ecs::registry& registry, ecs::entity entity, ecs::blackbody_component& blackbody);
  80. void on_atmosphere_construct(ecs::registry& registry, ecs::entity entity, ecs::atmosphere_component& atmosphere);
  81. void on_atmosphere_replace(ecs::registry& registry, ecs::entity entity, ecs::atmosphere_component& atmosphere);
  82. double universal_time;
  83. double time_scale;
  84. ecs::entity reference_body;
  85. double reference_body_axial_tilt;
  86. double reference_body_axial_rotation;
  87. double3 observer_location;
  88. scene::directional_light* sun_light;
  89. sky_pass* sky_pass;
  90. physics::frame<double> inertial_to_bcbf;
  91. physics::frame<double> bcbf_to_topocentric;
  92. physics::frame<double> inertial_to_topocentric;
  93. physics::frame<double> sez_to_ezs;
  94. physics::frame<double> ezs_to_sez;
  95. double3 rgb_wavelengths_nm;
  96. double3 rgb_wavelengths_m;
  97. };
  98. } // namespace ecs
  99. #endif // ANTKEEPER_ECS_ASTRONOMY_SYSTEM_HPP