From 95bceba0890705ee4fc6943e5d43de03c4d4681a Mon Sep 17 00:00:00 2001 From: SaraP Date: Wed, 19 Feb 2025 16:16:59 +0100 Subject: [PATCH] EgtGraphics 2.7b3 : - in vista prospettica con zoom standard introdotto valore massimo per fov. --- EgtGraphics.rc | Bin 11606 -> 11606 bytes Scene.h | 2 ++ SceneBasic.cpp | 16 +++++++++++++--- SceneCamera.cpp | 39 ++++++++++++++++++++++++--------------- 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/EgtGraphics.rc b/EgtGraphics.rc index 0780f2c070dabe289127d27e0f5836ae82cdaabe..b4de64ae37b519fd789c2594b8f31eafb3cb7dfe 100644 GIT binary patch delta 126 zcmcZ>buDVcCpK0i1|0_D&5d&W%*;s)#*+($bvGYS^kdxI!fnC~m)y@ZIZiSMNr4aJ T<`iKw{0iKpkrbd9KaCpzEixmn delta 126 zcmcZ>buDVcCpK0?1|0^Y&5d&W%*=@lMw1JLbvGYS^kdxI!fnC~m)y@ZIZiSMNr4aJ T<`iKw{0iKpkrbd9KaCpzDLNyb diff --git a/Scene.h b/Scene.h index 8d2da2e..86a01f9 100644 --- a/Scene.h +++ b/Scene.h @@ -401,3 +401,5 @@ class Scene : public IEGrScene //---------------------------------------------------------------------------- static const double PERSPECTIVE_NEAR_PLANE = 10 ; static const double PERSPECTIVE_STD_FOV = 45 ; +static const double PERSPECTIVE_MAX_FOV = 100 ; +static const double PERSPECTIVE_TAN_MAX_FOV = tan( 0.5 * PERSPECTIVE_MAX_FOV * DEGTORAD) ; diff --git a/SceneBasic.cpp b/SceneBasic.cpp index ec5af4b..c38e892 100644 --- a/SceneBasic.cpp +++ b/SceneBasic.cpp @@ -701,10 +701,20 @@ Scene::Prepare( void) else { // calcolo del fov : se dolly è costante, se zoom standard deve adattarsi alla vista double dFov = PERSPECTIVE_STD_FOV ; - if ( m_nPerspZoomType == ZT_STD) - dFov = 2 * atan2( m_dHalfHeight, m_dDistCamera) * RADTODEG ; + double dRatio = m_dHalfWidth / m_dHalfHeight ; + if ( m_nPerspZoomType == ZT_STD) { + // verifico che il fov non superi il valore massimo consentito + if ( m_dHalfHeight / m_dDistCamera > PERSPECTIVE_TAN_MAX_FOV) { + dFov = PERSPECTIVE_MAX_FOV ; + // aggiusto i valori di HalfHeight e HalfWidth + m_dHalfHeight = m_dDistCamera * PERSPECTIVE_TAN_MAX_FOV ; + m_dHalfWidth = dRatio * m_dHalfHeight ; + } + else + dFov = 2 * atan2( m_dHalfHeight, m_dDistCamera) * RADTODEG ; + } - gluPerspective( abs( dFov), m_dHalfWidth / m_dHalfHeight, m_dZNear, m_dZFar) ; + gluPerspective( abs( dFov), dRatio, m_dZNear, m_dZFar) ; } // imposto matrice modello/vista diff --git a/SceneCamera.cpp b/SceneCamera.cpp index b44646b..768c4ba 100644 --- a/SceneCamera.cpp +++ b/SceneCamera.cpp @@ -391,10 +391,8 @@ Scene::ZoomAll( void) m_dDistCamera = m_dHalfHeight / tan( PERSPECTIVE_STD_FOV * 0.5 * DEGTORAD) + ( m_b3ExtView.GetMax().z - m_b3ExtView.GetMin().z) * 0.5 ; } else { - // verifico di non finire dentro l'oggetto - double dDiam ; m_b3ExtView.GetDiameter( dDiam) ; - if ( m_dDistCamera < dDiam * 0.5) - m_dDistCamera = dDiam * 0.5 ; + // aggiusto la distanza della camera + m_b3ExtView.GetDiameter( m_dDistCamera) ; // il valore di m_dHalfHeight calcolato dal box non garantisce che l'oggetto sia interamente contenuto nel frustum // perchè è il valore in corrispondenza della faccia del box davanti alla camera. Per il calcolo del fov m_dHalfHeight @@ -537,19 +535,30 @@ Scene::ZoomOnPoint( const Point3d& ptWin, double dCoeff) Point3d ptOldCen = m_ptCenter ; Point3d ptNewCen = ptWorld + ( m_ptCenter - ptWorld) * dCoeff ; SetCenter( ptNewCen) ; - - // nel caso di dolly verifico se il nuovo zoom fa entrare negli oggetti - if ( ! m_bOrthographic && m_nPerspZoomType == ZT_DOLLY) { - double dMinDist = CalcMinCameraDistance() ; - if ( m_dDistCamera * dCoeff < dMinDist) { - // adatto il coefficiente di zoom e ricalcolo il centro - dCoeff = dMinDist / m_dDistCamera ; - Point3d ptNewCenter = ptWorld + ( ptOldCen - ptWorld) * dCoeff ; - SetCenter( ptNewCenter) ; - } - } m_bDistOk = true ; + if ( ! m_bOrthographic) { + if ( m_nPerspZoomType == ZT_DOLLY) { + // nel caso di dolly verifico se il nuovo zoom fa entrare negli oggetti + double dMinDist = CalcMinCameraDistance() ; + if ( m_dDistCamera * dCoeff < dMinDist) { + // adatto il coefficiente di zoom e ricalcolo il centro + dCoeff = dMinDist / m_dDistCamera ; + Point3d ptNewCenter = ptWorld + ( ptOldCen - ptWorld) * dCoeff ; + SetCenter( ptNewCenter) ; + } + } + else { + // nel caso standard verifico se il nuovo fov supera il valore massimo + if ( m_dHalfHeight * dCoeff / m_dDistCamera > PERSPECTIVE_TAN_MAX_FOV) { + // adatto il coefficiente di zoom e ricalcolo il centro + dCoeff = PERSPECTIVE_TAN_MAX_FOV * m_dDistCamera / m_dHalfHeight ; + Point3d ptNewCenter = ptWorld + ( ptOldCen - ptWorld) * dCoeff ; + SetCenter( ptNewCenter) ; + } + } + } + return ZoomChange( dCoeff) ; }