|
看到书上讲从相机那块,我就照着书上做了一下。发现用从相机的时候,viewer->addSlave(leftcam.get(),osg::Matrix(),osg::Matrix::rotate(osg:egreesToRadians(180.0),0.0,1.0,0.0),true);这句话的结果本来是,显示主相机的后视图,结果运行之后发现,后视图没有显示,也就是从相机。忘懂的人能给我解惑一下,谢谢~
- #include <osgDB/ReadFile>
- #include <osgViewer/Viewer>
- #include <osgGA/TrackballManipulator>
- #include <iostream>
- void CreateCamera(osgViewer::Viewer *viewer)
- {
- if(!viewer)
- {
- return;
- }
- //创建窗口系统接口
- osg::GraphicsContext::WindowingSystemInterface *wsi = osg::GraphicsContext::getWindowingSystemInterface();
- if(!wsi)
- {
- return;
- }
- //得到窗口分辨率
- unsigned int width,height;
- wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0),width,height);
- //设置图形环境特性
- osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
- traits->x = 0;
- traits->y = 0;
- traits->width = width;
- traits->height = height;
- traits->windowDecoration = false; //是否支持窗口扩展的功能,win32中的style
- traits->doubleBuffer =true;
- traits->sharedContext = 0;
- //创建图形环境
- osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits);
- if(!gc.valid())
- {
- return;
- }
- //创建相机
- osg::ref_ptr<osg::Camera> master = new osg::Camera;
- master->setGraphicsContext(gc);
- master->setViewport(width/2,height/2,width/2,height/2);
- viewer->addSlave(master.get());
- osg::ref_ptr<osg::Camera> leftcam = new osg::Camera;
- leftcam->setGraphicsContext(gc);
- leftcam->setViewport(0,0,width/2,height/2);
- GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
- //设置绘制缓冲,它在每帧绘制之前使用。注意:如果参数书GL_NONE,
- //则在每帧绘制后自动加载合适的参数
- leftcam->setDrawBuffer(buffer);
- //为拷贝操作设置读缓冲
- leftcam->setReadBuffer(buffer);
- //leftcam->setRenderOrder(osg::Camera::POST_RENDER);
- viewer->addSlave(leftcam.get(),osg::Matrix(),osg::Matrix::rotate(osg::DegreesToRadians(180.0),0.0,1.0,0.0),true);
- osg::ref_ptr<osg::Node> scene =osgDB::readNodeFile("cow.osg");
- viewer->setSceneData(scene);
- return;
-
- }
- int main()
- {
- osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
- CreateCamera(viewer);
- viewer->run();
- return 0;
- }
复制代码 |
-
运行结果[右上角为主,左下角为从相机]
|