Browse Source

Add solar system to game context

master
C. J. Howard 4 years ago
parent
commit
a2377af35a
8 changed files with 57 additions and 24 deletions
  1. +1
    -1
      src/game/astronomy/celestial-mechanics.cpp
  2. +9
    -0
      src/game/astronomy/celestial-mechanics.hpp
  3. +13
    -0
      src/game/bootloader.cpp
  4. +2
    -0
      src/game/game-context.hpp
  5. +6
    -0
      src/game/states/play-state.cpp
  6. +22
    -22
      src/game/systems/solar-system.cpp
  7. +3
    -0
      src/game/systems/solar-system.hpp
  8. +1
    -1
      src/game/systems/weather-system.cpp

+ 1
- 1
src/game/astronomy/celestial-mechanics.cpp View File

@ -177,7 +177,7 @@ double3 solve_kepler(double a, double ec, double w, double ma, double i, double
// Eccentric anomaly // Eccentric anomaly
double ea = ma + ec * std::sin(ma) * (1.0 + ec * std::cos(ma)); double ea = ma + ec * std::sin(ma) * (1.0 + ec * std::cos(ma));
// Find radial distance (r) and true anomaly (v)
// Radial distance (r) and true anomaly (v)
double x = a * (std::cos(ea) - ec); double x = a * (std::cos(ea) - ec);
double y = b * std::sin(ea); double y = b * std::sin(ea);
double r = std::sqrt(x * x + y * y); double r = std::sqrt(x * x + y * y);

+ 9
- 0
src/game/astronomy/celestial-mechanics.hpp View File

@ -69,6 +69,15 @@ struct kepler_orbit
double3 solve_kepler(const kepler_orbit& orbit, double t); double3 solve_kepler(const kepler_orbit& orbit, double t);
/**
*
* @param a Semi-major axis, a.
* @param ec Eccentricity, e.
* @param w Argument of periapsis, w (radians).
* @param ma Mean anomaly, M (radians).
* @param i Inclination, i (radians).
* @param om Longitude of the ascending node, OMEGA (radians).
*/
double3 solve_kepler(double a, double ec, double w, double ma, double i, double om); double3 solve_kepler(double a, double ec, double w, double ma, double i, double om);
} // namespace ast } // namespace ast

+ 13
- 0
src/game/bootloader.cpp View File

