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


C++ NodeRecPtr::addChild方法代码示例

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


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

示例1: keyboard

// react to keys
void keyboard(unsigned char k, int x, int y)
{
    switch(k)
    {
        case 27:    
        {
            delete _mgr;

            _client_win  = NULL;
            _cluster_win = NULL;
            _root        = NULL;

            OSG::osgExit();
            exit(0);
        }
        case 'n':
            while(_root->getNChildren() > 0)
                _root->subChild(_root->getChild(0));

            glutPostRedisplay();
        break;
        case 'l':
        {
            OSG::NodeUnrecPtr scene = 
                OSG::SceneFileHandler::the()->read("tie.wrl", NULL);

            if(scene != NULL)
            {
                _root->addChild(scene);

                _mgr->showAll();

                glutPostRedisplay();
            }
        }
        break;
        case 't':
        {
            OSG::NodeUnrecPtr scene = OSG::makeTorus(.5, 2, 16, 16);

            _root->addChild(scene);

            _mgr->showAll();

            glutPostRedisplay();
        }
        break;
        case 'c':
            connectCluster();
        break;
        case 'd':
            disconnectCluster();
        break;
    }
}
开发者ID:DaveHarrison,项目名称:OpenSGDevMaster,代码行数:56,代码来源:testDynamicClusterClient.cpp

示例2: createScene

OSG::NodeTransitPtr createScene(OSG::Window *win)
{
   OSG::NodeRecPtr rootN = OSG::makeNodeFor(OSG::Group::create());

   // Create ground:
   OSG::NodeUnrecPtr groundN = OSG::makePlane(25,25,1,1);
   OSG::Matrix m;
   OSG::Quaternion q;
   q.setValueAsAxisDeg(OSG::Vec3f(1,0,0), -90);
   m.setRotate(q);

   OSG::TransformUnrecPtr groundTransC = OSG::Transform::create();
   groundTransC->setMatrix(m);

   OSG::NodeUnrecPtr groundTransN = OSG::makeNodeFor(groundTransC);
   groundTransN->addChild(groundN);
   rootN->addChild(groundTransN);

   // Set ground material:
   OSG::SimpleMaterialUnrecPtr mat = OSG::SimpleMaterial::create();
   mat->setDiffuse(OSG::Color3f(0.8,0.8,0.8));
   dynamic_cast<OSG::Geometry*>(groundN->getCore())->setMaterial(mat);

//   // Create figure:
//   OSG::NodeUnrecPtr figure1N =
//         OSG::SceneFileHandler::the()->read("../Models/Figure.obj");

//   G.figure1TransC = OSG::Transform::create();
//   OSG::NodeUnrecPtr trans1N = OSG::makeNodeFor(G.figure1TransC);
//   trans1N->addChild(figure1N);
//   rootN->addChild(trans1N);

   OSG::NodeUnrecPtr figureModelA =
         OSG::SceneFileHandler::the()->read("../assets/Figure.obj");

   BoardGame::Figure* figureA = new BoardGame::Figure();
   figureA->setModel(figureModelA);
   rootN->addChild(figureA->getRoot());

   OSG::NodeUnrecPtr figureModelB =
         OSG::SceneFileHandler::the()->read("../assets/Figure.obj");

   BoardGame::Figure* figureB = new BoardGame::Figure();
   figureB->setModel(figureModelB);
   rootN->addChild(figureB->getRoot());

   G.selectedNode = figureModelA;

   return(OSG::NodeTransitPtr(rootN));
}
开发者ID:martinhecher,项目名称:Tomato,代码行数:50,代码来源:MenschAergereDichNicht.cpp

示例3: createScenegraph

OSG::NodeRecPtr createScenegraph(void)
{
    //create sun, planet & moon geometry

    OSG::GeometryRecPtr sun    = OSG::makeSphereGeo(3, 6);
    OSG::NodeRecPtr     planet = OSG::makeSphere   (3, 3);
    OSG::NodeRecPtr     moon   = OSG::makeSphere   (2, 1);

    //the root node will be the sun
    OSG::NodeRecPtr root = OSG::Node::create();
    root->setCore(sun);

    OSG::NodeRecPtr planetTransformNode = OSG::Node::create();
    OSG::NodeRecPtr moonTransformNode   = OSG::Node::create();

    // these were declared globally
    planetTransform = OSG::Transform::create();
    moonTransform   = OSG::Transform::create();

    // Now we need to fill it with live
    // We want to have the planet some distance away from the sun,
    // but initial with no rotation. The same aplies to the moon
    OSG::Matrix m,n;

    m.setIdentity();
    n.setIdentity();

    m.setTranslate(20, 0, 0);
    n.setTranslate( 8, 0, 0);

    planetTransform->setMatrix(m);
    moonTransform  ->setMatrix(n);

    //Insert the cores into the apropiate nodes and add the geometry
    planetTransformNode->setCore (planetTransform);
    planetTransformNode->addChild(planet         );

    moonTransformNode->setCore (moonTransform);
    moonTransformNode->addChild(moon         );

    //add the planet to the sun
    root->addChild(planetTransformNode);
    root->addChild(moonTransformNode  );

    //now we are done
    return OSG::NodeTransitPtr(root);
}
开发者ID:rdgoetz,项目名称:OpenSGDevMaster_Toolbox,代码行数:47,代码来源:06solarsystem3.cpp

