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

116 lines
3.6 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. namespace ecs {
  28. /**
  29. * Calculates apparent properties of celestial bodies relative to an observer (magnitude, angular radius, horizontal coordinates) and modifies their model component and/or light component to render them accordingly.
  30. */
  31. class astronomy_system:
  32. public entity_system
  33. {
  34. public:
  35. astronomy_system(ecs::registry& registry);
  36. /**
  37. * Scales then adds the timestep `dt` to the current time, then recalculates the positions of celestial bodies.
  38. *
  39. * @param t Time, in seconds.
  40. * @param dt Delta time, in seconds.
  41. */
  42. virtual void update(double t, double dt);
  43. /**
  44. * Sets the current universal time.
  45. *
  46. * @param time Universal time, in days.
  47. */
  48. void set_universal_time(double time);
  49. /**
  50. * Sets the factor by which the timestep `dt` will be scaled before being added to the current universal time.
  51. *
  52. * @param scale Factor by which to scale the timestep.
  53. */
  54. void set_time_scale(double scale);
  55. /**
  56. * Sets the reference body, from which observations are taking place.
  57. *
  58. * @param entity Entity of the reference body.
  59. */
  60. void set_reference_body(ecs::entity entity);
  61. /**
  62. * Sets the axial tilt of the reference body.
  63. *
  64. * @param angle Angle between the reference body's rotational axis and its orbital axis, in radians.
  65. */
  66. void set_reference_body_axial_tilt(double angle);
  67. /**
  68. * Sets the location of the observer using spherical coordinates in BCBF space.
  69. *
  70. * @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).
  71. */
  72. void set_observer_location(const double3& location);
  73. void set_sun_light(scene::directional_light* light);
  74. void set_sky_pass(sky_pass* pass);
  75. private:
  76. /**
  77. * Calculates the luminous flux of a spherical blackbody in vacuum using the CIE 1931 standard observer photopic luminosity function.
  78. *
  79. * @param t Temperature of the blackbody, in kelvin.
  80. * @param r Radius of the blackbody, in meters.
  81. * @return Luminous flux, in lumens.
  82. */
  83. static double blackbody_luminous_flux(double t, double r);
  84. double universal_time;
  85. double time_scale;
  86. ecs::entity reference_body;
  87. double reference_body_axial_tilt;
  88. double reference_body_axial_rotation;
  89. double3 observer_location;
  90. scene::directional_light* sun_light;
  91. sky_pass* sky_pass;
  92. physics::frame<double> inertial_to_bcbf;
  93. physics::frame<double> bcbf_to_topocentric;
  94. physics::frame<double> inertial_to_topocentric;
  95. physics::frame<double> sez_to_ezs;
  96. physics::frame<double> ezs_to_sez;
  97. };
  98. } // namespace ecs
  99. #endif // ANTKEEPER_ECS_ASTRONOMY_SYSTEM_HPP