コード例 #1
0
// Initialize WIN32 & OpenSG and set up the scene
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    {
        // Set up Window
        WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
        TutorialWindow->initWindow();

        // Create the SimpleSceneManager helper
        SimpleSceneManager sceneManager;
        TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
        TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));

        // Tell the Manager what to manage
        sceneManager.setWindow(TutorialWindow);

        //Attach to events
        TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager));
        TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager));
        TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
        TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));

        //Sound Emitter Node
        SoundEmitterRecPtr TheEmitter = SoundEmitter::create();
        TheEmitter->attachUpdateProducer(TutorialWindow);

        NodeUnrecPtr TheEmitterNode = Node::create();
        TheEmitterNode->setCore(TheEmitter);

        //Sphere Transformation Node
        Matrix Translate;
        Translate.setTranslate(0.0,0.0,-5.0);
        Matrix Rotation;
        Rotation.setRotate(Quaternion(Vec3f(0.0,1.0,0.0), 0.0));

        Matrix Total(Translate);
        Total.mult(Rotation);

        TransformRecPtr TheSphereTransform = Transform::create();
        TheSphereTransform->setMatrix(Total);

        NodeUnrecPtr SphereTransformNode = Node::create();
        SphereTransformNode->setCore(TheSphereTransform);
        SphereTransformNode->addChild(makeSphere(2, 1.0));
        SphereTransformNode->addChild(TheEmitterNode);

        // create the scene
        NodeUnrecPtr scene = Node::create();
        scene->setCore(Group::create());
        scene->addChild(SphereTransformNode);

        // tell the manager what to manage
        sceneManager.setRoot  (scene);

        CameraUnrecPtr TheCamera = sceneManager.getCamera();
        TheCamera->setNear(0.1);
        TheCamera->setFar(100.0);

        //Initialize the Sound Manager
        SoundManager::the()->attachUpdateProducer(TutorialWindow);
        SoundManager::the()->setCamera(sceneManager.getCamera());

        SoundRecPtr PopSound = SoundManager::the()->createSound();
        PopSound->setFile(BoostPath("./Data/pop.wav"));
        PopSound->setVolume(1.0);
        PopSound->setStreaming(false);
        PopSound->setLooping(-1);
        PopSound->setEnable3D(true);

        PopSound->connectSoundPlayed  (boost::bind(handleSoundPlayed,   _1));
        PopSound->connectSoundStopped (boost::bind(handleSoundStopped,  _1));
        PopSound->connectSoundPaused  (boost::bind(handleSoundPaused,   _1));
        PopSound->connectSoundUnpaused(boost::bind(handleSoundUnpaused, _1));
        PopSound->connectSoundLooped  (boost::bind(handleSoundLooped,   _1));

        //Attach this sound to the emitter node
        TheEmitter->setSound(PopSound);

        TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1,
                                                    TheEmitter.get()));
        TutorialWindow->connectUpdate(boost::bind(handleUpdate, _1,
                                                  TheSphereTransform.get()));

        //Create the Documentation
        SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow);

        Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
        Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
        TutorialWindow->openWindow(WinPos,
                                   WinSize,
                                   "02 Sound3D Window");


        //Enter main loop
        TutorialWindow->mainLoop();

    }
    osgExit();
    return 0;
}
コード例 #2
0
int main (int argc, char **argv)
{
    osgInit(argc,argv);
    
    // GLUT init

    glutInit(&argc, argv);
    glutInitDisplayMode( GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);

    glutInitWindowSize    (uiSize, uiSize);
    glutInitWindowPosition(100,100);


    int winid = glutCreateWindow("OpenSG");
    glutKeyboardFunc(key);
    glutVisibilityFunc(vis);
    glutReshapeFunc(reshape);
    glutDisplayFunc(display);       
    glutMouseFunc(mouse);   
    glutMotionFunc(motion); 
    
    glutIdleFunc(display);  

    // OSG

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

    // create the graph

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

    b1n->setCore( b1 );

    // transformation
    NodeUnrecPtr      t1n = Node::create();
    TransformUnrecPtr t1  = Transform::create();

    t1n->setCore (t1 );
    t1n->addChild(b1n);

    cam_trans = t1;

    // light
    
    NodeUnrecPtr             dlight = Node::create();
    DirectionalLightUnrecPtr dl     = 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              = Node:: create();
    GroupUnrecPtr gr1 = Group::create();

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

    // Load the file

    NodeUnrecPtr file = NULL;
    
    if(argc > 1)
    {
        file = SceneFileHandler::the()->read(argv[1], NULL);
    }

    if(file == NULL)
    {
        std::cerr << "Couldn't load file, ignoring" << std::endl;

        file = makeSphere(4, 20.0);
    }

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

    file->updateVolume();


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

                 scene_trans = Transform::create();
    NodeUnrecPtr sceneTrN    = Node::create();

    sceneTrN->setCore (scene_trans);
    sceneTrN->addChild(file       );


                 ref_trans = Transform::create();
    NodeUnrecPtr refTrN    = Node::create();

    refTrN->setCore (ref_trans);
    refTrN->addChild(makeSphere(4, 20.0));



#ifdef OLD_BBQ
    AlgorithmStageUnrecPtr pAlgoStage = AlgorithmStage::create();

    pAlgoStage->setInheritedTarget(true);
    pAlgoStage->setProjectionMode(AlgorithmStage::Ignore);
    pAlgoStage->setCopyViewing(true);

    CallbackAlgorithmUnrecPtr pAlgo = CallbackAlgorithm::create();


    pAlgo->setCallback(&terrainRenderCB, "");

    pAlgoStage->setAlgorithm(pAlgo);
#endif

    pSource = BbqOutOfCoreDataSource::create();

//    pSource->setFilename("data/ps_com.bbq");
    pSource->setFilename("data/ps.bbq");
//    pSource->setFilename("/home/gerrit/mtmp/ps.bbq");

    pSource->setHeightScale  (6500.0f);
    pSource->setHeightOffset (0.0f  );
    pSource->setSampleSpacing(1.0f  );

    pTerrain = BbqTerrain::create();

    pTerrain->setBeacon    (sceneTrN);
    pTerrain->setDataSource(pSource );

    pTerrain->setScreenSpaceError(6.0);

    NodeUnrecPtr pAlgoNode = Node::create();

    pAlgoNode->setCore(pTerrain);

    dlight->addChild(pAlgoNode);

    dlight->addChild(sceneTrN);
    dlight->addChild(refTrN  );

    OSG::commitChanges();

    const BbqDataSourceInformation &tInfo = 
        pSource->getInformation();

    fprintf(stderr, "%d %d\n",
            tInfo.heightSampleCount[0],
            tInfo.heightSampleCount[1]);

    fprintf(stderr, "min %f %f\n",
            tInfo.vOrigin[0],
            tInfo.vOrigin[1]);

    fprintf(stderr, "max %f %f\n",
            tInfo.vOrigin[0] + 
                tInfo.heightSampleCount[0] * tInfo.vPixelSize[0],
            tInfo.vOrigin[1] + 
                tInfo.heightSampleCount[1] * tInfo.vPixelSize[1]);

    fprintf(stderr, "ts: %f\n", tInfo.sampleSpacing);


    fprintf(stderr, "info Bbox min %f %f\n", 
            tInfo.gridBBoxMin[0],
            tInfo.gridBBoxMin[1]);

    fprintf(stderr, "info Bbox max %f %f\n", 
            tInfo.gridBBoxMax[0],
            tInfo.gridBBoxMax[1]);

    fUnitScale  = tInfo.sampleSpacing / tInfo.vPixelSize[0];
    fUnitScale1 = tInfo.sampleSpacing / tInfo.vPixelSize[1];

    //(- 285.728333 - (170.f * fUnitScale)
    
    vUnitOffset[0] = tInfo.gridBBoxMin[0] - (tInfo.vOrigin[0] * fUnitScale);
    //m4c[3][2] = (-m4c[3][2] - 40.f) * fUnitScale - 285.728333; 

    vUnitOffset[1] = tInfo.gridBBoxMin[1] - (tInfo.vOrigin[1] * fUnitScale1);

#if 1
    NodeUnrecPtr geoRef = Node::create();
    
    geoRef->setCore(Group::create());

    NodeUnrecPtr           pEll     = Node::create();
    MaterialGroupUnrecPtr  pEllMatG = MaterialGroup::create();
    SimpleMaterialUnrecPtr pEllMat  = SimpleMaterial::create();

    pEllMat->editDiffuse().setValuesRGB(0.3, 0.3, 0.3);

    pEllMatG->setMaterial(pEllMat);

    pEll->setCore(pEllMatG);

    pEll->addChild(makeLatLongEllipsoid(18, 
                                        36, 
                                        6378.137 * 0.95,
                                        6356.7523142 * 0.95));
    

    geoRef->addChild(pEll);
    
    geoRef->addChild(makeEllipsoidAxis(18, 
                                       36, 
                                       6378.137 * 1.05,
                                       6356.7523142 * 1.05));




#if 0
    NodeUnrecPtr           pEllSeg     = Node::create();
    MaterialGroupUnrecPtr  pEllSegMatG = MaterialGroup::create();
    SimpleMaterialUnrecPtr pEllSegMat  = SimpleMaterial::create();

    pEllSegMat->editDiffuse().setValuesRGB(1.0, 0.0, 0.0);
    

    pEllSegMatG->setMaterial(pEllSegMat);

    pEllSeg->setCore(pEllSegMatG);

    pEllSeg->addChild(makeLatLongEllipsoidSeg(18, 
                                              36, 
                                              6378.137 * 1.01,
                                              6356.7523142 * 1.01,
                                              osgDegree2Rad(-50.f),
                                              osgDegree2Rad(165.f),
                                              osgDegree2Rad(-35.f),
                                              osgDegree2Rad(180.f)));

    geoRef->addChild(pEllSeg);
#endif


    NodeUnrecPtr pCorner0 = Node::create();
    NodeUnrecPtr pCorner1 = Node::create();
    NodeUnrecPtr pCorner2 = Node::create();
    NodeUnrecPtr pCorner3 = Node::create();

    TransformUnrecPtr pCornerTr0 = Transform::create();
    TransformUnrecPtr pCornerTr1 = Transform::create();
    TransformUnrecPtr pCornerTr2 = Transform::create();
    TransformUnrecPtr pCornerTr3 = Transform::create();

    pCorner0->setCore(pCornerTr0);
    pCorner1->setCore(pCornerTr1);
    pCorner2->setCore(pCornerTr2);
    pCorner3->setCore(pCornerTr3);

    pCorner0->addChild(makeLatLongSphere(10, 10, 100.f));
    pCorner1->addChild(makeLatLongSphere(10, 10, 100.f));
    pCorner2->addChild(makeLatLongSphere(10, 10, 100.f));
    pCorner3->addChild(makeLatLongSphere(10, 10, 100.f));

    Pnt3f trpos(0.f, 0.f, 0.f);

    projectPnt(trpos, -50.f, 165, 10);

    pCornerTr0->editMatrix()[3][0] = trpos[0];
    pCornerTr0->editMatrix()[3][1] = trpos[1];
    pCornerTr0->editMatrix()[3][2] = trpos[2];

    projectPnt(trpos, -35.f, 165, 10);

    pCornerTr1->editMatrix()[3][0] = trpos[0];
    pCornerTr1->editMatrix()[3][1] = trpos[1];
    pCornerTr1->editMatrix()[3][2] = trpos[2];

    projectPnt(trpos, -50.f, 180, 10);

    pCornerTr2->editMatrix()[3][0] = trpos[0];
    pCornerTr2->editMatrix()[3][1] = trpos[1];
    pCornerTr2->editMatrix()[3][2] = trpos[2];

    projectPnt(trpos, -35.f, 180, 10);

    pCornerTr3->editMatrix()[3][0] = trpos[0];
    pCornerTr3->editMatrix()[3][1] = trpos[1];
    pCornerTr3->editMatrix()[3][2] = trpos[2];

    geoRef->addChild(pCorner0);
    geoRef->addChild(pCorner1);
    geoRef->addChild(pCorner2);
    geoRef->addChild(pCorner3);

    dlight->addChild(geoRef);
#endif

    Pnt3f x1;
    Pnt3f x2;

    projectPnt(x1, 170.0,               40.0, 0);
    projectPnt(x2, 170.000833333333333, 40.0, 0);

    Vec3f v1 = x1 - x2;

    fprintf(stderr, "l:%f\n", v1.length());

    // Camera
    
    cam = PerspectiveCamera::create();
    {
        cam->setBeacon( b1n );
        cam->setFov( osgDegree2Rad( 90 ) );
        cam->setNear( 0.1 );
        cam->setFar( 120000 );
    }

    // Background
    SolidBackgroundUnrecPtr bkgnd = SolidBackground::create();
    {
        bkgnd->setColor(Color3f(0,0,1));
    }

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


    // Window
    GLUTWindowUnrecPtr gwin;

    GLint glvp[4];

    glGetIntegerv(GL_VIEWPORT, glvp);

    gwin = GLUTWindow::create();
    {
        gwin->setGlutId(winid);
        gwin->setSize( glvp[2], glvp[3] );
        
        win = gwin;

        win->addPort( vp );

        win->init();
    }

    // Action
    rentravact = RenderAction::create();

    rentravact->setFrustumCulling(false);

#ifdef OLD_BBQ
    outOfCoreDataSource_ = new BbqOutOfCoreDataSource();

    bool rc = outOfCoreDataSource_->initialize( 
//        "data/ps.bbq", 
        "data/ps_com.bbq", 
        650.0f, 
        0.0f, 
        1.0f );

    fprintf(stderr, "ds::init %d\n", rc);

    const BbqDataSourceInformation &bbqInfo = 
        outOfCoreDataSource_->getInformation();
   

    fprintf(stderr, "%d %d\n",
            bbqInfo.levelCount,
            bbqInfo.nodeCount);

    fprintf(stderr, "%d %d %d\n",
            bbqInfo.heightTileSize,
            bbqInfo.heightSampleCount[0],
            bbqInfo.heightSampleCount[1]);

    fprintf(stderr, "%f %f %f\n",
            bbqInfo.heightScale,
            bbqInfo.heightOffset,
            bbqInfo.sampleSpacing);

    

    const int maxResidentNodeCount = 5000;

    terrain_ = new BbqTerrainEngine();

    rc = terrain_->initialize(outOfCoreDataSource_, maxResidentNodeCount);

    fprintf(stderr, "t::init %d\n", rc);

    terrainRenderOptions_.showSkirts           = false;
    terrainRenderOptions_.showSwitchDistance   = true;
#endif


    // tball
    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 );
    
    float scale = (max[2] - min[2] + max[1] - min[1] + max[0] - min[0]) / 6;

    Pnt3f tCenter(min[0] + (max[0] - min[0]) / 2,
                  min[1] + (max[1] - min[1]) / 2,
                  min[2] + (max[2] - min[2]) / 2);

    fprintf(stderr, "Startpos : %f %f %f\n", pos[0], pos[1], pos[2]);

    tball.setMode            (Trackball::OSGObject);
    tball.setStartPosition   (pos, true           );
    tball.setSum             (true                );
    tball.setTranslationMode (Trackball::OSGFree  );
    tball.setTranslationScale(scale * 400         );
    tball.setRotationCenter  (tCenter             );

    tScale = scale * 400;

    fprintf(stderr, "tscale %f\n", tScale);

