|
楼主 |
发表于 2010-6-22 13:06:03
|
显示全部楼层
1# zhoudeji
// 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));
camera->setProjectionMatrix(osg::Matrix::perspective(30.0,(double)traits->width/traits->height,0.1,1000));
camera->setClearColor(osg::Vec4(1.0f,1.0f,0.0f,1.0f));
// Add the Camera to the Viewer
mViewer->setCamera(camera.get());
// Add the Camera Manipulator to the Viewer
mViewer->setCameraManipulator(keyswitchManipulator.get());
// Set the Scene Data
mViewer->setSceneData(m_pDisplaySceneRoot.get());
// Realize the Viewer
mViewer->realize();
这时用鼠标选择模型
osgUtil:ineSegmentIntersector::Intersections intersections;
bool foundIntersection = view->computeIntersections(ea.getX(),ea.getY(),intersections);可以选中模型;现在我把traits设置成traits->x = 0;
traits->y = 0;
traits->width =100;
traits->height =100;其他的不变,选择模型时,bool foundIntersection = view->computeIntersections(ea.getX(),ea.getY(),intersections);返回值一直为false,就是选不了模型了 |
|