|
楼主 |
发表于 2014-8-25 16:10:24
|
显示全部楼层
啊,主摄像机要怎么设置??? 为啥SetCarmera下,模型会拉长
RECT rect;
::GetWindowRect(hWnd, &rect);
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
osg::ref_ptr<osg::Referenced> windata = new osgViewer::GraphicsWindowWin32::WindowData(hWnd);
traits->x = 0;
traits->y = 0;
traits->width = rect.right - rect.left;
traits->height = rect.bottom - rect.top;
traits->windowDecoration = true;
traits->doubleBuffer = true;
traits->sharedContext = 0;
traits->setInheritedWindowPixelFormat = true;
traits->inheritedWindowData = windata;
osg::GraphicsContext* gc = osg::GraphicsContext::createGraphicsContext(traits.get());
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
camera->setGraphicsContext(gc);
camera->setViewport(new osg::Viewport(traits->x, traits->y, traits->width, traits->height));
double fovy, aspectRatio, zNear, zFar;
fovy = aspectRatio = zNear = zFar = 0.f;
m_viewer.getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar);
camera->setProjectionMatrixAsPerspective(45,traits->width / traits->height,zNear, zFar);
m_viewer.SetCamera(camera.get());
|
|