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

111 lines
3.4 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_ENTITY_SYSTEM_ASTRONOMY_HPP
  20. #define ANTKEEPER_ENTITY_SYSTEM_ASTRONOMY_HPP
  21. #include "entity/systems/updatable.hpp"
  22. #include "entity/id.hpp"
  23. #include "scene/directional-light.hpp"
  24. #include "utility/fundamental-types.hpp"
  25. #include "physics/frame.hpp"
  26. #include "render/passes/sky-pass.hpp"
  27. #include "entity/components/atmosphere.hpp"
  28. #include "entity/components/celestial-body.hpp"
  29. #include "entity/components/orbit.hpp"
  30. namespace entity {
  31. namespace system {
  32. /**
  33. * Calculates apparent properties of celestial bodies relative to an observer.
  34. */
  35. class astronomy:
  36. public updatable
  37. {
  38. public:
  39. astronomy(entity::registry& registry);
  40. /**
  41. * Scales then adds the timestep `dt` to the current time, then recalculates the positions of celestial bodies.
  42. *
  43. * @param t Time, in seconds.
  44. * @param dt Delta time, in seconds.
  45. */
  46. virtual void update(double t, double dt);
  47. /**
  48. * Sets the current universal time.
  49. *
  50. * @param time Universal time, in days.
  51. */
  52. void set_universal_time(double time);
  53. /**
  54. * Sets the factor by which the timestep `dt` will be scaled before being added to the current universal time.
  55. *
  56. * @param scale Factor by which to scale the timestep.
  57. */
  58. void set_time_scale(double scale);
  59. /**
  60. * Sets the reference body entity, from which observations are taking place.
  61. *
  62. * @param entity Entity of the reference body.
  63. */
  64. void set_reference_body(entity::id entity_id);
  65. /**
  66. * Sets the location of the observer using spherical coordinates in BCBF space.
  67. *
  68. * @param location Spherical coordinates of the observer, in reference body BCBF space, in the ISO order of altitude (meters), latitude (radians), and longitude (radians).
  69. */
  70. void set_observer_location(const double3& location);
  71. void set_sun_light(scene::directional_light* light);
  72. void set_sky_pass(::render::sky_pass* pass);
  73. private:
  74. void on_celestial_body_construct(entity::registry& registry, entity::id entity_id, entity::component::celestial_body& celestial_body);
  75. void on_celestial_body_replace(entity::registry& registry, entity::id entity_id, entity::component::celestial_body& celestial_body);
  76. void update_bcbf_to_topocentric();
  77. double universal_time;
  78. double time_scale;
  79. entity::id reference_entity;
  80. double3 observer_location;
  81. physics::frame<double> inertial_to_bcbf;
  82. physics::frame<double> bcbf_to_topocentric;
  83. physics::frame<double> inertial_to_topocentric;
  84. physics::frame<double> sez_to_ezs;
  85. physics::frame<double> ezs_to_sez;
  86. scene::directional_light* sun_light;
  87. ::render::sky_pass* sky_pass;
  88. };
  89. } // namespace system
  90. } // namespace entity
  91. #endif // ANTKEEPER_ENTITY_SYSTEM_ASTRONOMY_HPP