Follow-up of f912fecad5 -> option to swap y/z axes extended to rotations

This commit is contained in:
Enrico Turri 2020-03-20 16:13:08 +01:00
parent f912fecad5
commit 7c56cc9f22
4 changed files with 19 additions and 17 deletions

View file

@ -150,14 +150,16 @@ bool Mouse3DController::State::apply(const Mouse3DController::Params &params, Ca
for (const QueueItem &input_queue_item : input_queue) {
if (input_queue_item.is_translation()) {
Vec3d translation = params.swap_yz_translations ? Vec3d(input_queue_item.vector(0), input_queue_item.vector(2), input_queue_item.vector(1)) : input_queue_item.vector;
Vec3d translation = params.swap_yz ? Vec3d(input_queue_item.vector(0), input_queue_item.vector(2), input_queue_item.vector(1)) : input_queue_item.vector;
double zoom_factor = camera.min_zoom() / camera.get_zoom();
camera.set_target(camera.get_target() + zoom_factor * params.translation.scale * (translation.x() * camera.get_dir_right() + translation.z() * camera.get_dir_up()));
if (translation.y() != 0.0)
camera.update_zoom(params.zoom.scale * translation.y());
} else if (input_queue_item.is_rotation()) {
Vec3d rot = params.rotation.scale * input_queue_item.vector * (PI / 180.);
camera.rotate_local_around_target(Vec3d(rot.x(), - rot.z(), rot.y()));
Vec3d rot = params.rotation.scale * input_queue_item.vector * (PI / 180.);
if (params.swap_yz)
rot = Vec3d(rot(0), -rot(2), -rot(1));
camera.rotate_local_around_target(Vec3d(rot.x(), - rot.z(), rot.y()));
break;
} else {
assert(input_queue_item.is_buttons());
@ -185,13 +187,13 @@ void Mouse3DController::load_config(const AppConfig &appconfig)
double translation_deadzone = Params::DefaultTranslationDeadzone;
float rotation_deadzone = Params::DefaultRotationDeadzone;
double zoom_speed = 2.0;
bool swap_yz_translations = false;
bool swap_yz = false;
appconfig.get_mouse_device_translation_speed(device_name, translation_speed);
appconfig.get_mouse_device_translation_deadzone(device_name, translation_deadzone);
appconfig.get_mouse_device_rotation_speed(device_name, rotation_speed);
appconfig.get_mouse_device_rotation_deadzone(device_name, rotation_deadzone);
appconfig.get_mouse_device_zoom_speed(device_name, zoom_speed);
appconfig.get_mouse_device_swap_yz_translations(device_name, swap_yz_translations);
appconfig.get_mouse_device_swap_yz(device_name, swap_yz);
// clamp to valid values
Params params;
params.translation.scale = Params::DefaultTranslationScale * std::clamp(translation_speed, 0.1, 10.0);
@ -199,7 +201,7 @@ void Mouse3DController::load_config(const AppConfig &appconfig)
params.rotation.scale = Params::DefaultRotationScale * std::clamp(rotation_speed, 0.1f, 10.0f);
params.rotation.deadzone = std::clamp(rotation_deadzone, 0.0f, Params::MaxRotationDeadzone);
params.zoom.scale = Params::DefaultZoomScale * std::clamp(zoom_speed, 0.1, 10.0);
params.swap_yz_translations = swap_yz_translations;
params.swap_yz = swap_yz;
m_params_by_device[device_name] = std::move(params);
}
}
@ -214,7 +216,7 @@ void Mouse3DController::save_config(AppConfig &appconfig) const
const Params &params = key_value_pair.second;
// Store current device parameters into the config
appconfig.set_mouse_device(device_name, params.translation.scale / Params::DefaultTranslationScale, params.translation.deadzone,
params.rotation.scale / Params::DefaultRotationScale, params.rotation.deadzone, params.zoom.scale / Params::DefaultZoomScale, params.swap_yz_translations);
params.rotation.scale / Params::DefaultRotationScale, params.rotation.deadzone, params.zoom.scale / Params::DefaultZoomScale, params.swap_yz);
}
}
@ -323,9 +325,9 @@ void Mouse3DController::render_settings_dialog(GLCanvas3D& canvas) const
imgui.text(_(L("Options:")));
ImGui::PopStyleColor();
bool swap_yz = params_copy.swap_yz_translations;
if (imgui.checkbox("Swap Y/Z translations", swap_yz)) {
params_copy.swap_yz_translations = swap_yz;
bool swap_yz = params_copy.swap_yz;
if (imgui.checkbox("Swap Y/Z axes", swap_yz)) {
params_copy.swap_yz = swap_yz;
params_changed = true;
}