Browse Source

Add 3DOF constraint directly to underground camera, reduce input delay

master
C. J. Howard 3 years ago
parent
commit
0944cd50bb
3 changed files with 63 additions and 39 deletions
  1. +24
    -24
      src/game/bootloader.cpp
  2. +1
    -1
      src/game/context.hpp
  3. +38
    -14
      src/game/states/brood.cpp

+ 24
- 24
src/game/bootloader.cpp View File

@ -990,11 +990,11 @@ void setup_controls(game::context* ctx)
// Create camera controls // Create camera controls
ctx->camera_control_modifier = new input::control(); 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_left = new input::control();
ctx->camera_control_mouse_right = new input::control(); ctx->camera_control_mouse_right = new input::control();
ctx->camera_control_mouse_down = new input::control(); ctx->camera_control_mouse_down = new input::control();
ctx->camera_control_mouse_up = 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_forward = new input::control();
ctx->camera_control_dolly_backward = new input::control(); ctx->camera_control_dolly_backward = new input::control();
ctx->camera_control_truck_left = 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_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_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_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_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)); 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) [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 // Update tweens
ctx->time_tween->update(); ctx->time_tween->update();
ctx->surface_sky_pass->update_tweens(); ctx->surface_sky_pass->update_tweens();
@ -1232,28 +1254,6 @@ void setup_callbacks(game::context* ctx)
ctx->ui_system->update(dt); ctx->ui_system->update(dt);
ctx->render_system->update(t, dt); ctx->render_system->update(t, dt);
ctx->animator->animate(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();
} }
); );

+ 1
- 1
src/game/context.hpp View File

@ -229,11 +229,11 @@ struct context
input::control* screenshot_control; input::control* screenshot_control;
input::control* toggle_fullscreen_control; input::control* toggle_fullscreen_control;
input::control* camera_control_mouse_rotate;
input::control* camera_control_mouse_left; input::control* camera_control_mouse_left;
input::control* camera_control_mouse_right; input::control* camera_control_mouse_right;
input::control* camera_control_mouse_down; input::control* camera_control_mouse_down;
input::control* camera_control_mouse_up; input::control* camera_control_mouse_up;
input::control* camera_control_orbit;
input::control* camera_control_dolly_forward; input::control* camera_control_dolly_forward;
input::control* camera_control_dolly_backward; input::control* camera_control_dolly_backward;
input::control* camera_control_truck_left; input::control* camera_control_truck_left;

+ 38
- 14
src/game/states/brood.cpp View File

