diff --git a/src/astro/illuminance.cpp b/src/astro/illuminance.cpp index ce2d44a..3d88192 100644 --- a/src/astro/illuminance.cpp +++ b/src/astro/illuminance.cpp @@ -23,6 +23,13 @@ namespace astro { +double vmag_to_brightness(double mv) +{ + // 100^(1/5) + static constexpr double fifth_root_100 = 2.5118864315095801110850320677993; + return std::pow(fifth_root_100, -mv); +} + double vmag_to_lux(double mv) { return std::pow(10.0, (-14.18 - mv) * 0.4); diff --git a/src/astro/illuminance.hpp b/src/astro/illuminance.hpp index 0c57f94..61dfdf6 100644 --- a/src/astro/illuminance.hpp +++ b/src/astro/illuminance.hpp @@ -22,6 +22,17 @@ namespace astro { + + +/** + * Converts apparent (visual) magnitude to a brightness factor relative to a 0th magnitude star. + * + * @param mv Illuminance in apparent magnitude. + * @return Relative brightness factor. + * + * @see https://en.wikipedia.org/wiki/Illuminance + */ +double vmag_to_brightness(double mv); /** * Converts apparent (visual) magnitude to lux. diff --git a/src/game/state/nuptial-flight.cpp b/src/game/state/nuptial-flight.cpp index de1d936..ad17e09 100644 --- a/src/game/state/nuptial-flight.cpp +++ b/src/game/state/nuptial-flight.cpp @@ -114,11 +114,6 @@ nuptial_flight::nuptial_flight(game::context& ctx): // Setup camera setup_camera(); - /* - ctx.surface_camera->look_at({0, 0, 1}, {0, 0, 0}, {0, 1, 0}); - ctx.surface_camera->set_exposure(-14.5f); - ctx.surface_scene->update_tweens(); - */ // Queue fade in ctx.fade_transition_color->set_value({1, 1, 1}); @@ -252,6 +247,7 @@ void nuptial_flight::enable_controls() bool gamepad_invert_pan = false; bool mouse_look_toggle = false; ctx.mouse_look = false; + const double time_scale = 5000.0; if (ctx.config->contains("mouse_tilt_sensitivity")) mouse_tilt_sensitivity = math::radians((*ctx.config)["mouse_tilt_sensitivity"].get()); @@ -542,6 +538,36 @@ void nuptial_flight::enable_controls() ); */ + // Fast-forward + ctx.controls["fast_forward"]->set_activated_callback + ( + [&ctx = this->ctx, time_scale]() + { + game::world::set_time_scale(ctx, time_scale); + } + ); + ctx.controls["fast_forward"]->set_deactivated_callback + ( + [&ctx = this->ctx, time_scale]() + { + game::world::set_time_scale(ctx, 0.0); + } + ); + ctx.controls["rewind"]->set_activated_callback + ( + [&ctx = this->ctx, time_scale]() + { + game::world::set_time_scale(ctx, -time_scale); + } + ); + ctx.controls["rewind"]->set_deactivated_callback + ( + [&ctx = this->ctx, time_scale]() + { + game::world::set_time_scale(ctx, 0.0); + } + ); + // Setup pause control ctx.controls["pause"]->set_activated_callback ( diff --git a/src/game/world.cpp b/src/game/world.cpp index f32a55c..8eab747 100644 --- a/src/game/world.cpp +++ b/src/game/world.cpp @@ -38,6 +38,7 @@ #include "gl/vertex-buffer.hpp" #include "physics/light/photometry.hpp" #include "physics/orbit/orbit.hpp" +#include "astro/illuminance.hpp" #include "render/material.hpp" #include "render/model.hpp" #include "render/passes/shadow-map-pass.hpp" @@ -110,14 +111,11 @@ void create_stars(game::context& ctx) // Transform XYZ color to ACEScg colorspace double3 color_acescg = color::xyz::to_acescg(color_xyz); - // Convert apparent magnitude to irradiance (W/m^2) - double vmag_irradiance = std::pow(10.0, 0.4 * (-vmag - 19.0 + 0.4)); - - // Convert irradiance to illuminance - double vmag_illuminance = vmag_irradiance * (683.0 * 0.14); + // Convert apparent magnitude to brightness factor relative to a 0th magnitude star + double brightness = astro::vmag_to_brightness(vmag); - // Scale color by illuminance - double3 scaled_color = color_acescg * vmag_illuminance; + // Scale color by relative brightness + double3 scaled_color = color_acescg * brightness; // Build vertex *(star_vertex++) = static_cast(position_inertial.x); @@ -126,7 +124,7 @@ void create_stars(game::context& ctx) *(star_vertex++) = static_cast(scaled_color.x); *(star_vertex++) = static_cast(scaled_color.y); *(star_vertex++) = static_cast(scaled_color.z); - *(star_vertex++) = static_cast(vmag); + *(star_vertex++) = static_cast(brightness); } // Unload star catalog