|
楼主 |
发表于 2010-4-14 10:39:42
|
显示全部楼层
本帖最后由 edisonsuper 于 2010-4-14 10:44 编辑
2# array
并没有删除操作,这个例子在控制台中运行正常,只是想把它移植到ViewerMFC的那个例子里面时运行出错
原控制台主函数如下:- osg::ref_ptr<osgViewer::Viewer>viewer = new osgViewer::Viewer();
- osg::ref_ptr<osg::Group>root = new osg::Group();
- osg::ref_ptr<osg::Node>node = osgDB::readNodeFile("D:/vpb/M.osga");
- osg::ref_ptr<osgText::Text>updatetext = new osgText::Text();
- CreateHUD * hudText = new CreateHUD();
- root->addChild(node.get());
- root->addChild(hudText->createHUD(updatetext.get()));
- viewer->addEventHandler(new CPickHandler(updatetext.get()));
- osgUtil::Optimizer optimizer;
- optimizer.optimize(root.get());
- viewer->setSceneData(root.get());
- viewer->realize();
- viewer->run();
复制代码 ViewerMFC中的调用如下:-
- InitSceneGraph();
- InitCameraConfig();
复制代码 其中:-
- void CiMaster::InitSceneGraph(void)
- {
- // Init the main Root Node/Group
- mRoot = new osg::Group;
- // Load the Model from the model name
- setlocale(LC_ALL , "chs");
- mModel = osgDB::readNodeFile(m_ModelName);
- // Optimize the model
- osgUtil::Optimizer optimizer;
- optimizer.optimize(mModel.get());
- optimizer.reset();
- // Add the model to the scene
- mRoot->addChild(mModel.get());
- }
- void CiMaster::InitCameraConfig(void)
- {
- // Local Variable to hold window size data
- RECT rect;
- // Create the viewer for this window
- mViewer = new osgViewer::Viewer();
- // Add a Stats Handler to the viewer
- mViewer->addEventHandler(new osgViewer::StatsHandler);
- /////////////////////////////////////////////////////////////////////////////
- //修改部分
- //pickhandler
- osg::ref_ptr<osgText::Text>updatetext = new osgText::Text();
- CreateHUD * hudText = new CreateHUD();
- mRoot->addChild(hudText->createHUD(updatetext.get()));
- CPickHandler* pickhandler = new CPickHandler(updatetext.get());
- pickhandler->setDataVariance(osg::Object:ataVariance:YNAMIC);
- mViewer->addEventHandler(pickhandler);
- //mViewer->addEventHandler(new CPickHandler(updatetext.get()));
- mViewer->addEventHandler(new osgViewer::HelpHandler);
- /////////////////////////////////////////////////////////////////////////////
- // Get the current window size
- ::GetWindowRect(m_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(m_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::GraphicsContext* gc = osg::GraphicsContext::createGraphicsContext(traits.get());
- // Init a new Camera (Master for this View)
- osg::ref_ptr<osg::Camera> camera = new osg::Camera;
- // Assign Graphics Context to the Camera
- camera->setGraphicsContext(gc);
- // Set the viewport for the Camera
- camera->setViewport(new osg::Viewport(traits->x, traits->y, traits->width, traits->height));
- // Add the Camera to the Viewer
- mViewer->addSlave(camera.get());
- // Add the Camera Manipulator to the Viewer
- mViewer->setCameraManipulator(keyswitchManipulator.get());
- // Set the Scene Data
- mViewer->setSceneData(mRoot.get());
- // Realize the Viewer
- mViewer->realize();
- // Correct aspect ratio
- double fovy,aspectRatio,z1,z2;
- mViewer->getCamera()->getProjectionMatrixAsPerspective(fovy,aspectRatio,z1,z2);
- aspectRatio=double(traits->width)/double(traits->height);
- mViewer->getCamera()->setProjectionMatrixAsPerspective(fovy,aspectRatio,z1,z2);
- }
复制代码 是这样的调用方式有问题吗,多谢指导! |
|