22 #include <engine/config.hpp>
69 static void load_ephemeris(::
game& ctx);
72 static void create_stars(::
game& ctx);
75 static void create_sun(::
game& ctx);
78 static void create_earth_moon_system(::
game& ctx);
81 static void create_earth(::
game& ctx);
84 static void create_moon(::
game& ctx);
93 create_earth_moon_system(ctx);
105 ctx.
entities[
"observer"] = observer_eid;
148 component.elevation = elevation;
149 component.latitude = latitude;
150 component.longitude = longitude;
166 catch (
const std::exception& e)
172 void set_time(::
game& ctx,
int year,
int month,
int day,
int hour,
int minute,
double second)
174 double longitude = 0.0;
189 const double utc_offset = physics::time::utc::offset<double>(longitude);
192 const double t = physics::time::gregorian::to_ut1<double>(year, month, day, hour, minute, second, utc_offset);
200 const double astronomical_scale =
scale / physics::time::seconds_per_day<double>;
206 void load_ephemeris(::
game& ctx)
211 void create_stars(::
game& ctx)
219 std::size_t star_count = 0;
220 if (star_catalog->rows.size() > 0)
221 star_count = star_catalog->
rows.size() - 1;
222 constexpr std::size_t star_vertex_stride = 7 *
sizeof(float);
223 std::vector<float> star_vertex_data(star_count * star_vertex_stride /
sizeof(
float));
224 float* star_vertex = star_vertex_data.data();
230 for (std::size_t i = 1;
i < star_catalog->rows.size(); ++
i)
232 const auto&
row = star_catalog->rows[
i];
241 ra = std::stof(row[1]);
242 dec = std::stof(row[2]);
243 vmag = std::stof(row[3]);
244 bv = std::stof(row[4]);
246 catch (
const std::exception&)
266 math::fvec3 color_rgb = config::scene_linear_color_space<float>.from_xyz * color_xyz;
275 *(star_vertex++) = color_rgb.
x();
276 *(star_vertex++) = color_rgb.
y();
277 *(star_vertex++) = color_rgb.
z();
278 *(star_vertex++) = brightness;
284 starlight_illuminance += illuminance;
288 std::shared_ptr<render::model> stars_model = std::make_shared<render::model>();
306 auto& vao = stars_model->get_vertex_array();
307 vao = std::make_unique<gl::vertex_array>(star_vertex_attributes);
310 auto& vbo = stars_model->get_vertex_buffer();
312 stars_model->set_vertex_offset(0);
313 stars_model->set_vertex_stride(star_vertex_stride);
316 stars_model->get_groups().resize(1);
318 stars_model_group.
id =
"stars";
322 stars_model_group.
vertex_count =
static_cast<std::uint32_t
>(star_count);
325 ctx.
sky_pass->set_stars_model(stars_model);
333 void create_sun(::
game& ctx)
344 ctx.
sun_light = std::make_unique<scene::directional_light>();
348 ctx.
sun_light->set_shadow_max_distance(20.0f);
349 ctx.
sun_light->set_shadow_fade_range(5.0f);
350 ctx.
sun_light->set_shadow_cascade_count(4);
351 ctx.
sun_light->set_shadow_cascade_distribution(0.8f);
363 void create_earth_moon_system(::
game& ctx)
371 ctx.
entities[
"em_bary"] = em_bary_eid;
383 void create_earth(::
game& ctx)
400 void create_moon(::
game& ctx)
417 ctx.
moon_light = std::make_unique<scene::directional_light>();
std::shared_ptr< gl::framebuffer > shadow_map_framebuffer
std::unique_ptr< scene::collection > surface_scene
std::unique_ptr< screen_transition > fade_transition
std::unique_ptr< scene::directional_light > sun_light
std::unique_ptr< scene::directional_light > moon_light
std::unique_ptr<::astronomy_system > astronomy_system
std::unique_ptr< resource_manager > resource_manager
std::unique_ptr< render::sky_pass > sky_pass
std::shared_ptr< render::matvar_fvec3 > fade_transition_color
std::unique_ptr<::atmosphere_system > atmosphere_system
std::unique_ptr< entity::registry > entity_registry
std::unique_ptr<::orbit_system > orbit_system
std::unordered_map< hash::fnv1a32_t, entity::id > entities
A material is associated with exactly one shader program and contains a set of material properties wh...
T bv_to_cct(T bv) noexcept
Approximates the temperature of a star, given its B-V index.
math::vec3< T > cct_to_xyz(T t)
Calculates CIE XYZ colorspace chromaticity coordinates given a correlated color temperature using Kry...
log_message< log_message_severity::warning, Args... > log_warning
Formats and logs a warning message.
log_message< log_message_severity::trace, Args... > log_trace
Formats and logs a trace message.
log_message< log_message_severity::error, Args... > log_error
Formats and logs an error message.
entt::entity id
Entity ID type.
@ static_draw
Data will be modified once, by the application, and used many times, for drawing commands.
@ point_list
Separate point primitives.
@ row
Faces are stored consecutively in a single row.
dvec< 3 > dvec3
n-dimensional vector of double-precision floating-point numbers.
constexpr T radians(T degrees) noexcept
Converts an angle given in degrees to radians.
constexpr mat4< T > scale(const vec3< T > &v)
Constructs a scale matrix.
constexpr T wrap_radians(T radians)
Wraps an angle to [-pi, pi].
T to_brightness(T mv)
Converts apparent magnitude to a brightness factor relative to a 0th magnitude star.
T to_illuminance(T mv)
Converts apparent magnitude to illuminance.
math::vec3< T > cartesian(const math::vec3< T > &v)
Converts BCI coordinates from spherical to Cartesian.
@ color
Vertex color (vec4)
@ position
Vertex position (vec3)
World creation and manipulation functions.
void cosmogenesis(::game &ctx)
Creates the cosmos.
void create_observer(::game &ctx)
Creates the observer.
void set_location(::game &ctx, double elevation, double latitude, double longitude)
Sets the location of the observer.
void enter_ecoregion(::game &ctx, const ecoregion &ecoregion)
Enters a ecoregion.
void switch_scene(::game &ctx)
void set_time_scale(::game &ctx, double scale)
Sets rate at which time passes.
void set_time(::game &ctx, double t)
Sets the current time.
Container for templated easing functions.
std::string name
Ecoregion name.
float latitude
Latitude, in radians.
math::fvec3 terrain_albedo
Terrain albedo.
float elevation
Elevation, in meters.
float longitude
Longitude, in radians.
entity::id create(entity::registry ®istry) const
Creates an instance of this archetype.
std::vector< std::vector< std::string > > rows
Rows of column strings.
constexpr element_type & x() noexcept
Returns a reference to the first element.
constexpr element_type & y() noexcept
Returns a reference to the second element.
constexpr element_type & z() noexcept
Returns a reference to the third element.
double latitude
Latitude of the observer, in radians.
entity::id reference_body_eid
Entity ID of a celestial body to which the observer position is relative.
double elevation
Elevation of the observer, in radians.
double longitude
Longitude of the observer, in radians.
Table of orbital trajectories.
Part of a model which is associated with exactly one material.
std::shared_ptr< render::material > material
gl::primitive_topology primitive_topology
std::uint32_t vertex_count
std::uint32_t first_vertex