From 1b6adccdc42c25e771875eea51d792f0a389e3e3 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 15 Mar 2010 14:47:22 +0000 Subject: [PATCH] From Wang Rui, "Here is a small fix in the eventTraversal() function of both viewer and composite viewer class. if (getCameraWithFocus()) { if (getCameraWithFocus()!=getCamera()) // Newly added { osg::Viewport* viewport = getCameraWithFocus()->getViewport(); osg::Matrix localCameraVPW = getCameraWithFocus()->getViewMatrix() * getCameraWithFocus()->getProjectionMatrix(); if (viewport) localCameraVPW *= viewport->computeWindowMatrix(); osg::Matrix matrix( osg::Matrix::inverse(localCameraVPW) * masterCameraVPW ); osg::Vec3d new_coord = osg::Vec3d(x,y,0.0) * matrix; x = new_coord.x(); y = new_coord.y(); } ... } I put an additional conditional statement here to ensure that _cameraWithCamera and _camera are different, otherwise it's no need to calculate the transition matrix from main camera to focus camera. The excess calculations of 'matrix' and 'new_coord' may cause floating-point error and return a slightly wrong result other than an identity matrix. It seems OK in most cases but will be still pain when there is little difference between two mouse moving events. " --- src/osgViewer/Viewer.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/osgViewer/Viewer.cpp b/src/osgViewer/Viewer.cpp index f331693ac..f0a55a086 100644 --- a/src/osgViewer/Viewer.cpp +++ b/src/osgViewer/Viewer.cpp @@ -701,16 +701,19 @@ void Viewer::eventTraversal() { if (getCameraWithFocus()) { - osg::Viewport* viewport = getCameraWithFocus()->getViewport(); - osg::Matrix localCameraVPW = getCameraWithFocus()->getViewMatrix() * getCameraWithFocus()->getProjectionMatrix(); - if (viewport) localCameraVPW *= viewport->computeWindowMatrix(); + if (getCameraWithFocus()!=getCamera()) + { + osg::Viewport* viewport = getCameraWithFocus()->getViewport(); + osg::Matrix localCameraVPW = getCameraWithFocus()->getViewMatrix() * getCameraWithFocus()->getProjectionMatrix(); + if (viewport) localCameraVPW *= viewport->computeWindowMatrix(); - osg::Matrix matrix( osg::Matrix::inverse(localCameraVPW) * masterCameraVPW ); + osg::Matrix matrix( osg::Matrix::inverse(localCameraVPW) * masterCameraVPW ); - osg::Vec3d new_coord = osg::Vec3d(x,y,0.0) * matrix; + osg::Vec3d new_coord = osg::Vec3d(x,y,0.0) * matrix; - x = new_coord.x(); - y = new_coord.y(); + x = new_coord.x(); + y = new_coord.y(); + } // OSG_NOTIFY(osg::NOTICE)<<"pointer event new_coord.x()="<