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

107 lines
3.2 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/atmosphere-component.hpp"
  28. #include "ecs/components/celestial-body-component.hpp"
  29. #include "ecs/components/orbit-component.hpp"
  30. namespace ecs {
  31. /**
  32. * Calculates apparent properties of celestial bodies relative to an observer.
  33. */
  34. class astronomy_system:
  35. public entity_system
  36. {
  37. public:
  38. astronomy_system(ecs::registry& registry);
  39. /**
  40. * Scales then adds the timestep `dt` to the current time, then recalculates the positions of celestial bodies.
  41. *
  42. * @param t Time, in seconds.
  43. * @param dt Delta time, in seconds.
  44. */
  45. virtual void update(double t, double dt);
  46. /**
  47. * Sets the current universal time.
  48. *
  49. * @param time Universal time, in days.
  50. */
  51. void set_universal_time(double time);
  52. /**
  53. * Sets the factor by which the timestep `dt` will be scaled before being added to the current universal time.
  54. *
  55. * @param scale Factor by which to scale the timestep.
  56. */
  57. void set_time_scale(double scale);
  58. /**
  59. * Sets the reference body entity, from which observations are taking place.
  60. *
  61. * @param entity Entity of the reference body.
  62. */
  63. void set_reference_body(ecs::entity entity);
  64. /**
  65. * Sets the location of the observer using spherical coordinates in BCBF space.
  66. *
  67. * @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).
  68. */
  69. void set_observer_location(const double3& location);
  70. void set_sun_light(scene::directional_light* light);
  71. void set_sky_pass(sky_pass* pass);
  72. private:
  73. double universal_time;
  74. double time_scale;
  75. ecs::entity reference_entity;
  76. const ecs::orbit_component* reference_orbit;
  77. const ecs::celestial_body_component* reference_body;
  78. const ecs::atmosphere_component* reference_atmosphere;
  79. double3 observer_location;
  80. physics::frame<double> inertial_to_bcbf;
  81. physics::frame<double> bcbf_to_topocentric;
  82. physics::frame<double> inertial_to_topocentric;
  83. physics::frame<double> sez_to_ezs;
  84. physics::frame<double> ezs_to_sez;
  85. scene::directional_light* sun_light;
  86. sky_pass* sky_pass;
  87. };
  88. } // namespace ecs
  89. #endif // ANTKEEPER_ECS_ASTRONOMY_SYSTEM_HPP