From bcb3c189a17e5d6894f1676fb404bc0adfd0f3d8 Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Thu, 22 Jan 2026 11:00:44 +0100 Subject: [PATCH] EgtGraphics : - migliorato calcolo centro di vista in Zwin utilizzando GetPixelZ. --- Scene.h | 1 + SceneBasic.cpp | 18 ++++++++++++++++++ SceneCamera.cpp | 6 +++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Scene.h b/Scene.h index 86a01f9..deaa245 100644 --- a/Scene.h +++ b/Scene.h @@ -246,6 +246,7 @@ class Scene : public IEGrScene bool MyDraw( bool bSwapBF) ; bool Background( void) ; bool Prepare( void) ; + bool GetPixelZ( const Point3d& ptWin, double& dWinZ) ; // Camera bool VerifyCamera( bool bUseOrizzOffsCamera = false) ; bool CalcDirUp( bool bUseOrizzOffsCamera = false) ; diff --git a/SceneBasic.cpp b/SceneBasic.cpp index c38e892..ddfbb2d 100644 --- a/SceneBasic.cpp +++ b/SceneBasic.cpp @@ -941,6 +941,24 @@ Scene::UnProject( const Point3d& ptView, Point3d& ptWorld) const return ( nRes == GL_TRUE) ; } +//---------------------------------------------------------------------------- +bool +Scene::GetPixelZ( const Point3d& ptWin, double& dWinZ) +{ + glGetError() ; + GLint Viewport[ 4] ; + glGetIntegerv( GL_VIEWPORT, Viewport) ; + float dZ ; + glReadBuffer( GL_FRONT) ; + glReadPixels( int( ptWin.x), Viewport[3] - int( ptWin.y), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &dZ) ; + if ( glGetError() == GL_NO_ERROR && dZ > 0.001 && dZ < 0.999) { + dWinZ = dZ ; + return true ; + } + dWinZ = GetProjectedCenter().z ; + return false ; +} + //---------------------------------------------------------------------------- void Scene::Destroy( void) diff --git a/SceneCamera.cpp b/SceneCamera.cpp index 768c4ba..74b0597 100644 --- a/SceneCamera.cpp +++ b/SceneCamera.cpp @@ -525,8 +525,12 @@ Scene::ZoomChange( double dCoeff) bool Scene::ZoomOnPoint( const Point3d& ptWin, double dCoeff) { + // leggo Z del pixel + double dWinZ ; + GetPixelZ( ptWin, dWinZ) ; + // porto il punto in coordinate mondo - Point3d ptView( ptWin.x, ptWin.y, GetProjectedCenter().z) ; + Point3d ptView( ptWin.x, ptWin.y, dWinZ) ; Point3d ptWorld ; if ( ! UnProject( ptView, ptWorld)) return false ;