|
打算用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,这方面真的不太懂,希望大神能帮忙解答一下
|
|