示例4: doMain

// Initialize GLUT & OpenSG and set up the scene
int doMain(int argc, char **argv)
{
    std::cout << "start a cluster server with './testClusterServer -w pipe0'\n"
                 "press 'c' to connect to the servers.\n"
                 "press 'd' to disconnect from the servers.\n"
                 "press 'n' to delete current scene.\n"
                 "press 't' to create a torus.\n"
                 "press 'l' to load scene 'tie.wrl'.\n"
              << std::endl;
    
    // OSG init
    OSG::osgInit(argc,argv);

    OSG::VTKPolyDataMapper::getClassType().dump();

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

    // the connection between GLUT and OpenSG

    _client_win = OSG::GLUTWindow::create();

    _client_win->setGlutId(winid);
    _client_win->init();
    _client_win->setSize(300,300);
    
    for(OSG::Int32 i=0;i<argc-1;++i)
    {
        if(argv[i+1] != NULL)
            _pipenames.push_back(argv[i+1]);
    }

    if(_pipenames.empty())
        _pipenames.push_back("pipe0");
    
    _root = OSG::Node::create();
    
    _root->setCore(OSG::Group::create());
    
    // create default scene
//    NodePtr scene = makeTorus(.5, 2, 16, 16);
    OSG::NodeUnrecPtr scene = initVTK();

    _root->addChild(scene);

    // create the SimpleSceneManager helper
    _mgr = OSG::SimpleSceneManager::create();

    // tell the manager what to manage
    _mgr->setWindow(_client_win );
    _mgr->setRoot  (_root);

    // show the whole scene
    _mgr->showAll();
    

    return 0;
}
开发者ID:jondo2010,项目名称:OpenSG,代码行数:59,代码来源:testVTKClusterConnect.cpp

示例5: main

int main( int argc, char **argv )
{
    OSG::osgInit(argc,argv);
    
    QApplication::setColorSpec( QApplication::CustomColor );
    QApplication a( argc, argv );

    if ( !QGLFormat::hasOpenGL() ) {
    qWarning( "This system has no OpenGL support. Exiting." );
    return -1;
    }
    
    OpenSGWidget w(QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer | QGL::Rgba |
                             QGL::DirectRendering));

    // create the scene
    OSG::NodeRecPtr scene;
    
    if(argc > 1)
    {
        scene = OSG::Node::create();
        OSG::GroupRecPtr g = OSG::Group::create();

        scene->setCore(g);
        
        for(OSG::UInt16 i = 1; i < argc; ++i)
            scene->addChild(OSG::SceneFileHandler::the()->read(argv[i]));
    }
    else
    {
        scene = OSG::makeTorus(.5, 3, 16, 16);
    }

    w.getManager()->setRoot(scene);
    w.getManager()->showAll();

    w.show();
    return a.exec();
}
开发者ID:DaveHarrison,项目名称:OpenSGDevMaster,代码行数:39,代码来源:testPassiveQT4.cpp

示例6: doMain


//.........这里部分代码省略.........
    OSG::TextureEnvChunkUnrecPtr tex_earth_night_env = 
        OSG::TextureEnvChunk::create();

    tex_earth_night->setImage(earth_night_map_img);
    tex_earth_night->setMinFilter(GL_LINEAR_MIPMAP_LINEAR);
    tex_earth_night->setMagFilter(GL_LINEAR);
    tex_earth_night->setWrapS(GL_REPEAT);
    tex_earth_night->setWrapT(GL_REPEAT);

    tex_earth_night_env->setEnvMode(GL_MODULATE);
    
    // Read the image for the normal texture
    OSG::ImageUnrecPtr earth_clouds_map_img = OSG::Image::create();
    if(!earth_clouds_map_img->read("EarthClouds.jpg"))
    {
        fprintf(stderr, "Couldn't read texture 'EarthClouds.jpg'\n");
        return 1;
    }

    OSG::TextureObjChunkUnrecPtr tex_earth_clouds     = 
        OSG::TextureObjChunk::create();
    OSG::TextureEnvChunkUnrecPtr tex_earth_clouds_env = 
        OSG::TextureEnvChunk::create();

    tex_earth_clouds->setImage(earth_clouds_map_img);
    tex_earth_clouds->setMinFilter(GL_LINEAR_MIPMAP_LINEAR);
    tex_earth_clouds->setMagFilter(GL_LINEAR);
    tex_earth_clouds->setWrapS(GL_REPEAT);
    tex_earth_clouds->setWrapT(GL_REPEAT);

    tex_earth_clouds_env->setEnvMode(GL_MODULATE);


    _shl = OSG::ShaderProgramChunk::create();

    _shl_vp = OSG::ShaderProgram::create();
    _shl_fp = OSG::ShaderProgram::create();
    
    if(!_shl_vp->readProgram("Earth.vp"))
        fprintf(stderr, "Couldn't read vertex program 'Earth.vp'\n");
    if(!_shl_fp->readProgram("Earth.fp"))
        fprintf(stderr, "Couldn't read fragment program 'Earth.fp'\n");

    _shl_vp->setShaderType(GL_VERTEX_SHADER);
    _shl_fp->setShaderType(GL_FRAGMENT_SHADER);

    _shl->addVertexShader  (_shl_vp);
    _shl->addFragmentShader(_shl_fp);

    _shl_fp->addUniformVariable("EarthDay", 0);
    _shl_fp->addUniformVariable("EarthNight", 1);
    _shl_fp->addUniformVariable("EarthCloudGloss", 2);

    _shl_vp->addUniformVariable("season", 0.0f);
    _shl_vp->addUniformVariable("cos_time_0_2PI", -0.406652f);
    _shl_vp->addUniformVariable("sin_time_0_2PI", -0.913583f);