//    pos.setValues(0, 400, 0);

    projectPnt(pos, -42.5, 172.5, 10);

    tCenter.setValues(min[0] + (max[0] - min[0]) / 2,
                      min[1] + (max[1] - min[1]) / 2,
                      min[2] + (max[2] - min[2]) / 2);
    
    fprintf(stderr, "Startpos : %f %f %f\n", pos[0], pos[1], pos[2]);

    tcamball.setMode            (Trackball::OSGObject);
    tcamball.setStartPosition   (pos, true           );
    tcamball.setSum             (true                );
    tcamball.setTranslationMode (Trackball::OSGFree  );
    tcamball.setTranslationScale(100                 );
    tcamball.setRotationCenter  (tCenter             );

    m1c.setIdentity();

    m1c[3][1] = 5000;

    m4c.setIdentity();

    m4c[3][1] = 5000;


    pActiveTBall = &tball;

    commitChanges();

    // run...
    glutMainLoop();
    
    return 0;
}
コード例 #3
0
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindow = createNativeWindow();
    TutorialWindow->initWindow();

    TutorialWindow->setDisplayCallback(display);
    TutorialWindow->setReshapeCallback(reshape);

    //Add Window Listener
    TutorialKeyListener TheKeyListener;
    TutorialWindow->addKeyListener(&TheKeyListener);
    TutorialMouseListener TheTutorialMouseListener;
    TutorialMouseMotionListener TheTutorialMouseMotionListener;
    TutorialWindow->addMouseListener(&TheTutorialMouseListener);
    TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(TutorialWindow);
	

	//Shader Material
	BlendChunkUnrecPtr ExampleBlendChunk = BlendChunk::create();
    ExampleBlendChunk->setSrcFactor(GL_SRC_ALPHA);
    ExampleBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);

	//Material Chunk
	MaterialChunkUnrecPtr ShaderMaterialChunk = MaterialChunk::create();
    ShaderMaterialChunk->setAmbient(Color4f(0.4f,0.4f,0.4f,1.0f));
    ShaderMaterialChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f));
    ShaderMaterialChunk->setSpecular(Color4f(1.0f,1.0f,1.0f,1.0f));

	//Shader Chunk
	SimpleSHLChunkUnrecPtr TheSHLChunk = SimpleSHLChunk::create();
    TheSHLChunk->setVertexProgram(createSHLVertexProg());
    TheSHLChunk->setFragmentProgram(createSHLFragProg());

	//Color Parameter
	ShaderVariableVec4fUnrecPtr Color1Parameter = ShaderVariableVec4f::create();
    Color1Parameter->setName("Color1");
    Color1Parameter->setValue(Vec4f(0.0f,1.0f,0.0f,1.0f));
	
	ShaderVariableVec4fUnrecPtr Color2Parameter = ShaderVariableVec4f::create();
    Color2Parameter->setName("Color2");
    Color2Parameter->setValue(Vec4f(1.0f,1.0f,1.0f,1.0f));


	//Shader Parameter Chunk
	SHLParameterChunkUnrecPtr SHLParameters = SHLParameterChunk::create();
    SHLParameters->getParameters().push_back(Color1Parameter);
    SHLParameters->getParameters().push_back(Color2Parameter);
    SHLParameters->setSHLChunk(TheSHLChunk);

	ChunkMaterialUnrecPtr ShaderMaterial = ChunkMaterial::create();
    ShaderMaterial->addChunk(ShaderMaterialChunk);
    ShaderMaterial->addChunk(TheSHLChunk);
    ShaderMaterial->addChunk(SHLParameters);

	//Torus Node
	GeometryUnrecPtr TorusGeometry = makeTorusGeo(5.0f,20.0f, 32,32);

    TorusGeometry->setMaterial(ShaderMaterial);

	NodeUnrecPtr TorusNode = Node::create();
    TorusNode->setCore(TorusGeometry);


    // Make Main Scene Node
    NodeUnrecPtr scene = Node::create();
    scene->setCore(Group::create());
    scene->addChild(TorusNode);

    mgr->setRoot(scene);

    // Show the whole Scene
    mgr->showAll();

	//Create the Animations
	initAnimations(Color1Parameter, "value");

    //Open Window
    Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
    TutorialWindow->openWindow(WinPos,
                               WinSize,
                               "04ShaderAnimation");

    //Main Loop
    TutorialWindow->mainLoop();

    osgExit();

    return 0;
}
コード例 #4
0
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindow = createNativeWindow();
    TutorialWindow->initWindow();

    TutorialWindow->setDisplayCallback(display);
    TutorialWindow->setReshapeCallback(reshape);

    //Add Window Listener
    TutorialKeyListener TheKeyListener;
    TutorialWindow->addKeyListener(&TheKeyListener);
    TutorialMouseListener TheTutorialMouseListener;
    TutorialMouseMotionListener TheTutorialMouseMotionListener;
    TutorialWindow->addMouseListener(&TheTutorialMouseListener);
    TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(TutorialWindow);

    //Print key command info
    std::cout << "\n\nKEY COMMANDS:" << std::endl
              << "space   Play/Pause the animation" << std::endl
              << "B       Show/Hide the bind pose skeleton" << std::endl
              << "P       Show/Hide the current pose skeleton" << std::endl
              << "CTRL-Q  Exit\n\n" << std::endl;


    //SkeletonDrawer System Material
    LineChunkUnrecPtr ExampleLineChunk = LineChunk::create();
    ExampleLineChunk->setWidth(2.0f);
    ExampleLineChunk->setSmooth(true);

    BlendChunkUnrecPtr ExampleBlendChunk = BlendChunk::create();
    ExampleBlendChunk->setSrcFactor(GL_SRC_ALPHA);
    ExampleBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);

    MaterialChunkUnrecPtr ExampleMaterialChunk = MaterialChunk::create();
    ExampleMaterialChunk->setAmbient(Color4f(1.0f,1.0f,1.0f,1.0f));
    ExampleMaterialChunk->setDiffuse(Color4f(0.0f,0.0f,0.0f,1.0f));
    ExampleMaterialChunk->setSpecular(Color4f(0.0f,0.0f,0.0f,1.0f));

    ChunkMaterialUnrecPtr ExampleMaterial = ChunkMaterial::create();
    ExampleMaterial->addChunk(ExampleLineChunk);
    ExampleMaterial->addChunk(ExampleMaterialChunk);
    ExampleMaterial->addChunk(ExampleBlendChunk);

    //===========================================Joints==================================================================
    Matrix TempMat;

    /*================================================================================================*/
    /*                                       Left Fingers                                                 */
    LeftFingers = Joint::create(); //create a joint called LeftFingers 
    TempMat.setTranslate(1.0,0.0,0.0);
    LeftFingers->setRelativeTransformation(TempMat);
    LeftFingers->setBindRelativeTransformation(TempMat);

    /*================================================================================================*/
    /*                                       Right Fingers                                                 */
    RightFingers = Joint::create(); //create a joint called RightFingers 
    TempMat.setTranslate(-1.0,0.0,0.0);
    RightFingers->setRelativeTransformation(TempMat);
    RightFingers->setBindRelativeTransformation(TempMat);
    /*================================================================================================*/
    /*                                       Left Hand                                                 */
    LeftHand = Joint::create(); //create a joint called LeftHand 
    TempMat.setTranslate(2.0,0.0,0.0);
    LeftHand->setRelativeTransformation(TempMat);
    LeftHand->setBindRelativeTransformation(TempMat);
    LeftHand->pushToChildJoints(LeftFingers);

    /*================================================================================================*/
    /*                                       Right Hand                                                 */
    RightHand = Joint::create(); //create a joint called RightHand 
    TempMat.setTranslate(-2.0,0.0,0.0);
    RightHand->setRelativeTransformation(TempMat);
    RightHand->setBindRelativeTransformation(TempMat);
    RightHand->pushToChildJoints(RightFingers);
    /*================================================================================================*/
    /*                                       Left Elbow                                                 */
    LeftElbow = Joint::create(); //create a joint called LeftElbow 
    TempMat.setTranslate(2.0,0.0,0.0);
    LeftElbow->setRelativeTransformation(TempMat);
    LeftElbow->setBindRelativeTransformation(TempMat);
    LeftElbow->pushToChildJoints(LeftHand);

    /*================================================================================================*/
    /*                                       Right Elbow                                                 */
    RightElbow = Joint::create(); //create a joint called RightElbow 
    TempMat.setTranslate(-2.0,0.0,0.0);
    RightElbow->setRelativeTransformation(TempMat);
    RightElbow->setBindRelativeTransformation(TempMat);
    RightElbow->pushToChildJoints(RightHand);
    /*================================================================================================*/
    /*                                       Left Shoulder                                                 */
    LeftShoulder = Joint::create(); //create a joint called LeftShoulder 
    TempMat.setTranslate(1.0,-0.5,0.0);
    LeftShoulder->setRelativeTransformation(TempMat);
    LeftShoulder->setBindRelativeTransformation(TempMat);
    LeftShoulder->pushToChildJoints(LeftElbow);

    /*================================================================================================*/
    /*                                       Right Shoulder                                                 */
    RightShoulder = Joint::create(); //create a joint called RightShoulder 
    TempMat.setTranslate(-1.0,-0.5,0.0);
    RightShoulder->setRelativeTransformation(TempMat);
    RightShoulder->setBindRelativeTransformation(TempMat);
    RightShoulder->pushToChildJoints(RightElbow);

    /*================================================================================================*/
    /*                                       Head                                                 */
    Head = Joint::create(); //create a joint called Head 
    TempMat.setTranslate(0.0,1.0,0.0);
    Head->setRelativeTransformation(TempMat);
    Head->setBindRelativeTransformation(TempMat);

    /*================================================================================================*/
    /*                                       Clavicle                                                   */
    Clavicle = Joint::create(); //create a joint called Clavicle 
    TempMat.setTranslate(0.0,5.0,0.0);
    Clavicle->setRelativeTransformation(TempMat);
    Clavicle->setBindRelativeTransformation(TempMat);
    Clavicle->pushToChildJoints(LeftShoulder);
    Clavicle->pushToChildJoints(RightShoulder);
    Clavicle->pushToChildJoints(Head);

    /*================================================================================================*/
    /*                                       Left Toes                                                 */
    LeftToes = Joint::create(); //create a bone called ExampleChildbone
    TempMat.setTranslate(0.0,0.0,1.0);
    LeftToes->setRelativeTransformation(TempMat);
    LeftToes->setBindRelativeTransformation(TempMat);

    /*================================================================================================*/
    /*                                       Right Toes                                                 */
    RightToes = Joint::create(); //create a joint called RightToes 
    TempMat.setTranslate(0.0,0.0,1.0);
    RightToes->setRelativeTransformation(TempMat);
    RightToes->setBindRelativeTransformation(TempMat);
    /*================================================================================================*/
    /*                                       Left Foot                                                 */
    LeftFoot = Joint::create(); //create a joint called LeftFoot 
    TempMat.setTranslate(0.0,-3.0,0.0);
    LeftFoot->setRelativeTransformation(TempMat);
    LeftFoot->setBindRelativeTransformation(TempMat);
    LeftFoot->pushToChildJoints(LeftToes);

    /*================================================================================================*/
    /*                                       Right Foot                                                 */
    RightFoot = Joint::create(); //create a joint called RightFoot 
    TempMat.setTranslate(0.0,-3.0,0.0);
    RightFoot->setRelativeTransformation(TempMat);
    RightFoot->setBindRelativeTransformation(TempMat);
    RightFoot->pushToChildJoints(RightToes);
    /*================================================================================================*/
    /*                                       Left Knee                                                 */
    LeftKnee = Joint::create(); //create a joint called LeftKnee 
    TempMat.setTranslate(0.0,-3.0,0.0);
    LeftKnee->setRelativeTransformation(TempMat);
    LeftKnee->setBindRelativeTransformation(TempMat);
    LeftKnee->pushToChildJoints(LeftFoot);

    /*================================================================================================*/
    /*                                       Right Knee                                                 */
    RightKnee = Joint::create(); //create a joint called RightKnee 
    TempMat.setTranslate(0.0,-3.0,0.0);
    RightKnee->setRelativeTransformation(TempMat);
    RightKnee->setBindRelativeTransformation(TempMat);
    RightKnee->pushToChildJoints(RightFoot);

    /*================================================================================================*/
    /*                                       Left Hip                                                 */
    LeftHip = Joint::create(); //create a joint called LeftHip 
    TempMat.setTranslate(1.0,-1.0,0.0);
    LeftHip->setRelativeTransformation(TempMat);
    LeftHip->setBindRelativeTransformation(TempMat);
    LeftHip->pushToChildJoints(LeftKnee);

    /*================================================================================================*/
    /*                                       Right Hip                                                 */
    RightHip = Joint::create(); //create a joint called RightHip 
    TempMat.setTranslate(-1.0,-1.0,0.0);
    RightHip->setRelativeTransformation(TempMat);
    RightHip->setBindRelativeTransformation(TempMat);
    RightHip->pushToChildJoints(RightKnee);

    /*================================================================================================*/
    /*                                       Pelvis                                                   */
    Pelvis = Joint::create(); //create a joint called Pelvis 
    TempMat.setTranslate(0.0,7.0,0.0);
    Pelvis->setRelativeTransformation(TempMat);
    Pelvis->setBindRelativeTransformation(TempMat);
    Pelvis->pushToChildJoints(LeftHip);
    Pelvis->pushToChildJoints(RightHip);
    Pelvis->pushToChildJoints(Clavicle);



    //Skeleton
    ExampleSkeleton = Skeleton::create();
    ExampleSkeleton->pushToRootJoints(Pelvis);  //Set Pelvis as root joint of skeleton

    //SkeletonDrawer
    SkeletonDrawableUnrecPtr ExampleSkeletonDrawable = SkeletonDrawable::create();
    ExampleSkeletonDrawable->setSkeleton(ExampleSkeleton);
    ExampleSkeletonDrawable->setMaterial(ExampleMaterial);
    ExampleSkeletonDrawable->setDrawBindPose(false);  //Be default, we won't draw the skeleton's bind pose
    ExampleSkeletonDrawable->setBindPoseColor(Color4f(0.0, 1.0, 0.0, 1.0));  //When drawn, the skeleton's bind pose renders green
    ExampleSkeletonDrawable->setDrawPose(true);  //Be default, we do draw the skeleton's current pose
    ExampleSkeletonDrawable->setPoseColor(Color4f(0.0, 0.0, 1.0, 1.0));  //The skeleton's current pose renders blue

    //Skeleton Node
    SkeletonNode = Node::create();
    SkeletonNode->setCore(ExampleSkeletonDrawable);

    //Create scene    
    NodeUnrecPtr scene = Node::create();
    scene->setCore(Group::create());
    scene->addChild(SkeletonNode);

    mgr->setRoot(scene);

    //Setup the Animation
    setupAnimation();



    // Show the whole Scene
    mgr->showAll();


    //Open Window
    Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
    TutorialWindow->openWindow(WinPos,
            WinSize,
            "12SkeletonAnimation");

    //Main Loop
    TutorialWindow->mainLoop();

    osgExit();

    return 0;
}
コード例 #5
0
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindow = createNativeWindow();

    //Initialize Window
    TutorialWindow->initWindow();

    TutorialWindow->setDisplayCallback(display);
    TutorialWindow->setReshapeCallback(reshape);

    //Add Window Listener
    TutorialKeyListener TheKeyListener;
    TutorialWindow->addKeyListener(&TheKeyListener);
    TutorialMouseListener TheTutorialMouseListener;
    TutorialMouseMotionListener TheTutorialMouseMotionListener;
    TutorialWindow->addMouseListener(&TheTutorialMouseListener);
    TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(TutorialWindow);

    //Setup the Animation
    setupAnimation();

    //Box Geometry
    GeometryUnrecPtr BoxGeometry = makeBoxGeo(1.0,1.0,1.0,1,1,1);
    BoxGeometry->setMaterial(TheBoxMaterial);
    
    NodeUnrecPtr BoxGeometryNode = Node::create();
    BoxGeometryNode->setCore(BoxGeometry);

    //Make Box Node
    NodeUnrecPtr BoxNode = Node::create();
    TransformUnrecPtr BoxNodeTrans;
    BoxNodeTrans = Transform::create();

    BoxNode->setCore(BoxNodeTrans);
    BoxNode->addChild(BoxGeometryNode);

    //Make Main Scene Node
    NodeUnrecPtr scene = Node::create();
    ComponentTransformUnrecPtr Trans;
    Trans = ComponentTransform::create();
    scene->setCore(Trans);

    // add the torus as a child
    scene->addChild(BoxNode);

    // tell the manager what to manage
    mgr->setRoot  (scene);

    // show the whole scene
    mgr->showAll();
    
    //Open Window
    Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);

    TutorialWindow->openWindow(WinPos,
                               WinSize,
                               "05TextureAnimation");

    //Main Loop
    TutorialWindow->mainLoop();

    osgExit();

    return 0;
}
コード例 #6
0
void VTKPolyDataMapper::initGeometries(void)
{
    NodeUnrecPtr pRoot = Node::create();
    
    pRoot->setCore(Group::create());

    setRoot(pRoot);

    for(UInt32 i = 0; i < 4; ++i)
    {
        GeometryUnrecPtr           pGeo      = Geometry::create();
    
        ChunkMaterialUnrecPtr      pMat      = ChunkMaterial::create();
        MaterialChunkUnrecPtr      pMatChunk = MaterialChunk::create();
        
        GeoPnt3fPropertyUnrecPtr   pPoints   = GeoPnt3fProperty  ::create();
        GeoUInt32PropertyUnrecPtr  pLengths  = GeoUInt32Property ::create();
        GeoUInt8PropertyUnrecPtr   pTypes    = GeoUInt8Property  ::create();
        GeoColor4fPropertyUnrecPtr pColors   = GeoColor4fProperty::create();
        GeoVec3fPropertyUnrecPtr   pNormals  = GeoVec3fProperty  ::create();

        if(i < 2)
        {
            pMatChunk->setLit(false);
        }
        
        pMatChunk->setDiffuse  (OSG::Color4f(1.0, 1.0, 1.0, 1.0));
        pMatChunk->setSpecular (OSG::Color4f(0.0, 0.0, 0.0, 1.0));
        pMatChunk->setShininess(10.0f);
        
        pMat->addChunk(pMatChunk);

        TwoSidedLightingChunkUnrecPtr pTSLChunk = 
            TwoSidedLightingChunk::create();
            
        pMat->addChunk(pTSLChunk);

        pGeo->setDlistCache(false   );
        
        pGeo->setMaterial  (pMat    );
        pGeo->setPositions (pPoints );
        pGeo->setLengths   (pLengths);
        pGeo->setTypes     (pTypes  );
        pGeo->setColors    (pColors );

        if(i > 1)
        {
            pGeo->setNormals(pNormals);
        }

        OSG::NodeUnrecPtr pGeoRoot = OSG::Node::create();
        
        pGeoRoot->setCore    (pGeo);
        pGeoRoot->setTravMask(0   );

        pRoot->addChild(pGeoRoot);

        this->pushToGeometries    (pGeo     );
        this->pushToMaterials     (pMat     );
        this->pushToMaterialChunks(pMatChunk);
        this->pushToPositions     (pPoints  );
        this->pushToLength        (pLengths );
        this->pushToTypes         (pTypes   );
        this->pushToColors        (pColors  );
        this->pushToNormals       (pNormals );
        this->pushToGeoRoots      (pGeoRoot );
    }
}
コード例 #7
0
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindow = createNativeWindow();
    TutorialWindow->initWindow();

    TutorialWindow->setDisplayCallback(display);
    TutorialWindow->setReshapeCallback(reshape);

    //Add Window Listener
    TutorialKeyListener TheKeyListener;
    TutorialWindow->addKeyListener(&TheKeyListener);
    TutorialMouseListener TheTutorialMouseListener;
    TutorialMouseMotionListener TheTutorialMouseMotionListener;
    TutorialWindow->addMouseListener(&TheTutorialMouseListener);
    TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(TutorialWindow);
	
	//Print key command info
	std::cout << "\n\nKEY COMMANDS:" << std::endl;
	std::cout << "space   Play/Pause the animation" << std::endl;
	std::cout << "B       Show/Hide the bind pose skeleton" << std::endl;
	std::cout << "P       Show/Hide the current pose skeleton" << std::endl;
	std::cout << "1       Play first example animation" << std::endl;
	std::cout << "2       Play second example animation" << std::endl;
	std::cout << "CTRL-Q  Exit\n\n" << std::endl;
										

	//SkeletonDrawer System Material
	LineChunkUnrecPtr ExampleLineChunk = LineChunk::create();
    ExampleLineChunk->setWidth(2.0f);
    ExampleLineChunk->setSmooth(true);

	BlendChunkUnrecPtr ExampleBlendChunk = BlendChunk::create();
    ExampleBlendChunk->setSrcFactor(GL_SRC_ALPHA);
    ExampleBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);

	MaterialChunkUnrecPtr ExampleMaterialChunk = MaterialChunk::create();
    ExampleMaterialChunk->setAmbient(Color4f(1.0f,1.0f,1.0f,1.0f));
    ExampleMaterialChunk->setDiffuse(Color4f(0.0f,0.0f,0.0f,1.0f));
    ExampleMaterialChunk->setSpecular(Color4f(0.0f,0.0f,0.0f,1.0f));

	ChunkMaterialUnrecPtr ExampleMaterial = ChunkMaterial::create();
    ExampleMaterial->addChunk(ExampleLineChunk);
    ExampleMaterial->addChunk(ExampleMaterialChunk);
    ExampleMaterial->addChunk(ExampleBlendChunk);

    GeometryRefPtr SphereGeometry = makeSphereGeo(2, 0.25f);
    GeometryRefPtr BoxGeometry = makeBoxGeo(0.5f,0.5f,0.5f,1,1,1);

    //Skeleton
    SkeletonBlendedGeometryUnrecPtr ExampleSkeleton = SkeletonBlendedGeometry::create();

    //Joint
	JointRecPtr ExampleRootJoint = Joint::create();

    //Add this joint to the skeleton
    ExampleSkeleton->pushToJoints(ExampleRootJoint, Matrix());

    NodeRecPtr ExampleRootJointNode = makeNodeFor(ExampleRootJoint);

    NodeRecPtr TempRootJointNode = ExampleRootJointNode;
    NodeRefPtr GeoNode = makeNodeFor(BoxGeometry);
    TempRootJointNode->addChild(GeoNode);

	Matrix TempMat;
	//Create a set of randomly placed child joints
	for (Real32 i = 0.0f; i < 5.0f; ++i)
	{
		JointRecPtr ExampleChildJoint = Joint::create();
		NodeRecPtr ExampleChildJointNode = makeNodeFor(ExampleChildJoint);

        GeoNode = makeNodeFor(SphereGeometry);
        ExampleChildJointNode->addChild(GeoNode);

		//TempMat.setTranslate(RandomPoolManager::getRandomReal32(0.0, 10.0f), RandomPoolManager::getRandomReal32(0.0f, 10.0f), RandomPoolManager::getRandomReal32(0.0f, 10.0f));
        switch((static_cast<UInt32>(i) % 3))
        {
            case 0:
                TempMat.setTranslate(2.0f,0.0f,0.0f);
                break;
            case 1:
                TempMat.setTranslate(0.0f,2.0f,0.0f);
                break;
            case 2:
                TempMat.setTranslate(0.0f,0.0f,2.0f);
                break;
        }
		
		//Set bind and current transformations to TempMat (calculated above)
        ExampleChildJoint->setJointTransformation(TempMat);

		//Add ExampleChildJoint as a child to the previous joint	
        TempRootJointNode->addChild(ExampleChildJointNode);//add a Child to the root joint

		//ExampleChildJoint will be the next parent joint
		TempRootJointNode = ExampleChildJointNode;
        
        //Add this joint to the skeleton
        Matrix InvBind(TempRootJointNode->getToWorld());
        InvBind.invert();
        ExampleSkeleton->pushToJoints(ExampleChildJoint, InvBind);
	}

    //SkeletonDrawer
    SkeletonDrawableUnrecPtr ExampleSkeletonDrawable = SkeletonDrawable::create();
    ExampleSkeletonDrawable->setSkeleton(ExampleSkeleton);
    ExampleSkeletonDrawable->setMaterial(ExampleMaterial);
    ExampleSkeletonDrawable->setDrawBindPose(false);  //By default, we won't draw the skeleton's bind pose
    ExampleSkeletonDrawable->setBindPoseColor(Color4f(0.0, 1.0, 0.0, 1.0));  //When the skeleton's bind pose is rendered, it will be green
    ExampleSkeletonDrawable->setDrawPose(true);  //By default, we do draw the skeleton's current pose
    ExampleSkeletonDrawable->setPoseColor(Color4f(0.0, 0.0, 1.0, 1.0));  //The skeleton's current pose is rendered in blue
	
	//Skeleton Node
	SkeletonNode = Node::create();
    SkeletonNode->setCore(ExampleSkeletonDrawable);

    //Create scene
    NodeUnrecPtr scene = Node::create();
    scene->setCore(Group::create());
    scene->addChild(SkeletonNode);
    scene->addChild(ExampleRootJointNode);

    mgr->setRoot(scene);

	//Setup the Animation
	setupAnimation(ExampleRootJoint,
                   dynamic_cast<Joint*>(ExampleRootJointNode->getChild(1)->getCore()));

	//Set the currently playing animation to TheJointAnimation (can be switched at runtime via a key command)
	TheCurrentAnimation = TheJointAnimation;


    // Show the whole Scene
    mgr->showAll();


    //Open Window
    Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
    TutorialWindow->openWindow(WinPos,
                        WinSize,
                                        "11BoneAnimation");

    //Main Loop
    TutorialWindow->mainLoop();

    osgExit();

    return 0;
}
コード例 #8
0
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    {
        // Set up Window
        WindowEventProducerRecPtr TutorialWindow = createNativeWindow();

        //Initialize Window
        TutorialWindow->initWindow();

        SimpleSceneManager sceneManager;
        TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
        TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));

        // Tell the Manager what to manage
        sceneManager.setWindow(TutorialWindow);

        //Attach to events
        TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager));
        TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager));
        TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
        TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));

        //Torus Material
        SimpleMaterialUnrecPtr TheTorusMaterial = SimpleMaterial::create();
        TheTorusMaterial->setAmbient(Color3f(0.3,0.3,0.3));
        TheTorusMaterial->setDiffuse(Color3f(0.7,0.7,0.7));
        TheTorusMaterial->setSpecular(Color3f(1.0,1.0,1.0));
        TheTorusMaterial->setShininess(20.0);

        //Torus Geometry
        GeometryUnrecPtr TorusGeometry = makeTorusGeo(.5, 2, 32, 32);
        TorusGeometry->setMaterial(TheTorusMaterial);

        NodeUnrecPtr TorusGeometryNode = Node::create();
        TorusGeometryNode->setCore(TorusGeometry);

        //Make Torus Node
        NodeUnrecPtr TorusNode = Node::create();
        TransformUnrecPtr TorusNodeTrans = Transform::create();
        setName(TorusNodeTrans, std::string("TorusNodeTransformationCore"));

        TorusNode->setCore(TorusNodeTrans);
        TorusNode->addChild(TorusGeometryNode);

        //Make Main Scene Node
        NodeUnrecPtr scene = Node::create();
        ComponentTransformUnrecPtr Trans = ComponentTransform::create();
        setName(Trans, std::string("MainTransformationCore"));
        scene->setCore(Trans);

        // add the torus as a child
        scene->addChild(TorusNode);

        AnimationGroupUnrecPtr TheAnimation = setupAnimation(TheTorusMaterial, TorusNodeTrans);
        TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1,
                                                      TheAnimation.get(),
                                                      TutorialWindow.get()));
        TheAnimation->attachUpdateProducer(TutorialWindow);
        TheAnimation->start();

        // tell the manager what to manage
        sceneManager.setRoot  (scene);

        //Create the Documentation
        SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow);

        // show the whole scene
        sceneManager.showAll();


        Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
        Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
        TutorialWindow->openWindow(WinPos,
                                   WinSize,
                                   "07AnimationGroup");

        //Enter main Loop
        TutorialWindow->mainLoop();
    }

    osgExit();

    return 0;
}
コード例 #9
0
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);
    {
        // Set up Window
        WindowEventProducerRecPtr TutorialWindow = createNativeWindow();

        //Initialize Window
        TutorialWindow->initWindow();

        SimpleSceneManager sceneManager;
        TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
        TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));

        // Tell the Manager what to manage
        sceneManager.setWindow(TutorialWindow);

        //Attach to events
        TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager));
        TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager));
        TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
        TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));
        TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, TutorialWindow.get()));

        //Shader Chunk
        SimpleSHLChunkUnrecPtr TheSHLChunk = SimpleSHLChunk::create();
        TheSHLChunk->setVertexProgram(createSHLVertexProg());
        TheSHLChunk->setFragmentProgram(createSHLFragProg());
        //TheSHLChunk->addUniformVariable("Color1",Vec4f(0.0f,1.0f,0.0f,1.0f));
        //TheSHLChunk->addUniformVariable("Color2",Vec4f(1.0f,1.0f,1.0f,1.0f));

        //Shader Parameter Chunk
        SimpleSHLVariableChunkUnrecPtr SHLParameters = SimpleSHLVariableChunk::create();
        //Color Parameter
        SHLParameters->addUniformVariable("Color1",Vec4f(0.0f,1.0f,0.0f,1.0f));
        SHLParameters->addUniformVariable("Color2",Vec4f(1.0f,1.0f,1.0f,1.0f));

        ChunkMaterialUnrecPtr ShaderMaterial = ChunkMaterial::create();
        ShaderMaterial->addChunk(TheSHLChunk);
        ShaderMaterial->addChunk(SHLParameters);

        //Torus Node
        GeometryUnrecPtr TorusGeometry = makeTorusGeo(5.0f,20.0f, 32,32);

        TorusGeometry->setMaterial(ShaderMaterial);

        NodeUnrecPtr TorusNode = Node::create();
        TorusNode->setCore(TorusGeometry);

        // Make Main Scene Node
        NodeUnrecPtr scene = Node::create();
        scene->setCore(Group::create());
        scene->addChild(TorusNode);

        sceneManager.setRoot(scene);

        // Show the whole Scene
        sceneManager.showAll();

        //Create the Animations

        ShaderVariableVec4fUnrecPtr Color1Parameter;
        ShaderVariableVec4fUnrecPtr Color2Parameter;

        Color1Parameter = dynamic_cast<ShaderVariableVec4f*>(const_cast<ShaderVariable*>(SHLParameters->getVariables()->getVariable("Color1")));
        Color2Parameter = dynamic_cast<ShaderVariableVec4f*>(const_cast<ShaderVariable*>(SHLParameters->getVariables()->getVariable("Color2")));
        commitChanges();

        AnimationUnrecPtr TheAnimation = setupAnimation(Color1Parameter, "value");
        TheAnimation->attachUpdateProducer(TutorialWindow);
        TheAnimation->start();

        //Open Window
        Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
        Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
        TutorialWindow->openWindow(WinPos,
                                   WinSize,
                                   "04ShaderAnimation");

        //Main Loop
        TutorialWindow->mainLoop();
    }

    osgExit();

    return 0;
}
コード例 #10
0
ファイル: OSGDXFInsert.cpp プロジェクト: chengzg/OSGAddOnsGV
/* Insert one or more shallow copies of a block (created by DXFBlock as
 * Transform Group) into a layer (created by DXFLayer as MaterialGroup) or
 * another block.
 * \todo 
 * Could there be a INSERT inside a block referring to another block which has
 * not been read yet? We then have to find a solution to enable deferred
 * instantiation of INSERT entities :-(
 */
