|
楼主 |
发表于 2009-7-23 09:57:49
|
显示全部楼层
我使用您的方法试了试 可是使用相机后模型就不会出来了 下面是最要代码:
osgViewer::Viewer viewer;
osg::Group* group = new osg::Group();
osg::ref_ptr<osg::Node> root = new osg::Node();
root = createEarth();
osg::Viewport* viewport = new osg::Viewport(0,1280,0,1024);
osg::Camera* camera = new osg::Camera;
camera->setReferenceFrame( osg::Transform::ABSOLUTE_RF);
camera->setViewport(viewport );
camera->setRenderOrder( osg::Camera:OST_RENDER );
camera->setClearMask( GL_DEPTH_BUFFER_BIT);
camera->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
osg::Node* cessna = osgDB::readNodeFile("cessna.osg");
osg::MatrixTransform* mt = new osg::MatrixTransform();
if (cessna)
{
osg::Matrix matrix;
matrix.identity();
osg::EllipsoidModel* elliposid = new osg::EllipsoidModel();
elliposid->computeLocalToWorldTransformFromLatLongHeight(0,0,10000,matrix);
float a = cessna->getBound().radius();
double s = 200000.0 / cessna->getBound().radius();
osg::MatrixTransform* scaler = new osg::MatrixTransform;
scaler->addChild(cessna);
scaler->setMatrix(osg::Matrixd::scale(s,s,s));
scaler->getOrCreateStateSet()->setMode(GL_RESCALE_NORMAL,osg::StateAttribute::ON);
mt->addChild(scaler);
mt->setMatrix(matrix);
camera->addChild(mt);
}
group->addChild(camera);
//group->addChild(mt); //添加后这一句是能够显示模型的,说明是相机的问题,但是不知道是什么问题,
group->addChild(root);
viewer.setSceneData(group);
viewer.run(); |
|