diff --git a/3d-viewer/3d_canvas/eda_3d_canvas.cpp b/3d-viewer/3d_canvas/eda_3d_canvas.cpp index 1bd8e1a253..8fa4e083d0 100644 --- a/3d-viewer/3d_canvas/eda_3d_canvas.cpp +++ b/3d-viewer/3d_canvas/eda_3d_canvas.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2015-2016 Mario Luzeiro - * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -465,14 +465,7 @@ void EDA_3D_CANVAS::OnMouseWheel( wxMouseEvent &event ) } else { - if( event.GetWheelRotation() > 0 ) - { - mouseActivity = m_settings.CameraGet().ZoomIn( 1.1f ); - } - else - { - mouseActivity = m_settings.CameraGet().ZoomOut( 1.1f ); - } + mouseActivity = m_settings.CameraGet().Zoom( event.GetWheelRotation() > 0 ? 1.1f : 1/1.1f ); } // If it results on a camera movement @@ -503,7 +496,7 @@ void EDA_3D_CANVAS::OnMagnify( wxMouseEvent& event ) float magnification = ( event.GetMagnification() + 1.0f ); - m_settings.CameraGet().ZoomIn( magnification ); + m_settings.CameraGet().Zoom( magnification ); DisplayStatus(); Request_refresh(); @@ -909,14 +902,14 @@ void EDA_3D_CANVAS::SetView3D( int keycode ) case WXK_F1: m_settings.CameraGet().SetInterpolateMode( INTERPOLATION_BEZIER ); m_settings.CameraGet().SetT0_and_T1_current_T(); - if( m_settings.CameraGet().ZoomIn_T1( 1.4f ) ) + if( m_settings.CameraGet().Zoom_T1( 1.4f ) ) request_start_moving_camera( 3.0f ); return; case WXK_F2: m_settings.CameraGet().SetInterpolateMode( INTERPOLATION_BEZIER ); m_settings.CameraGet().SetT0_and_T1_current_T(); - if( m_settings.CameraGet().ZoomOut_T1( 1.4f ) ) + if( m_settings.CameraGet().Zoom_T1( 1/1.4f ) ) request_start_moving_camera( 3.0f ); return; diff --git a/3d-viewer/3d_model_viewer/c3d_model_viewer.cpp b/3d-viewer/3d_model_viewer/c3d_model_viewer.cpp index ce28cce230..f013de5339 100644 --- a/3d-viewer/3d_model_viewer/c3d_model_viewer.cpp +++ b/3d-viewer/3d_model_viewer/c3d_model_viewer.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2015-2016 Mario Luzeiro - * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -390,14 +390,7 @@ void C3D_MODEL_VIEWER::OnMouseWheel( wxMouseEvent &event ) } else { - if( event.GetWheelRotation() > 0 ) - { - m_trackBallCamera.ZoomIn( 1.1f ); - } - else - { - m_trackBallCamera.ZoomOut( 1.1f ); - } + m_trackBallCamera.Zoom( event.GetWheelRotation() > 0 ? 1.1f : 1/1.1f ); //DisplayStatus(); Refresh( false ); diff --git a/3d-viewer/3d_rendering/ccamera.cpp b/3d-viewer/3d_rendering/ccamera.cpp index 55ed918648..ae442ae505 100644 --- a/3d-viewer/3d_rendering/ccamera.cpp +++ b/3d-viewer/3d_rendering/ccamera.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2015-2016 Mario Luzeiro - * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -451,91 +451,39 @@ void CCAMERA::ZoomReset() rebuildProjection(); } - -bool CCAMERA::ZoomIn( float aFactor ) +bool CCAMERA::Zoom( float aFactor ) { - if( m_zoom > MIN_ZOOM ) - { - const float old_zoom = m_zoom; + if ( ( m_zoom == MIN_ZOOM && aFactor > 1 ) || ( m_zoom == MAX_ZOOM && aFactor < 1 ) || aFactor == 1 ) + return false; - m_zoom /= aFactor; + m_zoom /= aFactor; + if( m_zoom <= MIN_ZOOM ) + m_zoom = MIN_ZOOM; + if( m_zoom >= MAX_ZOOM ) + m_zoom = MAX_ZOOM; - if( m_zoom <= MIN_ZOOM ) - m_zoom = MIN_ZOOM; + m_camera_pos.z = m_camera_pos_init.z * m_zoom; - m_camera_pos.z = m_zoom * m_camera_pos_init.z; + updateViewMatrix(); + rebuildProjection(); - if( old_zoom != m_zoom ) - { - updateViewMatrix(); - rebuildProjection(); - - return true; - } - } - - return false; + return true; } - -bool CCAMERA::ZoomOut( float aFactor ) +bool CCAMERA::Zoom_T1( float aFactor ) { - if( m_zoom < MAX_ZOOM ) - { - const float old_zoom = m_zoom; + if( ( m_zoom == MIN_ZOOM && aFactor > 1 ) || ( m_zoom == MAX_ZOOM && aFactor < 1 ) || aFactor == 1 ) + return false; - m_zoom *= aFactor; + m_zoom_t1 = m_zoom / aFactor; + if (m_zoom_t1 < MIN_ZOOM ) + m_zoom_t1 = MIN_ZOOM; + if (m_zoom_t1 > MAX_ZOOM ) + m_zoom_t1 = MAX_ZOOM; - if( m_zoom >= MAX_ZOOM ) - m_zoom = MAX_ZOOM; + m_camera_pos_t1.z = m_camera_pos_init.z * m_zoom_t1; - m_camera_pos.z = m_zoom * m_camera_pos_init.z; - - if( old_zoom != m_zoom ) - { - updateViewMatrix(); - rebuildProjection(); - - return true; - } - } - - return false; -} - -bool CCAMERA::ZoomIn_T1( float aFactor ) -{ - if( m_zoom > MIN_ZOOM ) - { - m_zoom_t1 = m_zoom / aFactor; - - if( m_zoom_t1 <= MIN_ZOOM ) - m_zoom_t1 = MIN_ZOOM; - - m_camera_pos_t1.z = m_zoom_t1 * m_camera_pos_init.z; - - return true; - } - - return false; -} - - -bool CCAMERA::ZoomOut_T1( float aFactor ) -{ - if( m_zoom < MAX_ZOOM ) - { - m_zoom_t1 = m_zoom * aFactor; - - if( m_zoom_t1 >= MAX_ZOOM ) - m_zoom_t1 = MAX_ZOOM; - - m_camera_pos_t1.z = m_zoom_t1 * m_camera_pos_init.z; - - return true; - } - - return false; + return true; } diff --git a/3d-viewer/3d_rendering/ccamera.h b/3d-viewer/3d_rendering/ccamera.h index aa8c2d556f..3531ad171a 100644 --- a/3d-viewer/3d_rendering/ccamera.h +++ b/3d-viewer/3d_rendering/ccamera.h @@ -170,13 +170,9 @@ class CCAMERA void ZoomReset(); - bool ZoomIn( float aFactor ); + bool Zoom( float aFactor ); - bool ZoomOut( float aFactor ); - - bool ZoomIn_T1( float aFactor ); - - bool ZoomOut_T1( float aFactor ); + bool Zoom_T1( float aFactor ); float ZoomGet() const ;