当前位置: 首页>>代码示例>>C++>>正文


C++ NodeRefPtr::findAttachment方法代码示例

本文整理汇总了C++中osg::NodeRefPtr::findAttachment方法的典型用法代码示例。如果您正苦于以下问题:C++ NodeRefPtr::findAttachment方法的具体用法?C++ NodeRefPtr::findAttachment怎么用?C++ NodeRefPtr::findAttachment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在osg::NodeRefPtr的用法示例。


在下文中一共展示了NodeRefPtr::findAttachment方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

OSG_END_NAMESPACE

// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
    // OSG init
    OSG::osgInit(argc,argv);

    // GLUT init
    int winid = setupGLUT(&argc, argv);

    // open a new scope, because the pointers below should go out of scope
    // before entering glutMainLoop.
    // Otherwise OpenSG will complain about objects being alive after shutdown.
    {
        // the connection between GLUT and OpenSG
        OSG::GLUTWindowRefPtr gwin = OSG::GLUTWindow::create();
        gwin->setGlutId(winid);
        gwin->init();
    
        // load the scene
    
        OSG::NodeRefPtr scene;
        
        if(argc < 2)
        {
            FWARNING(("No file given!\n"));
    
            scene = OSG::makeTorus(.5, 2, 16, 16);
        }
        else
        {
            scene = OSG::SceneFileHandler::the()->read(argv[1]);
        }
    
        /*   
        An Attachment is a special field container that can be attached to
        many of the internal classes like Nodes, NodeCores and many others.
        There can be multiple Attachments attached to an object.
    
        Attachments can be attached to all FieldContainers that are derived from
        AttachmentContainer. This includes most higher-level classes in the
        system, like Nodes, NodeCores, Windows, Viewports etc. See the
        inheritance graph for details.
    
        One predefined kind of Attachment is the Name, which can
        keep the name of an object. Some of loaders (e.g. the WRL loader)
        create these kinds of Attachments for named nodes.
        */
        
        /*
            An Attachment is a FieldContainer and as such needs to be created using
            ::create().
        */
        OSG::NameRefPtr name = OSG::Name::create();
        
        /* 
            The NameAttachment only has a single field, there's no need to use the
            mask here.
        */
        name->editFieldPtr()->setValue("Scene");
        
        /*
            Attach the name to the scene node.
        */
        scene->addAttachment(name);
        
        /*
            Check if the scene has a Name attachment
            
            Attachments are categorized by the GroupID of their class. Every
            AttachmentContainer generally keeps only one attachment of a specific
            kind. 
        */
        OSG::AttachmentRefPtr a;
        
        a = scene->findAttachment(OSG::Name::getClassType());
        
        if(a != NULL)
        {
            OSG::NameRefPtr n = OSG::dynamic_pointer_cast<OSG::Name>(a);
            
            SLOG << "Node name: " << n->getField().getValue() << OSG::endLog;
        }
        else
        {
            SLOG << "Node has no name!" << OSG::endLog;
        }
        
        /*
            As names are used quite often there are two convenience functions 
            that wrap the code given above: setName and getName. They are declared
            in OSGSimpleAttachments.h.
        */
        if(getName(scene))
        {
            SLOG << "Node is named: " << getName(scene) << OSG::endLog;
        }
        else
        {
//.........这里部分代码省略.........
开发者ID:DaveHarrison,项目名称:OpenSGDevMaster,代码行数:101,代码来源:attachments.cpp


注:本文中的osg::NodeRefPtr::findAttachment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。