//    _shl->setUniformParameter("foo", -0.913583f);

    
    cmat->addChunk(_shl);
    cmat->addChunk(tex_earth);
    cmat->addChunk(tex_earth_env);
    cmat->addChunk(tex_earth_night);
    cmat->addChunk(tex_earth_night_env);
    cmat->addChunk(tex_earth_clouds);
    cmat->addChunk(tex_earth_clouds_env);


    // create root node
    _scene = OSG::Node::create();

    OSG::GeometryUnrecPtr geo = OSG::makeLatLongSphereGeo (100, 100, 1.0);

    geo->setMaterial(cmat);


    OSG::NodeUnrecPtr torus = OSG::Node::create();
    
    torus->setCore(geo);


    // add torus to scene
    OSG::GroupUnrecPtr group = OSG::Group::create();

    _scene->setCore(group);
    _scene->addChild(torus);


    // create the SimpleSceneManager helper
    _mgr = OSG::SimpleSceneManager::create();

    // tell the manager what to manage
    _mgr->setWindow(gwin );
    _mgr->setRoot(_scene);

    // show the whole scene
    _mgr->showAll();

    return 0;
}
开发者ID:Himbeertoni,项目名称:OpenSGDevMaster,代码行数:101,代码来源:testSHLEarth_shaderprog.cpp

示例7: main

// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
    printf("Usage: testCGShader <filename.vp> <filename.fp>\n");

    if( argc < 3 )
        return 0;
    
    // OSG init
    OSG::osgInit(argc,argv);

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

    // the connection between GLUT and OpenSG
    OSG::GLUTWindowUnrecPtr gwin= OSG::GLUTWindow::create();
    gwin->setGlutId(winid);
    gwin->setSize( 800, 800 );
    gwin->init();

    // Create the shader material
    OSG::ChunkMaterialUnrecPtr cmat = OSG::ChunkMaterial::create();

    OSG::MaterialChunkUnrecPtr matc = OSG::MaterialChunk::create();

    matc->setAmbient(OSG::Color4f(0.1, 0.1, 0.1, 1.0));
    matc->setDiffuse(OSG::Color4f(0.3, 0.3, 0.3, 1.0));
    matc->setSpecular(OSG::Color4f(0.8, 0.8, 0.8, 1.0));
    matc->setShininess(100);
    matc->setLit(true);

    OSG::SHLChunkUnrecPtr shl = OSG::SHLChunk::create();

    shl->readVertexProgram(argv[1]);
    shl->readFragmentProgram(argv[2]);

    cmat->addChunk(shl);


    // create root node
    _scene = OSG::Node::create();

    // create torus
    OSG::GeometryUnrecPtr geo = OSG::makeTorusGeo(.8, 1.8, 128, 128);
    geo->setMaterial(cmat);

    OSG::NodeUnrecPtr torus = OSG::Node::create();
    torus->setCore(geo);

    // add torus to scene
    OSG::GroupUnrecPtr group = OSG::Group::create();
    _scene->setCore(group);
    _scene->addChild(torus);

    // create the SimpleSceneManager helper
    _mgr = OSG::SimpleSceneManager::create();

    // tell the manager what to manage
    _mgr->setWindow(gwin );
    _mgr->setRoot(_scene);

    /*
    // create point headlight
    _mgr->turnHeadlightOff();
    NodePtr headlight = _mgr->getHighlight();
    PointLightPtr light    = PointLight::create();
    beginEditCP(light);
        light->setAmbient  (.3, .3, .3, 1);
        light->setDiffuse  ( 1,  1,  1, 1);
        light->setSpecular ( 1,  1,  1, 1);
        light->setBeacon   (_mgr->getCamera()->getBeacon());
    endEditCP(light);
    beginEditCP(_scene);
        _scene->setCore(light);
    endEditCP(_scene);
    */

    // show the whole scene
    _mgr->showAll();

    // GLUT main loop
    glutMainLoop();

    return 0;
}
开发者ID:Himbeertoni,项目名称:OpenSGDevMaster,代码行数:85,代码来源:testSHL_compat.cpp

示例8: main

