From 165f4fdea146df8cd97ec83c17e47025a79d3dc0 Mon Sep 17 00:00:00 2001 From: "C. J. Howard" Date: Sun, 30 Aug 2020 18:23:21 -0700 Subject: [PATCH] Move rotation controls to control system and make rotation continuous --- src/game/bootloader.cpp | 18 ++---------------- src/game/game-context.hpp | 2 -- src/game/systems/control-system.cpp | 7 +++++++ 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/game/bootloader.cpp b/src/game/bootloader.cpp index 8c6764d..db55b69 100644 --- a/src/game/bootloader.cpp +++ b/src/game/bootloader.cpp @@ -910,18 +910,6 @@ void setup_controls(game_context* ctx) } ); - // Create rotation controls - ctx->rotate_ccw_control = new control(); - ctx->rotate_ccw_control->set_activated_callback - ( - std::bind(&camera_system::pan, ctx->camera_system, math::radians(90.0f)) - ); - ctx->rotate_cw_control = new control(); - ctx->rotate_cw_control->set_activated_callback - ( - std::bind(&camera_system::pan, ctx->camera_system, math::radians(-90.0f)) - ); - // Create menu back control ctx->menu_back_control = new control(); ctx->menu_back_control->set_activated_callback @@ -936,8 +924,6 @@ void setup_controls(game_context* ctx) ctx->application_controls = new control_set(); ctx->application_controls->add_control(ctx->toggle_fullscreen_control); ctx->application_controls->add_control(ctx->screenshot_control); - ctx->application_controls->add_control(ctx->rotate_ccw_control); - ctx->application_controls->add_control(ctx->rotate_cw_control); // Create menu control set ctx->menu_controls = new control_set(); @@ -952,8 +938,6 @@ void setup_controls(game_context* ctx) // Application control mappings ctx->input_event_router->add_mapping(key_mapping(ctx->toggle_fullscreen_control, nullptr, scancode::f11)); ctx->input_event_router->add_mapping(key_mapping(ctx->screenshot_control, nullptr, scancode::f12)); - ctx->input_event_router->add_mapping(key_mapping(ctx->rotate_ccw_control, nullptr, scancode::q)); - ctx->input_event_router->add_mapping(key_mapping(ctx->rotate_cw_control, nullptr, scancode::e)); // Add menu control mappings ctx->input_event_router->add_mapping(key_mapping(ctx->menu_back_control, nullptr, scancode::escape)); @@ -1021,6 +1005,8 @@ void setup_controls(game_context* ctx) ctx->input_event_router->add_mapping(game_controller_button_mapping(ctx->control_system->get_descend_control(), nullptr, game_controller_button::a)); ctx->input_event_router->add_mapping(game_controller_axis_mapping(ctx->control_system->get_zoom_out_control(), nullptr, game_controller_axis::trigger_left, false)); ctx->input_event_router->add_mapping(game_controller_axis_mapping(ctx->control_system->get_zoom_in_control(), nullptr, game_controller_axis::trigger_right, false)); + ctx->input_event_router->add_mapping(key_mapping(ctx->control_system->get_rotate_ccw_control(), nullptr, scancode::q)); + ctx->input_event_router->add_mapping(key_mapping(ctx->control_system->get_rotate_cw_control(), nullptr, scancode::e)); ctx->input_event_router->add_mapping(key_mapping(ctx->control_system->get_equip_forceps_control(), nullptr, scancode::one)); ctx->input_event_router->add_mapping(key_mapping(ctx->control_system->get_equip_brush_control(), nullptr, scancode::two)); diff --git a/src/game/game-context.hpp b/src/game/game-context.hpp index fdff8d0..d64a560 100644 --- a/src/game/game-context.hpp +++ b/src/game/game-context.hpp @@ -204,8 +204,6 @@ struct game_context control* menu_back_control; control* menu_select_control; control* screenshot_control; - control* rotate_ccw_control; - control* rotate_cw_control; control* toggle_fullscreen_control; // Entities diff --git a/src/game/systems/control-system.cpp b/src/game/systems/control-system.cpp index c72757b..be0f27d 100644 --- a/src/game/systems/control-system.cpp +++ b/src/game/systems/control-system.cpp @@ -96,6 +96,13 @@ void control_system::update(double t, double dt) if (zoom_out_control.is_active()) camera_system->zoom(-zoom_speed * dt); + // Rotate camera + const float rotation_speed = math::radians(270.0f); + if (rotate_ccw_control.is_active()) + camera_system->pan(rotation_speed * dt * std::min(1.0f, rotate_ccw_control.get_current_value())); + if (rotate_cw_control.is_active()) + camera_system->pan(-rotation_speed * dt * std::min(1.0f, rotate_cw_control.get_current_value())); + // Move camera float3 movement{0.0f, 0.0f, 0.0f}; if (move_right_control.is_active())