diff options
author | Enrico Turri <enricoturri@seznam.cz> | 2020-01-03 16:42:52 +0300 |
---|---|---|
committer | Enrico Turri <enricoturri@seznam.cz> | 2020-01-03 16:42:52 +0300 |
commit | 83cbe1dd3307f1698d4643edf9f9e2af214fac36 (patch) | |
tree | 6593df3bf46c42cb183ed7afbdc6be181c69952c /src/slic3r/GUI/Mouse3DController.cpp | |
parent | a4ad0a0925bbe52d2a1f69510664a69251caac53 (diff) |
3DConnexion devices' Y axis used for zoom in/zoom out
Diffstat (limited to 'src/slic3r/GUI/Mouse3DController.cpp')
-rw-r--r-- | src/slic3r/GUI/Mouse3DController.cpp | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/src/slic3r/GUI/Mouse3DController.cpp b/src/slic3r/GUI/Mouse3DController.cpp index e91b6175f..707a1d143 100644 --- a/src/slic3r/GUI/Mouse3DController.cpp +++ b/src/slic3r/GUI/Mouse3DController.cpp @@ -57,13 +57,19 @@ const double Mouse3DController::State::DefaultTranslationScale = 2.5; const double Mouse3DController::State::MaxTranslationDeadzone = 0.2; const double Mouse3DController::State::DefaultTranslationDeadzone = 0.5 * Mouse3DController::State::MaxTranslationDeadzone; const float Mouse3DController::State::DefaultRotationScale = 1.0f; -const float Mouse3DController::State::MaxRotationDeadzone = (float)Mouse3DController::State::MaxTranslationDeadzone; +const float Mouse3DController::State::MaxRotationDeadzone = 0.2f; const float Mouse3DController::State::DefaultRotationDeadzone = 0.5f * Mouse3DController::State::MaxRotationDeadzone; +#if ENABLE_3DCONNEXION_Y_AS_ZOOM +const double Mouse3DController::State::DefaultZoomScale = 0.1; +#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM Mouse3DController::State::State() : m_buttons_enabled(false) , m_translation_params(DefaultTranslationScale, DefaultTranslationDeadzone) , m_rotation_params(DefaultRotationScale, DefaultRotationDeadzone) +#if ENABLE_3DCONNEXION_Y_AS_ZOOM + , m_zoom_params(DefaultZoomScale, 0.0) +#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM , m_mouse_wheel_counter(0) #if ENABLE_3DCONNEXION_DEVICES_DEBUG_OUTPUT , m_translation_queue_max_size(0) @@ -149,7 +155,13 @@ bool Mouse3DController::State::apply(Camera& camera) if (has_translation()) { const Vec3d& translation = m_translation.queue.front(); +#if ENABLE_3DCONNEXION_Y_AS_ZOOM + camera.set_target(camera.get_target() + m_translation_params.scale * (translation(0) * camera.get_dir_right() + translation(2) * camera.get_dir_up())); + if (translation(1) != 0.0) + camera.update_zoom(m_zoom_params.scale * translation(1) / std::abs(translation(1))); +#else camera.set_target(camera.get_target() + m_translation_params.scale * (translation(0) * camera.get_dir_right() + translation(1) * camera.get_dir_forward() + translation(2) * camera.get_dir_up())); +#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM m_translation.queue.pop(); ret = true; } @@ -309,20 +321,30 @@ void Mouse3DController::render_settings_dialog(unsigned int canvas_width, unsign ImGui::PopStyleColor(); float translation_scale = (float)m_state.get_translation_scale() / State::DefaultTranslationScale; - if (imgui.slider_float(_(L("Translation")) + "##1", &translation_scale, 0.5f, 5.0f, "%.1f")) + if (imgui.slider_float(_(L("Translation")) + "##1", &translation_scale, 0.2f, 5.0f, "%.1f")) m_state.set_translation_scale(State::DefaultTranslationScale * (double)translation_scale); float rotation_scale = m_state.get_rotation_scale() / State::DefaultRotationScale; - if (imgui.slider_float(_(L("Rotation")) + "##1", &rotation_scale, 0.5f, 5.0f, "%.1f")) + if (imgui.slider_float(_(L("Rotation")) + "##1", &rotation_scale, 0.2f, 5.0f, "%.1f")) m_state.set_rotation_scale(State::DefaultRotationScale * rotation_scale); +#if ENABLE_3DCONNEXION_Y_AS_ZOOM + float zoom_scale = m_state.get_zoom_scale() / State::DefaultZoomScale; + if (imgui.slider_float(_(L("Zoom")), &zoom_scale, 0.2f, 5.0f, "%.1f")) + m_state.set_zoom_scale(State::DefaultZoomScale * zoom_scale); +#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM + ImGui::Separator(); ImGui::PushStyleColor(ImGuiCol_Text, color); imgui.text(_(L("Deadzone:"))); ImGui::PopStyleColor(); float translation_deadzone = (float)m_state.get_translation_deadzone(); +#if ENABLE_3DCONNEXION_Y_AS_ZOOM + if (imgui.slider_float(_(L("Translation")) + "/" + _(L("Zoom")), &translation_deadzone, 0.0f, (float)State::MaxTranslationDeadzone, "%.2f")) +#else if (imgui.slider_float(_(L("Translation")) + "##2", &translation_deadzone, 0.0f, (float)State::MaxTranslationDeadzone, "%.2f")) +#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM m_state.set_translation_deadzone((double)translation_deadzone); float rotation_deadzone = m_state.get_rotation_deadzone(); @@ -629,15 +651,24 @@ bool Mouse3DController::connect_device() float rotation_speed = 1.0; double translation_deadzone = State::DefaultTranslationDeadzone; float rotation_deadzone = State::DefaultRotationDeadzone; +#if ENABLE_3DCONNEXION_Y_AS_ZOOM + double zoom_speed = 1.0; +#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM wxGetApp().app_config->get_mouse_device_translation_speed(m_device_str, translation_speed); wxGetApp().app_config->get_mouse_device_translation_deadzone(m_device_str, translation_deadzone); wxGetApp().app_config->get_mouse_device_rotation_speed(m_device_str, rotation_speed); wxGetApp().app_config->get_mouse_device_rotation_deadzone(m_device_str, rotation_deadzone); +#if ENABLE_3DCONNEXION_Y_AS_ZOOM + wxGetApp().app_config->get_mouse_device_zoom_speed(m_device_str, zoom_speed); +#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM // clamp to valid values - m_state.set_translation_scale(State::DefaultTranslationScale * std::max(0.5, std::min(2.0, translation_speed))); - m_state.set_translation_deadzone(std::max(0.0, std::min(State::MaxTranslationDeadzone, translation_deadzone))); - m_state.set_rotation_scale(State::DefaultRotationScale * std::max(0.5f, std::min(2.0f, rotation_speed))); - m_state.set_rotation_deadzone(std::max(0.0f, std::min(State::MaxRotationDeadzone, rotation_deadzone))); + m_state.set_translation_scale(State::DefaultTranslationScale * std::clamp(translation_speed, 0.2, 5.0)); + m_state.set_translation_deadzone(std::clamp(translation_deadzone, 0.0, State::MaxTranslationDeadzone)); + m_state.set_rotation_scale(State::DefaultRotationScale * std::clamp(rotation_speed, 0.2f, 5.0f)); + m_state.set_rotation_deadzone(std::clamp(rotation_deadzone, 0.0f, State::MaxRotationDeadzone)); +#if ENABLE_3DCONNEXION_Y_AS_ZOOM + m_state.set_zoom_scale(State::DefaultZoomScale * std::clamp(zoom_speed, 0.2, 5.0)); +#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM } #if ENABLE_3DCONNEXION_DEVICES_DEBUG_OUTPUT else @@ -663,8 +694,13 @@ void Mouse3DController::disconnect_device() m_thread.join(); // Store current device parameters into the config +#if ENABLE_3DCONNEXION_Y_AS_ZOOM + wxGetApp().app_config->set_mouse_device(m_device_str, m_state.get_translation_scale() / State::DefaultTranslationScale, m_state.get_translation_deadzone(), + m_state.get_rotation_scale() / State::DefaultRotationScale, m_state.get_rotation_deadzone(), m_state.get_zoom_scale() / State::DefaultZoomScale); +#else wxGetApp().app_config->set_mouse_device(m_device_str, m_state.get_translation_scale() / State::DefaultTranslationScale, m_state.get_translation_deadzone(), m_state.get_rotation_scale() / State::DefaultRotationScale, m_state.get_rotation_deadzone()); +#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM wxGetApp().app_config->save(); // Close the 3Dconnexion device |