OSGのOSGプログラミング:: NodeVisitor

  この記事は「エンジンの設計と実践をレンダリングOpenSceneGraph 3D、」本からのすべてのコンテンツ。

  この記事の焦点はOSGノードへのアクセスです。

  最初からアクセスノードを受信するためのアクセス・ノードは、受け入れ()関数内のノードのユーザは、特定のオブジェクトがアクセスノードに渡されます。

  第二の工程は、次に、アクセスノードの適用()関数を実行し、独自のアクセス制御を渡します。

  この2段階のプロセスは、関数式にコードの非常に単純な線で達成することができます。

ノード::(NodeVisitor&受け入れNV)
{ 
    nv.apply( * これを)。
}

  以下は、アクセスノードの具体例です。

#include <OSG /ノード> 
の#include <osgDB / ReadFile関数> 
の#include <iostreamの> クラス InfoVisitor:公共OSG :: NodeVisitor 
{ パブリック
    InfoVisitor():OSG :: NodeVisitor(TRAVERSE_ALL_CHILDREN)、_indent(0 ){} 仮想ボイド(OSG ::ノード&適用ノード)
    { ためint型 i = 0 ; I <_indent ++ I)
            のstd :: COUT << " " 
        std :: coutの << " [ " << _インデント+ 1 <




     
         ] " << node.libraryName()
             << " ::  << node.className()<< はstd :: ENDL; 

        _indent ++ ; 
        (ノード)トラバース; 
        _indent - ; 
    } 

    仮想 ボイド(OSGを適用する::ジオード・ノード)
    { 
        ためint型 i = 0 ; I <_indent; ++ I)
            のstd :: COUT << "  " ; 
        のstd :: COUT << " [ " <<_indent + 1 << "] " << node.libraryName()
             << " ::  << node.className()<< はstd :: ENDL; 

        のための(符号なし整数 N = 0、N <node.getNumDrawables(); ++ N)
        { 
            OSG :: Drawableの *描画可能= node.getDrawable(N);
             場合(!描画可能)
                 継続;
             のためint型私= 0 ;私<_indent; ++ I)
                のstd :: coutの << "  " ; 
            のstd ::コスト<< drawable-> LIBRARYNAME()
                 << " :: " << drawable->クラス名()<< はstd ::てendl; 
        } 
        _indent ++ 
        (ノード)トラバース。
        _indent - ; 
    } 
保護int型_indent。
}。

INT メイン()
{ 
    OSG ::ノード *ルート= osgDB :: readNodeFile(" osgcool.osgt " )。
    InfoVisitor infoVisitor; 
    もし(ルート)
        ルート > - ;(infoVisitorを)受け入れます
    リターン 0; 
}

  OSGを学ぶために続けて、侯侯

ます。https://www.cnblogs.com/gattaca/p/4562708.htmlで再現

おすすめ

転載: blog.csdn.net/weixin_34310785/article/details/93401840