官术网_书友最值得收藏!

Time for action—improving the "Hello World" example

The included headers, <osgDB/ReadFile> and <osgViewer/Viewer>, do not need to be modified. We only add a root variable that provides the runtime access to the Cessna model and assigns it to the setSceneData() method.

  1. In the main entry, record the Cessna model with a variable named root:
    osg::ref_ptr<osg::Node> root = osgDB::readNodeFile("cessna.osg");
    osgViewer::Viewer viewer;
    viewer.setSceneData( root.get() );
    return viewer.run();
  2. Build and run it at once:
    Time for action—improving the "Hello World" example
  3. You will see no difference between this example and the previous "Hello World". So what actually happened?

What just happened?

In this example, we introduced two new OSG classes: osg::ref_ptr<> and osg::Node. The osg::Node class represents the basic element of a scene graph. The variable root stands for the root node of a Cessna model, which is used as the scene data to be visualized.

Meanwhile, an instance of the osg::ref_ptr<> class template is created to manage the node object. It is a smart pointer, which provides additional features for the purpose of efficient memory management.

主站蜘蛛池模板: 津市市| 礼泉县| 慈利县| 自贡市| 弥渡县| 雷山县| 西平县| 潍坊市| 长丰县| 玛多县| 桃源县| 乐都县| 永德县| 麻江县| 揭阳市| 翁牛特旗| 遵化市| 尤溪县| 河东区| 新泰市| 盐池县| 东海县| 龙山县| 静安区| 陆河县| 哈密市| 普洱| 鄂托克前旗| 剑川县| 镶黄旗| 方山县| 富锦市| 东山县| 开江县| 久治县| 赤水市| 惠东县| 巴中市| 稷山县| 广平县| 独山县|