|
- #include <osgViewer/Viewer>
- #include <osg/Node>
- #include <osg/Geode>
- #include <osg/Group>
- #include <osg/CoordinateSystemNode>
- #include <osg/ShapeDrawable>
- #include <osgDB/ReadFile>
- #include <osgGA/TrackballManipulator>
- #include <iostream>
- osg::ref_ptr<osg::Node> createEarth()
- {
- osg::ref_ptr<osg::ShapeDrawable> sd = new osg::ShapeDrawable(
- new osg::Sphere(osg::Vec3(0.0,0.0,0.0),osg::WGS_84_RADIUS_POLAR));
-
- osg::ref_ptr<osg::Geode> geode = new osg::Geode;
- geode->addDrawable(sd.get());
- std::string filename("Images/land_shallow_topo_2048.jpg");
- geode->getOrCreateStateSet()->setTextureAttributeAndModes(0,
- new osg::Texture2D(osgDB::readImageFile(filename)));
- osg::ref_ptr<osg::CoordinateSystemNode> csn = new osg::CoordinateSystemNode;
- csn->setEllipsolidModel(new osg::EllipsolidModel);
- csn->addChild(geode.get());
- return csn;
- }
- int main()
- {
- osgViewer::Viewer viewer;
- osg::ref_ptr<osg::Group> root = new osg::Group;
- root->addChild(createEarth().get());
- osgGA::TrackballManipulator *Tman = new osgGA::TrackballManipulator;
- viewer.addCameraManipulator(Tman);
- viewer.setSceneGraph(root.get());
- viewer.getCamera()->setClearColor(osg::Vec4(0.0,0.0,0.0,1.0));
- //如果没有以下两句,程序执行正常
- //如果有以下两句,为什么只绘制了部分图形
- viewer.getCamera()->setComputeNearFarMode(osg::Camera:DO_NOT_COMPUTE_NEAR_FAR);
- viewer.getCamera()->setProjectionMatrixAsPerspective(45.0,1.0,0.01,osg::WGS_84_RADIUS_POLAR*100);
- return viewer.run();
- }
复制代码 |
|