void ShaderShadowMapEngine::updateLightPassMaterial(SSMEngineData *data)
{
    if(data->getMFLightPassMaterials()->empty() == true)
    {
        MaterialChunkUnrecPtr newMatChunk = MaterialChunk::createLocal();
        newMatChunk->setLit          (false  );
        newMatChunk->setColorMaterial(GL_NONE);

        ColorMaskChunkUnrecPtr newCMaskChunk = ColorMaskChunk::create();
        newCMaskChunk->setMaskR(false);
        newCMaskChunk->setMaskG(false);
        newCMaskChunk->setMaskB(false);
        newCMaskChunk->setMaskA(false);

        PolygonChunkUnrecPtr newPolyChunk = PolygonChunk::createLocal();
        newPolyChunk->setOffsetFill  (true                   );
        newPolyChunk->setOffsetFactor(this->getOffsetFactor());
        newPolyChunk->setOffsetBias  (this->getOffsetBias  ());

        ChunkMaterialUnrecPtr newLightPassMat = ChunkMaterial::createLocal();
        newLightPassMat->addChunk(newMatChunk  );
        newLightPassMat->addChunk(newCMaskChunk);
        newLightPassMat->addChunk(newPolyChunk );

        data->editMFLightPassMaterials()->push_back(newLightPassMat);
    }
}
MaterialUnrecPtr Graphics3DExtrude::createDefaultMaterial(void)
{
	MaterialChunkUnrecPtr TheMaterialChunk = MaterialChunk::create();

		TheMaterialChunk->setAmbient(Color4f(0.4,0.4,0.4,1.0));
		TheMaterialChunk->setDiffuse(Color4f(0.8,0.8,0.8,1.0));
		TheMaterialChunk->setSpecular(Color4f(0.85,0.85,0.85,1.0));
		TheMaterialChunk->setEmission(Color4f(0.0,0.0,0.0,1.0));
		TheMaterialChunk->setShininess(50.0);
		TheMaterialChunk->setLit(true);
		TheMaterialChunk->setColorMaterial(true);
	
	ChunkMaterialUnrecPtr TheMaterial = ChunkMaterial::create();

    TheMaterial->addChunk(TheMaterialChunk);

	return TheMaterial;
}
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 );
    }
}
Ejemplo n.º 4
0
PostShaderStage::RenderPassData::RenderPassData(
    const std::string         &       szVertexProgram,
    const std::string         &       szFragmentProgram,
          bool                        isLastPass,
          UInt32                      uiIndex,
          Int32                       iPixelWidth,
          Int32                       iPixelHeight,
          PostShaderStageData *       pStageData,
    const Vec2f               &       vFBOSize,
          TextureObjChunk     * const pSceneColorTex,
          TextureObjChunk     * const pSceneDepthTex,
    const RenderPassVector    &       vPasses,
          FrameBufferObject   * const pSceneFBO) : 

    _pShader                (NULL      ),
    _pFBO                   (NULL      ),
    _pOutputTexture         (NULL      ),
    _bIsLassPass            (isLastPass),
    _uiIndex                (uiIndex   ),
    _vFBOSize               (vFBOSize  ),
    _vWidthRefs             (          ),
    _vHeightRefs            (          ),

    _bShaderHasSceneColorTex(false     ),
    _bShaderHasSceneDepthTex(false     ),
    _bShaderHasFBOWidth     (false     ),
    _bShaderHasFBOHeight    (false     ),
    _bShaderHasCameraNear   (false     ),
    _bShaderHasCameraFar    (false     )
{
    //If this pass is not the last
    if(!_bIsLassPass)
    {
        _pFBO = FrameBufferObject::createLocal();

        _pOutputTexture                  = TextureObjChunk::createLocal();
        TextureEnvChunkUnrecPtr pTexEnv  = TextureEnvChunk::createLocal();
        ImageUnrecPtr           pImg     = Image          ::createLocal();
        
        pImg->set(Image::OSG_RGB_PF, 
                  static_cast<Real32>(iPixelWidth)  * _vFBOSize.x() , 
                  static_cast<Real32>(iPixelHeight) * _vFBOSize.y(),
                  1,
                  1,
                  1,
                  0.0,
                  0,
                  Image::OSG_UINT8_IMAGEDATA,
                  false);
        
        _pOutputTexture   ->setImage         (pImg             ); 
        _pOutputTexture   ->setMinFilter     (GL_LINEAR        );
        _pOutputTexture   ->setMagFilter     (GL_LINEAR        );
        _pOutputTexture   ->setWrapS         (GL_CLAMP_TO_EDGE );
        _pOutputTexture   ->setWrapT         (GL_CLAMP_TO_EDGE );
        _pOutputTexture   ->setInternalFormat(GL_RGB           );

        pTexEnv->setEnvMode       (GL_REPLACE       );
        
        TextureBufferUnrecPtr pTexBuffer   = TextureBuffer::createLocal();
        
        pTexBuffer->setTexture(_pOutputTexture);
        
        _pFBO->setSize(static_cast<Real32>(iPixelWidth)  * _vFBOSize.x(),
                       static_cast<Real32>(iPixelHeight) * _vFBOSize.y());
        _pFBO->setColorAttachment(pTexBuffer, 0);
        _pFBO->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT);

        pStageData->pushToRenderTargets(_pFBO);

        OSG_ASSERT(pStageData->getMFRenderTargets()->size() == _uiIndex + 1);
    }
    else
    {
        _pFBO = pSceneFBO;
    }

    //Update the flags on what uniforms are present
    _bShaderHasSceneColorTex = 
        ((szFragmentProgram.find(
              PostShaderStage::ShaderSceneColorTexName) != std::string::npos) ||
         (szVertexProgram  .find(
              PostShaderStage::ShaderSceneColorTexName) != std::string::npos));

    _bShaderHasSceneDepthTex = 
        ((szFragmentProgram.find(
              PostShaderStage::ShaderSceneDepthTexName) != std::string::npos) ||
         (szVertexProgram  .find(
              PostShaderStage::ShaderSceneDepthTexName) != std::string::npos));

    _bShaderHasFBOWidth = 
        ((szFragmentProgram.find(
              PostShaderStage::ShaderFBOWidthName) != std::string::npos) ||
         (szVertexProgram  .find(
              PostShaderStage::ShaderFBOWidthName) != std::string::npos));

    _bShaderHasFBOHeight = 
        ((szFragmentProgram.find(
              PostShaderStage::ShaderFBOHeightName) != std::string::npos) ||
         (szVertexProgram  .find(
              PostShaderStage::ShaderFBOHeightName) != std::string::npos));

    _bShaderHasCameraNear = 
        ((szFragmentProgram.find(
              PostShaderStage::ShaderCameraNearName) != std::string::npos) ||
         (szVertexProgram  .find(
              PostShaderStage::ShaderCameraNearName) != std::string::npos));

    _bShaderHasCameraFar = 
        ((szFragmentProgram.find(
              PostShaderStage::ShaderCameraFarName) != std::string::npos) ||
         (szVertexProgram  .find(
              PostShaderStage::ShaderCameraFarName) != std::string::npos));

    //Create the material used by this pass
    ChunkMaterialUnrecPtr pPostShaderMat = ChunkMaterial::createLocal();

    UInt16 uiTextureId = 0;

    _pShader = SimpleSHLChunk::createLocal();

    TextureEnvChunkUnrecPtr pGenericTexEnv  = TextureEnvChunk::createLocal();

    pGenericTexEnv->setEnvMode(GL_REPLACE);

    //Scene Color Texture
    if(_bShaderHasSceneColorTex)
    {
         pPostShaderMat->addChunk(pSceneColorTex,  uiTextureId);
         pPostShaderMat->addChunk(pGenericTexEnv,  uiTextureId);

        _pShader->addUniformVariable(
            PostShaderStage::ShaderSceneColorTexName.c_str(), uiTextureId);

        ++uiTextureId;
    }
    //Scene Depth Texture
    if(_bShaderHasSceneDepthTex)
    {
         pPostShaderMat->addChunk(pSceneDepthTex, uiTextureId);
         pPostShaderMat->addChunk(pGenericTexEnv, uiTextureId);

        _pShader->addUniformVariable(
            PostShaderStage::ShaderSceneDepthTexName.c_str(), uiTextureId);

        ++uiTextureId;
    }

    _vHeightRefs.clear();
    _vWidthRefs .clear();

    //Preceding passes variables
    std::string szVariableName;

    RenderPassVector::const_iterator passIt = vPasses.begin();

    for(; passIt != vPasses.end(); ++passIt)
    {
        szVariableName = (*passIt)->getOutputTextureName();

        if((szFragmentProgram.find(szVariableName) != std::string::npos) ||
           (szVertexProgram  .find(szVariableName) != std::string::npos)  )
        {
             pPostShaderMat->addChunk((*passIt)->getOutputTexture(), 
                                      uiTextureId);

             pPostShaderMat->addChunk(pGenericTexEnv, uiTextureId);

            _pShader->addUniformVariable(szVariableName.c_str(), uiTextureId);

            ++uiTextureId;
        }

        szVariableName = (*passIt)->getWidthName();

        if((szFragmentProgram.find(szVariableName) != std::string::npos) ||
           (szVertexProgram  .find(szVariableName) != std::string::npos)  )
        {
            _pShader->addUniformVariable<Real32>(
                szVariableName.c_str(),
                (*passIt)->getOutputTexture()->getImage()->getWidth());

            _vWidthRefs.push_back((*passIt)->getIndex());
        }

        szVariableName = (*passIt)->getHeightName();

        if((szFragmentProgram.find(szVariableName) != std::string::npos) ||
           (szVertexProgram  .find(szVariableName) != std::string::npos)  )
        {
            _pShader->addUniformVariable<Real32>(
                szVariableName.c_str(),
                (*passIt)->getOutputTexture()->getImage()->getHeight());

            _vHeightRefs.push_back((*passIt)->getIndex());
        }
    }

    MaterialChunkUnrecPtr pMatChunk = MaterialChunk::createLocal();

    pMatChunk     ->setLit(false);
    pPostShaderMat->addChunk(pMatChunk);

    _pShader->setVertexProgram  (szVertexProgram);
    _pShader->setFragmentProgram(szFragmentProgram);
    
    //Add the uniform parameters
    _pShader->addUniformVariable(ShaderFBOWidthName  .c_str(), 0.0f);
    _pShader->addUniformVariable(ShaderFBOHeightName .c_str(), 0.0f);
    _pShader->addUniformVariable(ShaderCameraNearName.c_str(), 0.0f);
    _pShader->addUniformVariable(ShaderCameraFarName .c_str(), 1.0f);
    
    pPostShaderMat->addChunk(_pShader, 0);
    
    pStageData->pushToShaderMaterials(pPostShaderMat);

    OSG_ASSERT(pStageData->getMFShaderMaterials()->size() == _uiIndex + 1);
}
DepthPeelingStageDataTransitPtr
    DepthPeelingStage::setupStageData(Int32 iPixelWidth,
                                      Int32 iPixelHeight)
{
    DepthPeelingStageDataTransitPtr returnValue =
        DepthPeelingStageData::createLocal();

    if(returnValue == NULL)
        return returnValue;

    OSG::Thread::setCurrentLocalFlags();

    //Depth, Blend chunks and Background in Data?
    DepthChunkUnrecPtr pDepthOffChunk = DepthChunk::createLocal();
    pDepthOffChunk->setEnable(false);

    DepthChunkUnrecPtr pDepthOnChunk = DepthChunk::createLocal();
    pDepthOnChunk->setEnable(true);

    returnValue->setDepthChunk(pDepthOnChunk);

    ShaderProgramVariableChunkUnrecPtr pSPVChunk1 =
        ShaderProgramVariableChunk::createLocal();
    pSPVChunk1->addUniformVariable("uIsPeelPass", true);

    returnValue->setSpvIsPeelChunk(pSPVChunk1);

    ShaderProgramVariableChunkUnrecPtr pSPVChunk2 =
        ShaderProgramVariableChunk::createLocal();
    pSPVChunk2->addUniformVariable("uIsPeelPass", false);

    returnValue->setSpvIsInitialChunk(pSPVChunk2);

    BlendChunkUnrecPtr pBlendChunk = BlendChunk::createLocal();
    pBlendChunk->setSrcFactor(GL_DST_ALPHA);
    pBlendChunk->setDestFactor(GL_ONE);
    pBlendChunk->setAlphaSrcFactor(GL_ZERO);
    pBlendChunk->setAlphaDestFactor(GL_ONE_MINUS_SRC_ALPHA);
    pBlendChunk->setEquation(GL_FUNC_ADD);

    SolidBackgroundUnrecPtr pSolidBackground = SolidBackground::createLocal();
    pSolidBackground->setColor(Color3f(0.f, 0.f, 0.f));
    pSolidBackground->setAlpha(0.f);
    returnValue->setBackground(pSolidBackground);

    SimpleSHLChunkUnrecPtr pQuadShader = SimpleSHLChunk::createLocal();
    pQuadShader->setFragmentProgram(std::string(blendFS));
    pQuadShader->addUniformVariable("uSampler", 0);

    //2 FBOs (Ping-Pong)
    FrameBufferObjectUnrecPtr pPeelFBOs[2];
    TextureBufferUnrecPtr pPeelColorTexBuffers[2];
    TextureBufferUnrecPtr pPeelDepthTexBuffers[2];

    TextureObjChunkUnrecPtr pColorTexs[2];
    ImageUnrecPtr           pColorImgs[2];

    TextureObjChunkUnrecPtr pDepthTexs[2];
    ImageUnrecPtr           pDepthImgs[2];

    for (int i=0; i<2; ++i)
    {
        //Color textures
        pColorTexs[i]     = TextureObjChunk::createLocal();
        pColorImgs[i]     = Image          ::createLocal();

        pColorImgs[i]->set(Image::OSG_RGBA_PF,
                  iPixelWidth,
                  iPixelHeight,
                  1,
                  1,
                  1,
                  0.0,
                  0,
                  Image::OSG_FLOAT32_IMAGEDATA,
                  false);

        pColorTexs[i]   ->setImage         (pColorImgs[i]   );
        pColorTexs[i]   ->setMinFilter     (GL_NEAREST       );
        pColorTexs[i]   ->setMagFilter     (GL_NEAREST       );
        pColorTexs[i]   ->setWrapS         (GL_CLAMP_TO_EDGE );
        pColorTexs[i]   ->setWrapT         (GL_CLAMP_TO_EDGE );
        pColorTexs[i]   ->setInternalFormat(GL_RGBA8);

        pPeelColorTexBuffers[i]   = TextureBuffer::createLocal();
        pPeelColorTexBuffers[i]->setTexture(pColorTexs[i]);

        //Depth textures
        pDepthTexs[i]      = TextureObjChunk::createLocal();
        pDepthImgs[i]      = Image          ::createLocal();

        pDepthImgs[i]->set(Image::OSG_DEPTH_PF,
                  iPixelWidth,
                  iPixelHeight,
                  1,
                  1,
                  1,
                  0.0,
                  0,
                  Image::OSG_FLOAT32_IMAGEDATA,
                  false);

        pDepthTexs[i]   ->setImage         (pDepthImgs[i]   );
        pDepthTexs[i]   ->setMinFilter     (GL_NEAREST       );
        pDepthTexs[i]   ->setMagFilter     (GL_NEAREST       );
        pDepthTexs[i]   ->setWrapS         (GL_CLAMP_TO_EDGE );
        pDepthTexs[i]   ->setWrapT         (GL_CLAMP_TO_EDGE );
        pDepthTexs[i]   ->setInternalFormat(GL_DEPTH_COMPONENT32F);
        pDepthTexs[i]   ->setExternalFormat(GL_DEPTH_COMPONENT);

        pPeelDepthTexBuffers[i] = TextureBuffer::createLocal();
        pPeelDepthTexBuffers[i]->setTexture(pDepthTexs[i]);

        pPeelFBOs[i] = FrameBufferObject::createLocal();

        pPeelFBOs[i]->setSize(iPixelWidth, iPixelHeight);
        pPeelFBOs[i]->setColorAttachment(pPeelColorTexBuffers[i], 0);
        pPeelFBOs[i]->setDepthAttachment(pPeelDepthTexBuffers[i]);
        pPeelFBOs[i]->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT);

        //Peel material for Quad (!)
        ChunkMaterialUnrecPtr pPeelMat  = ChunkMaterial  ::createLocal();
        pPeelMat->addChunk(pQuadShader, 0);
        pPeelMat->addChunk(pColorTexs[i],     0);
        pPeelMat->addChunk(pDepthOffChunk);
        pPeelMat->addChunk(pBlendChunk);

        if (i == 0)
        {
            returnValue->setPeelPingFBO(pPeelFBOs[i]);
            returnValue->setPeelPingMaterial(pPeelMat);
        }
        else
        {
            returnValue->setPeelPongFBO(pPeelFBOs[i]);
            returnValue->setPeelPongMaterial(pPeelMat);
        }
    }

    // The final color blend target
    FrameBufferObjectUnrecPtr pBlendFBO      = FrameBufferObject::createLocal();

    //Color texture
    TextureObjChunkUnrecPtr   pBlendColorTex = TextureObjChunk::createLocal();
    ImageUnrecPtr             pBlendColorImg = Image          ::createLocal();

    pBlendColorImg->set(Image::OSG_RGBA_PF,
              iPixelWidth,
              iPixelHeight,
              1,
              1,
              1,
              0.0,
              0,
              Image::OSG_FLOAT32_IMAGEDATA,
              false);

    pBlendColorTex->setImage         (pBlendColorImg   );
    pBlendColorTex->setMinFilter     (GL_NEAREST       );
    pBlendColorTex->setMagFilter     (GL_NEAREST       );
    pBlendColorTex->setWrapS         (GL_CLAMP_TO_EDGE );
    pBlendColorTex->setWrapT         (GL_CLAMP_TO_EDGE );
    pBlendColorTex->setInternalFormat(GL_RGBA8);

    TextureBufferUnrecPtr pBlendColorTexBuffer   = TextureBuffer::createLocal();
    pBlendColorTexBuffer->setTexture(pBlendColorTex);

    TextureBufferUnrecPtr pBlendDepthTexBuffer   = TextureBuffer::createLocal();
    pBlendDepthTexBuffer->setTexture(pDepthTexs[0]);

    pBlendFBO->setSize(iPixelWidth, iPixelHeight);
    pBlendFBO->setColorAttachment(pBlendColorTexBuffer, 0);
    pBlendFBO->setDepthAttachment(pBlendDepthTexBuffer);

    pBlendFBO->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT);

    returnValue->setBlendFBO(pBlendFBO);

    // Blend Final Material
    ChunkMaterialUnrecPtr pBlendFinalMat = ChunkMaterial::createLocal();

    pBlendFinalMat->addChunk(pDepthOffChunk);
    pBlendFinalMat->addChunk(pBlendColorTex,     0);

    SimpleSHLChunkUnrecPtr pBlendFinalShader = SimpleSHLChunk::createLocal();
    pBlendFinalShader->setFragmentProgram(std::string(blendFinalFS));
    pBlendFinalShader->addUniformVariable("uSampler", 0);

    pBlendFinalMat->addChunk(pBlendFinalShader, 0);
    returnValue->setBlendFinalMaterial(pBlendFinalMat);

    OSG::Thread::resetCurrentLocalFlags();

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

    return returnValue;
}
Ejemplo n.º 6
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;
}
Ejemplo n.º 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);


    //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;
}
void TrapezoidalShadowMapEngine::updateLightPassMaterial(
    TSMEngineData *data, UInt16 faceIdx, const Matrixr &matNT)
{
    if(data->getMFLightPassMaterials()->size() < 6)
        data->editMFLightPassMaterials()->resize(6, NULL);

    ChunkMaterial *lightPassMat = data->getLightPassMaterials(faceIdx);

    if(lightPassMat == NULL)
    {
        ColorMaskChunkUnrecPtr newCMaskChunk = ColorMaskChunk::create();
        newCMaskChunk->setMaskR(false);
        newCMaskChunk->setMaskG(false);
        newCMaskChunk->setMaskB(false);
        newCMaskChunk->setMaskA(false);

#ifdef OSG_TSME_LIGHTPASS_EXACT

        ShaderProgramUnrecPtr newLightPassVP = ShaderProgram::createLocal();
        newLightPassVP->setShaderType(GL_VERTEX_SHADER);
        newLightPassVP->setProgram   (_lightPassVPCode);
        newLightPassVP->addUniformVariable("TSME_matNT", matNT);

        ShaderProgramUnrecPtr newLightPassFP = ShaderProgram::createLocal();
        newLightPassFP->setShaderType(GL_FRAGMENT_SHADER);
        newLightPassFP->setProgram   (_lightPassFPCode  );
        newLightPassFP->addUniformVariable("TSME_offsetFactor", getOffsetFactor());
        newLightPassFP->addUniformVariable("TSME_offsetBias",   getOffsetBias  ());

        ShaderProgramChunkUnrecPtr newLightPassSHChunk =
            ShaderProgramChunk::createLocal();
        newLightPassSHChunk->addVertexShader  (newLightPassVP);
        newLightPassSHChunk->addFragmentShader(newLightPassFP);

        ChunkMaterialUnrecPtr  newLightPassMat = ChunkMaterial::createLocal();
        newLightPassMat->addChunk(newCMaskChunk      );
        newLightPassMat->addChunk(newLightPassSHChunk);

        lightPassMat = newLightPassMat;
        data->editMFLightPassMaterials()->replace(faceIdx, newLightPassMat);

#else
        
        PolygonChunkUnrecPtr newPolyChunk = PolygonChunk::createLocal();
        newPolyChunk->setOffsetFill  (true             );
        newPolyChunk->setOffsetFactor(getOffsetFactor());
        newPolyChunk->setOffsetBias  (getOffsetBias  ());

        ShaderProgramUnrecPtr newLightPassVP = ShaderProgram::createLocal();
        newLightPassVP->setShaderType     (GL_VERTEX_SHADER   );
        newLightPassVP->setProgram        (_lightPassVPCode   );
        newLightPassVP->addUniformVariable("TSME_matNT", matNT);

        ShaderProgramChunkUnrecPtr newLightPassSHChunk =
            ShaderProgramChunk::createLocal();
        newLightPassSHChunk->addVertexShader(newLightPassVP);

        ChunkMaterialUnrecPtr  newLightPassMat = ChunkMaterial::createLocal();
        newLightPassMat->addChunk(newCMaskChunk      );
        newLightPassMat->addChunk(newPolyChunk       );
        newLightPassMat->addChunk(newLightPassSHChunk);

        lightPassMat = newLightPassMat;
        (*data->editMFLightPassMaterials())[faceIdx] = newLightPassMat;

#endif

        
    }
    else
    {
        ShaderProgramChunk *lightPassSHChunk =
            dynamic_cast<ShaderProgramChunk *>(
                lightPassMat->find(ShaderProgramChunk::getClassType()));
    
        if(lightPassSHChunk != NULL)
        {
            ShaderProgram *lightPassVP = lightPassSHChunk->getVertexShader(0);
            lightPassVP->updateUniformVariable("TSME_matNT", matNT);
        }
    }
}
Ejemplo n.º 9
0
HDRStageDataTransitPtr HDRStage::setupStageData(Int32 iPixelWidth,
                                                Int32 iPixelHeight)
{
    HDRStageDataTransitPtr returnValue = HDRStageData::createLocal();

    if(returnValue == NULL)
        return returnValue;

    OSG::Thread::setCurrentLocalFlags();

    // Scene Target

    FrameBufferObjectUnrecPtr pSceneFBO    = FrameBufferObject::createLocal();

    RenderBufferUnrecPtr      pDepthBuffer = RenderBuffer     ::createLocal();

    pDepthBuffer->setInternalFormat(GL_DEPTH_COMPONENT24   );

        
    TextureObjChunkUnrecPtr pSceneTex     = TextureObjChunk::createLocal();
    TextureEnvChunkUnrecPtr pSceneTexEnv  = TextureEnvChunk::createLocal();
    ImageUnrecPtr           pImg          = Image          ::createLocal();
    
    pImg->set(Image::OSG_RGB_PF, 
              iPixelWidth, 
              iPixelHeight,
              1,
              1,
              1,
              0.0,
              0,
              Image::OSG_FLOAT32_IMAGEDATA,
              false);
    
    pSceneTex   ->setImage         (pImg             ); 
    pSceneTex   ->setMinFilter     (GL_LINEAR        );
    pSceneTex   ->setMagFilter     (GL_LINEAR        );
    pSceneTex   ->setWrapS         (GL_CLAMP_TO_EDGE );
    pSceneTex   ->setWrapT         (GL_CLAMP_TO_EDGE );
    pSceneTex   ->setInternalFormat(getBufferFormat());

    pSceneTexEnv->setEnvMode       (GL_REPLACE       );
    
    TextureBufferUnrecPtr pSceneTexBuffer   = TextureBuffer::createLocal();
    
    pSceneTexBuffer->setTexture(pSceneTex);
    

    
    pSceneFBO->setSize(iPixelWidth, iPixelHeight);
    
    pSceneFBO->setColorAttachment(pSceneTexBuffer, 0);
    pSceneFBO->setDepthAttachment(pDepthBuffer      );
    
    pSceneFBO->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT);
    
    setRenderTarget(pSceneFBO);
    



    // Shrink Target (w/2, h/2)

    FrameBufferObjectUnrecPtr pShrinkFBO     = FrameBufferObject::createLocal();

    TextureObjChunkUnrecPtr   pShrinkTex     = TextureObjChunk::createLocal();
    TextureEnvChunkUnrecPtr   pShrinkTexEnv  = TextureEnvChunk::createLocal();
                              pImg           = Image          ::createLocal();
    
    pImg->set(Image::OSG_RGB_PF, 
              iPixelWidth  / 2, 
              iPixelHeight / 2,
              1,
              1,
              1,
              0.0,
              0,
              Image::OSG_FLOAT32_IMAGEDATA,
              false);
    
    pShrinkTex   ->setImage         (pImg             ); 
    pShrinkTex   ->setMinFilter     (GL_LINEAR        );
    pShrinkTex   ->setMagFilter     (GL_LINEAR        );
    pShrinkTex   ->setWrapS         (GL_CLAMP_TO_EDGE );
    pShrinkTex   ->setWrapT         (GL_CLAMP_TO_EDGE );
    pShrinkTex   ->setInternalFormat(getBufferFormat());

    pShrinkTexEnv->setEnvMode       (GL_REPLACE       );
    
    TextureBufferUnrecPtr pShrinkTexBuffer   = TextureBuffer::createLocal();
    
    pShrinkTexBuffer->setTexture(pShrinkTex);
    

    
    pShrinkFBO->setSize(iPixelWidth / 2, iPixelHeight / 2);
    
    pShrinkFBO->setColorAttachment(pShrinkTexBuffer, 0);
    
    pShrinkFBO->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT);
    
    returnValue->setShrinkRenderTarget(pShrinkFBO);





    // blur (w/4, h/4)


    FrameBufferObjectUnrecPtr pBlurFBO     = FrameBufferObject::createLocal();

    TextureObjChunkUnrecPtr   pBlurTex1    = TextureObjChunk  ::createLocal();
    TextureEnvChunkUnrecPtr   pBlurTex1Env = TextureEnvChunk  ::createLocal();
    
    
    pImg = Image::createLocal();
    
    pImg->set(Image::OSG_RGB_PF, 
              iPixelWidth  / 4,
              iPixelHeight / 4,
              1,
              1,
              1,
              0.0,
              0,
              Image::OSG_FLOAT32_IMAGEDATA,
              false);
    
    pBlurTex1   ->setImage         (pImg             ); 
    pBlurTex1   ->setMinFilter     (GL_LINEAR        );
    pBlurTex1   ->setMagFilter     (GL_LINEAR        );
    pBlurTex1   ->setWrapS         (GL_CLAMP_TO_EDGE );
    pBlurTex1   ->setWrapT         (GL_CLAMP_TO_EDGE );
    pBlurTex1   ->setInternalFormat(getBufferFormat());

    pBlurTex1Env->setEnvMode       (GL_REPLACE       );
    
    TextureBufferUnrecPtr pBlurTexBuffer1 = TextureBuffer::createLocal();
    
    pBlurTexBuffer1->setTexture(pBlurTex1);
    
    
    
    TextureObjChunkUnrecPtr pBlurTex2    = TextureObjChunk::createLocal();
    TextureEnvChunkUnrecPtr pBlurTex2Env = TextureEnvChunk::createLocal();
    
    
    pImg = Image::createLocal();

    pImg->set(Image::OSG_RGB_PF, 
              iPixelWidth  / 4,
              iPixelHeight / 4,
              1,
              1,
              1,
              0.0,
              0,
              Image::OSG_FLOAT32_IMAGEDATA,
              false);
    
    pBlurTex2   ->setImage         (pImg             ); 
    pBlurTex2   ->setMinFilter     (GL_LINEAR        );
    pBlurTex2   ->setMagFilter     (GL_LINEAR        );
    pBlurTex2   ->setWrapS         (GL_CLAMP_TO_EDGE );
    pBlurTex2   ->setWrapT         (GL_CLAMP_TO_EDGE );
    pBlurTex2   ->setInternalFormat(getBufferFormat());

    pBlurTex2Env->setEnvMode       (GL_REPLACE       );
    
    TextureBufferUnrecPtr pBlurTexBuffer2 = TextureBuffer::createLocal();

    pBlurTexBuffer2->setTexture(pBlurTex2);


    pBlurFBO->setSize(iPixelWidth  / 4,
                      iPixelHeight / 4);
    
    pBlurFBO->setColorAttachment(pBlurTexBuffer1,  0);
    pBlurFBO->setColorAttachment(pBlurTexBuffer2,  1);
    
    returnValue->setBlurRenderTarget(pBlurFBO);


    // general mat chunk


    MaterialChunkUnrecPtr pMatChunk = MaterialChunk::createLocal();
        
    pMatChunk->setLit(false);




    // tone map material

    ChunkMaterialUnrecPtr    pTonemapMat  = ChunkMaterial  ::createLocal();
    
    pTonemapMat->addChunk(pMatChunk         );
    pTonemapMat->addChunk(pSceneTex,       0);
    pTonemapMat->addChunk(pSceneTexEnv,    0);
    pTonemapMat->addChunk(pBlurTex1,       1);
    pTonemapMat->addChunk(pBlurTex1Env,    1);

    SimpleSHLChunkUnrecPtr pTonemapShader = generateHDRFragmentProgram();
    
    pTonemapShader->addUniformVariable("sceneTex",     0);
    pTonemapShader->addUniformVariable("blurTex",      1);
    pTonemapShader->addUniformVariable("blurAmount",   getBlurAmount  ());
    pTonemapShader->addUniformVariable("exposure",     getExposure    ());
    pTonemapShader->addUniformVariable("effectAmount", getEffectAmount());
    pTonemapShader->addUniformVariable("gamma",        getGamma       ());
    
    pTonemapMat->addChunk(pTonemapShader, 0);
    
    returnValue->setToneMappingMaterial(pTonemapMat);




    // Shrink material

    ChunkMaterialUnrecPtr pShrinkMat = ChunkMaterial::createLocal();
    
    pShrinkMat->addChunk(pMatChunk   );
    
    pShrinkMat->addChunk(pSceneTex,     0);
    pShrinkMat->addChunk(pSceneTexEnv,  0);

    SimpleSHLChunkUnrecPtr pShrinkShader = generate2DShrinkHalfFilterFP();
        
    pShrinkShader->addUniformVariable("inputTex", 0);
    
    pShrinkMat->addChunk(pShrinkShader, 0);
    
    returnValue->setShrinkMaterial(pShrinkMat);




    // Blur material

    ChunkMaterialUnrecPtr pBlurMat = ChunkMaterial::createLocal();
    
    pBlurMat->addChunk(pMatChunk   );
    
    pBlurMat->addChunk(pShrinkTex,    0);
    pBlurMat->addChunk(pShrinkTexEnv, 0);
    pBlurMat->addChunk(pBlurTex1,     1);
    pBlurMat->addChunk(pBlurTex1Env,  1);
    pBlurMat->addChunk(pBlurTex2,     2);
    pBlurMat->addChunk(pBlurTex2Env,  2);

    pBlurMat->addChunk(pShrinkShader, 0);
    
    returnValue->setBlurMaterial(pBlurMat);


    // generate blur fragment programs
    SimpleSHLChunkUnrecPtr pHBlurShader = 
        generate1DConvolutionFilterFP(getBlurWidth(), 
                                      false, 
                                      true, 
                                      iPixelWidth  / 2, 
                                      iPixelHeight / 2);
    
   
    pHBlurShader->addUniformVariable("inputTex", 0);

    returnValue->setHBlurShader(pHBlurShader);

    
    
    // VBlur Override


    SimpleSHLChunkUnrecPtr pVBlurShader = 
        generate1DConvolutionFilterFP(getBlurWidth(),  
                                      true, 
                                      true, 
                                      iPixelWidth  / 2, 
                                      iPixelHeight / 2);
    
    pVBlurShader->addUniformVariable("inputTex", 1);
    
    returnValue->setVBlurShader(pVBlurShader);

    OSG::Thread::resetCurrentLocalFlags();

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

    return returnValue;
}
Ejemplo n.º 10
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;
}
Ejemplo n.º 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);

    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;
}
Ejemplo n.º 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 << "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;
}
DisplayFilterStageDataTransitPtr 
    DisplayFilterStage::setupStageData(Int32 iPixelWidth,
                                       Int32 iPixelHeight)
{
    DisplayFilterStageDataTransitPtr returnValue = 
        DisplayFilterStageData::createLocal();

    if(returnValue == NULL)
        return returnValue;

    // Scene Buffer

    FrameBufferObjectUnrecPtr pFBO     = FrameBufferObject::createLocal();
    RenderBufferUnrecPtr      pDBuffer = RenderBuffer     ::createLocal();
    TextureBufferUnrecPtr     pTBuffer = TextureBuffer    ::createLocal();

    TextureObjChunkUnrecPtr   pTex     = TextureObjChunk  ::createLocal();
    ImageUnrecPtr             pImg     = Image            ::createLocal();

    pImg->set(Image::OSG_RGB_PF, 
              iPixelWidth, 
              iPixelHeight,
              1,
              1,
              1,
              0.0,
              0,
              Image::OSG_UINT8_IMAGEDATA,
              false);
    
    pTex    ->setImage         (pImg             ); 
    pTex    ->setMinFilter     (GL_NEAREST       );
    pTex    ->setMagFilter     (GL_NEAREST       );
    pTex    ->setWrapS         (GL_CLAMP_TO_EDGE );
    pTex    ->setWrapT         (GL_CLAMP_TO_EDGE );
    
    pTBuffer->setTexture(pTex);

    pDBuffer->setInternalFormat(GL_DEPTH_COMPONENT24);
 

    pFBO->setSize(iPixelWidth, iPixelHeight);
    
    pFBO->setColorAttachment(pTBuffer, 0);
    pFBO->setDepthAttachment(pDBuffer   );

    pFBO->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT);


    pFBO->setEnableMultiSample  (this->getEnableMultiSample  ());
    pFBO->setColorSamples       (this->getColorSamples       ());
    pFBO->setCoverageSamples    (this->getCoverageSamples    ());
    pFBO->setFixedSampleLocation(this->getFixedSampleLocation());

    returnValue->setTarget(pFBO);


    ChunkMaterialUnrecPtr pCMat = ChunkMaterial::createLocal();

    pCMat->addChunk(pTex);

    returnValue->setBaseMaterial(pCMat);

    returnValue->setWidth (iPixelWidth );
    returnValue->setHeight(iPixelHeight);

    commitChanges();

    return returnValue;
}
Ejemplo n.º 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);

    //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;
}
Ejemplo n.º 15
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;
}
Ejemplo n.º 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(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;
}
Ejemplo n.º 17
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;
}
Ejemplo n.º 18
0
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));

        //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));

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

        VideoWrapperRecPtr TheVideo  = getDefaultVideoManager()->createVideoWrapper();
        TheVideo->attachUpdateProducer(TutorialWindow);

	    TheVideo->connectStarted(boost::bind(handleVideoStarted, _1));
	    TheVideo->connectPaused(boost::bind(handleVideoPaused, _1));
	    TheVideo->connectUnpaused(boost::bind(handleVideoUnpaused, _1));
	    TheVideo->connectStopped(boost::bind(handleVideoStopped, _1));
	    TheVideo->connectClosed(boost::bind(handleVideoClosed, _1));
	    TheVideo->connectSeeked(boost::bind(handleVideoSeeked, _1));
	    TheVideo->connectCycled(boost::bind(handleVideoCycled, _1));
	    TheVideo->connectOpened(boost::bind(handleVideoOpened, _1));
	    TheVideo->connectEnded(boost::bind(handleVideoEnded, _1));
        
        BoostPath VideoFilePath("./Data/ExampleVideo.avi");
        if(argc >= 2)
        {
            VideoFilePath = BoostPath(argv[1]);
            if(!boost::filesystem::exists(VideoFilePath))
            {
                std::cerr << "Could not load file: "<< VideoFilePath.string()
                          << ", because no such files exists."<< std::endl;
                VideoFilePath = BoostPath("./Data/ExampleVideo.avi");
            }
        }

        TheVideo->open(VideoFilePath, TutorialWindow);
	    TheVideo->pause();
        if(TheVideo->hasAudio())
        {
	        TheVideo->enableAudio();
	        TheVideo->setAudioVolume(0.5f);
        }

        //Wait for the video to initialize
        std::cout << "Dimensions: " << TheVideo->getWidth()
                  << "x"            << TheVideo->getHeight()
                  << std::endl;
        Real32 AspectRatio(static_cast<Real32>(TheVideo->getWidth())/static_cast<Real32>(TheVideo->getHeight()));
        //Real32 AspectRatio(4.0f/3.0f);

        // Set filtering modes. LINEAR is cheap and good if the image size
        // changes very little (i.e. the window is about the same size as 
        // the images).
        //TheVideo->setMinFilter(GL_LINEAR);
        TheVideo->setMinFilter(GL_NEAREST);
        TheVideo->setMagFilter(GL_LINEAR);
        //TheVideo->setMagFilter(GL_NEAREST);        
        
        // Set the wrapping modes. We don't need repetition, it might actually
        // introduce artifactes at the borders, so switch it off.
        TheVideo->setWrapS(GL_CLAMP_TO_EDGE);
        TheVideo->setWrapT(GL_CLAMP_TO_EDGE);   
        
        TheVideo->setScale(false);            

	    ChunkMaterialUnrecPtr VideoMaterial = ChunkMaterial::create();

	    VideoMaterial->addChunk(TheVideo);
        StateChunkUnrecPtr pMChunk = MaterialChunk::create();
	    VideoMaterial->addChunk(pMChunk);

        // create the scene
        //Plane Geometry
	    GeometryRecPtr PlaneGeometry = makePlaneGeo(10.0*AspectRatio,10.0,10,10);
        PlaneGeometry->setMaterial(VideoMaterial);
    	
        NodeRecPtr PlaneGeometryNode = Node::create();
        PlaneGeometryNode->setCore(PlaneGeometry);

        //Box Geometry
	    GeometryRecPtr BoxGeometry = makeBoxGeo(10.0*AspectRatio,10.0,10.0,2,2,2);
        BoxGeometry->setMaterial(VideoMaterial);
    	
        NodeRecPtr BoxGeometryNode = Node::create();
        BoxGeometryNode->setCore(BoxGeometry);

        //Sphere Geometry
	    GeometryRecPtr SphereGeometry = makeSphereGeo(2,5.0);
        SphereGeometry->setMaterial(VideoMaterial);
    	
        NodeRecPtr SphereGeometryNode = Node::create();
        SphereGeometryNode->setCore(SphereGeometry);
        

        //Torus Geometry
	    GeometryRecPtr TorusGeometry = makeTorusGeo(2.0,5.0,32,32);
        TorusGeometry->setMaterial(VideoMaterial);
    	
        NodeRecPtr TorusGeometryNode = Node::create();
        TorusGeometryNode->setCore(TorusGeometry);

        //Switch Node
        SwitchRecPtr GeometryNodeSwitch = Switch::create();
        GeometryNodeSwitch->setChoice(0);

        NodeRecPtr SwitchNode = Node::create();
        SwitchNode->setCore(GeometryNodeSwitch);
        SwitchNode->addChild(PlaneGeometryNode);
        SwitchNode->addChild(BoxGeometryNode);
        SwitchNode->addChild(SphereGeometryNode);
        SwitchNode->addChild(TorusGeometryNode);


        NodeRecPtr scene = Node::create();
        TransformRecPtr trans = Transform::create();
        scene->setCore(trans);
	    scene->addChild(SwitchNode);

        TutorialWindow->connectKeyTyped(boost::bind(handleKeyTyped, _1, TheVideo.get(), GeometryNodeSwitch.get()));
        sceneManager.setRoot(scene);

        // 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,
                                   "01PlayVideo");

        commitChanges();

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

    osgExit();

    return 0;
}