|
以下是OSG世界坐标系转屏幕坐标系,在OSG自带的窗口中没问题,但是将该窗口嵌入到Qt中,就会出现问题。
比如窗口大小是397*259,但是算的点的屏幕坐标却超出范围,比如点云数据中的第一个点屏幕坐标为(361.56,918.08,-5.49)。
y坐标就超出了(此时点云均显示在窗口范围内),不能理解,希望帮忙解决。
- osg::ref_ptr<osg::Vec3Array> PickHandler::WorldToScreen(osg::ref_ptr<osgViewer::Viewer> viewer, osg::ref_ptr<osg::Vec3Array> worldVector)
- {
- osg::ref_ptr<osg::Vec3Array> screenVector = new osg::Vec3Array;
- osg::ref_ptr<osg::Camera> camera = viewer->getCamera();
- osg::Matrix VPW = camera->getViewMatrix() *
- camera->getProjectionMatrix() *
- camera->getViewport()->computeWindowMatrix();
-
- osg::Vec3 worldPoint;
- osg::Vec3 screenPoint;
-
- for (int i=0; i<(int)(worldVector->size()); i++)
- {
- worldPoint = worldVector->at(i);
- screenPoint = worldPoint * VPW;
- screenVector->push_back(screenPoint);
- }
- return screenVector.get();
- }
复制代码
|
-
调试截图
|