From 4205cb32c51bbaa3432049917f8c16d63a199ddc Mon Sep 17 00:00:00 2001 From: Mario Luzeiro Date: Sun, 5 Jan 2020 19:02:54 +0000 Subject: [PATCH] 3d-viewer, make ortho projection zoom similar as prespective projection Fixes #1843 Fixes reload of Raytracing when the projection button is pressed. (cherry picked from commit 2c00540ad62e197fb5b475641e1e9f3a57274a2b) --- 3d-viewer/3d_rendering/ccamera.cpp | 18 ++++++++++-------- 3d-viewer/3d_viewer/eda_3d_viewer.cpp | 6 +++++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/3d-viewer/3d_rendering/ccamera.cpp b/3d-viewer/3d_rendering/ccamera.cpp index e18faea6c9..b8f6ac18ab 100644 --- a/3d-viewer/3d_rendering/ccamera.cpp +++ b/3d-viewer/3d_rendering/ccamera.cpp @@ -163,7 +163,7 @@ void CCAMERA::rebuildProjection() m_projectionMatrixInv = glm::inverse( m_projectionMatrix ); - m_frustum.tang = glm::tan( glm::radians( m_frustum.angle ) * 0.5f ) ; + m_frustum.tang = glm::tan( glm::radians( m_frustum.angle ) * 0.5f ); m_focalLen.x = ( (float)m_windowSize.y / (float)m_windowSize.x ) / m_frustum.tang; m_focalLen.y = 1.0f / m_frustum.tang; @@ -178,19 +178,21 @@ void CCAMERA::rebuildProjection() m_frustum.nearD = -m_frustum.farD; // Use a symmetrical clip plane for ortho projection - const float orthoReductionFactor = m_zoom / 75.0f; + // This formula was found by trial and error + const float orthoReductionFactor = glm::length( m_camera_pos_init ) * + m_zoom * m_zoom * 0.5f; // Initialize Projection Matrix for Ortographic View - m_projectionMatrix = glm::ortho( -m_windowSize.x * orthoReductionFactor, - m_windowSize.x * orthoReductionFactor, - -m_windowSize.y * orthoReductionFactor, - m_windowSize.y * orthoReductionFactor, + m_projectionMatrix = glm::ortho( -m_frustum.ratio * orthoReductionFactor, + m_frustum.ratio * orthoReductionFactor, + -orthoReductionFactor, + orthoReductionFactor, m_frustum.nearD, m_frustum.farD ); m_projectionMatrixInv = glm::inverse( m_projectionMatrix ); - m_frustum.nw = m_windowSize.x * orthoReductionFactor * 2.0f; - m_frustum.nh = m_windowSize.y * orthoReductionFactor * 2.0f; + m_frustum.nw = orthoReductionFactor * 2.0f * m_frustum.ratio; + m_frustum.nh = orthoReductionFactor * 2.0f; m_frustum.fw = m_frustum.nw; m_frustum.fh = m_frustum.nh; diff --git a/3d-viewer/3d_viewer/eda_3d_viewer.cpp b/3d-viewer/3d_viewer/eda_3d_viewer.cpp index d6159e6a0b..6b8352508a 100644 --- a/3d-viewer/3d_viewer/eda_3d_viewer.cpp +++ b/3d-viewer/3d_viewer/eda_3d_viewer.cpp @@ -369,7 +369,11 @@ void EDA_3D_VIEWER::Process_Special_Functions( wxCommandEvent &event ) case ID_ORTHO: m_settings.CameraGet().ToggleProjection(); - m_canvas->Request_refresh(); + + if( m_settings.RenderEngineGet() == RENDER_ENGINE::OPENGL_LEGACY ) + m_canvas->Request_refresh(); + else + m_canvas->RenderRaytracingRequest(); return; case ID_TOOL_SCREENCOPY_TOCLIBBOARD: