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. "
This commit is contained in:
parent
b40c1b355c
commit
1b6adccdc4
@ -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()="<<new_coord.x()<<" new_coord.y()="<<new_coord.y()<<std::endl;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user