|
发表于 2009-8-29 11:59:18
|
显示全部楼层
在多相机多视口的情况下,osg会自动对鼠标点坐标从当前视口映射到主相机视口,简单说就是通过屏幕坐标反算出空间坐标,然后再算出该空间坐标在主相机视口中的视口坐标,这个坐标值就是使用getX获得的值了
可以看一下osgViewer::Viewer::eventTraversal的代码:- if (getCameraWithFocus())
- {
- 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();
- // osg::notify(osg::NOTICE)<<"pointer event new_coord.x()="<<new_coord.x()<<" new_coord.y()="<<new_coord.y()<<std::endl;
- event->setInputRange(eventState->getXmin(), eventState->getYmin(), eventState->getXmax(), eventState->getYmax());
- event->setX(x);
- event->setY(y);
- event->setMouseYOrientation(osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS);
- }
复制代码 |
|