Browse Source

Add support for toggling mouse look

master
C. J. Howard 3 years ago
parent
commit
7dfe0bbaee
3 changed files with 30 additions and 16 deletions
  1. +1
    -0
      src/game/context.hpp
  2. +28
    -15
      src/game/states/forage.cpp
  3. +1
    -1
      src/game/states/loading.cpp

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

@ -216,6 +216,7 @@ struct context
input::mapper* input_mapper; input::mapper* input_mapper;
input::listener* input_listener; input::listener* input_listener;
std::unordered_map<std::string, input::control*> controls; std::unordered_map<std::string, input::control*> controls;
bool mouse_look;
// Parallel processes // Parallel processes
std::unordered_map<std::string, std::function<void(double, double)>> processes; std::unordered_map<std::string, std::function<void(double, double)>> processes;

+ 28
- 15
src/game/states/forage.cpp View File

@ -279,6 +279,8 @@ void setup_controls(game::context* ctx)
float gamepad_pan_sensitivity = 1.0f; float gamepad_pan_sensitivity = 1.0f;
bool gamepad_invert_tilt = false; bool gamepad_invert_tilt = false;
bool gamepad_invert_pan = false; bool gamepad_invert_pan = false;
bool mouse_look_toggle = false;
ctx->mouse_look = false;
if (ctx->config->contains("mouse_tilt_sensitivity")) if (ctx->config->contains("mouse_tilt_sensitivity"))
mouse_tilt_sensitivity = math::radians((*ctx->config)["mouse_tilt_sensitivity"].get<float>()); mouse_tilt_sensitivity = math::radians((*ctx->config)["mouse_tilt_sensitivity"].get<float>());
@ -288,6 +290,8 @@ void setup_controls(game::context* ctx)
mouse_invert_tilt = math::radians((*ctx->config)["mouse_invert_tilt"].get<bool>()); mouse_invert_tilt = math::radians((*ctx->config)["mouse_invert_tilt"].get<bool>());
if (ctx->config->contains("mouse_invert_pan")) if (ctx->config->contains("mouse_invert_pan"))
mouse_invert_pan = math::radians((*ctx->config)["mouse_invert_pan"].get<bool>()); mouse_invert_pan = math::radians((*ctx->config)["mouse_invert_pan"].get<bool>());
if (ctx->config->contains("mouse_look_toggle"))
mouse_look_toggle = math::radians((*ctx->config)["mouse_look_toggle"].get<bool>());
if (ctx->config->contains("gamepad_tilt_sensitivity")) if (ctx->config->contains("gamepad_tilt_sensitivity"))
gamepad_tilt_sensitivity = math::radians((*ctx->config)["gamepad_tilt_sensitivity"].get<float>()); gamepad_tilt_sensitivity = math::radians((*ctx->config)["gamepad_tilt_sensitivity"].get<float>());
@ -300,7 +304,7 @@ void setup_controls(game::context* ctx)
const input::control* move_slow = ctx->controls["move_slow"]; const input::control* move_slow = ctx->controls["move_slow"];
const input::control* move_fast = ctx->controls["move_fast"]; const input::control* move_fast = ctx->controls["move_fast"];
const input::control* mouse_rotate = ctx->controls["mouse_rotate"];
const input::control* mouse_look = ctx->controls["mouse_look"];
float mouse_tilt_factor = mouse_tilt_sensitivity * (mouse_invert_tilt ? -1.0f : 1.0f); float mouse_tilt_factor = mouse_tilt_sensitivity * (mouse_invert_tilt ? -1.0f : 1.0f);
float mouse_pan_factor = mouse_pan_sensitivity * (mouse_invert_pan ? -1.0f : 1.0f); float mouse_pan_factor = mouse_pan_sensitivity * (mouse_invert_pan ? -1.0f : 1.0f);
@ -409,18 +413,27 @@ void setup_controls(game::context* ctx)
); );
// Mouse rotate // Mouse rotate
ctx->controls["mouse_rotate"]->set_activated_callback
ctx->controls["mouse_look"]->set_activated_callback
( (
[ctx]()
[ctx, mouse_look_toggle]()
{ {
ctx->app->set_relative_mouse_mode(true);
if (mouse_look_toggle)
ctx->mouse_look = !ctx->mouse_look;
else
ctx->mouse_look = true;
ctx->app->set_relative_mouse_mode(ctx->mouse_look);
} }
); );
ctx->controls["mouse_rotate"]->set_deactivated_callback
ctx->controls["mouse_look"]->set_deactivated_callback
( (
[ctx]()
[ctx, mouse_look_toggle]()
{ {
ctx->app->set_relative_mouse_mode(false);
if (!mouse_look_toggle)
{
ctx->mouse_look = false;
ctx->app->set_relative_mouse_mode(false);
}
} }
); );
@ -435,9 +448,9 @@ void setup_controls(game::context* ctx)
); );
ctx->controls["pan_left_mouse"]->set_active_callback ctx->controls["pan_left_mouse"]->set_active_callback
( (
[ctx, three_dof_eid, mouse_pan_factor, mouse_rotate](float value)
[ctx, three_dof_eid, mouse_pan_factor](float value)
{ {
if (!mouse_rotate->is_active())
if (!ctx->mouse_look)
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);
@ -456,9 +469,9 @@ void setup_controls(game::context* ctx)
); );
ctx->controls["pan_right_mouse"]->set_active_callback ctx->controls["pan_right_mouse"]->set_active_callback
( (
[ctx, three_dof_eid, mouse_pan_factor, mouse_rotate](float value)
[ctx, three_dof_eid, mouse_pan_factor](float value)
{ {
if (!mouse_rotate->is_active())
if (!ctx->mouse_look)
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);
@ -478,9 +491,9 @@ void setup_controls(game::context* ctx)
); );
ctx->controls["tilt_up_mouse"]->set_active_callback ctx->controls["tilt_up_mouse"]->set_active_callback
( (
[ctx, three_dof_eid, mouse_tilt_factor, mouse_rotate](float value)
[ctx, three_dof_eid, mouse_tilt_factor](float value)
{ {
if (!mouse_rotate->is_active())
if (!ctx->mouse_look)
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);
@ -501,9 +514,9 @@ void setup_controls(game::context* ctx)
); );
ctx->controls["tilt_down_mouse"]->set_active_callback ctx->controls["tilt_down_mouse"]->set_active_callback
( (
[ctx, three_dof_eid, mouse_tilt_factor, mouse_rotate](float value)
[ctx, three_dof_eid, mouse_tilt_factor](float value)
{ {
if (!mouse_rotate->is_active())
if (!ctx->mouse_look)
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);

+ 1
- 1
src/game/states/loading.cpp View File

@ -144,7 +144,7 @@ void load_controls(game::context* ctx)
ctx->controls["pedestal_down"] = new input::control(); ctx->controls["pedestal_down"] = new input::control();
ctx->controls["move_slow"] = new input::control(); ctx->controls["move_slow"] = new input::control();
ctx->controls["move_fast"] = new input::control(); ctx->controls["move_fast"] = new input::control();
ctx->controls["mouse_rotate"] = new input::control();
ctx->controls["mouse_look"] = new input::control();
ctx->controls["pan_left_gamepad"] = new input::control(); ctx->controls["pan_left_gamepad"] = new input::control();
ctx->controls["pan_left_mouse"] = new input::control(); ctx->controls["pan_left_mouse"] = new input::control();
ctx->controls["pan_right_gamepad"] = new input::control(); ctx->controls["pan_right_gamepad"] = new input::control();

Loading…
Cancel
Save