int main(int argc, char **argv)
{
    OSG::osgInit(argc,argv);
    
    if(argc > 1 && !strcmp(argv[1],"-s"))
    {
        show = false;
        argv++;
        argc--;
    }
    
    if(argc > 1 && !strcmp(argv[1],"-d"))
    {
        debug = true;
        argv++;
        argc--;
    }

    
    if(argc > 1)
    {
        scene = OSG::Node::create();
        OSG::GroupUnrecPtr g = OSG::Group::create();
        
        scene->setCore(g);
        
        for(OSG::UInt16 i = 1; i < argc; ++i)
            scene->addChild(OSG::SceneFileHandler::the()->read(argv[i]));
    }
    else
    {
        scene = OSG::makeTorus(.5, 3, 16, 16);
    }

    // GLUT init
    glutInit(&argc, argv);
    
    glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);

    glutInitWindowSize(1024, 768);
    mainwinid = glutCreateWindow("OpenSG");
    
    glutReshapeFunc(reshape);
    glutDisplayFunc(display);
    glutIdleFunc(idle);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutKeyboardFunc(keyboard);

    OSG::GLUTWindowUnrecPtr mainwin=OSG::GLUTWindow::create();
    mainwin->setGlutId(mainwinid);
    mainwin->init();
    
    // create the SimpleSceneManager helper
    mgr = OSG::SimpleSceneManager::create();

    // create the window and initial camera/viewport
    mgr->setWindow(mainwin);
    // tell the manager what to manage
    mgr->setRoot  (scene);

    OSG::commitChanges();

    // show the whole scene
    mgr->showAll();

    mgr->setUseTraversalAction(true);

    tact      = OSG::RenderAction::create();
#ifdef OSG_OLD_RENDER_ACTION
    act       = OSG::RenderAction::create();
