|
本帖最后由 lglgaigogo 于 2013-4-19 17:18 编辑
请无视这个问题,_我不知为什么把tmpView->getCamera()->setAllowEventFocus( false )写了两遍,注释的时候只注释了一个。
如图:
有两个CView,对应到osg里的两个osgViewer::View。如下初始化:- void cOSG::SetupCamera(HWND hWnd,short ID)
- {
- if (NULL == m_CompositeViewer)
- {
- TRACE(_T("Viewer not ready"));
- return;
- }
- osg::ref_ptr<osgViewer::View> _tmpView;
- switch(ID)
- {
- case MAPVIEW:
- m_MapView = new osgViewer::View;
- _tmpView = m_MapView;
- break;
- case MAINVIEW:
- default:
- m_MainView = new osgViewer::View;
- _tmpView = m_MainView;
- break;
- }
- m_CompositeViewer->addView(_tmpView.get());
- // Add a Stats Handler to the viewer
- //用来显示系统运行的信息,包括帧率,CPU占用等
- osg::ref_ptr<osgViewer::StatsHandler> stats_handler = new osgViewer::StatsHandler;
- //按“i”键显示
- stats_handler->setKeyEventTogglesOnScreenStats('i');
- _tmpView->addEventHandler(stats_handler.get());
- // Local Variable to hold window size data
- RECT rect;
- // Get the current window size
- ::GetWindowRect(hWnd, &rect);
- // Init the GraphicsContext Traits
- osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
- // Init the Windata Variable that holds the handle for the Window to display OSG in.
- osg::ref_ptr<osg::Referenced> windata = new osgViewer::GraphicsWindowWin32::WindowData(hWnd);
- // Setup the traits parameters
- traits->x = 0;
- traits->y = 0;
- traits->width = rect.right - rect.left;
- traits->height = rect.bottom - rect.top;
- traits->windowDecoration = false;
- traits->doubleBuffer = true;
- traits->sharedContext = 0;
- traits->setInheritedWindowPixelFormat = true;
- traits->inheritedWindowData = windata;
- // Create the Graphics Context
- osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
- // Assign Graphics Context to the Camera
- _tmpView->getCamera()->setGraphicsContext(gc.get());
- // Set the viewport for the Camera
- _tmpView->getCamera()->setViewport(new osg::Viewport(traits->x, traits->y, traits->width, traits->height));
- float scale = 17.0;
- switch(ID)
- {
- case MAPVIEW:
- _tmpView->getCamera()->setClearColor( osg::Vec4(0.0f, 0.2f, 0.0f, 1.0f) );
- _tmpView->getCamera()->setRenderOrder( osg::Camera::POST_RENDER );
- _tmpView->getCamera()->setAllowEventFocus( false );/////在这里,我没有看见啊。。。。
- _tmpView->getCamera()->setClearMask( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- _tmpView->getCamera()->setReferenceFrame( osg::Transform::ABSOLUTE_RF );
- _tmpView->getCamera()->setViewMatrix( osg::Matrixd::lookAt(osg::Vec3(0.0f, 0.0f, 120.0f), osg::Vec3(0.0,0.0,0.0), osg::Y_AXIS) );
- _tmpView->getCamera()->setProjectionMatrix( osg::Matrixd::ortho2D(-1.0*scale*traits->width, 1.0*scale*traits->width, -1.0*scale*traits->height, 1.0*scale*traits->height) );
-
- _tmpView->addEventHandler(new testkeyhandler());
- _tmpView->setSceneData(m_MapRoot.get());
- break;
- case MAINVIEW:
- default:
- //设置主视图相机
- _tmpView->getCamera()->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
- _tmpView->getCamera()->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
- _tmpView->getCamera()->setClearColor(osg::Vec4f(0.2f, 0.2f, 0.4f, 1.0f));
- _tmpView->getCamera()->setProjectionMatrixAsPerspective(
- 60.0f, static_cast<double>(traits->width)/static_cast<double>(traits->height), 1.0, 1000.0);
-
- // Add the Camera Manipulator to the Viewer
- _tmpView->setCameraManipulator(m_keyswitchManipulator.get());
- _tmpView->setSceneData(m_MainRoot.get());
- break;
- }
- // Set the Scene Data
- }
复制代码 这个函数的第一个参数就是MFC里的CView的hWnd。
现在的问题是:显示没有问题,就是第2个View(小地图)不能响应事件。 |
|