@ -165,6 +165,7 @@ void setup_camera(game::context* ctx)
target_transform.warp = true; target_transform.warp = true;
ctx->entity_registry->assign<entity::component::transform>(target_eid, target_transform); ctx->entity_registry->assign<entity::component::transform>(target_eid, target_transform);
/*
// 3DOF constraint // 3DOF constraint
entity::id three_dof_eid = entity::command::create(*ctx->entity_registry, "underground_cam_3dof"); entity::id three_dof_eid = entity::command::create(*ctx->entity_registry, "underground_cam_3dof");
entity::component::constraint::three_dof three_dof; entity::component::constraint::three_dof three_dof;
@ -182,6 +183,7 @@ void setup_camera(game::context* ctx)
entity::component::constraint_stack constraint_stack; entity::component::constraint_stack constraint_stack;
constraint_stack.head = three_dof_eid; constraint_stack.head = three_dof_eid;
ctx->entity_registry->assign<entity::component::constraint_stack>(target_eid, constraint_stack); ctx->entity_registry->assign<entity::component::constraint_stack>(target_eid, constraint_stack);
*/
} }
// Create camera entity // Create camera entity
@ -199,6 +201,24 @@ void setup_camera(game::context* ctx)
camera.object = ctx->underground_camera; camera.object = ctx->underground_camera;
ctx->entity_registry->assign<entity::component::camera>(camera_eid, camera); ctx->entity_registry->assign<entity::component::camera>(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<entity::component::constraint::three_dof>(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<entity::component::constraint_stack_node>(three_dof_constraint_eid, node);
}
// Create camera spring to constraint entity // Create camera spring to constraint entity
entity::id spring_constraint_eid = entity::command::create(*ctx->entity_registry); 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<float>}; 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<float>};
spring.translation.w = hz_to_rads(8.0f); 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<float>};
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<float>};
//spring.rotation.w = hz_to_rads(5.0f);
spring.spring_translation = true; spring.spring_translation = true;
spring.spring_rotation = true;
spring.spring_rotation = false;
ctx->entity_registry->assign<entity::component::constraint::spring_to>(spring_constraint_eid, spring); ctx->entity_registry->assign<entity::component::constraint::spring_to>(spring_constraint_eid, spring);
// Create constraint stack node component // Create constraint stack node component
entity::component::constraint_stack_node node; entity::component::constraint_stack_node node;
node.active = true; node.active = true;
node.weight = 1.0f; node.weight = 1.0f;
node.next = entt::null;
node.next = three_dof_constraint_eid;
ctx->entity_registry->assign<entity::component::constraint_stack_node>(spring_constraint_eid, node); ctx->entity_registry->assign<entity::component::constraint_stack_node>(spring_constraint_eid, node);
} }
@ -258,9 +278,10 @@ void setup_controls(game::context* ctx)
const float dolly_speed = 10.0f; const float dolly_speed = 10.0f;
const float truck_speed = dolly_speed; const float truck_speed = dolly_speed;
const float pedestal_speed = 20.0f; 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; const float tilt_speed = pan_speed;
// Dolly forward
ctx->camera_control_dolly_forward->set_active_callback ctx->camera_control_dolly_forward->set_active_callback
( (
[ctx, target_eid, three_dof_eid, truck_speed](float value) [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->camera_control_dolly_backward->set_active_callback
( (
[ctx, target_eid, three_dof_eid, truck_speed](float value) [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->camera_control_truck_right->set_active_callback
( (
[ctx, target_eid, three_dof_eid, truck_speed](float value) [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->camera_control_truck_left->set_active_callback
( (
[ctx, target_eid, three_dof_eid, truck_speed](float value) [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]()
{ {
ctx->app->set_relative_mouse_mode(true); ctx->app->set_relative_mouse_mode(true);
} }
); );
ctx->camera_control_orbit->set_deactivated_callback
ctx->camera_control_mouse_rotate->set_deactivated_callback
( (
[ctx]() [ctx]()
{ {
@ -376,7 +400,7 @@ void setup_controls(game::context* ctx)
( (
[ctx, three_dof_eid, pan_speed](float value) [ctx, three_dof_eid, pan_speed](float value)
{ {
if (!ctx->camera_control_orbit->is_active())
if (!ctx->camera_control_mouse_rotate->is_active())
return; return;
auto& three_dof = ctx->entity_registry->get<entity::component::constraint::three_dof>(three_dof_eid); auto& three_dof = ctx->entity_registry->get<entity::component::constraint::three_dof>(three_dof_eid);
@ -389,7 +413,7 @@ void setup_controls(game::context* ctx)
( (
[ctx, three_dof_eid, pan_speed](float value) [ctx, three_dof_eid, pan_speed](float value)
{ {
if (!ctx->camera_control_orbit->is_active())
if (!ctx->camera_control_mouse_rotate->is_active())
return; return;
auto& three_dof = ctx->entity_registry->get<entity::component::constraint::three_dof>(three_dof_eid); auto& three_dof = ctx->entity_registry->get<entity::component::constraint::three_dof>(three_dof_eid);
@ -402,12 +426,12 @@ void setup_controls(game::context* ctx)
( (
[ctx, three_dof_eid, tilt_speed](float value) [ctx, three_dof_eid, tilt_speed](float value)
{ {
if (!ctx->camera_control_orbit->is_active())
if (!ctx->camera_control_mouse_rotate->is_active())
return; return;
auto& three_dof = ctx->entity_registry->get<entity::component::constraint::three_dof>(three_dof_eid); auto& three_dof = ctx->entity_registry->get<entity::component::constraint::three_dof>(three_dof_eid);
three_dof.pitch -= tilt_speed * value * (1.0f / 60.0f); three_dof.pitch -= tilt_speed * value * (1.0f / 60.0f);
three_dof.pitch = std::max<float>(math::radians(-89.0f), three_dof.pitch);
three_dof.pitch = std::max<float>(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) [ctx, three_dof_eid, tilt_speed](float value)
{ {
if (!ctx->camera_control_orbit->is_active())
if (!ctx->camera_control_mouse_rotate->is_active())
return; return;
auto& three_dof = ctx->entity_registry->get<entity::component::constraint::three_dof>(three_dof_eid); auto& three_dof = ctx->entity_registry->get<entity::component::constraint::three_dof>(three_dof_eid);
three_dof.pitch += tilt_speed * value * (1.0f / 60.0f); three_dof.pitch += tilt_speed * value * (1.0f / 60.0f);
three_dof.pitch = std::min<float>(math::radians(89.0f), three_dof.pitch);
three_dof.pitch = std::min<float>(math::radians(89.9f), three_dof.pitch);
} }
); );
} }

Loading…
Cancel
Save