#endif
    debugact  = OSG::RenderAction::create();
    tact->setOcclusionCulling(true);


    // Open the debug window
    if(debug)
    {
        OSG::traverse(scene, initMask);

        glutInitWindowSize(800, 400);
        debugwinid = glutCreateWindow("OpenSG Occlusion Debugging");

        glutReshapeFunc(reshape);
        glutDisplayFunc(display);
        glutIdleFunc(display);
        glutKeyboardFunc(keyboard);

        debugwin=OSG::GLUTWindow::create();
        debugwin->setGlutId(debugwinid);
        debugwin->init();       
        
        OSG::ViewportUnrecPtr vp = mainwin->getPort(0);
        
        OSG::ViewportUnrecPtr newvp = OSG::Viewport::create();        
        newvp->setLeft(0);
        newvp->setRight(0.5);
        newvp->setBottom(0);
        newvp->setTop(1);
//.........这里部分代码省略.........
开发者ID:Himbeertoni,项目名称:OpenSGDevMaster,代码行数:101,代码来源:testOcclusionCulling.cpp

示例9: main

int main( int argc, char **argv )
{
    // OSG init
    OSG::osgInit(argc, argv);

    OSG::SceneFileHandler::the()->print();

    // create the graph

    // beacon for camera and light  
    OSG::NodeRecPtr b1n = OSG::Node::create();
    OSG::GroupRecPtr b1 = OSG::Group::create();
    b1n->setCore( b1 );

    // transformation
    OSG::NodeRecPtr t1n = OSG::Node::create();
    OSG::TransformRecPtr t1 = OSG::Transform::create();
    t1n->setCore( t1 );
    t1n->addChild( b1n );

    cam_trans = t1;

    // light
    OSG::NodeRecPtr dlight = OSG::Node::create();
    OSG::DirectionalLightRecPtr dl = OSG::DirectionalLight::create();

    dlight->setCore( dl );
    
    dl->setAmbient( .3, .3, .3, 1 );
    dl->setDiffuse( 1, 1, 1, 1 );
    dl->setDirection(0,0,1);
    dl->setBeacon( b1n);

    // root
    root = OSG::Node::create();
    OSG::GroupRecPtr gr1 = OSG::Group::create();
    root->setCore( gr1 );
    root->addChild( t1n );
    root->addChild( dlight );

    // Load the file
    OSG::NodeRecPtr file = NULL;
    
    if ( argc > 1 )
        file = OSG::SceneFileHandler::the()->read(argv[1]);
    
    if ( file == NULL )
    {
        std::cerr << "Couldn't load file, ignoring" << std::endl;
        file = OSG::makeTorus( .5, 2, 16, 16 );
    }

    OSG::commitChanges();
    
    file->updateVolume();

    OSG::Vec3f min,max;
    file->getVolume().getBounds( min, max );
    
    std::cout << "Volume: from " << min << " to " << max << std::endl;

    dlight->addChild( file );

    std::cerr << "Tree: " << std::endl;
    root->dump();

    // Camera
    OSG::PerspectiveCameraRecPtr cam = OSG::PerspectiveCamera::create();

    cam->setBeacon( b1n );
    cam->setFov( OSG::osgDegree2Rad( 60 ) );
    cam->setNear( 1 );
    cam->setFar( 4000 );

    // Background
    OSG::SolidBackgroundRecPtr bkgnd = OSG::SolidBackground::create();
    bkgnd->setColor( OSG::Color3f( 0,0,1 ) );

    // Viewport
    vp = OSG::Viewport::create();
    vp->setCamera( cam );
    vp->setBackground( bkgnd );
    vp->setRoot( root );
    vp->setSize( 0,0, 1,1 );
    
    // Action
    ract = OSG::RenderAction::create();

    // QT init
    QApplication::setColorSpec( QApplication::CustomColor );
    a = new QApplication( argc, argv );

    if ( !QGLFormat::hasOpenGL() )
    {
        qWarning( "This system has no OpenGL support. Exiting." );
        return -1;
    }

    OSG::Vec3f pos( 0, 0, max[2] + ( max[2] - min[2] ) * 1.5 );

//.........这里部分代码省略.........
开发者ID:Himbeertoni,项目名称:OpenSGDevMaster,代码行数:101,代码来源:testWindowQT4_qt.cpp

示例10: init

void init(std::vector<std::string> &filenames)
{
    size_t i;
    OSG::DirectionalLightUnrecPtr dl;
    OSG::Real32 x,y,z;
    OSG::BoxVolume volume;
    OSG::Vec3f min,max;
    OSG::Vec3f size;

    glEnable( GL_DEPTH_TEST );
    glEnable( GL_LIGHTING );
    glEnable( GL_LIGHT0 );
//    GLint twoSide = 1;
//    glLightModeliv(GL_LIGHT_MODEL_TWO_SIDE,&twoSide);
    glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );

    // create the graph

    // beacon for camera and light
    OSG::NodeUnrecPtr b1n = OSG::Node::create();
    OSG::GroupUnrecPtr b1 = OSG::Group::create();
    b1n->setCore( b1 );

    // transformation
    OSG::NodeUnrecPtr t1n = OSG::Node::create();
    OSG::TransformUnrecPtr t1 = OSG::Transform::create();
    t1n->setCore( t1 );
    t1n->addChild( b1n );

    cam_trans = t1;

    // light

    OSG::NodeUnrecPtr dlight = OSG::Node::create();
    dl = OSG::DirectionalLight::create();

    dlight->setCore( dl );

    dl->setAmbient( .3f, .3f, .3f, 1 );
    dl->setDiffuse( 1, 1, 1, 1 );
    dl->setDirection(0,0,1);
    dl->setBeacon( b1n);

    // root
    root = OSG::Node::create();

    OSG::GroupUnrecPtr gr1 = OSG::Group::create();

    root->setCore( gr1 );
    root->addChild( t1n );
    root->addChild( dlight );

    // Load the file
    OSG::NodeUnrecPtr scene = OSG::Node::create();
    scene->setCore(OSG::Group::create());

    OSG::NodeUnrecPtr file;
    for(i=0;i<filenames.size();i++)
    {
        file = OSG::SceneFileHandler::the()->read(filenames[i].c_str(),0);
        if(file != NULL)
            scene->addChild(file);
        else
            std::cerr << "Couldn't load file, ignoring " << filenames[i] << std::endl;
    }
	if ( filenames.size()==0 )
	{
        file = OSG::makeTorus( .5, 2, 16, 16 );
        scene->addChild(file);
//        scene->addChild(makeBox(.6,.6,.6,5,5,5));
    }

    prepareSceneGraph(scene);

    OSG::Thread::getCurrentChangeList()->commitChanges();

    scene->invalidateVolume();
    scene->updateVolume();
    volume=scene->getVolume();
    volume.getBounds(min,max);
    size = max-min;

    if(ca>0)
    {
        if(cb==-1)
            cb=ca;
        if(cc==-1)
            cc=cb;
            
        OSG::NodeUnrecPtr node;
        OSG::NodeUnrecPtr geoNode;
        OSG::TransformUnrecPtr trans;
        for(x=-ca/2.0 ; x<ca/2.0 ; x++)
            for(y=-cb/2.0 ; y<cb/2.0 ; y++)
                for(z=-cc/2.0 ; z<cc/2.0 ; z++)
                {
                    trans=OSG::Transform::create();
                    node=OSG::Node::create();
                    
                    node->setCore(trans);
//.........这里部分代码省略.........
开发者ID:Himbeertoni,项目名称:OpenSGDevMaster,代码行数:101,代码来源:testClusterClient.cpp

示例11: doMain

int doMain (int argc, char **argv)
{
    osx_AllowForeground();

    // OSG init

    OSG::osgInit(argc, argv);

    // create the graph

    // beacon for camera and light
    OSG::NodeUnrecPtr b1n = OSG::Node::create();
    OSG::GroupUnrecPtr b1 = OSG::Group::create();
    b1n->setCore( b1 );

    // transformation
    OSG::NodeUnrecPtr t1n = OSG::Node::create();
    OSG::TransformUnrecPtr t1 = OSG::Transform::create();
    t1n->setCore( t1 );
    t1n->addChild( b1n );

    cam_trans = t1;

    // light

    OSG::NodeUnrecPtr dlight = OSG::Node::create();
    OSG::DirectionalLightUnrecPtr dl = OSG::DirectionalLight::create();

    dlight->setCore( dl );

    dl->setAmbient( .0, .0, .0, 1 );
    dl->setDiffuse( .8, .8, .8, .8 );
    dl->setDirection(0,0,1);
    dl->setBeacon( b1n);

    // root
    root = OSG::Node::create();
    OSG::GroupUnrecPtr gr1 = OSG::Group::create();

    root->setCore( gr1 );
    root->addChild( t1n );
    root->addChild( dlight );

    // Load the file

    OSG::NodeUnrecPtr file = NULL;

    if ( argc > 1 )
        file = OSG::SceneFileHandler::the()->read(argv[1]);

    if ( file == NULL )
    {
        std::cerr << "Couldn't load file, ignoring" << std::endl;
        file = OSG::makeTorus( .5, 2, 16, 16 );
    }

    OSG::Thread::getCurrentChangeList()->commitChanges();
    file->updateVolume();

    OSG::Vec3f min,max;
    file->getVolume().getBounds( min, max );

    std::cout << "Volume: from " << min << " to " << max << std::endl;

    dlight->addChild( file );

    std::cerr << "Tree: " << std::endl;
    //root->dump();

    // Camera
    cam = OSG::PerspectiveCamera::create();

    cam->setBeacon( b1n );
    cam->setFov( OSG::osgDegree2Rad( 90 ) );
    cam->setNear( 0.1 );
    cam->setFar( 100000 );

    // Background
    OSG::SolidBackgroundUnrecPtr bkgnd = OSG::SolidBackground::create();

    bkgnd->setColor(OSG::Color3f(0,0,1));

    // Viewport

    vp = OSG::Viewport::create();
    vp->setCamera( cam );
    vp->setBackground( bkgnd );
    vp->setRoot( root );
    vp->setSize( 0,0, 1,1 );

    // Action

    ract = OSG::RenderAction::create();

    // tball

    OSG::Vec3f pos;
    pos.setValues(min[0] + ((max[0] - min[0]) * 0.5), 
                  min[1] + ((max[1] - min[1]) * 0.5), 
                  max[2] + ( max[2] - min[2] ) * 1.5 );
//.........这里部分代码省略.........
开发者ID:Himbeertoni,项目名称:OpenSGDevMaster,代码行数:101,代码来源:testWindowCarbon.cpp

示例12: doMain

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

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

    // the connection between GLUT and OpenSG
    OSG::GLUTWindowUnrecPtr gwin = OSG::GLUTWindow::create();
    gwin->setGlutId(winid);
    gwin->setSize( 800, 800 );
    gwin->init();

    // Create the shader material
    OSG::ChunkMaterialUnrecPtr cmat = OSG::ChunkMaterial::create();

    OSG::SHLChunkUnrecPtr shl = OSG::SHLChunk::create();

    shl->setProgramParameter(GL_GEOMETRY_INPUT_TYPE_EXT, 
                             GL_TRIANGLES);
    shl->setProgramParameter(GL_GEOMETRY_OUTPUT_TYPE_EXT, 
                             GL_TRIANGLE_STRIP);
    shl->setProgramParameter(GL_GEOMETRY_VERTICES_OUT_EXT, 6);

    shl->setVertexProgram(_vertex_shader);
    shl->setFragmentProgram(_fragment_shader);
    shl->setGeometryProgram(_geometry_shader);

    cmat->addChunk(shl);

    // create root node
    _scene = OSG::Node::create();

    // create torus
    OSG::GeometryUnrecPtr geo = OSG::makeTorusGeo(.8, 1.8, 128, 128);

    geo->setMaterial(cmat);

    OSG::NodeUnrecPtr torus = OSG::Node::create();

    torus->setCore(geo);

    // add torus to scene
    OSG::GroupUnrecPtr group = OSG::Group::create();

    _scene->setCore(group);
    _scene->addChild(torus);

    // create the SimpleSceneManager helper
    _mgr = OSG::SimpleSceneManager::create();

    // tell the manager what to manage
    _mgr->setWindow(gwin );
    _mgr->setRoot(_scene);

    // show the whole scene
    _mgr->showAll();

    return 0;
}
开发者ID:Himbeertoni,项目名称:OpenSGDevMaster,代码行数:62,代码来源:testSHLGeometryShader_compat.cpp

示例13: doMain

// Initialize GLUT & OpenSG and set up the scene
int doMain(int argc, char **argv)
{
    printf("Press key '1', '2', or '3' to toggle the light sources.\n");
    // OSG init
    OSG::osgInit(argc,argv);

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

    // the connection between GLUT and OpenSG
    OSG::GLUTWindowUnrecPtr gwin= OSG::GLUTWindow::create();

    gwin->setGlutId(winid);
    gwin->setSize( 800, 800 );
    gwin->init();

    // Create the shader material

    OSG::ChunkMaterialUnrecPtr cmat = OSG::ChunkMaterial::create();

    OSG::MaterialChunkUnrecPtr matc = OSG::MaterialChunk::create();

    matc->setAmbient(OSG::Color4f(0.1f, 0.1f, 0.1f, 1.0f));
    matc->setDiffuse(OSG::Color4f(0.3f, 0.3f, 0.3f, 1.0f));
    matc->setSpecular(OSG::Color4f(0.8f, 0.8f, 0.8f, 1.0f));
    matc->setShininess(100);
    matc->setLit(true);

    OSG::ShaderProgramChunkUnrecPtr shl = OSG::ShaderProgramChunk::create();

    OSG::ShaderProgramUnrecPtr shl_vp = 
        OSG::ShaderProgram::createVertexShader();

    shl_vp->setProgram(_vp_program);

    shl->addShader(shl_vp);

    OSG::ShaderProgramUnrecPtr shl_fp = 
        OSG::ShaderProgram::createFragmentShader();

    shl_fp->setProgram(_fp_program);

    shl->addShader(shl_fp);

    shl_vp->addProceduralVariable    ("Light0Active", &light0Active);
    shl_vp->addProceduralVariable    ("Light1Active", &light1Active);
    shl_vp->addNodeProceduralVariable("Light2Active", &light2Active);

    cmat->addChunk(matc);
    cmat->addChunk(shl);

    // create root node
    _scene = OSG::Node::create();

    // create two light sources.

    OSG::TransformUnrecPtr point1_trans;

    OSG::NodeUnrecPtr point1        = 
        OSG::makeCoredNode<OSG::PointLight>(&_point1_core);
    point1_beacon = OSG::makeCoredNode<OSG::Transform >(&point1_trans);

    point1_trans->editMatrix().setTranslate(-10.0, 5.0, 5.0);

    _point1_core->setAmbient(0.0f, 0.0f, 0.0f , 1.0f);
    _point1_core->setDiffuse(1.0f, 0.0f, 0.0f, 1.0f);
    _point1_core->setSpecular(1.0f, 1.0f, 1.0f, 1.0f);
    _point1_core->setBeacon(point1_beacon);
    _point1_core->setOn(true);


    OSG::TransformUnrecPtr point2_trans;

    OSG::NodeUnrecPtr point2        =
        OSG::makeCoredNode<OSG::PointLight>(&_point2_core);
    point2_beacon = OSG::makeCoredNode<OSG::Transform >(&point2_trans);

    point2_trans->editMatrix().setTranslate(10.0, 5.0, 5.0);

    _point2_core->setAmbient(0.0f, 0.0f, 0.0f, 1.0f);
    _point2_core->setDiffuse(0.0f, 1.0f, 0.0f, 1.0f);
    _point2_core->setSpecular(1.0f, 1.0f, 1.0f, 1.0f);
    _point2_core->setBeacon(point2_beacon);
    _point2_core->setOn(true);

    point1->addChild(point2);
    
    OSG::TransformUnrecPtr point3_trans;

    OSG::NodeUnrecPtr point3        = 
        OSG::makeCoredNode<OSG::PointLight>(&_point3_core);
    
    point3_beacon = OSG::makeCoredNode<OSG::Transform >(&point3_trans);

    point3_trans->editMatrix().setTranslate(0.0, -12.0, 5.0);

    _point3_core->setAmbient(0.0f, 0.0f, 0.0f, 1.0f);
    _point3_core->setDiffuse(0.5f, 0.0f, 1.0f, 1.0f);
    _point3_core->setSpecular(1.0f, 1.0f, 1.0f, 1.0f);
//.........这里部分代码省略.........
开发者ID:martinhecher,项目名称:OpenSGDevMaster,代码行数:101,代码来源:testSHLProcLights_shaderprog.cpp

示例14: createScenegraph

OSG::NodeTransitPtr createScenegraph(void)
{
    // At first we load all needed models from file
    OSG::NodeRecPtr w_high   = 
        OSG::SceneFileHandler::the()->read("Data/woman_high.wrl");

    OSG::NodeRecPtr w_medium = 
        OSG::SceneFileHandler::the()->read("Data/woman_medium.wrl");

    OSG::NodeRecPtr w_low    = 
        OSG::SceneFileHandler::the()->read("Data/woman_low.wrl");
    
    // we check the result
    if((w_high == NULL) || (w_medium == NULL)|| (w_low == NULL))
    {
        std::cout << "It was not possible to load all needed models from file"
                << std::endl;
        return OSG::NodeTransitPtr();
    }
    
    // now the LOD core
    OSG::DistanceLODRecPtr lod = OSG::DistanceLOD::create();
    lod->editSFCenter()->setValue(OSG::Pnt3f(0,0,0));
    lod->editMFRange()->push_back(200);
    lod->editMFRange()->push_back(500);
    
    // the node containing the LOD core. The three models will be
    // added as its children
    OSG::NodeRecPtr lodNode = OSG::Node::create();
    lodNode->setCore(lod);
    lodNode->addChild(w_high);
    lodNode->addChild(w_medium);
    lodNode->addChild(w_low);
    
    // create the node with switch core ********************
    OSG::SwitchRecPtr sw = OSG::Switch::create();
    //Notice: the first choice is 0
    sw->setChoice(0);
    
    OSG::NodeRecPtr switchNode = OSG::Node::create();
    switchNode->setCore(sw);
    switchNode->addChild(lodNode);
    
    //end switch creation **********************************
    
    OSG::NodeRecPtr root = OSG::Node::create();
    root->setCore(OSG::Group::create());
    root->addChild(switchNode);
    
    // we know want to extract the mesh geometry out of the graph
    // it is sufficent to pass the model only as root for searching
    OSG::NodeRecPtr     womanGeometry = checkName(w_high);
    OSG::GeometryRecPtr geo = 
        dynamic_cast<OSG::Geometry *>(womanGeometry->getCore());
    
    //new node with "old" geometry core referenced
    OSG::NodeRecPtr woman = OSG::Node::create();
    woman->setCore(geo);
    
    //translate it a bit to see both women
    OSG::NodeRecPtr      womanTrans = OSG::Node     ::create();
    OSG::TransformRecPtr t          = OSG::Transform::create();
    OSG::Matrix m;
    m.setIdentity();
    m.setTranslate(OSG::Vec3f(0,0,200));
    t->setMatrix(m);
        
    womanTrans->setCore(t);
    womanTrans->addChild(woman);
    
    //add it to the root
    root->addChild(womanTrans);
    
    return OSG::NodeTransitPtr(root);
}
开发者ID:Himbeertoni,项目名称:OpenSGDevMaster,代码行数:75,代码来源:08coresdemo1.cpp

示例15: doMain

// Initialize GLUT & OpenSG and set up the scene
int doMain(int argc, char **argv)
{
    printf("Usage: testCGShader [normal map filename]\n");
    const char *normal_map_img_name = "opensg_logoDOT3.png";

    OSG::Color4f tmp;

    if( argc > 1 )
        normal_map_img_name = argv[1];

    // OSG init
    OSG::osgInit(argc,argv);

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

    // the connection between GLUT and OpenSG
    OSG::GLUTWindowUnrecPtr gwin= OSG::GLUTWindow::create();
    gwin->setGlutId(winid);
    gwin->setSize( 800, 800 );
    gwin->init();

    // Create the shader material

    // Read the image for the normal texture
    OSG::ImageUnrecPtr normal_map_img = OSG::Image::create();
    if(!normal_map_img->read(normal_map_img_name))
    {
        fprintf(stderr, "Couldn't read normalmap texture '%s'!\n", normal_map_img_name);
        return 1;
    }

    OSG::ChunkMaterialUnrecPtr cmat = OSG::ChunkMaterial::create();

    OSG::MaterialChunkUnrecPtr matc = OSG::MaterialChunk::create();

    matc->setAmbient(OSG::Color4f(0.1, 0.1, 0.1, 1.0));
    matc->setDiffuse(OSG::Color4f(0.3, 0.3, 0.3, 1.0));
    matc->setSpecular(OSG::Color4f(0.8, 0.8, 0.8, 1.0));
    matc->setShininess(100);
    matc->setLit(true);

    OSG::ShaderProgramChunkUnrecPtr shl = OSG::ShaderProgramChunk::create();

    OSG::ShaderProgramUnrecPtr shl_vp = 
        OSG::ShaderProgram::createVertexShader();
    
    shl_vp->setProgram(_vp_program);
    shl_vp->setProgramAttribute(OSG::ShaderConstants::TexCoordsIndex, "TexCoord0");
    shl_vp->setProgramAttribute(OSG::ShaderConstants::NormalsIndex,   "Normal"  );
    shl_vp->setProgramAttribute(OSG::ShaderConstants::PositionsIndex, "Position");

    shl->addShader(shl_vp);

    OSG::ShaderProgramUnrecPtr shl_fp = 
        OSG::ShaderProgram::createFragmentShader();

    shl_fp->setProgram(_fp_program);

    shl->addShader(shl_fp);


    OSG::TextureObjChunkUnrecPtr tex_normal_map     = 
        OSG::TextureObjChunk::create();
    OSG::TextureEnvChunkUnrecPtr tex_normal_map_env = 
        OSG::TextureEnvChunk::create();

    tex_normal_map->setImage(normal_map_img);
    tex_normal_map->setMinFilter(GL_LINEAR_MIPMAP_LINEAR);
    tex_normal_map->setMagFilter(GL_LINEAR);
    tex_normal_map->setWrapS(GL_REPEAT);
    tex_normal_map->setWrapT(GL_REPEAT);
    tex_normal_map_env->setEnvMode(GL_MODULATE);

        //cmat->addChunk(matc);
    cmat->addChunk(shl);
    cmat->addChunk(tex_normal_map);
    cmat->addChunk(tex_normal_map_env);


    // create root node
    _scene = OSG::Node::create();

    // create geometry
    //GeometryPtr geo = makeLatLongSphereGeo (100, 100, 1.0);
    OSG::GeometryUnrecPtr geo = OSG::makePlaneGeo(1.0, 1.0, 100, 100);

    geo->setMaterial(cmat);

    OSG::NodeUnrecPtr torus = OSG::Node::create();
    torus->setCore(geo);

    // add torus to scene
    OSG::GroupUnrecPtr group = OSG::Group::create();

    _scene->setCore(group);
    _scene->addChild(torus);

    // create the SimpleSceneManager helper
//.........这里部分代码省略.........
开发者ID:DaveHarrison,项目名称:OpenSGDevMaster,代码行数:101,代码来源:testSHLBumpMapAttr_shaderprog.cpp


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