From 9ac47d2fe0b2c6fd39570ecc329b18e56b95e017 Mon Sep 17 00:00:00 2001 From: "C. J. Howard" Date: Mon, 10 Oct 2022 06:46:04 +0800 Subject: [PATCH] Add logarithmic zoom to nuptial flight cam --- src/game/ant/swarm.cpp | 2 +- src/game/state/main-menu.cpp | 3 +++ src/game/state/nuptial-flight.cpp | 45 ++++++++++++++++++------------- src/game/state/nuptial-flight.hpp | 4 +++ src/game/state/pause-menu.cpp | 1 + src/game/state/splash.cpp | 3 ++- 6 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src/game/ant/swarm.cpp b/src/game/ant/swarm.cpp index e93c005..aa1d718 100644 --- a/src/game/ant/swarm.cpp +++ b/src/game/ant/swarm.cpp @@ -71,7 +71,7 @@ entity::id create_swarm(game::context& ctx) // Init picking component game::component::picking picking; - picking.sphere = {float3{0, 0, 0}, 0.5f}; + picking.sphere = {float3{0, 0, 0}, 0.5f * 2.0f}; std::uint32_t male_picking_flags = 0b01; std::uint32_t queen_picking_flags = 0b10; diff --git a/src/game/state/main-menu.cpp b/src/game/state/main-menu.cpp index a1c9888..3bc71f0 100644 --- a/src/game/state/main-menu.cpp +++ b/src/game/state/main-menu.cpp @@ -290,6 +290,9 @@ main_menu::~main_menu() game::menu::remove_text_from_ui(ctx); game::menu::delete_text(ctx); + // Hide menu BG + ctx.menu_bg_billboard->set_active(false); + // Destruct title animation ctx.animator->remove_animation(&title_fade_animation); diff --git a/src/game/state/nuptial-flight.cpp b/src/game/state/nuptial-flight.cpp index 02d931e..1b79ccb 100644 --- a/src/game/state/nuptial-flight.cpp +++ b/src/game/state/nuptial-flight.cpp @@ -118,7 +118,7 @@ nuptial_flight::nuptial_flight(game::context& ctx): ); // Queue fade in - ctx.fade_transition_color->set_value({0, 0, 0}); + ctx.fade_transition_color->set_value({1, 1, 1}); ctx.function_queue.push(std::bind(&screen_transition::transition, ctx.fade_transition, config::nuptial_flight_fade_in_duration, true, ease::out_sine, true, nullptr)); // Queue control setup @@ -259,6 +259,8 @@ void nuptial_flight::create_camera_rig() ctx.entity_registry->emplace(camera_rig_eid, camera_rig_camera); ctx.entity_registry->emplace(camera_rig_eid, camera_rig_transform); ctx.entity_registry->emplace(camera_rig_eid, camera_rig_constraint_stack); + + set_camera_rig_zoom(0.5f); } void nuptial_flight::destroy_camera_rig() @@ -271,7 +273,24 @@ void nuptial_flight::destroy_camera_rig() ctx.entity_registry->destroy(camera_rig_focus_eid); ctx.entity_registry->destroy(camera_rig_focus_ease_to_eid); +} +void nuptial_flight::set_camera_rig_zoom(float zoom) +{ + const float near_distance = 1.0f; + const float far_distance = 50.0f; + + camera_rig_zoom = zoom; + const float distance = math::log_lerp(far_distance, near_distance, camera_rig_zoom); + + ctx.entity_registry->patch + ( + camera_rig_spring_translation_eid, + [&](auto& component) + { + component.spring.x1[2] = distance; + } + ); } void nuptial_flight::enable_controls() @@ -320,6 +339,8 @@ void nuptial_flight::enable_controls() const float gamepad_tilt_factor = gamepad_tilt_sensitivity * (gamepad_invert_tilt ? -1.0f : 1.0f); const float gamepad_pan_factor = gamepad_pan_sensitivity * (gamepad_invert_pan ? -1.0f : 1.0f); + const float dolly_zoom_speed = 4.0f; + // Mouse look ctx.controls["mouse_look"]->set_activated_callback ( @@ -484,32 +505,18 @@ void nuptial_flight::enable_controls() // Dolly in control ctx.controls["move_up"]->set_active_callback ( - [&](float value) + [&, dolly_zoom_speed](float value) { - ctx.entity_registry->patch - ( - camera_rig_spring_translation_eid, - [&](auto& component) - { - component.spring.x1[2] -= 100.0f * static_cast(ctx.loop.get_update_period()); - } - ); + set_camera_rig_zoom(std::min(1.0f, camera_rig_zoom + dolly_zoom_speed * static_cast(ctx.loop.get_update_period()))); } ); // Dolly out control ctx.controls["move_down"]->set_active_callback ( - [&](float value) + [&, dolly_zoom_speed](float value) { - ctx.entity_registry->patch - ( - camera_rig_spring_translation_eid, - [&](auto& component) - { - component.spring.x1[2] += 100.0f * static_cast(ctx.loop.get_update_period()); - } - ); + set_camera_rig_zoom(std::max(0.0f, camera_rig_zoom - dolly_zoom_speed * static_cast(ctx.loop.get_update_period()))); } ); diff --git a/src/game/state/nuptial-flight.hpp b/src/game/state/nuptial-flight.hpp index 2773663..a9f7f93 100644 --- a/src/game/state/nuptial-flight.hpp +++ b/src/game/state/nuptial-flight.hpp @@ -37,6 +37,8 @@ private: void create_camera_rig(); void destroy_camera_rig(); + void set_camera_rig_zoom(float zoom); + void enable_controls(); void disable_controls(); @@ -52,6 +54,8 @@ private: entity::id camera_rig_copy_translation_eid; entity::id camera_rig_pivot_eid; + float camera_rig_zoom; + entity::id swarm_eid; std::uint32_t selected_picking_flag; diff --git a/src/game/state/pause-menu.cpp b/src/game/state/pause-menu.cpp index 4723830..00621ee 100644 --- a/src/game/state/pause-menu.cpp +++ b/src/game/state/pause-menu.cpp @@ -139,6 +139,7 @@ pause_menu::pause_menu(game::context& ctx): { ctx.menu_bg_billboard->set_active(false); ctx.state_machine.pop(); + ctx.state_machine.pop(); ctx.state_machine.emplace(new game::state::main_menu(ctx, true)); } ); diff --git a/src/game/state/splash.cpp b/src/game/state/splash.cpp index fc412a5..0e6efec 100644 --- a/src/game/state/splash.cpp +++ b/src/game/state/splash.cpp @@ -117,7 +117,8 @@ splash::splash(game::context& ctx): [&ctx]() { ctx.state_machine.pop(); - ctx.state_machine.emplace(new game::state::nuptial_flight(ctx)); + ctx.state_machine.emplace(new game::state::main_menu(ctx, true)); + //ctx.state_machine.emplace(new game::state::nuptial_flight(ctx)); } ); }