|
问题描述:我在主场景中又加了一个camera节点 用来加载显示一组模型,但其中有一个模型不显示,我测试了下,发现不是模型的问题是不在视点内,我用了osg::MatrixTransform 来对节点进行了平移,发现不行。又用了 osg:ositionAttitudeTransform 来直接对模型进行位置设定,发现还是不行。不知道该怎么弄了,寻求帮助。 谢谢!
部分代码:
int main()
{
osg::ref_ptr<osg::Node> Scense=osgDB::readNodeFile("UP.IVE");
osg::ref_ptr<osgViewer::Viewer>viewer =new osgViewer::Viewer;
osg::ref_ptr<osg::PositionAttitudeTransform>pat=new osg::PositionAttitudeTransform();
pat->addChild(Scense.get());
pat->setPosition(osg::Vec3(2.0f,0.0f,2.0f));
osg::ref_ptr<osg::Camera>camera=new osg::Camera;
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->x = 0;
traits->y = 0;
traits->width =1000;
traits->height = 800;
traits->doubleBuffer = true;
traits->windowDecoration=true;
traits->sharedContext = 0;
// 创建图形上下文
osg::ref_ptr<osg::GraphicsContext>gc= osg::GraphicsContext::createGraphicsContext(traits.get());
camera->setViewport(new osg::Viewport(30,30,300,300));
camera->setGraphicsContext(gc.get());
camera->setCullingActive(true);
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
camera->setProjectionMatrix(osg::Matrix::rotate(osg:uat(osg::inDegrees(-90.0),0,0,1))*
osg::Matrix::scale(0.08f,0.08f,0.08f));
camera->setClearMask(GL_DEPTH_BUFFER_BIT);
camera->setRenderOrder(osg::Camera::POST_RENDER);
camera->addChild(pat.get());
//优化场景数据
osgUtil::Optimizer optimizer;
optimizer.optimize(camera.get());
viewer->setSceneData(camera.get());
viewer->realize();
viewer->run();
return 0;
}发现在viewer中直接加入该模型是可以显示的,但是把这个模型给了camera再加入到viewer中就不显示了,进行了变换貌似也没有用。 |
|