diff --git a/src/game/bootloader.cpp b/src/game/bootloader.cpp index 9ebf4d6..76c851b 100644 --- a/src/game/bootloader.cpp +++ b/src/game/bootloader.cpp @@ -990,11 +990,11 @@ void setup_controls(game::context* ctx) // Create camera controls ctx->camera_control_modifier = new input::control(); + ctx->camera_control_mouse_rotate = new input::control(); ctx->camera_control_mouse_left = new input::control(); ctx->camera_control_mouse_right = new input::control(); ctx->camera_control_mouse_down = new input::control(); ctx->camera_control_mouse_up = new input::control(); - ctx->camera_control_orbit = new input::control(); ctx->camera_control_dolly_forward = new input::control(); ctx->camera_control_dolly_backward = new input::control(); ctx->camera_control_truck_left = new input::control(); @@ -1108,7 +1108,7 @@ void setup_controls(game::context* ctx) ctx->input_event_router->add_mapping(input::mouse_wheel_mapping(ctx->camera_control_pedestal_up, nullptr, input::mouse_wheel_axis::positive_y)); ctx->input_event_router->add_mapping(input::mouse_wheel_mapping(ctx->camera_control_pedestal_down, nullptr, input::mouse_wheel_axis::negative_y)); - ctx->input_event_router->add_mapping(input::mouse_button_mapping(ctx->camera_control_orbit, nullptr, 3)); + ctx->input_event_router->add_mapping(input::mouse_button_mapping(ctx->camera_control_mouse_rotate, nullptr, 3)); ctx->input_event_router->add_mapping(input::mouse_motion_mapping(ctx->camera_control_mouse_left, nullptr, input::mouse_motion_axis::negative_x)); ctx->input_event_router->add_mapping(input::mouse_motion_mapping(ctx->camera_control_mouse_right, nullptr, input::mouse_motion_axis::positive_x)); ctx->input_event_router->add_mapping(input::mouse_motion_mapping(ctx->camera_control_mouse_down, nullptr, input::mouse_motion_axis::positive_y)); @@ -1181,6 +1181,28 @@ void setup_callbacks(game::context* ctx) ( [ctx](double t, double dt) { + // Update controls + ctx->application_controls->update(); + ctx->menu_controls->update(); + ctx->camera_controls->update(); + ctx->control_system->update(t, dt); + ctx->camera_control_modifier->update(); + ctx->camera_control_mouse_rotate->update(); + ctx->camera_control_mouse_left->update(); + ctx->camera_control_mouse_right->update(); + ctx->camera_control_mouse_down->update(); + ctx->camera_control_mouse_up->update(); + ctx->camera_control_dolly_forward->update(); + ctx->camera_control_dolly_backward->update(); + ctx->camera_control_truck_left->update(); + ctx->camera_control_truck_right->update(); + ctx->camera_control_pedestal_up->update(); + ctx->camera_control_pedestal_down->update(); + ctx->camera_control_pan_left->update(); + ctx->camera_control_pan_right->update(); + ctx->camera_control_tilt_up->update(); + ctx->camera_control_tilt_down->update(); + // Update tweens ctx->time_tween->update(); ctx->surface_sky_pass->update_tweens(); @@ -1232,28 +1254,6 @@ void setup_callbacks(game::context* ctx) ctx->ui_system->update(dt); ctx->render_system->update(t, dt); ctx->animator->animate(dt); - - ctx->application_controls->update(); - ctx->menu_controls->update(); - ctx->camera_controls->update(); - - ctx->control_system->update(t, dt); - ctx->camera_control_modifier->update(); - ctx->camera_control_mouse_left->update(); - ctx->camera_control_mouse_right->update(); - ctx->camera_control_mouse_down->update(); - ctx->camera_control_mouse_up->update(); - ctx->camera_control_dolly_forward->update(); - ctx->camera_control_dolly_backward->update(); - ctx->camera_control_truck_left->update(); - ctx->camera_control_truck_right->update(); - ctx->camera_control_pedestal_up->update(); - ctx->camera_control_pedestal_down->update(); - ctx->camera_control_pan_left->update(); - ctx->camera_control_pan_right->update(); - ctx->camera_control_tilt_up->update(); - ctx->camera_control_tilt_down->update(); - ctx->camera_control_orbit->update(); } ); diff --git a/src/game/context.hpp b/src/game/context.hpp index 64e655e..9365fba 100644 --- a/src/game/context.hpp +++ b/src/game/context.hpp @@ -229,11 +229,11 @@ struct context input::control* screenshot_control; input::control* toggle_fullscreen_control; + input::control* camera_control_mouse_rotate; input::control* camera_control_mouse_left; input::control* camera_control_mouse_right; input::control* camera_control_mouse_down; input::control* camera_control_mouse_up; - input::control* camera_control_orbit; input::control* camera_control_dolly_forward; input::control* camera_control_dolly_backward; input::control* camera_control_truck_left; diff --git a/src/game/states/brood.cpp b/src/game/states/brood.cpp index 94e469b..b89c20c 100644 --- a/src/game/states/brood.cpp +++ b/src/game/states/brood.cpp @@ -165,6 +165,7 @@ void setup_camera(game::context* ctx) target_transform.warp = true; ctx->entity_registry->assign(target_eid, target_transform); + /* // 3DOF constraint entity::id three_dof_eid = entity::command::create(*ctx->entity_registry, "underground_cam_3dof"); entity::component::constraint::three_dof three_dof; @@ -182,6 +183,7 @@ void setup_camera(game::context* ctx) entity::component::constraint_stack constraint_stack; constraint_stack.head = three_dof_eid; ctx->entity_registry->assign(target_eid, constraint_stack); + */ } // Create camera entity @@ -199,6 +201,24 @@ void setup_camera(game::context* ctx) camera.object = ctx->underground_camera; ctx->entity_registry->assign(camera_eid, camera); + // Create camera 3DOF constraint entity + entity::id three_dof_constraint_eid = entity::command::create(*ctx->entity_registry, "underground_cam_3dof"); + { + // Create 3DOF to constraint + entity::component::constraint::three_dof three_dof; + three_dof.yaw = 0.0f; + three_dof.pitch = 0.0f; + three_dof.roll = 0.0f; + ctx->entity_registry->assign(three_dof_constraint_eid, three_dof); + + // Create constraint stack node component + entity::component::constraint_stack_node node; + node.active = true; + node.weight = 1.0f; + node.next = entt::null; + ctx->entity_registry->assign(three_dof_constraint_eid, node); + } + // Create camera spring to constraint entity entity::id spring_constraint_eid = entity::command::create(*ctx->entity_registry); { @@ -208,18 +228,18 @@ void setup_camera(game::context* ctx) spring.translation = {{0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}, 1.0f, math::two_pi}; spring.translation.w = hz_to_rads(8.0f); - spring.rotation = {{1.0f, 0.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 0.0f}, 1.0f, math::two_pi}; - spring.rotation.w = hz_to_rads(8.0f); + //spring.rotation = {{1.0f, 0.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 0.0f}, 1.0f, math::two_pi}; + //spring.rotation.w = hz_to_rads(5.0f); spring.spring_translation = true; - spring.spring_rotation = true; + spring.spring_rotation = false; ctx->entity_registry->assign(spring_constraint_eid, spring); // Create constraint stack node component entity::component::constraint_stack_node node; node.active = true; node.weight = 1.0f; - node.next = entt::null; + node.next = three_dof_constraint_eid; ctx->entity_registry->assign(spring_constraint_eid, node); } @@ -258,9 +278,10 @@ void setup_controls(game::context* ctx) const float dolly_speed = 10.0f; const float truck_speed = dolly_speed; const float pedestal_speed = 20.0f; - const float pan_speed = math::radians(10.0f); + const float pan_speed = math::radians(8.0f); const float tilt_speed = pan_speed; + // Dolly forward ctx->camera_control_dolly_forward->set_active_callback ( [ctx, target_eid, three_dof_eid, truck_speed](float value) @@ -273,6 +294,7 @@ void setup_controls(game::context* ctx) } ); + // Dolly backward ctx->camera_control_dolly_backward->set_active_callback ( [ctx, target_eid, three_dof_eid, truck_speed](float value) @@ -285,6 +307,7 @@ void setup_controls(game::context* ctx) } ); + // Truck right ctx->camera_control_truck_right->set_active_callback ( [ctx, target_eid, three_dof_eid, truck_speed](float value) @@ -297,6 +320,7 @@ void setup_controls(game::context* ctx) } ); + // Truck left ctx->camera_control_truck_left->set_active_callback ( [ctx, target_eid, three_dof_eid, truck_speed](float value) @@ -355,15 +379,15 @@ void setup_controls(game::context* ctx) } ); - ctx->camera_control_orbit->set_activated_callback + // Mouse rotate + ctx->camera_control_mouse_rotate->set_activated_callback ( [ctx]() { ctx->app->set_relative_mouse_mode(true); } ); - - ctx->camera_control_orbit->set_deactivated_callback + ctx->camera_control_mouse_rotate->set_deactivated_callback ( [ctx]() { @@ -376,7 +400,7 @@ void setup_controls(game::context* ctx) ( [ctx, three_dof_eid, pan_speed](float value) { - if (!ctx->camera_control_orbit->is_active()) + if (!ctx->camera_control_mouse_rotate->is_active()) return; auto& three_dof = ctx->entity_registry->get(three_dof_eid); @@ -389,7 +413,7 @@ void setup_controls(game::context* ctx) ( [ctx, three_dof_eid, pan_speed](float value) { - if (!ctx->camera_control_orbit->is_active()) + if (!ctx->camera_control_mouse_rotate->is_active()) return; auto& three_dof = ctx->entity_registry->get(three_dof_eid); @@ -402,12 +426,12 @@ void setup_controls(game::context* ctx) ( [ctx, three_dof_eid, tilt_speed](float value) { - if (!ctx->camera_control_orbit->is_active()) + if (!ctx->camera_control_mouse_rotate->is_active()) return; auto& three_dof = ctx->entity_registry->get(three_dof_eid); three_dof.pitch -= tilt_speed * value * (1.0f / 60.0f); - three_dof.pitch = std::max(math::radians(-89.0f), three_dof.pitch); + three_dof.pitch = std::max(math::radians(-89.9f), three_dof.pitch); } ); @@ -416,12 +440,12 @@ void setup_controls(game::context* ctx) ( [ctx, three_dof_eid, tilt_speed](float value) { - if (!ctx->camera_control_orbit->is_active()) + if (!ctx->camera_control_mouse_rotate->is_active()) return; auto& three_dof = ctx->entity_registry->get(three_dof_eid); three_dof.pitch += tilt_speed * value * (1.0f / 60.0f); - three_dof.pitch = std::min(math::radians(89.0f), three_dof.pitch); + three_dof.pitch = std::min(math::radians(89.9f), three_dof.pitch); } ); }