@ -79,6 +79,7 @@
#include "game/systems/tracking-system.hpp" #include "game/systems/tracking-system.hpp"
#include "game/systems/painting-system.hpp" #include "game/systems/painting-system.hpp"
#include "game/systems/weather-system.hpp" #include "game/systems/weather-system.hpp"
#include "game/systems/solar-system.hpp"
#include "game/components/marker-component.hpp" #include "game/components/marker-component.hpp"
#include "game/entity-commands.hpp" #include "game/entity-commands.hpp"
#include "utility/paths.hpp" #include "utility/paths.hpp"
@ -886,6 +887,13 @@ void setup_systems(game_context* ctx)
ctx->weather_system->set_time_scale(ctx->config->get<float>("time_scale")); ctx->weather_system->set_time_scale(ctx->config->get<float>("time_scale"));
} }
// Setup solar system
ctx->solar_system = new solar_system(*ctx->ecs_registry);
if (ctx->config->has("time_scale"))
{
ctx->solar_system->set_time_scale(ctx->config->get<float>("time_scale"));
}
// Setup render system // Setup render system
ctx->render_system = new ::render_system(*ctx->ecs_registry); ctx->render_system = new ::render_system(*ctx->ecs_registry);
ctx->render_system->add_layer(ctx->overworld_scene); ctx->render_system->add_layer(ctx->overworld_scene);
@ -1183,6 +1191,7 @@ void setup_controls(game_context* ctx)
[ctx, time_scale]() [ctx, time_scale]()
{ {
ctx->weather_system->set_time_scale(time_scale * 50.0f); ctx->weather_system->set_time_scale(time_scale * 50.0f);
ctx->solar_system->set_time_scale(time_scale * 50.0f);
} }
); );
ctx->control_system->get_fast_forward_control()->set_deactivated_callback ctx->control_system->get_fast_forward_control()->set_deactivated_callback
@ -1190,6 +1199,7 @@ void setup_controls(game_context* ctx)
[ctx, time_scale]() [ctx, time_scale]()
{ {
ctx->weather_system->set_time_scale(time_scale); ctx->weather_system->set_time_scale(time_scale);
ctx->solar_system->set_time_scale(time_scale);
} }
); );
ctx->control_system->get_rewind_control()->set_activated_callback ctx->control_system->get_rewind_control()->set_activated_callback
@ -1197,6 +1207,7 @@ void setup_controls(game_context* ctx)
[ctx, time_scale]() [ctx, time_scale]()
{ {
ctx->weather_system->set_time_scale(time_scale * -50.0f); ctx->weather_system->set_time_scale(time_scale * -50.0f);
ctx->solar_system->set_time_scale(time_scale * -50.0f);
} }
); );
ctx->control_system->get_rewind_control()->set_deactivated_callback ctx->control_system->get_rewind_control()->set_deactivated_callback
@ -1204,6 +1215,7 @@ void setup_controls(game_context* ctx)
[ctx, time_scale]() [ctx, time_scale]()
{ {
ctx->weather_system->set_time_scale(time_scale); ctx->weather_system->set_time_scale(time_scale);
ctx->solar_system->set_time_scale(time_scale);
} }
); );
@ -1264,6 +1276,7 @@ void setup_callbacks(game_context* ctx)
ctx->tracking_system->update(t, dt); ctx->tracking_system->update(t, dt);
ctx->painting_system->update(t, dt); ctx->painting_system->update(t, dt);
ctx->weather_system->update(t, dt); ctx->weather_system->update(t, dt);
ctx->solar_system->update(t, dt);
//(*ctx->focal_point_tween)[1] = ctx->orbit_cam->get_focal_point(); //(*ctx->focal_point_tween)[1] = ctx->orbit_cam->get_focal_point();

+ 2
- 0
src/game/game-context.hpp View File

@ -87,6 +87,7 @@ class outline_pass;
class tracking_system; class tracking_system;
class painting_system; class painting_system;
class weather_system; class weather_system;
class solar_system;
struct biome; struct biome;
template <typename T> class animation; template <typename T> class animation;
template <typename T> class material_property; template <typename T> class material_property;
@ -244,6 +245,7 @@ struct game_context
tracking_system* tracking_system; tracking_system* tracking_system;
painting_system* painting_system; painting_system* painting_system;
weather_system* weather_system; weather_system* weather_system;
solar_system* solar_system;
// Game // Game
biome* biome; biome* biome;

+ 6
- 0
src/game/states/play-state.cpp View File

