From d13d0775b4e0e02e0ae0da7293477a6e49c09e67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Tue, 16 Aug 2016 13:41:10 +0200 Subject: [PATCH] #168 Fixed zoom along ray problem making the camera end up with the scene behind it. --- .../cafViewer/cafTrackBallBasedNavigation.cpp | 2 ++ Fwk/AppFwk/cafViewer/cafViewer.cpp | 14 +++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.cpp b/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.cpp index 4223f20970..a5c3ecc88c 100644 --- a/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.cpp +++ b/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.cpp @@ -159,6 +159,8 @@ void caf::TrackBallBasedNavigation::zoomAlongRay(cvf::Ray* ray, int delta) m_viewer->mainCamera()->setFromLookAt(newPos, newVrp, up ); m_viewer->updateParallelProjectionHeightFromMoveZoom(m_pointOfInterest); + m_viewer->updateParallelProjectionCameraPosFromPointOfInterestMove(m_pointOfInterest); + m_viewer->navigationPolicyUpdate(); } } diff --git a/Fwk/AppFwk/cafViewer/cafViewer.cpp b/Fwk/AppFwk/cafViewer/cafViewer.cpp index 23db2f5cef..94b6142ae2 100644 --- a/Fwk/AppFwk/cafViewer/cafViewer.cpp +++ b/Fwk/AppFwk/cafViewer/cafViewer.cpp @@ -1050,9 +1050,8 @@ void caf::Viewer::enableParallelProjection(bool enableOrtho) // so we do not need to update the camera position based on orthoHeight and fieldOfView. // We assume the camera is in a sensible position. - // Set a dummy near plane to be > 0 and < farPlane. These wll be updated by the optimize clipping planes - double dummyNearPlane = m_mainCamera->farPlane() *0.1; - m_mainCamera->setProjectionAsPerspective(m_cameraFieldOfViewYDeg, dummyNearPlane, m_mainCamera->farPlane()); + // Set dummy near and far plane. These wll be updated by the optimize clipping planes + m_mainCamera->setProjectionAsPerspective(m_cameraFieldOfViewYDeg, 0.1, 1.0); this->m_renderingSequence->setDefaultFFLightPositional(cvf::Vec3f(0.5, 5.0, 7.0)); m_globalUniformSet->setHeadLightPosition(cvf::Vec3f(0.5, 5.0, 7.0)); @@ -1073,7 +1072,7 @@ double calculateOrthoHeight(double perspectiveViewAngleYDeg, double focusPlaneDi /// //-------------------------------------------------------------------------------------------------- -double calculateDistToPlaneOfInterest(double perspectiveViewAngleYDeg, double orthoHeight) +double calculateDistToPlaneOfOrthoHeight(double perspectiveViewAngleYDeg, double orthoHeight) { return orthoHeight / (2 * (cvf::Math::tan( cvf::Math::toRadians(0.5 * perspectiveViewAngleYDeg) ))); } @@ -1097,7 +1096,7 @@ double distToPlaneOfInterest(const cvf::Camera* camera, const cvf::Vec3d& pointO Vec3d eyeToFocus = pointOfInterest - eye; double distToFocusPlane = eyeToFocus*camDir; - return cvf::Math::abs(distToFocusPlane); + return distToFocusPlane; } //-------------------------------------------------------------------------------------------------- @@ -1111,8 +1110,9 @@ void caf::Viewer::updateParallelProjectionHeightFromMoveZoom(const cvf::Vec3d& p if (!camera || camera->projection() != Camera::ORTHO) return; + // Negative distance can occur. If so, do not set a negative ortho. - double distToFocusPlane = distToPlaneOfInterest(camera, pointOfInterest); + double distToFocusPlane = cvf::Math::abs( distToPlaneOfInterest(camera, pointOfInterest)); double orthoHeight = calculateOrthoHeight(m_cameraFieldOfViewYDeg, distToFocusPlane); @@ -1134,7 +1134,7 @@ void caf::Viewer::updateParallelProjectionCameraPosFromPointOfInterestMove(const double orthoHeight = camera->frontPlaneFrustumHeight(); //Trace::show(String::number(orthoHeight)); - double neededDistToFocusPlane = calculateDistToPlaneOfInterest(m_cameraFieldOfViewYDeg, orthoHeight); + double neededDistToFocusPlane = calculateDistToPlaneOfOrthoHeight(m_cameraFieldOfViewYDeg, orthoHeight); Vec3d eye, vrp, up; camera->toLookAt(&eye, &vrp, &up);