DXFResult DXFInsert::endEntity(void)
{
    NodeUnrecPtr                ctrafoNodeP = NULL;
//    ComponentTransformUnrecPtr  ctrafoCoreP = NULL;
    TransformUnrecPtr           ctrafoCoreP = NULL;
    NodeUnrecPtr                blockNodeP  = NULL;

    Node                       *parentNodeP = getParentNode();
    
    StringToNodePtrMap::iterator itr = _blocksMapP->find(_blockName);
    if (itr != _blocksMapP->end() && parentNodeP != NULL)
    {
        blockNodeP = itr->second;
        // TODO: check fetched INSERT Data for consistency!

        // Insert multiple times in a grid...
        Vec3f offset(0.0, 0.0, 0.0);
        for(Int16 column = 0; column < _columnCount; ++ column)
        {
            offset[0] = column * _columnSpacing;
            for(Int16 row = 0; row < _rowCount; ++ row)
            {
                offset[1] = row * _rowSpacing;
                // TODO: find out about DXF insert semantics!

                ctrafoNodeP = Node::create();
                ctrafoCoreP = Transform::create();
                
#if 0
                beginEditCP(ctrafoCoreP);
#endif
                {
					if(_blockName == std::string("Rectangular Mullion - 64 x 128 rectangular-V1-Level 1"))
					{
						std::cout << blockNodeP->getNChildren() << std::endl;
					}
					OSG::TransformationMatrix<Real32> transMat;
					transMat.setIdentity();
		
					transMat.setTranslate(_insertionPoint + offset);

					OSG::TransformationMatrix<Real32> rotMat;
					rotMat.setIdentity();
					OSG::Quaternion rot(OSG::Vec3f(0,0,1),osgDegree2Rad(_rotationAngle));
					rotMat.setRotate(rot);
					OSG::TransformationMatrix<Real32> scaleMat;
					scaleMat.setIdentity();
					scaleMat.setScale(_scaleFactor);
					
					OSG::Vec3f vin(-40, 65, 0);
					OSG::Vec3f vout;
					transMat.mult(rotMat);
					transMat.mult(scaleMat);
					if(_extrusionDirection[2]<0)
					{
						transMat[0][0] *= -1.0;
						transMat[1][0] *= -1.0;
						transMat[2][0] *= -1.0;
						transMat[3][0] *= -1.0;
					}
					ctrafoCoreP->setMatrix(transMat);
                }
#if 0
                endEditCP(ctrafoCoreP);
#endif
#if 0
                beginEditCP(ctrafoNodeP);
#endif
                {
                    ctrafoNodeP->setCore(ctrafoCoreP);
#if 0
                    ctrafoNodeP->addChild(blockNodeP->clone());
#endif
                    NodeUnrecPtr pClone = cloneTree(blockNodeP);
                    ctrafoNodeP->addChild(pClone);
                }
#if 0
                endEditCP(ctrafoNodeP);
#endif                
#if 0
                beginEditCP(parentNodeP);
#endif
                {
                    parentNodeP->addChild(ctrafoNodeP);
                }
#if 0
                endEditCP(parentNodeP);
#endif
            }
        }

        // Warn for details not implemented or assured yet! TODO: better
        // implement missing features!
        
        /*if(fabs(_rotationAngle) > Eps)
            FWARNING(("DXF Loader: before line %d: "
                      "DXFInsert does not yet support ROTATION "
                      "(group code 50). "
                      "Most likely the graphics are incorrect!\n",
                      DXFRecord::getLineNumber()
                     ));*/
        /*if(_scaleFactor != Vec3f(1.0,1.0,1.0))
            FWARNING(("DXF Loader: before line %d: "
                      "DXFInsert may not interpret SCALING "
                      "(group codes 41, 42, 43) correctly."
                      "Graphics may be incorrect!\n",
                      DXFRecord::getLineNumber()
                     ));*/
        
        if(_columnCount != 1 || _rowCount != 1)
            FWARNING(("DXF Loader: before line %d: "
                      "DXFInsert may not interpret REPEATED INSERTION " 
                      "(group codes 70, 71, 44, 45) correctly."
                      "Graphics may be incorrect!\n",
                      DXFRecord::getLineNumber()
                     ));
        
    }
    else
    {
        if(itr == _blocksMapP->end())
            FWARNING(("DXF Loader: before line %d (inside %s section): "
                  "BLOCK '%s' to be inserted not found!\n",
                  DXFRecord::getLineNumber(),
                  _parent->getEntityTypeName(),
                  _blockName.c_str()
                  ));
        if(parentNodeP == NULL)
            FWARNING(("DXF Loader: before line %d (inside %s section): "
                  "layer %s to be inserted to not found!\n",
                  DXFRecord::getLineNumber(),
                  _parent->getEntityTypeName(),
                  _layerName.c_str()
                  ));
    }
    //set back to default value;
	_insertionPoint.setNull(),
    _scaleFactor[0]=_scaleFactor[1]=_scaleFactor[2]=1.0;
    _rotationAngle=0.0;
    _columnCount=1;
    _rowCount=1;
    _columnSpacing=0.0;
    _rowSpacing=0.0;
	_extrusionDirection[0]=0;
	_extrusionDirection[1]=0;
	_extrusionDirection[2]=1;
    return DXFStateContinue;
}
コード例 #11
0
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindow = createNativeWindow();
    TutorialWindow->initWindow();

    TutorialWindow->setDisplayCallback(display);
    TutorialWindow->setReshapeCallback(reshape);

    //Add Window Listener
    TutorialKeyListener TheKeyListener;
    TutorialWindow->addKeyListener(&TheKeyListener);
    TutorialMouseListener TheTutorialMouseListener;
    TutorialMouseMotionListener TheTutorialMouseMotionListener;
    TutorialWindow->addMouseListener(&TheTutorialMouseListener);
    TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(TutorialWindow);
	
	//Print key command info
	std::cout << "\n\nKEY COMMANDS:" << std::endl;
	std::cout << "space   Play/Pause the animation" << std::endl;
	std::cout << "B       Show/Hide the bind pose skeleton" << std::endl;
	std::cout << "P       Show/Hide the current pose skeleton" << std::endl;
	std::cout << "1       Play first example animation" << std::endl;
	std::cout << "2       Play second example animation" << std::endl;
	std::cout << "CTRL-Q  Exit\n\n" << std::endl;
										

	//SkeletonDrawer System Material
	LineChunkUnrecPtr ExampleLineChunk = LineChunk::create();
    ExampleLineChunk->setWidth(2.0f);
    ExampleLineChunk->setSmooth(true);

	BlendChunkUnrecPtr ExampleBlendChunk = BlendChunk::create();
    ExampleBlendChunk->setSrcFactor(GL_SRC_ALPHA);
    ExampleBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);

	MaterialChunkUnrecPtr ExampleMaterialChunk = MaterialChunk::create();
    ExampleMaterialChunk->setAmbient(Color4f(1.0f,1.0f,1.0f,1.0f));
    ExampleMaterialChunk->setDiffuse(Color4f(0.0f,0.0f,0.0f,1.0f));
    ExampleMaterialChunk->setSpecular(Color4f(0.0f,0.0f,0.0f,1.0f));

	ChunkMaterialUnrecPtr ExampleMaterial = ChunkMaterial::create();
    ExampleMaterial->addChunk(ExampleLineChunk);
    ExampleMaterial->addChunk(ExampleMaterialChunk);
    ExampleMaterial->addChunk(ExampleBlendChunk);

    //Joint
	JointUnrecPtr ExampleRootJoint = Joint::create();
	JointUnrecPtr TempRootJoint;
	TempRootJoint = ExampleRootJoint;
	Matrix TempMat;

	//Create a set of randomly placed joints
	for (Real32 i = 1.0f; i < 9.0f; i++)
	{
		JointUnrecPtr ExampleChildJoint;

		TempMat.setTranslate(RandomPoolManager::getRandomReal32(0.0, 10.0f), RandomPoolManager::getRandomReal32(0.0f, 10.0f), RandomPoolManager::getRandomReal32(0.0f, 10.0f));
		ExampleChildJoint = Joint::create(); //create a joint called ExampleChildJoint

		//Set ExampleChildJoint's current and bind transformations to TempMat (calculated above)
        ExampleChildJoint->setRelativeTransformation(TempMat);
        ExampleChildJoint->setBindRelativeTransformation(TempMat);
        ExampleChildJoint->setUseParentTranslation(true);

		//Add ExampleChildJoint as a child to the previously created joint
        TempRootJoint->pushToChildJoints(ExampleChildJoint);//add a Child to the previous joint
		
		//ExampleChildJoint will be the next parent joint
		TempRootJoint = TempRootJoint->getChildJoints(0);
	}

	

    //Skeleton
    SkeletonUnrecPtr ExampleSkeleton = Skeleton::create();
    ExampleSkeleton->pushToRootJoints(ExampleRootJoint);

    //SkeletonDrawer
    SkeletonDrawableUnrecPtr ExampleSkeletonDrawable = SkeletonDrawable::create();
    ExampleSkeletonDrawable->setSkeleton(ExampleSkeleton);
    ExampleSkeletonDrawable->setMaterial(ExampleMaterial);
    ExampleSkeletonDrawable->setDrawBindPose(false);  //By default, we won't draw the skeleton's bind pose
    ExampleSkeletonDrawable->setBindPoseColor(Color4f(0.0, 1.0, 0.0, 1.0));  //When the skeleton's bind pose is rendered, it will be green
    ExampleSkeletonDrawable->setDrawPose(true);  //By default, we do draw the skeleton's current pose
    ExampleSkeletonDrawable->setPoseColor(Color4f(0.0, 0.0, 1.0, 1.0));  //The skeleton's current pose is rendered in blue
	
	//Skeleton Node
	SkeletonNode = Node::create();
    SkeletonNode->setCore(ExampleSkeletonDrawable);

    //Create scene
    NodeUnrecPtr scene = Node::create();
    scene->setCore(Group::create());
    scene->addChild(SkeletonNode);

    mgr->setRoot(scene);

	//Setup the Animation
	setupAnimation(ExampleRootJoint, ExampleRootJoint->getChildJoints(0));

	//Set the currently playing animation to TheJointAnimation (can be switched at runtime via a key command)
	TheCurrentAnimation = TheJointAnimation;


    // Show the whole Scene
    mgr->showAll();


    //Open Window
    Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
    TutorialWindow->openWindow(WinPos,
                        WinSize,
                                        "11BoneAnimation");

    //Main Loop
    TutorialWindow->mainLoop();

    osgExit();

    return 0;
}
コード例 #12
0
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindow = createNativeWindow();
    TutorialWindow->initWindow();

    TutorialWindow->setDisplayCallback(display);
    TutorialWindow->setReshapeCallback(reshape);

    //Add Window Listener
    TutorialKeyListener TheKeyListener;
    TutorialWindow->addKeyListener(&TheKeyListener);
    TutorialMouseListener TheTutorialMouseListener;
    TutorialMouseMotionListener TheTutorialMouseMotionListener;
    TutorialWindow->addMouseListener(&TheTutorialMouseListener);
    TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(TutorialWindow);

    //Print key command info
    std::cout << "\n\nKEY COMMANDS:" << std::endl;
    std::cout << "space   Play/Pause the animation" << std::endl;
    std::cout << "B       Show/Hide the bind pose skeleton" << std::endl;
    std::cout << "SHIFT-B Show/Hide the bind pose mesh" << std::endl;
    std::cout << "P       Show/Hide the current pose skeleton" << std::endl;
    std::cout << "SHIFT-P Show/Hide the current pose mesh" << std::endl;
    std::cout << "CTRL-Q  Exit\n\n" << std::endl;


    //SkeletonDrawer System Material
    LineChunkUnrecPtr ExampleLineChunk = LineChunk::create();
    ExampleLineChunk->setWidth(2.0f);
    ExampleLineChunk->setSmooth(true);

    BlendChunkUnrecPtr ExampleBlendChunk = BlendChunk::create();
    ExampleBlendChunk->setSrcFactor(GL_SRC_ALPHA);
    ExampleBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);

    MaterialChunkUnrecPtr ExampleMaterialChunk = MaterialChunk::create();
    ExampleMaterialChunk->setAmbient(Color4f(1.0f,1.0f,1.0f,1.0f));
    ExampleMaterialChunk->setDiffuse(Color4f(0.0f,0.0f,0.0f,1.0f));
    ExampleMaterialChunk->setSpecular(Color4f(0.0f,0.0f,0.0f,1.0f));

    ChunkMaterialUnrecPtr ExampleMaterial = ChunkMaterial::create();
    ExampleMaterial->addChunk(ExampleLineChunk);
    ExampleMaterial->addChunk(ExampleMaterialChunk);
    ExampleMaterial->addChunk(ExampleBlendChunk);


    //Skeleton
    ExampleSkeleton = SkeletonBlendedGeometry::create();

    //===========================================Joints==================================================================
    Matrix TempMat;
    Matrix InvBind;

    /*================================================================================================*/
    /*                                       Pelvis                                                   */
    Pelvis = Joint::create(); //create a joint called Pelvis 
    TempMat.setTranslate(0.0,7.0,0.0);
    Pelvis->setJointTransformation(TempMat);

    NodeRecPtr PelvisNode = makeNodeFor(Pelvis);

    InvBind = PelvisNode->getToWorld();
    InvBind.invert();
    ExampleSkeleton->pushToJoints(Pelvis, InvBind);
    setName(Pelvis, "Pelvis Joint");
    setName(PelvisNode, "Pelvis Node");
    
    /*================================================================================================*/
    /*                                       Clavicle                                                   */
    Clavicle = Joint::create(); //create a joint called Clavicle 
    TempMat.setTranslate(0.0,5.0,0.0);
    Clavicle->setJointTransformation(TempMat);

    NodeRecPtr ClavicleNode = makeNodeFor(Clavicle);
    PelvisNode->addChild(ClavicleNode);

    InvBind = ClavicleNode->getToWorld();
    InvBind.invert();
    ExampleSkeleton->pushToJoints(Clavicle, InvBind);
    setName(Clavicle, "Clavicle Joint");
    setName(ClavicleNode, "Clavicle Node");

    /*================================================================================================*/
    /*                                       Left Shoulder                                                 */
    LeftShoulder = Joint::create(); //create a joint called LeftShoulder 
    TempMat.setTranslate(1.0,-0.5,0.0);
    LeftShoulder->setJointTransformation(TempMat);

    NodeRecPtr LeftShoulderNode = makeNodeFor(LeftShoulder);
    ClavicleNode->addChild(LeftShoulderNode);

    InvBind = LeftShoulderNode->getToWorld();
    InvBind.invert();
    ExampleSkeleton->pushToJoints(LeftShoulder, InvBind);
    setName(LeftShoulder, "Left Shoulder Joint");
    setName(LeftShoulderNode, "Left Shoulder Node");

    /*================================================================================================*/
    /*                                       Left Elbow                                                 */
    LeftElbow = Joint::create(); //create a joint called LeftElbow 
    TempMat.setTranslate(2.0,0.0,0.0);
    LeftElbow->setJointTransformation(TempMat);

    NodeRecPtr LeftElbowNode = makeNodeFor(LeftElbow);
    LeftShoulderNode->addChild(LeftElbowNode);

    InvBind = LeftElbowNode->getToWorld();
    InvBind.invert();
    ExampleSkeleton->pushToJoints(LeftElbow, InvBind);
    setName(LeftElbow, "Left Elbow Joint");
    setName(LeftElbowNode, "Left Elbow Node");

    /*================================================================================================*/
    /*                                       Left Hand                                                 */
    LeftHand = Joint::create(); //create a joint called LeftHand 
    TempMat.setTranslate(2.0,0.0,0.0);
    LeftHand->setJointTransformation(TempMat);

    NodeRecPtr LeftHandNode = makeNodeFor(LeftHand);
    LeftElbowNode->addChild(LeftHandNode);

    InvBind = LeftHandNode->getToWorld();
    InvBind.invert();
    ExampleSkeleton->pushToJoints(LeftHand, InvBind);
    setName(LeftHand, "Left Hand Joint");
    setName(LeftHandNode, "Left Hand Node");
    /*================================================================================================*/
    /*                                       Left Fingers                                                 */
    LeftFingers = Joint::create(); //create a joint called LeftFingers 
    TempMat.setTranslate(1.0,0.0,0.0);
    LeftFingers->setJointTransformation(TempMat);

    NodeRecPtr LeftFingersNode = makeNodeFor(LeftFingers);
    LeftHandNode->addChild(LeftFingersNode);

    InvBind = LeftFingersNode->getToWorld();
    InvBind.invert();
    ExampleSkeleton->pushToJoints(LeftFingers, InvBind);
    setName(LeftFingers, "Left Fingers Joint");
    setName(LeftFingersNode, "Left Fingers Node");

    /*================================================================================================*/
    /*                                       Right Shoulder                                                 */
    RightShoulder = Joint::create(); //create a joint called RightShoulder 
    TempMat.setTranslate(-1.0,-0.5,0.0);
    RightShoulder->setJointTransformation(TempMat);

    NodeRecPtr RightShoulderNode = makeNodeFor(RightShoulder);
    ClavicleNode->addChild(RightShoulderNode);

    InvBind = RightShoulderNode->getToWorld();
    InvBind.invert();
    ExampleSkeleton->pushToJoints(RightShoulder, InvBind);
    setName(RightShoulder, "Right Shoulder Joint");
    setName(RightShoulderNode, "Right Shoulder Node");

    /*================================================================================================*/
    /*                                       Right Elbow                                                 */
    RightElbow = Joint::create(); //create a joint called RightElbow 
    TempMat.setTranslate(-2.0,0.0,0.0);
    RightElbow->setJointTransformation(TempMat);

    NodeRecPtr RightElbowNode = makeNodeFor(RightElbow);
    RightShoulderNode->addChild(RightElbowNode);

    InvBind = RightElbowNode->getToWorld();
    InvBind.invert();
    ExampleSkeleton->pushToJoints(RightElbow, InvBind);
    setName(RightElbow, "Right Elbow Joint");
    setName(RightElbowNode, "Right Elbow Node");

    /*================================================================================================*/
    /*                                       Right Hand                                                 */
    RightHand = Joint::create(); //create a joint called RightHand 
    TempMat.setTranslate(-2.0,0.0,0.0);
    RightHand->setJointTransformation(TempMat);

    NodeRecPtr RightHandNode = makeNodeFor(RightHand);
    RightElbowNode->addChild(RightHandNode);

    InvBind = RightHandNode->getToWorld();
    InvBind.invert();
    ExampleSkeleton->pushToJoints(RightHand, InvBind);
    setName(RightHand, "Right Hand Joint");
    setName(RightHandNode, "Right Hand Node");

    /*================================================================================================*/
    /*                                       Right Fingers                                                 */
    RightFingers = Joint::create(); //create a joint called RightFingers 
    TempMat.setTranslate(-1.0,0.0,0.0);
    RightFingers->setJointTransformation(TempMat);

    NodeRecPtr RightFingersNode = makeNodeFor(RightFingers);
    RightHandNode->addChild(RightFingersNode);

    InvBind = RightFingersNode->getToWorld();
    InvBind.invert();
    ExampleSkeleton->pushToJoints(RightFingers, InvBind);
    setName(RightFingers, "Right Fingers Joint");
    setName(RightFingersNode, "Right Fingers Node");

    /*================================================================================================*/
    /*                                       Head                                                 */
    Head = Joint::create(); //create a joint called Head 
    TempMat.setTranslate(0.0,1.0,0.0);
    Head->setJointTransformation(TempMat);

    NodeRecPtr HeadNode = makeNodeFor(Head);
    ClavicleNode->addChild(HeadNode);

    InvBind = HeadNode->getToWorld();
    InvBind.invert();
    ExampleSkeleton->pushToJoints(Head, InvBind);
    setName(Head, "Head Joint");
    setName(HeadNode, "Head Node");

    /*================================================================================================*/
    /*                                       Left Hip                                                 */
    LeftHip = Joint::create(); //create a joint called LeftHip 
    TempMat.setTranslate(1.0,-1.0,0.0);
    LeftHip->setJointTransformation(TempMat);

    NodeRecPtr LeftHipNode = makeNodeFor(LeftHip);
    PelvisNode->addChild(LeftHipNode);

    InvBind = LeftHipNode->getToWorld();
    InvBind.invert();
    ExampleSkeleton->pushToJoints(LeftHip, InvBind);
    setName(LeftHip, "Left Hip Joint");
    setName(LeftHipNode, "Left Hip Node");

    /*================================================================================================*/
    /*                                       Left Knee                                                 */
    LeftKnee = Joint::create(); //create a joint called LeftKnee 
    TempMat.setTranslate(0.0,-3.0,0.0);
    LeftKnee->setJointTransformation(TempMat);

    NodeRecPtr LeftKneeNode = makeNodeFor(LeftKnee);
    LeftHipNode->addChild(LeftKneeNode);

    InvBind = LeftKneeNode->getToWorld();
    InvBind.invert();
    ExampleSkeleton->pushToJoints(LeftKnee, InvBind);
    setName(LeftKnee, "Left Knee Joint");
    setName(LeftKneeNode, "Left Knee Node");

    /*================================================================================================*/
    /*                                       Left Foot                                                 */
    LeftFoot = Joint::create(); //create a joint called LeftFoot 
    TempMat.setTranslate(0.0,-3.0,0.0);
    LeftFoot->setJointTransformation(TempMat);

    NodeRecPtr LeftFootNode = makeNodeFor(LeftFoot);
    LeftKneeNode->addChild(LeftFootNode);

    InvBind = LeftFootNode->getToWorld();
    InvBind.invert();
    ExampleSkeleton->pushToJoints(LeftFoot, InvBind);
    setName(LeftFoot, "Left Foot Joint");
    setName(LeftFootNode, "Left Foot Node");

    /*================================================================================================*/
    /*                                       Left Toes                                                 */
    LeftToes = Joint::create(); //create a bone called ExampleChildbone
    TempMat.setTranslate(0.0,0.0,1.0);
    LeftToes->setJointTransformation(TempMat);

    NodeRecPtr LeftToesNode = makeNodeFor(LeftToes);
    LeftFootNode->addChild(LeftToesNode);

    InvBind = LeftToesNode->getToWorld();
    InvBind.invert();
    ExampleSkeleton->pushToJoints(LeftToes, InvBind);
    setName(LeftToes, "Left Toes Joint");
    setName(LeftToesNode, "Left Toes Node");

    /*================================================================================================*/
    /*                                       Right Hip                                                 */
    RightHip = Joint::create(); //create a joint called RightHip 
    TempMat.setTranslate(-1.0,-1.0,0.0);
    RightHip->setJointTransformation(TempMat);

    NodeRecPtr RightHipNode = makeNodeFor(RightHip);
    PelvisNode->addChild(RightHipNode);

    InvBind = RightHipNode->getToWorld();
    InvBind.invert();
    ExampleSkeleton->pushToJoints(RightHip, InvBind);
    setName(RightHip, "Right Hip Joint");
    setName(RightHipNode, "Right Hip Node");

    /*================================================================================================*/
    /*                                       Right Knee                                                 */
    RightKnee = Joint::create(); //create a joint called RightKnee 
    TempMat.setTranslate(0.0,-3.0,0.0);
    RightKnee->setJointTransformation(TempMat);

    NodeRecPtr RightKneeNode = makeNodeFor(RightKnee);
    RightHipNode->addChild(RightKneeNode);

    InvBind = RightKneeNode->getToWorld();
    InvBind.invert();
    ExampleSkeleton->pushToJoints(RightKnee, InvBind);
    setName(RightKnee, "Right Knee Joint");
    setName(RightKneeNode, "Right Knee Node");

    /*================================================================================================*/
    /*                                       Right Foot                                                 */
    RightFoot = Joint::create(); //create a joint called RightFoot 
    TempMat.setTranslate(0.0,-3.0,0.0);
    RightFoot->setJointTransformation(TempMat);

    NodeRecPtr RightFootNode = makeNodeFor(RightFoot);
    RightKneeNode->addChild(RightFootNode);

    InvBind = RightFootNode->getToWorld();
    InvBind.invert();
    ExampleSkeleton->pushToJoints(RightFoot, InvBind);
    setName(RightFoot, "Right Foot Joint");
    setName(RightFootNode, "Right Foot Node");
    
    /*================================================================================================*/
    /*                                       Right Toes                                                 */
    RightToes = Joint::create(); //create a joint called RightToes 
    TempMat.setTranslate(0.0,0.0,1.0);
    RightToes->setJointTransformation(TempMat);

    NodeRecPtr RightToesNode = makeNodeFor(RightToes);
    RightFootNode->addChild(RightToesNode);

    InvBind = RightToesNode->getToWorld();
    InvBind.invert();
    ExampleSkeleton->pushToJoints(RightToes, InvBind);
    setName(RightToes, "Right Toes Joint");
    setName(RightToesNode, "Right Toes Node");


    //Create a geometry to attach to the skeleton (i.e-> skin)
    GeoUInt8PropertyUnrecPtr type = GeoUInt8Property::create();        
        type->push_back(GL_QUADS);

    GeoUInt32PropertyUnrecPtr lens = GeoUInt32Property::create();    
        lens->push_back(72);
    GeoPnt3fPropertyUnrecPtr  pnts  = GeoPnt3fProperty ::create();
        // the points of the Quads

        //Back
        pnts->push_back(Pnt3f(-0.5,  6.0,  0));
        pnts->push_back(Pnt3f( 0.5,  6.0,  0));
        pnts->push_back(Pnt3f( 0.5,  12.0,  0));
        pnts->push_back(Pnt3f(-0.5,  12.0,  0));

        //Head
        pnts->push_back(Pnt3f(-0.5,  12,  0));
        pnts->push_back(Pnt3f( 0.5,  12,  0));
        pnts->push_back(Pnt3f( 0.5,  13,  0));
        pnts->push_back(Pnt3f(-0.5,  13,  0));

        //Left Shoulder
        pnts->push_back(Pnt3f(0.0,  11.5,  0));
        pnts->push_back(Pnt3f(0.0,  12.5,  0));
        pnts->push_back(Pnt3f(1.0,  12.0,  0));
        pnts->push_back(Pnt3f(1.0,  11.0,  0));

        //Left Humerus
        pnts->push_back(Pnt3f(1.0,  11.0,  0));
        pnts->push_back(Pnt3f(1.0,  12.0,  0));
        pnts->push_back(Pnt3f(3.0,  12.0,  0));
        pnts->push_back(Pnt3f(3.0,  11.0,  0));

        //Left Radius
        pnts->push_back(Pnt3f(3.0,  11.0,  0));
        pnts->push_back(Pnt3f(3.0,  12.0,  0));
        pnts->push_back(Pnt3f(5.0,  12.0,  0));
        pnts->push_back(Pnt3f(5.0,  11.0,  0));

        //Left Hand
        pnts->push_back(Pnt3f(5.0,  11.0,  0));
        pnts->push_back(Pnt3f(5.0,  12.0,  0));
        pnts->push_back(Pnt3f(6.0,  12.0,  0));
        pnts->push_back(Pnt3f(6.0,  11.0,  0));

        //Right Shoulder
        pnts->push_back(Pnt3f(0.0,  11.5,  0));
        pnts->push_back(Pnt3f(0.0,  12.5,  0));
        pnts->push_back(Pnt3f(-1.0,  12.0,  0));
        pnts->push_back(Pnt3f(-1.0,  11.0,  0));

        //Right Humerus
        pnts->push_back(Pnt3f(-1.0,  11.0,  0));
        pnts->push_back(Pnt3f(-1.0,  12.0,  0));
        pnts->push_back(Pnt3f(-3.0,  12.0,  0));
        pnts->push_back(Pnt3f(-3.0,  11.0,  0));

        //Right Radius
        pnts->push_back(Pnt3f(-3.0,  11.0,  0));
        pnts->push_back(Pnt3f(-3.0,  12.0,  0));
        pnts->push_back(Pnt3f(-5.0,  12.0,  0));
        pnts->push_back(Pnt3f(-5.0,  11.0,  0));

        //Right Hand
        pnts->push_back(Pnt3f(-5.0,  11.0,  0));
        pnts->push_back(Pnt3f(-5.0,  12.0,  0));
        pnts->push_back(Pnt3f(-6.0,  12.0,  0));
        pnts->push_back(Pnt3f(-6.0,  11.0,  0));

        //Left Hip
        pnts->push_back(Pnt3f(0.0, 6.5,  0));
        pnts->push_back(Pnt3f(0.5, 7.5,  0));
        pnts->push_back(Pnt3f( 1.5,  6.0,  0));
        pnts->push_back(Pnt3f(0.5,  6.0,  0));

        //Left Femur
        pnts->push_back(Pnt3f(0.5,  6.0,  0));
        pnts->push_back(Pnt3f( 1.5,  6.0,  0));
        pnts->push_back(Pnt3f( 1.5,  3.0,  0));
        pnts->push_back(Pnt3f(0.5,  3.0,  0));

        //Left Tibia
        pnts->push_back(Pnt3f(0.5,  3.0,  0));
        pnts->push_back(Pnt3f( 1.5,  3.0,  0));
        pnts->push_back(Pnt3f( 1.5,  0.0,  0));
        pnts->push_back(Pnt3f(0.5,  0.0,  0));

        //Left Foot
        pnts->push_back(Pnt3f(0.5,  0.0,  0));
        pnts->push_back(Pnt3f( 1.5,  0.0,  0));
        pnts->push_back(Pnt3f( 1.5,  0.0,  1.0));
        pnts->push_back(Pnt3f(0.5,  0.0,  1.0));


        //Right Hip
        pnts->push_back(Pnt3f(0.0, 6.5,  0));
        pnts->push_back(Pnt3f(-0.5, 7.5,  0));
        pnts->push_back(Pnt3f( -1.5,  6.0,  0));
        pnts->push_back(Pnt3f(-0.5,  6.0,  0));

        //Right Femur
        pnts->push_back(Pnt3f(-0.5,  6.0,  0));
        pnts->push_back(Pnt3f( -1.5,  6.0,  0));
        pnts->push_back(Pnt3f( -1.5,  3.0,  0));
        pnts->push_back(Pnt3f(-0.5,  3.0,  0));

        //Right Tibia
        pnts->push_back(Pnt3f(-0.5,  3.0,  0));
        pnts->push_back(Pnt3f( -1.5,  3.0,  0));
        pnts->push_back(Pnt3f( -1.5,  0.0,  0));
        pnts->push_back(Pnt3f(-0.5,  0.0,  0));

        //Right Foot
        pnts->push_back(Pnt3f(-0.5,  0.0,  0));
        pnts->push_back(Pnt3f( -1.5,  0.0,  0));
        pnts->push_back(Pnt3f( -1.5,  0.0,  1.0));
        pnts->push_back(Pnt3f(-0.5,  0.0,  1.0));

    //Normals
    GeoVec3fPropertyUnrecPtr  norms = GeoVec3fProperty ::create();
    geo=Geometry::create();
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));

    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));

    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));

    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));

    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));

    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));

    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));

    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));

    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));

    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));

    //Left Hip
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));

    //Left Femur
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));

    //Left Tibia
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));

    //Left Foot
    norms->push_back(Vec3f( 0.0,1.0,0.0));
    norms->push_back(Vec3f( 0.0,1.0,0.0));
    norms->push_back(Vec3f( 0.0,1.0,0.0));
    norms->push_back(Vec3f( 0.0,1.0,0.0));

    //Right Hip
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));

    //Right Femur
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));

    //Right Tibia
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));
    norms->push_back(Vec3f( 0.0,0.0,1.0));

    //Right Foot
    norms->push_back(Vec3f( 0.0,1.0,0.0));
    norms->push_back(Vec3f( 0.0,1.0,0.0));
    norms->push_back(Vec3f( 0.0,1.0,0.0));
    norms->push_back(Vec3f( 0.0,1.0,0.0));

    //Tell the geometry (geo) to use the points and normals we just defined
    geo->setTypes    (type);
    geo->setLengths  (lens);
    geo->setPositions(pnts);
    geo->setNormals(norms);

    // assign a material to the geometry to make it visible. The details
    // of materials are defined later.
    geo->setMaterial(getDefaultMaterial());   

    //Create unbound geometry node (for displaying mesh in its bind pose)
    UnboundGeometry = Node::create();
    UnboundGeometry->setCore(geo);
    UnboundGeometry->setTravMask(0);  //By default, we won't show the mesh's bind pose




    //SkeletonDrawer
    SkeletonDrawableUnrecPtr ExampleSkeletonDrawable = SkeletonDrawable::create();
    ExampleSkeletonDrawable->setSkeleton(ExampleSkeleton);
    ExampleSkeletonDrawable->setMaterial(ExampleMaterial);
    ExampleSkeletonDrawable->setDrawBindPose(false);  //By default, we don't draw the skeleton's bind pose
    ExampleSkeletonDrawable->setBindPoseColor(Color4f(0.0, 1.0, 0.0, 1.0));  //When drawn, the skeleton's bind pose renders green
    ExampleSkeletonDrawable->setDrawPose(true);  //By default, we do draw the skeleton's current pose
    ExampleSkeletonDrawable->setPoseColor(Color4f(0.0, 0.0, 1.0, 1.0));  //The skeleton's current pose renders blue

    //Skeleton Node
    SkeletonNode = Node::create();
    SkeletonNode->setCore(ExampleSkeletonDrawable);




    // Skeleton Blended Geometry
    // Here we are attaching the "skin" to the skeleton so that when the skeleton is animated, the skin moves with it
    ExampleSkeleton->setBaseGeometry(geo);
    //Back
    ExampleSkeleton->addJointBlending(0,Pelvis,1.0f);
    ExampleSkeleton->addJointBlending(1,Pelvis,1.0f);
    ExampleSkeleton->addJointBlending(2,Clavicle,1.0f);
    ExampleSkeleton->addJointBlending(3,Clavicle,1.0f);

    //Head
    ExampleSkeleton->addJointBlending(4,Clavicle,1.0f);
    ExampleSkeleton->addJointBlending(5,Clavicle,1.0f);
    ExampleSkeleton->addJointBlending(6,Head,1.0f);
    ExampleSkeleton->addJointBlending(7,Head,1.0f);

    //Left Shoulder
    ExampleSkeleton->addJointBlending(8,Clavicle,1.0f);
    ExampleSkeleton->addJointBlending(9,Clavicle,1.0f);
    ExampleSkeleton->addJointBlending(10,LeftShoulder,1.0f);
    ExampleSkeleton->addJointBlending(11,LeftShoulder,1.0f);

    //Left Humerus
    ExampleSkeleton->addJointBlending(12,LeftShoulder,1.0f);
    ExampleSkeleton->addJointBlending(13,LeftShoulder,1.0f);
    ExampleSkeleton->addJointBlending(14,LeftElbow,0.8f);
    ExampleSkeleton->addJointBlending(15,LeftElbow,0.8f);
    ExampleSkeleton->addJointBlending(14,LeftHand,0.2f);
    ExampleSkeleton->addJointBlending(15,LeftHand,0.2f);

    //Left Radius
    ExampleSkeleton->addJointBlending(16,LeftElbow,1.0f);
    ExampleSkeleton->addJointBlending(17,LeftElbow,1.0f);
    ExampleSkeleton->addJointBlending(18,LeftHand,1.0f);
    ExampleSkeleton->addJointBlending(19,LeftHand,1.0f);

    //Left Hand
    ExampleSkeleton->addJointBlending(20,LeftHand,1.0f);
    ExampleSkeleton->addJointBlending(21,LeftHand,1.0f);
    ExampleSkeleton->addJointBlending(22,LeftFingers,1.0f);
    ExampleSkeleton->addJointBlending(23,LeftFingers,1.0f);

    //Right Shoulder
    ExampleSkeleton->addJointBlending(24,Clavicle,1.0f);
    ExampleSkeleton->addJointBlending(25,Clavicle,1.0f);
    ExampleSkeleton->addJointBlending(26,RightShoulder,1.0f);
    ExampleSkeleton->addJointBlending(27,RightShoulder,1.0f);

    //Right Humerus
    ExampleSkeleton->addJointBlending(28,RightShoulder,1.0f);
    ExampleSkeleton->addJointBlending(29,RightShoulder,1.0f);
    ExampleSkeleton->addJointBlending(30,RightElbow,1.0f);
    ExampleSkeleton->addJointBlending(31,RightElbow,1.0f);

    //Right Radius
    ExampleSkeleton->addJointBlending(32,RightElbow,1.0f);
    ExampleSkeleton->addJointBlending(33,RightElbow,1.0f);
    ExampleSkeleton->addJointBlending(34,RightHand,1.0f);
    ExampleSkeleton->addJointBlending(35,RightHand,1.0f);

    //Right Hand
    ExampleSkeleton->addJointBlending(36,RightHand,1.0f);
    ExampleSkeleton->addJointBlending(37,RightHand,1.0f);
    ExampleSkeleton->addJointBlending(38,RightFingers,1.0f);
    ExampleSkeleton->addJointBlending(39,RightFingers,1.0f);

    //Left Hip
    ExampleSkeleton->addJointBlending(40,Pelvis,1.0f);
    ExampleSkeleton->addJointBlending(41,Pelvis,1.0f);
    ExampleSkeleton->addJointBlending(42,LeftHip,1.0f);
    ExampleSkeleton->addJointBlending(43,LeftHip,1.0f);

    //Left Femur
    ExampleSkeleton->addJointBlending(44,LeftHip,1.0f);
    ExampleSkeleton->addJointBlending(45,LeftHip,1.0f);
    ExampleSkeleton->addJointBlending(46,LeftKnee,1.0f);
    ExampleSkeleton->addJointBlending(47,LeftKnee,1.0f);

    //Left Tibia
    ExampleSkeleton->addJointBlending(48,LeftKnee,1.0f);
    ExampleSkeleton->addJointBlending(49,LeftKnee,1.0f);
    ExampleSkeleton->addJointBlending(50,LeftFoot,1.0f);
    ExampleSkeleton->addJointBlending(51,LeftFoot,1.0f);

    //Left Foot
    ExampleSkeleton->addJointBlending(52,LeftFoot,1.0f);
    ExampleSkeleton->addJointBlending(53,LeftFoot,1.0f);
    ExampleSkeleton->addJointBlending(54,LeftToes,1.0f);
    ExampleSkeleton->addJointBlending(55,LeftToes,1.0f);

    //Right Hip
    ExampleSkeleton->addJointBlending(56,Pelvis,1.0f);
    ExampleSkeleton->addJointBlending(57,Pelvis,1.0f);
    ExampleSkeleton->addJointBlending(58,RightHip,1.0f);
    ExampleSkeleton->addJointBlending(59,RightHip,1.0f);

    //Right Femur
    ExampleSkeleton->addJointBlending(60,RightHip,1.0f);
    ExampleSkeleton->addJointBlending(61,RightHip,1.0f);
    ExampleSkeleton->addJointBlending(62,RightKnee,1.0f);
    ExampleSkeleton->addJointBlending(63,RightKnee,1.0f);

    //Right Tibia
    ExampleSkeleton->addJointBlending(64,RightKnee,1.0f);
    ExampleSkeleton->addJointBlending(65,RightKnee,1.0f);
    ExampleSkeleton->addJointBlending(66,RightFoot,1.0f);
    ExampleSkeleton->addJointBlending(67,RightFoot,1.0f);

    //Right Foot
    ExampleSkeleton->addJointBlending(68,RightFoot,1.0f);
    ExampleSkeleton->addJointBlending(69,RightFoot,1.0f);
    ExampleSkeleton->addJointBlending(70,RightToes,1.0f);
    ExampleSkeleton->addJointBlending(71,RightToes,1.0f);

    MeshNode = Node::create();
    MeshNode->setCore(ExampleSkeleton);

    //Create scene node 
    NodeUnrecPtr scene = Node::create();
    scene->setCore(Group::create());
    scene->addChild(UnboundGeometry);
    scene->addChild(SkeletonNode);
    scene->addChild(MeshNode);

    mgr->setRoot(scene);

    //Setup the Animation
    setupAnimation();

    //Save to an xml file
    FCFileType::FCPtrStore Containers;
    Containers.insert(ExampleSkeleton);
    Containers.insert(PelvisNode);
    Containers.insert(TheSkeletonAnimation);

    //Use an empty Ignore types vector
    FCFileType::FCTypeVector IgnoreTypes;
    //IgnoreTypes.push_back(Node::getClassType().getId());
    
    //Write the Field Containers to a xml file
    FCFileHandler::the()->write(Containers,BoostPath("./13Output.xml"),IgnoreTypes);

    // Show the whole Scene
    mgr->showAll();


    //Open Window
    Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
    TutorialWindow->openWindow(WinPos,
            WinSize,
            "13MeshBlending");

    //Main Loop
    TutorialWindow->mainLoop();


    osgExit();

    return 0;
}
コード例 #13
0
// Initialize GLUT & OpenSG and set up the rootNode
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindow = createNativeWindow();
    TutorialWindow->initWindow();

    TutorialWindow->setDisplayCallback(display);
    TutorialWindow->setReshapeCallback(reshape);

    TutorialKeyListener TheKeyListener;
    TutorialWindow->addKeyListener(&TheKeyListener);
    TutorialMouseListener TheTutorialMouseListener;
    TutorialMouseMotionListener TheTutorialMouseMotionListener;
    TutorialWindow->addMouseListener(&TheTutorialMouseListener);
    TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

	
    // Tell the Manager what to manage
    mgr->setWindow(TutorialWindow);

    //Make Torus Node
    NodeUnrecPtr TorusNode = makeTorus(.5, 2, 32, 32);

    //Make Main Scene Node
	NodeUnrecPtr scene = makeCoredNode<Group>();
    setName(scene, "scene");
    rootNode = Node::create();
    setName(rootNode, "rootNode");
    ComponentTransformUnrecPtr Trans;
    Trans = ComponentTransform::create();
        rootNode->setCore(Trans);
 
        // add the torus as a child
        rootNode->addChild(scene);

    //Setup Physics Scene
    physicsWorld = PhysicsWorld::create();
        physicsWorld->setWorldContactSurfaceLayer(0.005);
        physicsWorld->setAutoDisableFlag(1);
        physicsWorld->setAutoDisableTime(0.75);
        physicsWorld->setWorldContactMaxCorrectingVel(100.0);
        physicsWorld->setGravity(Vec3f(0.0, 0.0, -9.81));

    //physicsSpace = PhysicsSimpleSpace::create();
    //physicsSpace = PhysicsQuadTreeSpace::create();
    //physicsSpace = PhysicsHashSpace::create();
    physicsSpace = PhysicsSweepAndPruneSpace::create();

    CollisionContactParametersUnrecPtr DefaultCollisionParams = CollisionContactParameters::createEmpty();
        DefaultCollisionParams->setMode(dContactApprox1 | dContactBounce);
        DefaultCollisionParams->setMu(0.3);
        DefaultCollisionParams->setMu2(0.0);
        DefaultCollisionParams->setBounce(0.2);
        DefaultCollisionParams->setBounceSpeedThreshold(0.1);
        DefaultCollisionParams->setSoftCFM(0.1);
        DefaultCollisionParams->setSoftERP(0.2);
        DefaultCollisionParams->setMotion1(0.0);
        DefaultCollisionParams->setMotion2(0.0);
        DefaultCollisionParams->setMotionN(0.0);
        DefaultCollisionParams->setSlip1(0.0);
        DefaultCollisionParams->setSlip2(0.0);

        physicsSpace->setDefaultCollisionParameters(DefaultCollisionParams);

    physHandler = PhysicsHandler::create();
        physHandler->setWorld(physicsWorld);
        physHandler->pushToSpaces(physicsSpace);
        physHandler->setUpdateNode(rootNode);
    physHandler->attachUpdateProducer(TutorialWindow->editEventProducer());
    

        rootNode->addAttachment(physHandler);    
        rootNode->addAttachment(physicsWorld);
        rootNode->addAttachment(physicsSpace);


	/************************************************************************/
	/* create spaces, geoms and bodys                                                                     */
	/************************************************************************/
    //create a group for our space
    GroupUnrecPtr spaceGroup;
	spaceGroupNode = makeCoredNode<Group>(&spaceGroup);
    //create the ground plane
    GeometryUnrecPtr plane;
	NodeUnrecPtr planeNode = makeBox(30.0, 30.0, 1.0, 1, 1, 1);
    plane = dynamic_cast<Geometry*>(planeNode->getCore());
    //and its Material
	SimpleMaterialUnrecPtr plane_mat = SimpleMaterial::create();
		plane_mat->setAmbient(Color3f(0.7,0.7,0.7));
		plane_mat->setDiffuse(Color3f(0.9,0.6,1.0));
	    plane->setMaterial(plane_mat);


    //create Physical Attachments
	PhysicsBoxGeomUnrecPtr planeGeom = PhysicsBoxGeom::create();
        planeGeom->setLengths(Vec3f(30.0, 30.0, 1.0));
        //add geoms to space for collision
        planeGeom->setSpace(physicsSpace);

	//add Attachments to nodes...
	    spaceGroupNode->addAttachment(physicsSpace);
        spaceGroupNode->addChild(planeNode);

        planeNode->addAttachment(planeGeom);
    
	    scene->addChild(spaceGroupNode);

    //Create Statistics Foreground
    SimpleStatisticsForegroundUnrecPtr PhysicsStatForeground = SimpleStatisticsForeground::create();
        PhysicsStatForeground->setSize(25);
        PhysicsStatForeground->setColor(Color4f(0,1,0,0.7));
        PhysicsStatForeground->addElement(PhysicsHandler::statPhysicsTime, 
            "Physics time: %.3f s");
        PhysicsStatForeground->addElement(PhysicsHandler::statCollisionTime, 
            "Collision time: %.3f s");
        PhysicsStatForeground->addElement(PhysicsHandler::statSimulationTime, 
            "Simulation time: %.3f s");
        PhysicsStatForeground->addElement(PhysicsHandler::statNCollisions, 
            "%d collisions");
        PhysicsStatForeground->addElement(PhysicsHandler::statNCollisionTests, 
            "%d collision tests");
        PhysicsStatForeground->addElement(PhysicsHandler::statNPhysicsSteps, 
            "%d simulation steps per frame");

    // tell the manager what to manage
    mgr->setRoot  (rootNode);

    mgr->getWindow()->getPort(0)->addForeground(PhysicsStatForeground);
    physHandler->setStatistics(PhysicsStatForeground->getCollector());

    // show the whole rootNode
    mgr->showAll();
    
    Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
    TutorialWindow->openWindow(WinPos,
            WinSize,
            "05Explosion");

    //Enter main Loop
    TutorialWindow->mainLoop();

    osgExit();

    return 0;
}
コード例 #14
0
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindow = createNativeWindow();
    TutorialWindow->initWindow();

    TutorialWindow->setDisplayCallback(display);
    TutorialWindow->setReshapeCallback(reshape);

    //Add Window Listener
    TutorialKeyListener TheKeyListener;
    TutorialWindow->addKeyListener(&TheKeyListener);
    TutorialMouseListener TheTutorialMouseListener;
    TutorialMouseMotionListener TheTutorialMouseMotionListener;
    TutorialWindow->addMouseListener(&TheTutorialMouseListener);
    TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(TutorialWindow);
	
	//SkeletonDrawer System Material
	LineChunkUnrecPtr ExampleLineChunk = LineChunk::create();
    ExampleLineChunk->setWidth(4.0f);
    ExampleLineChunk->setSmooth(true);

	BlendChunkUnrecPtr ExampleBlendChunk = BlendChunk::create();
    ExampleBlendChunk->setSrcFactor(GL_SRC_ALPHA);
    ExampleBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);

	MaterialChunkUnrecPtr ExampleMaterialChunk = MaterialChunk::create();
    ExampleMaterialChunk->setAmbient(Color4f(1.0f,1.0f,1.0f,1.0f));
    ExampleMaterialChunk->setDiffuse(Color4f(0.0f,0.0f,0.0f,1.0f));
    ExampleMaterialChunk->setSpecular(Color4f(0.0f,0.0f,0.0f,1.0f));

	ChunkMaterialUnrecPtr ExampleMaterial = ChunkMaterial::create();
    ExampleMaterial->addChunk(ExampleLineChunk);
    ExampleMaterial->addChunk(ExampleMaterialChunk);
    ExampleMaterial->addChunk(ExampleBlendChunk);

    GeometryRefPtr SphereGeometry = makeSphereGeo(2, 0.25f);
    GeometryRefPtr BoxGeometry = makeBoxGeo(0.5f,0.5f,0.5f,1,1,1);

    //Skeleton
    SkeletonBlendedGeometryUnrecPtr ExampleSkeleton = SkeletonBlendedGeometry::create();

    //Joint
	TransformRecPtr ExampleRootJoint = Transform::create();

    NodeRecPtr ExampleRootJointNode = makeNodeFor(ExampleRootJoint);

    //Add this joint to the skeleton
    ExampleSkeleton->pushToJoints(ExampleRootJointNode, Matrix());

    NodeRecPtr TempRootJointNode = ExampleRootJointNode;
    NodeRefPtr GeoNode = makeNodeFor(BoxGeometry);
    TempRootJointNode->addChild(GeoNode);

	Matrix TempMat;
	//Create a set of randomly placed child joints
	for (Real32 i = 0.0f; i < 5.0f; ++i)
	{
		TransformRecPtr ExampleChildJoint = Transform::create();
		NodeRecPtr ExampleChildJointNode = makeNodeFor(ExampleChildJoint);

        GeoNode = makeNodeFor(SphereGeometry);
        ExampleChildJointNode->addChild(GeoNode);

		//TempMat.setTranslate(RandomPoolManager::getRandomReal32(0.0, 10.0f), RandomPoolManager::getRandomReal32(0.0f, 10.0f), RandomPoolManager::getRandomReal32(0.0f, 10.0f));
        switch((static_cast<UInt32>(i) % 3))
        {
            case 0:
                TempMat.setTranslate(2.0f,0.0f,0.0f);
                break;
            case 1:
                TempMat.setTranslate(0.0f,2.0f,0.0f);
                break;
            case 2:
                TempMat.setTranslate(0.0f,0.0f,2.0f);
                break;
        }
		
		//Set bind and current transformations to TempMat (calculated above)
        ExampleChildJoint->setMatrix(TempMat);

		//Add ExampleChildJoint as a child to the previous joint	
        TempRootJointNode->addChild(ExampleChildJointNode);//add a Child to the root joint

		//ExampleChildJoint will be the next parent joint
		TempRootJointNode = ExampleChildJointNode;
        
        //Add this joint to the skeleton
        Matrix InvBind(TempRootJointNode->getToWorld());
        InvBind.invert();
        ExampleSkeleton->pushToJoints(ExampleChildJointNode, InvBind);
	}


    //SkeletonDrawer
    SkeletonDrawableUnrecPtr ExampleSkeletonDrawable = SkeletonDrawable::create();
    ExampleSkeletonDrawable->setSkeleton(ExampleSkeleton);
    ExampleSkeletonDrawable->setMaterial(ExampleMaterial);
	
	//Skeleton Particle System Node
	NodeUnrecPtr SkeletonNode = Node::create();
    SkeletonNode->setCore(ExampleSkeletonDrawable);


    // Make Main Scene Node and add the Torus
    NodeUnrecPtr scene = Node::create();
    scene->setCore(Group::create());
    scene->addChild(SkeletonNode);
    scene->addChild(ExampleRootJointNode);

    mgr->setRoot(scene);

    // Show the whole Scene
    mgr->showAll();


    //Open Window
    Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
    TutorialWindow->openWindow(WinPos,
            WinSize,
            "10SkeletonDrawer");

    //Main Loop
    TutorialWindow->mainLoop();

    osgExit();

    return 0;
}
コード例 #15
0
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    {
        // Set up Window
        WindowEventProducerRecPtr TutorialWindow = createNativeWindow();

        //Initialize Window
        TutorialWindow->initWindow();

        SimpleSceneManager sceneManager;
        TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
        TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));

        // Tell the Manager what to manage
        sceneManager.setWindow(TutorialWindow);

        //Attach to events
        TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager));
        TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager));
        TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
        TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));
        TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, TutorialWindow.get()));

        //Torus Node
        NodeUnrecPtr TorusGeometryNode = makeTorus(.5, 2, 32, 32);

        //Make Torus Node
        NodeUnrecPtr TorusNode = Node::create();
        TransformUnrecPtr TorusNodeTrans;
        TorusNodeTrans = Transform::create();

        TorusNode->setCore(TorusNodeTrans);
        TorusNode->addChild(TorusGeometryNode);

        //Make Main Scene Node
        NodeUnrecPtr scene = Node::create();
        ComponentTransformUnrecPtr Trans;
        Trans = ComponentTransform::create();
        scene->setCore(Trans);

        // add the torus as a child
        scene->addChild(TorusNode);

        //Make a gradient Background
        GradientBackgroundUnrecPtr TutorialBackground = GradientBackground::create();
        TutorialBackground->addLine(Color3f(1.0,0.0,0.0),0.0);
        TutorialBackground->addLine(Color3f(0.0,1.0,0.0),0.5);
        TutorialBackground->addLine(Color3f(0.0,0.0,1.0),1.0);
        setName(TutorialBackground, std::string("TutorialGradientBackground"));

        AnimationUnrecPtr TheAnimation = setupAnimation(TutorialBackground);
        TheAnimation->attachUpdateProducer(TutorialWindow);
        TheAnimation->start();

        // tell the manager what to manage
        sceneManager.setRoot  (scene);
        sceneManager.getWindow()->getPort(0)->setBackground(TutorialBackground);

        //Create the Documentation
        SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow);

        // show the whole scene
        sceneManager.showAll();

        //Open Window
        Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
        Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
        TutorialWindow->openWindow(WinPos,
                                   WinSize,
                                   "03MFieldAnimation");

        //Main Loop
        TutorialWindow->mainLoop();
    }

    osgExit();

    return 0;
}
コード例 #16
0
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindow = createNativeWindow();
    TutorialWindow->initWindow();

    TutorialWindow->setDisplayCallback(display);
    TutorialWindow->setReshapeCallback(reshape);

    //Add Window Listener
    TutorialKeyListener TheKeyListener;
    TutorialWindow->addKeyListener(&TheKeyListener);
    TutorialMouseListener TheTutorialMouseListener;
    TutorialMouseMotionListener TheTutorialMouseMotionListener;
    TutorialWindow->addMouseListener(&TheTutorialMouseListener);
    TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(TutorialWindow);


    //SkeletonDrawer System Material
    LineChunkUnrecPtr ExampleLineChunk = LineChunk::create();
    ExampleLineChunk->setWidth(2.0f);
    ExampleLineChunk->setSmooth(true);

    BlendChunkUnrecPtr ExampleBlendChunk = BlendChunk::create();
    ExampleBlendChunk->setSrcFactor(GL_SRC_ALPHA);
    ExampleBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);

    MaterialChunkUnrecPtr ExampleMaterialChunk = MaterialChunk::create();
    ExampleMaterialChunk->setAmbient(Color4f(1.0f,1.0f,1.0f,1.0f));
    ExampleMaterialChunk->setDiffuse(Color4f(0.0f,0.0f,0.0f,1.0f));
    ExampleMaterialChunk->setSpecular(Color4f(0.0f,0.0f,0.0f,1.0f));

    ChunkMaterialUnrecPtr ExampleMaterial = ChunkMaterial::create();
    ExampleMaterial->addChunk(ExampleLineChunk);


    //Read skeleton from XML file
    FCFileType::FCPtrStore NewContainers;
    NewContainers = FCFileHandler::the()->read(BoostPath("./Data/16Skeleton.xml"));

    SkeletonUnrecPtr ExampleSkeleton;

    FCFileType::FCPtrStore::iterator Itor;
    for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor)
    {
        //Only import skeleton data; we ignore anything else saved in the XML file
        if( (*Itor)->getType() == (Skeleton::getClassType()))
        {
            //Set the Skeleton to the one we just read in
            ExampleSkeleton = (dynamic_pointer_cast<Skeleton>(*Itor));
        }
    }

    //SkeletonDrawer
    SkeletonDrawableUnrecPtr ExampleSkeletonDrawable = SkeletonDrawable::create();
    ExampleSkeletonDrawable->setSkeleton(ExampleSkeleton);
    ExampleSkeletonDrawable->setMaterial(ExampleMaterial);

    //Skeleton Particle System Node
    NodeUnrecPtr SkeletonNode = Node::create();
    SkeletonNode->setCore(ExampleSkeletonDrawable);


    //Torus Node
    NodeUnrecPtr TorusNode = makeTorus(.5, 2, 32, 32);

    // Make Main Scene Node and add the Torus
    NodeUnrecPtr scene = Node::create();
    scene->setCore(Group::create());
    scene->addChild(SkeletonNode);
    //scene->addChild(TorusNode);
    scene->addChild(makeCoordAxis(10.0));

    mgr->setRoot(scene);
    mgr->turnHeadlightOff();

    // Show the whole Scene
    mgr->showAll();

    Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
    TutorialWindow->openWindow(WinPos,
            WinSize,
            "16LoadXMLSkeleton");

    //Enter main Loop
    TutorialWindow->mainLoop();

    osgExit();

    return 0;
}
コード例 #17
0
int doMain(int argc, char **argv)
{
    osgInit(argc,argv);
    
    // GLUT init

    glutInit(&argc, argv);
    glutInitDisplayMode( GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
    int winid = glutCreateWindow("OpenSG");
    glutKeyboardFunc(key);
    glutVisibilityFunc(vis);
    glutReshapeFunc(reshape);
    glutDisplayFunc(display);       
    glutMouseFunc(mouse);   
    glutMotionFunc(motion); 
    
    glutIdleFunc(display);  

    // OSG

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

    // create the graph

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

    b1n->setCore( b1 );

    // transformation
    NodeUnrecPtr      t1n = Node::create();
    TransformUnrecPtr t1  = Transform::create();

    t1n->setCore (t1 );
    t1n->addChild(b1n);

    cam_trans = t1;

    // light
    
    NodeUnrecPtr             dlight = Node::create();
    DirectionalLightUnrecPtr dl     = 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              = Node:: create();
    GroupUnrecPtr gr1 = Group::create();

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

    // Load the file

    NodeUnrecPtr file = NULL;
    
#if 0
    if(argc > 1)
    {
        file = SceneFileHandler::the()->read(argv[1], NULL);
    }
#endif

    if(file == NULL)
    {
#if 0
        std::cerr << "Couldn't load file, ignoring" << std::endl;

        NodeUnrecPtr geoRef = Node::create();
    
        geoRef->setCore(Group::create());

        NodeUnrecPtr           pEll     = Node::create();
        MaterialGroupUnrecPtr  pEllMatG = MaterialGroup::create();
        SimpleMaterialUnrecPtr pEllMat  = SimpleMaterial::create();

        pEllMat->editDiffuse().setValuesRGB(0.3, 0.3, 0.3);

        pEllMatG->setMaterial(pEllMat);

        pEll->setCore(pEllMatG);

        pEll->addChild(makeLatLongEllipsoid(18, 
                                            36, 
                                            6378137. * 0.95,
                                            6356752.3142 * 0.95));
    

        geoRef->addChild(pEll);
    
        geoRef->addChild(makeEllipsoidAxis(18, 
                                           36, 
                                           6378137. * 1.05,
                                           6356752.3142 * 1.05));

        file = geoRef; //makeSphere(4, 2.0);
#endif

        file = makeSphere(4, 2.0);
    }

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

    file->updateVolume();


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

/*
    min[0] = -500;
    min[1] = 0;
    min[2] = -500;

    max[0] = 500;
    max[1] = 100;
    max[2] = 500;
 */

                 scene_trans = Transform::create();
    NodeUnrecPtr sceneTrN    = Node::create();

    sceneTrN->setCore (scene_trans);
    sceneTrN->addChild(file       );

    AlgorithmStageUnrecPtr pAlgoStage = AlgorithmStage::create();

    pAlgoStage->setInheritedTarget(true);
    pAlgoStage->setProjectionMode (AlgorithmStage::Ignore);
    pAlgoStage->setCopyViewing    (true);

    CallbackAlgorithmUnrecPtr pAlgo = CallbackAlgorithm::create();

    pAlgo->setCallback(&terrainRenderCB, "");

    pAlgoStage->setAlgorithm(pAlgo);

    NodeUnrecPtr pAlgoNode = Node::create();

    pAlgoNode->setCore(pAlgoStage);

    sceneTrN->addChild(pAlgoNode);

    dlight->addChild(sceneTrN);

    // Camera
    
    cam = PerspectiveCamera::create();
    {
        cam->setBeacon( b1n );
        cam->setFov( osgDegree2Rad( 90 ) );
        cam->setNear( 1000 );
        cam->setFar( 100000000 );
    }

    // Background
    SolidBackgroundUnrecPtr bkgnd = SolidBackground::create();
    {
        bkgnd->setColor(Color3f(0,0,1));
    }

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


    // Window
    GLUTWindowUnrecPtr gwin;

    GLint glvp[4];

    glGetIntegerv(GL_VIEWPORT, glvp);

    gwin = GLUTWindow::create();
    {
        gwin->setGlutId(winid);
        gwin->setSize( glvp[2], glvp[3] );
        
        win = gwin;

        win->addPort( vp );

        win->init();
    }

    // Action
    rentravact = RenderAction::create();
    
    rentravact->setFrustumCulling(false);

    int cols = 1;
    int rows = 1;
    
    terrain = new miniload(); 

    terrain->configure_mipmaps(0);

    terrain->setloader(hw_request_callback,
                       NULL);

#if 1
    static const char *abasepath1 = 
        "/home/gerrit/SoftwareBuild/Hawaii/data/HawaiiTileset/tiles";
    static const char *abasepath2 =
        "/home/gerrit/SoftwareBuild/Hawaii/data/HawaiiTileset/landsat";

    static const float viewx = 0.f; //-560309.0f;
    static const float viewy = 0.f; //72234.0f;

    // vertical exaggeration
    static const float exaggeration=1.5f; // exaggeration=150%

    float tscale = 1.f; //00.0f; // 1:100

    // number of columns and rows
    cols = 32;
    rows = 24;

    // approximate value of one arc-second in meters
    static float arcsec[3];

    // resampling output parameters
    static float outparams[5];

    std::string szTilePath;
    std::string szLandSatPath;

    if(argc > 1)
    {
        fprintf(stderr, "loading from %s\n", argv[1]);

        szTilePath   .assign(argv[1]);
        szLandSatPath.assign(argv[1]);

        szTilePath    += "/data/HawaiiTileset/tiles";
        szLandSatPath += "/data/HawaiiTileset/landsat";

        abasepath1 = szTilePath   .c_str();
        abasepath2 = szLandSatPath.c_str();
    }


    // load resampled tiles
    terrain->load(cols,rows, // number of columns and rows

                  abasepath1,
                  abasepath2,
                  NULL, // directories for tiles and textures (and no fogmaps)

                  -viewx,-viewy, // horizontal offset in arc-seconds
                  0.0f, // no vertical offset
                  1.0f,1.0f,1.0f, // no horizontal stretching
                  exaggeration,tscale, // vertical exaggeration and global scale
                  0.0f,0.0f, // no fog parameters required
                  0.0f, // choose default minimum resolution
                  0.0f, // disable base offset safety
                  outparams, // geometric output parameters
                  arcsec); // one arcsec in meters
#endif

#if 1
    fprintf(stderr, "%f %f %f\n",
            terrain->getminitile()->getcenterx(),
            terrain->getminitile()->getcentery(),
            terrain->getminitile()->getcenterz());

    fprintf(stderr, "%f %f \n",
            terrain->getminitile()->getsizex(),
            terrain->getminitile()->getsizez());
#endif            

    max[0] = terrain->getminitile()->getcenterx();
    max[1] = terrain->getminitile()->getcentery();
    max[2] = terrain->getminitile()->getcenterz();

    min[0] = 
        terrain->getminitile()->getcenterx() -
        (terrain->getminitile()->getsizex() / 2.f);

    min[1] = terrain->getminitile()->getcentery();

    min[2] = 
        terrain->getminitile()->getcenterz() -
        (terrain->getminitile()->getsizez() / 2.f);

    // tball
    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 );
    
    float scale = (max[2] - min[2] + max[1] - min[1] + max[0] - min[0]) / 6;

    //scale = 100;

    Pnt3f tCenter(min[0] + (max[0] - min[0]) / 2,
                  min[1] + (max[1] - min[1]) / 2,
                  min[2] + (max[2] - min[2]) / 2);


    fprintf(stderr, "Startpos : %f %f %f\n", 
            pos[0], pos[1], pos[2]);
    fprintf(stderr, "tcenter  : %f %f %f\n", 
            tCenter[0], tCenter[1], tCenter[2]);

    tball.setMode            (Trackball::OSGObject);
    tball.setStartPosition   (pos, true           );
    tball.setSum             (true                );
    tball.setTranslationMode (Trackball::OSGFree  );
    tball.setTranslationScale(scale               );
    tball.setRotationCenter  (tCenter             );

    return 0;
}
コード例 #18
0
Action::ResultE GeometryMergeGraphOp::traverseLeave(
        Node * const node, Action::ResultE res)
{
    if(isInExcludeList(node))
        return Action::Skip;

    NodeCore *core = node->getCore();
    
    // skip cores with a dependency on the children number/order
    // TODO: find a way to make this extendable
    if(core == NULL                                               ||
       core->getType().isDerivedFrom(DistanceLOD::getClassType()) ||
       core->getType().isDerivedFrom(ScreenLOD  ::getClassType()) ||
       core->getType().isDerivedFrom(Switch     ::getClassType()) ||
       core->getType().isDerivedFrom(MultiCore  ::getClassType())   )
    {
        return Action::Continue;
    }
    
    typedef std::vector<NodeUnrecPtr> NodeStore;
    NodeStore addStore;     // nodes to add as children to current one
    NodeStore subStore;     // nodes (children) to remove from current one
    
    typedef std::vector<Node *    > MergeGroup; // geometries that can be merged
    typedef std::vector<MergeGroup> MergeList;  // list of merge groups
    
    MergeList                            ml;
    Node::MFChildrenType::const_iterator childIt  =
            node->getMFChildren()->begin();
    Node::MFChildrenType::const_iterator childEnd =
            node->getMFChildren()->end  ();
    
    // group geometry children that are mergeable
    for(; childIt != childEnd; ++childIt)
    {
        if((*childIt)->getCore()->getType() != Geometry::getClassType())
            continue;
        
        if(isInExcludeList(*childIt) || isInPreserveList(*childIt))
            continue;
        
        Geometry *geo = dynamic_cast<Geometry *>((*childIt)->getCore());
        Material *mat = geo->getMaterial();
        
        MergeList::iterator mlIt  = ml.begin();
        MergeList::iterator mlEnd = ml.end  ();
        
        bool done = false;
        
        for(; mlIt != mlEnd && !done; ++mlIt)
        {
            Geometry *mlGeo =
                    dynamic_cast<Geometry *>(mlIt->front()->getCore());
            Material *mlMat = mlGeo->getMaterial();
            
            if(compareContainerEqual(mlMat, mat) &&
               mergeableGeo         (mlGeo, geo)   )
            {
                mlIt->push_back(*childIt);
                done = true;
            }
        }
        
        if(!done)
        {
            ml       .push_back(MergeGroup());
            ml.back().push_back(*childIt    );
        }
    }
    
    // merge geometry in the same group and replace obsolete children with
    // new geometry
    MergeList::iterator mlIt  = ml.begin();
    MergeList::iterator mlEnd = ml.end  ();
    
    for(; mlIt != mlEnd; ++mlIt)
    {
        // only one geometry in merge group -> nothing to do
        if(mlIt->size() <= 1)
            continue;
        
        FINFO(("GeometryMergeGraphOp::traverseLeave: Merging [%" PRISize "] "
               "Geometries.\n", mlIt->size()));
        
        GeometryUnrecPtr     geo1;
        GeometryUnrecPtr     geo2;
        NodeUnrecPtr         newNode = Node::create();
        MergeGroup::iterator mgIt    = mlIt->begin();
        MergeGroup::iterator mgEnd   = mlIt->end  ();
        
        geo1 = dynamic_cast<Geometry *>((*mgIt)->getCore());

        // remove the first geo as well
        subStore.push_back(*mgIt);

        ++mgIt;
        
        for(UInt32 i = 0; mgIt != mgEnd; ++mgIt, ++i)
        {
            geo2 = dynamic_cast<Geometry *>((*mgIt)->getCore());
            
            if(i > _mergeThreshold && (mgIt + 1) != mgEnd)
            {
                newNode->setCore(geo1);
                addStore.push_back(newNode);
                
                i       = 0;
                newNode = Node::create();
                geo1    = dynamic_cast<Geometry *>((*mgIt)->getCore());
                ++mgIt;
            }
            
            geo1 = mergeGeo(geo1, geo2);
            geo1->setMaterial(geo2->getMaterial());
            
            subStore.push_back(*mgIt);
        }
        
       newNode->setCore(geo1);
       addStore.push_back(newNode);
    }
    
    // add newly created geometries to current node
    NodeStore::const_iterator storeIt  = subStore.begin();
    NodeStore::const_iterator storeEnd = subStore.end  ();
    
    for(; storeIt != storeEnd; ++storeIt)
       node->subChild(*storeIt);
    
    storeIt  = addStore.begin();
    storeEnd = addStore.end  ();
    
    for(; storeIt != storeEnd; ++storeIt)
       node->addChild(*storeIt);
    
    return Action::Continue;
}
コード例 #19
0
void OSGLoader::beginNode(const Char8 *szNodeTypename,
                          const Char8 *szNodename)
{
    FieldContainerUnrecPtr pNewNode;

    if(szNodeTypename == NULL)
        return;

    PINFO << "Begin node : " << szNodeTypename << " | ";

    if(szNodename == NULL)
    {
        PINFO << "NULL";
    }
    else
    {
        PINFO << szNodename;
    }

    PINFO << std::endl;

    pNewNode =
        FieldContainerFactory::the()->createContainer(szNodeTypename);

    
    if(pNewNode == NULL)
    {
        PWARNING << "Unknow container type " << szNodeTypename << std::endl;
    }
    
    PINFO << "  Got ptr " << pNewNode << std::endl;

    if(szNodename != NULL && pNewNode != NULL)
    {
        AttachmentContainer *pAttCon =
            dynamic_cast<AttachmentContainer *>(pNewNode.get());

        if(pAttCon != NULL)
        {
            setName(pAttCon, szNodename);
        }

        _defMap.insert(std::make_pair(std::string(szNodename), pNewNode));
    }

    // assign nodepointer to current sf|mf field

    _pCurrentFC = pNewNode;

    _fcStack.push(_pCurrentFC);

    if(_fcStack.size() == 1)
    {
        if(_bReadContainer == false)
        {
            NodeUnrecPtr pNode = NULL;
            
            if(_pCurrentFC->getType().isNode())
            {
                pNode = dynamic_cast<Node *>(_pCurrentFC.get());
            }
            else if(_pCurrentFC->getType().isNodeCore())
            {
                pNode = Node::create();
                
                pNode->setCore(dynamic_cast<NodeCore *>(_pCurrentFC.get()));
            }
            else
            {
                SLOG << "Fieldcontainer " << szNodeTypename
                     << "is neither Node nor NodeCore " << std::endl;
            }
            
            if(_pRootNode == NULL)
            {
                GroupUnrecPtr pGroup = Group::create();
                
                _pRootNode = Node::create();
                
                _pRootNode->setCore(pGroup);
            }
            
            _pRootNode->addChild(pNode);
        }
        else
        {
            _pRootContainer = pNewNode;
        }
    }

    _sChangedStack.push(_bvChanged);

    _bvChanged = 0;
}
コード例 #20
0
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
    OSG::preloadSharedObject("OSGFileIO");
    OSG::preloadSharedObject("OSGImageFileIO");
    // OSG init
    osgInit(argc,argv);
    {
        // Set up Window
        WindowEventProducerRecPtr TutorialWindow = createNativeWindow();

        //Initialize Window
        TutorialWindow->initWindow();

        SimpleSceneManager sceneManager;
        TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
        TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));

        // Tell the Manager what to manage
        sceneManager.setWindow(TutorialWindow);

        //Attach to events
        TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager));
        TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager));
        TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
        TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));
        TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, TutorialWindow.get()));

        //Box Geometry
        GeometryUnrecPtr BoxGeometry = makeBoxGeo(1.0,1.0,1.0,1,1,1);
        ChunkMaterialUnrecPtr TheBoxMaterial = ChunkMaterial::create();
        BoxGeometry->setMaterial(TheBoxMaterial);

        NodeUnrecPtr BoxGeometryNode = Node::create();
        BoxGeometryNode->setCore(BoxGeometry);

        //Make Box Node
        NodeUnrecPtr BoxNode = Node::create();
        TransformUnrecPtr BoxNodeTrans;
        BoxNodeTrans = Transform::create();

        BoxNode->setCore(BoxNodeTrans);
        BoxNode->addChild(BoxGeometryNode);

        //Make Main Scene Node
        NodeUnrecPtr scene = Node::create();
        ComponentTransformUnrecPtr Trans;
        Trans = ComponentTransform::create();
        scene->setCore(Trans);

        // add the torus as a child
        scene->addChild(BoxNode);

        //Setup the Animation
        AnimationUnrecPtr TheAnimation = setupAnimation(TheBoxMaterial);
        TheAnimation->attachUpdateProducer(TutorialWindow);
        TheAnimation->start();

        // tell the manager what to manage
        sceneManager.setRoot  (scene);

        //Create the Documentation
        SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow);

        // show the whole scene
        sceneManager.showAll();

        //Open Window
        Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
        Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);

        TutorialWindow->openWindow(WinPos,
                                   WinSize,
                                   "09TextureSelectAnimation");

        //Main Loop
        TutorialWindow->mainLoop();
    }

    osgExit();

    return 0;
}
コード例 #21
0
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindow = createNativeWindow();
    TutorialWindow->initWindow();

    TutorialWindow->setDisplayCallback(display);
    TutorialWindow->setReshapeCallback(reshape);

    //Add Window Listener
    TutorialKeyListener TheKeyListener;
    TutorialWindow->addKeyListener(&TheKeyListener);
    TutorialMouseListener TheTutorialMouseListener;
    TutorialMouseMotionListener TheTutorialMouseMotionListener;
    TutorialWindow->addMouseListener(&TheTutorialMouseListener);
    TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(TutorialWindow);
	
    //Torus Node
    NodeUnrecPtr TorusGeometryNode = makeTorus(.5, 2, 32, 32);

    //Make Torus Node
    NodeUnrecPtr TorusNode = Node::create();
    TransformUnrecPtr TorusNodeTrans;
    TorusNodeTrans = Transform::create();

    TorusNode->setCore(TorusNodeTrans);
    TorusNode->addChild(TorusGeometryNode);

    //Make Main Scene Node
    NodeUnrecPtr scene = Node::create();
    ComponentTransformUnrecPtr Trans;
    Trans = ComponentTransform::create();
    scene->setCore(Trans);

    // add the torus as a child
    scene->addChild(TorusNode);

    //Make a gradient Background
    TutorialBackground = GradientBackground::create();
    TutorialBackground->addLine(Color3f(1.0,0.0,0.0),0.0);
    TutorialBackground->addLine(Color3f(0.0,1.0,0.0),0.5);
    TutorialBackground->addLine(Color3f(0.0,0.0,1.0),1.0);
    setName(TutorialBackground, std::string("TutorialGradientBackground"));

    setupAnimation();

    // tell the manager what to manage
    mgr->setRoot  (scene);
    mgr->getWindow()->getPort(0)->setBackground(TutorialBackground);

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

    //Open Window
    Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
    TutorialWindow->openWindow(WinPos,
                               WinSize,
                               "03MFieldAnimation");

    //Main Loop
    TutorialWindow->mainLoop();

    osgExit();

    return 0;
}
コード例 #22
0
// Initialize GLUT & OpenSG and set up the rootNode
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindow = createNativeWindow();
    TutorialWindow->initWindow();

    TutorialWindow->setDisplayCallback(display);
    TutorialWindow->setReshapeCallback(reshape);

    TutorialKeyListener TheKeyListener;
    TutorialWindow->addKeyListener(&TheKeyListener);
    TutorialMouseListener TheTutorialMouseListener;
    TutorialMouseMotionListener TheTutorialMouseMotionListener;
    TutorialWindow->addMouseListener(&TheTutorialMouseListener);
    TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);
	TutorialUpdateListener TheTutorialUpdateListener;
    TutorialWindow->addUpdateListener(&TheTutorialUpdateListener);


    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

	
    // Tell the Manager what to manage
    mgr->setWindow(TutorialWindow);

    //Make Main Scene Node
	NodeRefPtr scene = makeCoredNode<Group>();
    setName(scene, "scene");
    rootNode = Node::create();
    setName(rootNode, "rootNode");
    ComponentTransformRefPtr Trans;
    Trans = ComponentTransform::create();
    {
        rootNode->setCore(Trans);
 
        // add the torus as a child
        rootNode->addChild(scene);
    }

    //Make The Physics Characteristics Node
    PhysicsCharacteristicsDrawableUnrecPtr PhysDrawable = PhysicsCharacteristicsDrawable::create();
        PhysDrawable->setRoot(rootNode);

	PhysDrawableNode = Node::create();
    PhysDrawableNode->setCore(PhysDrawable);
    PhysDrawableNode->setTravMask(TypeTraits<UInt32>::getMin());

    rootNode->addChild(PhysDrawableNode);

    //Light Beacon
    NodeRefPtr TutorialLightBeacon = makeCoredNode<Transform>();

    //Light Node
    DirectionalLightRefPtr TutorialLight = DirectionalLight::create();
    TutorialLight->setDirection(0.0,0.0,-1.0);
    TutorialLight->setBeacon(TutorialLightBeacon);

    NodeRefPtr TutorialLightNode = Node::create();
    TutorialLightNode->setCore(TutorialLight);

    scene->addChild(TutorialLightNode);
    scene->addChild(TutorialLightBeacon);


    //Setup Physics Scene
    physicsWorld = PhysicsWorld::create();
        physicsWorld->setWorldContactSurfaceLayer(0.01);
        physicsWorld->setAutoDisableFlag(1);
        physicsWorld->setAutoDisableTime(0.75);
        physicsWorld->setWorldContactMaxCorrectingVel(1.0);
        //physicsWorld->setGravity(Vec3f(0.0, 0.0, -9.81));
        //physicsWorld->setCfm(0.001);
        //physicsWorld->setErp(0.2);

    hashSpace = PhysicsHashSpace::create();

    physHandler = PhysicsHandler::create();
        physHandler->setWorld(physicsWorld);
        physHandler->pushToSpaces(hashSpace);
        physHandler->setUpdateNode(rootNode);
    physHandler->attachUpdateProducer(TutorialWindow->editEventProducer());
    

        rootNode->addAttachment(physHandler);    
        rootNode->addAttachment(physicsWorld);
        rootNode->addAttachment(hashSpace);


	/************************************************************************/
	/* create spaces, geoms and bodys                                                                     */
	/************************************************************************/
    //create a group for our space
    GroupRefPtr spaceGroup;
	spaceGroupNode = makeCoredNode<Group>(&spaceGroup);
	//add Attachments to nodes...
	    spaceGroupNode->addAttachment(hashSpace);

	    TutorialLightNode->addChild(spaceGroupNode);

    //Create Character
    ShipBody = buildShip(Vec3f(3.0,3.0,10.0), Pnt3f((Real32)(rand()%100)-50.0,(Real32)(rand()%100)-50.0,25.0));
    ShipMotor = buildMotor(ShipBody);

    for(UInt32 i(0) ; i<5 ; ++i)
    {
        buildBox(Vec3f(10.0,10.0,10.0), Pnt3f((Real32)(rand()%100)-50.0,(Real32)(rand()%100)-50.0,25.0));
    }

    // tell the manager what to manage
    mgr->setRoot  (rootNode);

    // show the whole rootNode
    mgr->showAll();
    
    Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
    TutorialWindow->openWindow(WinPos,
            WinSize,
            "04ZeroGravityShip");

    //Enter main Loop
    TutorialWindow->mainLoop();

    osgExit();

    return 0;
}
コード例 #23
0
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindow = createNativeWindow();
    TutorialWindow->initWindow();

    TutorialWindow->setDisplayCallback(display);
    TutorialWindow->setReshapeCallback(reshape);

    //Add Window Listener
    TutorialKeyListener TheKeyListener;
    TutorialWindow->addKeyListener(&TheKeyListener);
    TutorialMouseListener TheTutorialMouseListener;
    TutorialMouseMotionListener TheTutorialMouseMotionListener;
    TutorialWindow->addMouseListener(&TheTutorialMouseListener);
    TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(TutorialWindow);

    //Torus Material
    TheTorusMaterial = SimpleMaterial::create();
    dynamic_pointer_cast<SimpleMaterial>(TheTorusMaterial)->setAmbient(Color3f(0.3,0.3,0.3));
    dynamic_pointer_cast<SimpleMaterial>(TheTorusMaterial)->setDiffuse(Color3f(0.7,0.7,0.7));
    dynamic_pointer_cast<SimpleMaterial>(TheTorusMaterial)->setSpecular(Color3f(1.0,1.0,1.0));
    dynamic_pointer_cast<SimpleMaterial>(TheTorusMaterial)->setShininess(20.0);

    //Torus Geometry
    GeometryUnrecPtr TorusGeometry = makeTorusGeo(.5, 2, 32, 32);
    TorusGeometry->setMaterial(TheTorusMaterial);
    
    NodeUnrecPtr TorusGeometryNode = Node::create();
    TorusGeometryNode->setCore(TorusGeometry);

    //Make Torus Node
    NodeUnrecPtr TorusNode = Node::create();
    TorusNodeTrans = Transform::create();
    setName(TorusNodeTrans, std::string("TorusNodeTransformationCore"));

    TorusNode->setCore(TorusNodeTrans);
    TorusNode->addChild(TorusGeometryNode);

    //Make Main Scene Node
    NodeUnrecPtr scene = Node::create();
    ComponentTransformUnrecPtr Trans;
    Trans = ComponentTransform::create();
    setName(Trans, std::string("MainTransformationCore"));
    scene->setCore(Trans);

    // add the torus as a child
    scene->addChild(TorusNode);

    setupAnimation();

    // tell the manager what to manage
    mgr->setRoot  (scene);

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

    
    Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
    TutorialWindow->openWindow(WinPos,
            WinSize,
            "OpenSG 07AnimationGroup Window");

    //Enter main Loop
    TutorialWindow->mainLoop();

    osgExit();

    return 0;
}
コード例 #24
0
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindow = createNativeWindow();
    TutorialWindow->initWindow();

    TutorialWindow->setDisplayCallback(display);
    TutorialWindow->setReshapeCallback(reshape);

    //Add Window Listener
    TutorialKeyListener TheKeyListener;
    TutorialWindow->addKeyListener(&TheKeyListener);
    TutorialMouseListener TheTutorialMouseListener;
    TutorialMouseMotionListener TheTutorialMouseMotionListener;
    TutorialWindow->addMouseListener(&TheTutorialMouseListener);
    TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(TutorialWindow);


    //Print key command info
    std::cout << "\n\nKEY COMMANDS:" << std::endl;
    std::cout << "CTRL-Q  Exit\n\n" << std::endl;


    //SkeletonDrawer System Material
    LineChunkUnrecPtr ExampleLineChunk = LineChunk::create();
    ExampleLineChunk->setWidth(2.0f);
    ExampleLineChunk->setSmooth(true);

    BlendChunkUnrecPtr ExampleBlendChunk = BlendChunk::create();
    ExampleBlendChunk->setSrcFactor(GL_SRC_ALPHA);
    ExampleBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);

    MaterialChunkUnrecPtr ExampleMaterialChunk = MaterialChunk::create();
    ExampleMaterialChunk->setAmbient(Color4f(1.0f,1.0f,1.0f,1.0f));
    ExampleMaterialChunk->setDiffuse(Color4f(0.0f,0.0f,0.0f,1.0f));
    ExampleMaterialChunk->setSpecular(Color4f(0.0f,0.0f,0.0f,1.0f));

    ChunkMaterialUnrecPtr ExampleMaterial = ChunkMaterial::create();
    ExampleMaterial->addChunk(ExampleLineChunk);
    ExampleMaterial->addChunk(ExampleMaterialChunk);
    ExampleMaterial->addChunk(ExampleBlendChunk);

    //Joint Node Hierarchy
    NodeRecPtr ExampleJointNode;

    //Create a new skeleton
    SkeletonBlendedGeometryRecPtr ExampleSkeleton;

    //Load skeleton from an XML file
    FCFileType::FCPtrStore NewContainers;
    NewContainers = FCFileHandler::the()->read(BoostPath("./Data/14Skeleton.xml"));

    FCFileType::FCPtrStore::iterator Itor;
    for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor)
    {
        //We only want the skeleton; ignore anything else saved in the XML file
        if( (*Itor)->getType() == (SkeletonBlendedGeometry::getClassType()))
        {
            ExampleSkeleton = (dynamic_pointer_cast<SkeletonBlendedGeometry>(*Itor));
        }

        if( (*Itor)->getType() == (Node::getClassType()) && 
            (dynamic_pointer_cast<Node>(*Itor)->getParent() == NULL))
        {
            ExampleJointNode = (dynamic_pointer_cast<Node>(*Itor));
        }
    }



    //SkeletonDrawer
    SkeletonDrawableUnrecPtr ExampleSkeletonDrawable = SkeletonDrawable::create();
    ExampleSkeletonDrawable->setSkeleton(ExampleSkeleton);
    ExampleSkeletonDrawable->setMaterial(ExampleMaterial);

    //Skeleton Node 
    NodeUnrecPtr SkeletonNode = Node::create();
    SkeletonNode->setCore(ExampleSkeletonDrawable);


    // Make Main Scene Node and add the Torus
    NodeUnrecPtr scene = Node::create();
    scene->setCore(Group::create());
    scene->addChild(SkeletonNode);

    mgr->setRoot(scene);

    // Show the whole Scene
    mgr->showAll();


    //Open Window
    Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
    TutorialWindow->openWindow(WinPos,
            WinSize,
            "14SkeletonLoader");

    //Main Loop
    TutorialWindow->mainLoop();

    osgExit();

    return 0;
}
コード例 #25
0
// Initialize OpenSG and set up the scene
int main(int argc, char **argv)
{
	//Print key command info
	std::cout << "\n\nKEY COMMANDS:" << std::endl;
	std::cout << "space   Play/Pause the animation" << std::endl;
	std::cout << "CTRL-Q  Exit\n\n" << std::endl;

    // OSG init
    osgInit(argc,argv);


    // Set up Window
    TutorialWindow = createNativeWindow();
    TutorialWindow->initWindow();

    TutorialWindow->setDisplayCallback(display);
    TutorialWindow->setReshapeCallback(reshape);

    //Add Window Listener
    TutorialKeyListener TheKeyListener;
    TutorialWindow->addKeyListener(&TheKeyListener);
    TutorialMouseListener TheTutorialMouseListener;
    TutorialMouseMotionListener TheTutorialMouseMotionListener;
    TutorialWindow->addMouseListener(&TheTutorialMouseListener);
    TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(TutorialWindow);

    //Torus Geometry
    TorusGeometry = makeTorusGeo(.5, 2, 16, 16);
    
    NodeUnrecPtr TorusGeometryNode = Node::create();
    TorusGeometryNode->setCore(TorusGeometry);

    //Make Torus Node
    NodeUnrecPtr TorusNode = Node::create();
    TransformUnrecPtr TorusNodeTrans;
    TorusNodeTrans = Transform::create();
    setName(TorusNodeTrans, std::string("TorusNodeTransformationCore"));

    TorusNode->setCore(TorusNodeTrans);
    TorusNode->addChild(TorusGeometryNode);

    //Make Main Scene Node
    NodeUnrecPtr scene = Node::create();
    //ComponentTransformUnrecPtr Trans;
    //Trans = ComponentTransform::create();
    //setName(Trans, std::string("MainTransformationCore"));
    scene->setCore(Group::create());

    // add the torus as a child
    scene->addChild(TorusNode);


	setupAnimation();
    mgr->setRoot  (scene);

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


    Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
    TutorialWindow->openWindow(WinPos,
                        WinSize,
                                        "15LoadXMLAnimation");

    //Enter main Loop
    TutorialWindow->mainLoop();

    osgExit();


    return 0;
}