• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            eryar

            PipeCAD - Plant Piping Design Software.
            RvmTranslator - Translate AVEVA RVM to OBJ, glTF, etc.
            posts - 603, comments - 590, trackbacks - 0, articles - 0

            OpenSceneGraph 場(chǎng)景節(jié)點(diǎn)

            一、OSG場(chǎng)景節(jié)點(diǎn)簡(jiǎn)介及組合模式介紹

            OSG中的場(chǎng)景是樹形結(jié)構(gòu)表示的層次結(jié)構(gòu),如下圖所示:

            Scene node

            Figure 1.1 OpenSceneGraph場(chǎng)景樹形層次結(jié)構(gòu)

            根據(jù)其源碼中的注釋得知,OSG中場(chǎng)景節(jié)點(diǎn)的管理采用了組合(Composite)模式。先簡(jiǎn)要介紹一下組合模式,其類圖為:

            Composite

            Figure 1.2 Composite Pattern's Structure

            使用組合模式的目的是為了將對(duì)象合成樹形結(jié)構(gòu)以表示“部分—整體”的層次結(jié)構(gòu)。Composite使得用戶對(duì)單個(gè)對(duì)象和組合的使用具有一致性。組合模式通常用于以下情況:

            l 你想表示對(duì)象的部分—整體層次結(jié)構(gòu);

            l 你希望用戶忽略組合對(duì)象與單個(gè)對(duì)象的不同,用戶將統(tǒng)一地使用組合結(jié)構(gòu)中的所有對(duì)象;

            為了達(dá)到葉子節(jié)點(diǎn)與組合節(jié)點(diǎn)的一致性,也可以給葉子節(jié)點(diǎn)定義與組合節(jié)點(diǎn)一樣的操作,但是這些操作什么也不做,與引入Null Object模式類似,這里引入Null Operation

            組合模式中主要的參與者有三個(gè):

            l Component

            n Declares the interface for objects in the composition

            n Implements default behavior for the interface common to all classes, as appropriate;

            n Declares and interface for accessing and managing its child components;

            n (optional)Defines an interface for accessing a component's parent in the recursive structure and implements it if that's appropriate;

            l Leaf

            n Represents leaf objects in the composition. A leaf has no children;

            n Defines behavior for primitive objects in the composition;

            l Composite

            n Defines behavior for components having children;

            n Stores child components;

            l Client

            n Manipulates objects in the composition through the Component interface.

            二、OSG中組合Composite模式的應(yīng)用

            根據(jù)OSG的文檔得到其場(chǎng)景節(jié)點(diǎn)的類圖,如下圖所示:

            class

            Figure 1.3 Inheritance Diagram for osg::Node

            結(jié)合紅星標(biāo)示出的三個(gè)類:osg::Nodeosg::Geodeosg::Group來(lái)講述組合模式的具體應(yīng)用。以下為聲明類osg::Node時(shí)給出的注釋:

            /** Base class for all internal nodes in the scene graph.

            Provides interface for most common node operations (Composite Pattern).

            */

            osg::Node類為所有場(chǎng)景圖形的基類,為大多數(shù)能用節(jié)點(diǎn)操作提供接口,采用提組合模式。

            以下為聲明類osg::Geode時(shí)給出的注釋:

            /** A \c Geode is a "geometry node", that is, a leaf node on the scene graph

            * that can have "renderable things" attached to it. In OSG, renderable things

            * are represented by objects from the \c Drawable class, so a \c Geode is a

            * \c Node whose purpose is grouping <tt>Drawable</tt>s.

            */

            osg::Geode類是一個(gè)幾何節(jié)點(diǎn),即場(chǎng)景節(jié)點(diǎn)中的一個(gè)葉子節(jié)點(diǎn),可以把可渲染的東西綁定在它上面。在OSG中,可渲染的東西表示為由類Drawable生成的對(duì)象。所以,一個(gè)Geode目的就是使Drawable成組。具體實(shí)現(xiàn)的程序代碼為:

            typedef std::vector< ref_ptr<Drawable> > DrawableList;

            保護(hù)成員變量:

            DrawableList _drawables;

            以下為聲明類osg::Group時(shí)給出的注釋:

            /** General group node which maintains a list of children.

            * Children are reference counted. This allows children to be shared

            * with memory management handled automatically via osg::Referenced.

            */

            osg::Group節(jié)點(diǎn)維護(hù)一個(gè)孩子表,孩子是引用計(jì)數(shù)的。這樣就可以由內(nèi)存管理機(jī)制來(lái)管理這些孩子。具體實(shí)現(xiàn)的程序代碼為:

            typedef std::vector< ref_ptr<Node> > NodeList;

            保護(hù)成員變量:

            NodeList _children;

            綜上所述,得出它們的類圖:

            Figure 1.4 OSG Node Class Diagram

            由類圖可知,這個(gè)類圖與圖1.2所示的組合模式的類圖相似。其中,類osg::Node可以看成是Component類,為所有的場(chǎng)景節(jié)點(diǎn)的通用操作聲明接口;osg::Geode類可看作Leaf類,是一個(gè)具體的可渲染的場(chǎng)景節(jié)點(diǎn);osg::Group類可看作Composite類,它可以包含葉節(jié)點(diǎn)或其它節(jié)點(diǎn)。

            三、程序示例

            編程實(shí)現(xiàn)由多個(gè)模型來(lái)構(gòu)成一個(gè)場(chǎng)景,為了簡(jiǎn)便起見,模型由文件得到。場(chǎng)景的樹形層次結(jié)構(gòu)如下圖所示:

            node

            Figure 1.5 Add More Models to Scene Graph

            程序代碼如下:

            //--------------------------------------------------------------------------

            // Copyright (c) 2012 eryar All Rights Reserved.

            //

            // File : Main.cpp

            // Author : eryar@163.com

            // Date : 2012-1-3 20:58

            // Version : 1.0v

            //

            // Description : Add more models to the Secne.

            //

            //==========================================================================

            #include <osg/Node>

            #include <osgDB/ReadFile>

            #include <osgViewer/Viewer>

            #include <osgViewer/ViewerEventHandlers>

            int main(int argc, char* argv[])

            {

            osgViewer::Viewer viewer;

            osg::ref_ptr<osg::Group> root = new osg::Group;

            osg::ref_ptr<osg::Group> group = new osg::Group;

            root->addChild(osgDB::readNodeFile("glider.osg"));

            group->addChild(osgDB::readNodeFile("osgcool.osgt"));

            group->addChild(osgDB::readNodeFile("axes.osgt"));

            root->addChild(group);

            viewer.setSceneData(root);

            viewer.realize();

            viewer.addEventHandler(new osgViewer::WindowSizeHandler);

            viewer.addEventHandler(new osgViewer::StatsHandler);

            return viewer.run();

            }

            程序效果圖如下圖所示:

            Figure 1.6 Render OSG Node

             

            PDF Version

            人妻无码αv中文字幕久久琪琪布| 久久久精品人妻无码专区不卡 | 九九久久精品国产| 很黄很污的网站久久mimi色| 久久久久99精品成人片牛牛影视| 久久亚洲电影| 久久久婷婷五月亚洲97号色| 女人香蕉久久**毛片精品| 色偷偷91久久综合噜噜噜噜| 日韩精品久久久久久免费| 国产成人无码精品久久久久免费| 亚洲精品视频久久久| 国产精品久久久久影院嫩草| 伊人久久大香线蕉综合5g| 国产午夜久久影院| 狠狠色婷婷久久一区二区| 久久人人爽人人爽人人片AV麻豆| 久久精品国产亚洲AV无码偷窥| 亚洲AⅤ优女AV综合久久久| 国产一区二区三区久久精品| 久久久久高潮综合影院| 精品久久人人做人人爽综合 | 999久久久免费精品国产| 久久99国产精品久久99小说| 国产精品热久久毛片| 久久青青草原国产精品免费| 久久夜色精品国产噜噜亚洲AV| 欧美亚洲另类久久综合婷婷| 国产精品无码久久久久| 91久久成人免费| 99久久国产综合精品五月天喷水| 国产色综合久久无码有码| 亚洲人成电影网站久久| 一本色综合久久| 精品久久久中文字幕人妻| 久久亚洲精品国产亚洲老地址 | 色综合久久88色综合天天 | 久久久人妻精品无码一区| 国产精品日韩欧美久久综合| 精品久久久久久久久久久久久久久 | 99精品久久精品一区二区|