3Dconnexion devices translation linearly dependent on zoom

This commit is contained in:
Enrico Turri 2020-01-16 10:17:07 +01:00
parent 9f7feedc8b
commit 3f2ccf08d2
6 changed files with 18 additions and 32 deletions

View File

@ -80,6 +80,7 @@ public:
#endif // !ENABLE_6DOF_CAMERA
double get_zoom() const { return m_zoom; }
double get_inv_zoom() const { assert(m_zoom != 0.0); return 1.0 / m_zoom; }
void update_zoom(double delta_zoom);
void set_zoom(double zoom);

View File

@ -390,8 +390,7 @@ Rect GLCanvas3D::LayersEditing::get_bar_rect_viewport(const GLCanvas3D& canvas)
float half_w = 0.5f * (float)cnv_size.get_width();
float half_h = 0.5f * (float)cnv_size.get_height();
float zoom = (float)canvas.get_camera().get_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
float inv_zoom = (float)canvas.get_camera().get_inv_zoom();
#if ENABLE_ADAPTIVE_LAYER_HEIGHT_PROFILE
return Rect((half_w - thickness_bar_width(canvas)) * inv_zoom, half_h * inv_zoom, half_w * inv_zoom, -half_h * inv_zoom);
@ -407,8 +406,7 @@ Rect GLCanvas3D::LayersEditing::get_reset_rect_viewport(const GLCanvas3D& canvas
float half_w = 0.5f * (float)cnv_size.get_width();
float half_h = 0.5f * (float)cnv_size.get_height();
float zoom = (float)canvas.get_camera().get_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
float inv_zoom = (float)canvas.get_camera().get_inv_zoom();
return Rect((half_w - thickness_bar_width(canvas)) * inv_zoom, (-half_h + reset_button_height(canvas)) * inv_zoom, half_w * inv_zoom, -half_h * inv_zoom);
}
@ -468,8 +466,7 @@ void GLCanvas3D::LayersEditing::_render_tooltip_texture(const GLCanvas3D& canvas
const float width = (float)m_tooltip_texture.get_width() * scale;
const float height = (float)m_tooltip_texture.get_height() * scale;
float zoom = (float)canvas.get_camera().get_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
float inv_zoom = (float)canvas.get_camera().get_inv_zoom();
float gap = 10.0f * inv_zoom;
float bar_left = bar_rect.get_left();
@ -964,8 +961,7 @@ void GLCanvas3D::WarningTexture::render(const GLCanvas3D& canvas) const
if ((m_id > 0) && (m_original_width > 0) && (m_original_height > 0) && (m_width > 0) && (m_height > 0))
{
const Size& cnv_size = canvas.get_canvas_size();
float zoom = (float)canvas.get_camera().get_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
float inv_zoom = (float)canvas.get_camera().get_inv_zoom();
float left = (-0.5f * (float)m_original_width) * inv_zoom;
float top = (-0.5f * (float)cnv_size.get_height() + (float)m_original_height + 2.0f) * inv_zoom;
float right = left + (float)m_original_width * inv_zoom;
@ -1327,8 +1323,7 @@ void GLCanvas3D::LegendTexture::render(const GLCanvas3D& canvas) const
if ((m_id > 0) && (m_original_width > 0) && (m_original_height > 0) && (m_width > 0) && (m_height > 0))
{
const Size& cnv_size = canvas.get_canvas_size();
float zoom = (float)canvas.get_camera().get_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
float inv_zoom = (float)canvas.get_camera().get_inv_zoom();
float left = (-0.5f * (float)cnv_size.get_width()) * inv_zoom;
float top = (0.5f * (float)cnv_size.get_height()) * inv_zoom;
float right = left + (float)m_original_width * inv_zoom;
@ -4973,8 +4968,7 @@ void GLCanvas3D::_render_main_toolbar() const
#endif // ENABLE_RETINA_GL
Size cnv_size = get_canvas_size();
float zoom = (float)m_camera.get_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
float inv_zoom = (float)m_camera.get_inv_zoom();
float top = 0.5f * (float)cnv_size.get_height() * inv_zoom;
float left = -0.5f * (m_main_toolbar.get_width() + m_undoredo_toolbar.get_width()) * inv_zoom;
@ -5000,8 +4994,7 @@ void GLCanvas3D::_render_undoredo_toolbar() const
#endif // ENABLE_RETINA_GL
Size cnv_size = get_canvas_size();
float zoom = (float)m_camera.get_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
float inv_zoom = (float)m_camera.get_inv_zoom();
float top = 0.5f * (float)cnv_size.get_height() * inv_zoom;
float left = (m_main_toolbar.get_width() - 0.5f * (m_main_toolbar.get_width() + m_undoredo_toolbar.get_width())) * inv_zoom;
@ -5023,8 +5016,7 @@ void GLCanvas3D::_render_view_toolbar() const
#endif // ENABLE_RETINA_GL
Size cnv_size = get_canvas_size();
float zoom = (float)m_camera.get_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
float inv_zoom = (float)m_camera.get_inv_zoom();
// places the toolbar on the bottom-left corner of the 3d scene
float top = (-0.5f * (float)cnv_size.get_height() + m_view_toolbar.get_height()) * inv_zoom;

View File

@ -69,8 +69,7 @@ namespace GUI {
return;
const Camera& camera = canvas.get_camera();
float zoom = (float)camera.get_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
float inv_zoom = (float)camera.get_inv_zoom();
Size cnv_size = canvas.get_canvas_size();
float cnv_half_width = 0.5f * (float)cnv_size.get_width();

View File

@ -653,8 +653,7 @@ std::string GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLC
{
// NB: mouse_pos is already scaled appropriately
float zoom = (float)parent.get_camera().get_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
float inv_zoom = (float)parent.get_camera().get_inv_zoom();
float factor = m_layout.scale * inv_zoom;
Size cnv_size = parent.get_canvas_size();
@ -758,8 +757,7 @@ std::string GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCan
{
// NB: mouse_pos is already scaled appropriately
float zoom = (float)parent.get_camera().get_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
float inv_zoom = (float)parent.get_camera().get_inv_zoom();
float factor = m_layout.scale * inv_zoom;
Size cnv_size = parent.get_canvas_size();
@ -875,8 +873,7 @@ int GLToolbar::contains_mouse_horizontal(const Vec2d& mouse_pos, const GLCanvas3
{
// NB: mouse_pos is already scaled appropriately
float zoom = (float)parent.get_camera().get_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
float inv_zoom = (float)parent.get_camera().get_inv_zoom();
float factor = m_layout.scale * inv_zoom;
Size cnv_size = parent.get_canvas_size();
@ -949,8 +946,7 @@ int GLToolbar::contains_mouse_vertical(const Vec2d& mouse_pos, const GLCanvas3D&
{
// NB: mouse_pos is already scaled appropriately
float zoom = (float)parent.get_camera().get_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
float inv_zoom = (float)parent.get_camera().get_inv_zoom();
float factor = m_layout.scale * inv_zoom;
Size cnv_size = parent.get_canvas_size();
@ -1102,8 +1098,7 @@ void GLToolbar::render_horizontal(const GLCanvas3D& parent) const
int tex_width = m_icons_texture.get_width();
int tex_height = m_icons_texture.get_height();
float zoom = (float)parent.get_camera().get_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
float inv_zoom = (float)parent.get_camera().get_inv_zoom();
float factor = inv_zoom * m_layout.scale;
float scaled_icons_size = m_layout.icons_size * factor;
@ -1151,8 +1146,7 @@ void GLToolbar::render_vertical(const GLCanvas3D& parent) const
int tex_width = m_icons_texture.get_width();
int tex_height = m_icons_texture.get_height();
float zoom = (float)parent.get_camera().get_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
float inv_zoom = (float)parent.get_camera().get_inv_zoom();
float factor = inv_zoom * m_layout.scale;
float scaled_icons_size = m_layout.icons_size * factor;

View File

@ -850,7 +850,7 @@ void GLGizmosManager::do_render_overlay() const
float cnv_w = (float)m_parent.get_canvas_size().get_width();
float cnv_h = (float)m_parent.get_canvas_size().get_height();
float zoom = (float)m_parent.get_camera().get_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
float inv_zoom = (float)m_parent.get_camera().get_inv_zoom();
float height = get_scaled_total_height();
float width = get_scaled_total_width();

View File

@ -156,7 +156,7 @@ bool Mouse3DController::State::apply(Camera& camera)
{
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()));
camera.set_target(camera.get_target() + camera.get_inv_zoom() * 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