查看: 1438|回复: 0

osg+qt实现四视图的问题

[复制链接]

该用户从未签到

发表于 2019-9-25 09:19:39 | 显示全部楼层 |阅读模式
打算用osg+qt实现一个类似于3dmax的四视图界面

我创建了两个立方体,
javascript:;
大体的思路是在CompositeViewer中添加四个子Viewer,每个子Viewer设置一个TrackballManipulator,调用其setRotation方法来更改初始视角

主要的代码如下:
void GraphicsView::createview(int pos)
{
    const double fov = 30;
    const double aspect = (double)  Width/Height;
    osgViewer::View * view;
//    Manipulator继承自TrackballManipulator
    Manipulator * manipulator = new Manipulator;
    manipulator->home(0.0);
    switch(pos)
    {
    case 1://右下角源视图
        m_view = new osgViewer::View;
        m_view->setName("m_view");
        view = m_view;
        view->getCamera()->setViewport(new osg::Viewport(Width*1.01/2,0,Width*0.99/2,Height/2));
        m_picker=new picker(m_view);
        break;
    case 2://俯视图左上角
        topview = new osgViewer::View;
        topview->setName("topview");
        view = topview;
        view->getCamera()->setViewport(new osg::Viewport(0,Height*1.01/2,Width*1/2,Height*0.99/2));
        manipulator->setRotation(osg:uat(0.0f,0.0f,0.0f,1.0f));
//        manipulator->topview();
        break;
    case 3://侧视图左上角
        sideview = new osgViewer::View;
        view = sideview;
        view->getCamera()->setViewport(new osg::Viewport(0,0,Width/2,Height/2));
        manipulator->setRotation(osg::Quat(1.0f,-1.0f,-1.0f,1.0f));
        break;
    case 4://主视图右上角
        frontview = new osgViewer::View;
        view = frontview;
        frontview->getCamera()->setViewport(new osg::Viewport(Width*1.01/2,Height*1.01/2,Width*0.99/2,Height*0.99/2));
        manipulator->setRotation(osg::Quat(0.0f,1.0f,1.0f,1.0f));
        break;
    }
    if(view==NULL) return;

    //用于显示帧率等状态信息
    view->addEventHandler(new osgViewer::StatsHandler);
    //对渲染状态进行控制
    view->addEventHandler(new osgGA::StateSetManipulator(view->getCamera()->getOrCreateStateSet()));
    //背景色
//    m_view->getCamera()->setClearColor(osg::Vec4(155.0,0.0,155.0,1.0));

    view->getCamera()->setGraphicsContext(gc.get());
    //动态调节远近剪裁面,解决近裁剪面过远的问题
    view->getCamera()->setNearFarRatio(0.0000002);
    //设置计算裁剪面的方式,解决了抖动问题
    view->getCamera()->setComputeNearFarMode(osg::CullSettings::COMPUTE_NEAR_FAR_USING_PRIMITIVES);

    view->getCamera()->setCullingMode(view->getCamera()->getCullingMode()& ~osg::CullStack::SMALL_FEATURE_CULLING);

    view->getCamera()->setProjectionMatrixAsPerspective( fov, aspect, 1, 10 );

    view->getLight()->setPosition(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
    // 环境光
    view->getLight()->setAmbient(osg::Vec4(0.6f, 0.6f, 0.6f, 1.0f));
    // 漫反射光
    view->getLight()->setDiffuse(osg::Vec4(0.2f, 0.2f, 0.2f, 1.0f));
//    //设置镜面
    view->getLight()->setSpecular(osg::Vec4(0.2f, 0.2f, 0.2f, 1.0f));

    view->setSceneData(m_pSceneData);

    view->setCameraManipulator(manipulator);

    viewer->addView(view);
}

但实际结果却只有四个初始视角
javascript:;
刚接触osg,这方面真的不太懂,希望大神能帮忙解答一下
YZ(G4PF)VG5}U8GUMA$H044.png
2`H`L4_$2S41{D03TWX1CQI.png

test9_25.zip

121.25 KB, 下载次数: 16, 下载积分: 威望 1

您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表