@ -55,9 +55,11 @@
#include "game/systems/render-system.hpp" #include "game/systems/render-system.hpp"
#include "game/systems/tool-system.hpp" #include "game/systems/tool-system.hpp"
#include "game/systems/weather-system.hpp" #include "game/systems/weather-system.hpp"
#include "game/systems/solar-system.hpp"
#include "game/biome.hpp" #include "game/biome.hpp"
#include "utility/fundamental-types.hpp" #include "utility/fundamental-types.hpp"
#include "utility/gamma.hpp" #include "utility/gamma.hpp"
#include "game/astronomy/celestial-time.hpp"
void play_state_enter(game_context* ctx) void play_state_enter(game_context* ctx)
{ {
@ -87,6 +89,10 @@ void play_state_enter(game_context* ctx)
ctx->weather_system->set_ambient_palette(ctx->biome->ambient_palette); ctx->weather_system->set_ambient_palette(ctx->biome->ambient_palette);
ctx->weather_system->set_moon_palette(ctx->biome->moon_palette); ctx->weather_system->set_moon_palette(ctx->biome->moon_palette);
ctx->weather_system->set_shadow_palette(ctx->biome->shadow_palette); ctx->weather_system->set_shadow_palette(ctx->biome->shadow_palette);
ctx->solar_system->set_observer_location(ctx->biome->location[0], ctx->biome->location[1], ctx->biome->location[2]);
double jd = ast::ut_to_jd(2017, 6, 1, 5, 0, 0.0) - -7.0 / 24.0;
ctx->solar_system->set_julian_date(jd);
resource_manager* resource_manager = ctx->resource_manager; resource_manager* resource_manager = ctx->resource_manager;
entt::registry& ecs_registry = *ctx->ecs_registry; entt::registry& ecs_registry = *ctx->ecs_registry;

+ 22
- 22
src/game/systems/solar-system.cpp View File

@ -44,28 +44,28 @@ void solar_system::update(double t, double dt)
// Update horizontal (topocentric) positions of orbiting bodies // Update horizontal (topocentric) positions of orbiting bodies
registry.view<orbit_component, transform_component>().each( registry.view<orbit_component, transform_component>().each(
[&](auto entity, auto& orbit, auto& transform)
{
double a = orbit.a;
double ec = orbit.ec;
double w = orbit.w;
double ma = orbit.ma;
double i = orbit.i;
double om = orbit.om;
double3 ecliptic = ast::solve_kepler(a, ec, w, ma, i, om);
double3 horizontal = ecliptic_to_horizontal * ecliptic;
// Subtract Earth's radius (in AU), for positon of observer
horizontal.z -= 4.25875e-5;
// Transform into local right-handed coordinates
double3 translation = ast::horizontal_to_right_handed * horizontal;
double3x3 rotation = ast::horizontal_to_right_handed * ecliptic_to_horizontal;
transform.local.translation = math::type_cast<float>(translation);
transform.local.rotation = math::type_cast<float>(math::quaternion_cast(rotation));
});
[&](auto entity, auto& orbit, auto& transform)
{
double a = orbit.a;
double ec = orbit.ec;
double w = orbit.w;
double ma = orbit.ma;
double i = orbit.i;
double om = orbit.om;
double3 ecliptic = ast::solve_kepler(a, ec, w, ma, i, om);
double3 horizontal = ecliptic_to_horizontal * ecliptic;
// Subtract Earth's radius (in AU), for positon of observer
horizontal.z -= 4.25875e-5;
// Transform into local right-handed coordinates
double3 translation = ast::horizontal_to_right_handed * horizontal;
double3x3 rotation = ast::horizontal_to_right_handed * ecliptic_to_horizontal;
transform.local.translation = math::type_cast<float>(translation);
transform.local.rotation = math::type_cast<float>(math::quaternion_cast(rotation));
});
} }
void solar_system::set_julian_date(double jd) void solar_system::set_julian_date(double jd)

+ 3
- 0
src/game/systems/solar-system.hpp View File

@ -23,6 +23,9 @@
#include "entity-system.hpp" #include "entity-system.hpp"
#include "utility/fundamental-types.hpp" #include "utility/fundamental-types.hpp"
/**
*
*/
class solar_system: class solar_system:
public entity_system public entity_system
{ {

+ 1
- 1
src/game/systems/weather-system.cpp View File

@ -90,7 +90,7 @@ void weather_system::update(double t, double dt)
float3 moon_position = math::normalize(math::type_cast<float>(moon_positiond)); float3 moon_position = math::normalize(math::type_cast<float>(moon_positiond));
//double3 moon_sphericald = ast::rectangular_to_spherical(moon_positiond); //double3 moon_sphericald = ast::rectangular_to_spherical(moon_positiond);
//std::cout << "old azel: " << math::degrees(moon_az_el.x) << ", " << math::degrees(moon_az_el.y) << std::endl;
std::cout << "old azel: " << math::degrees(sun_az_el.x) << ", " << math::degrees(sun_az_el.y) << std::endl;
//std::cout << "new azel: " << math::degrees(moon_sphericald.z) << ", " << math::degrees(moon_sphericald.y) << std::endl; //std::cout << "new azel: " << math::degrees(moon_sphericald.z) << ", " << math::degrees(moon_sphericald.y) << std::endl;
double3x3 moon_rotation_matrix = ast::horizontal_to_right_handed * ecliptic_to_horizontal; double3x3 moon_rotation_matrix = ast::horizontal_to_right_handed * ecliptic_to_horizontal;

Loading…
Cancel
Save