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 Manipulator::onCreate(const Manipulator* source)
{
    Inherited::onCreate(source);

    SimpleMaterialUnrecPtr pMat;

//    SimpleMaterial *simpleMat;
    Geometry       *geo;

    setExternalUpdateHandler(NULL);

    // add a name attachment
    NameUnrecPtr nameN = Name::create();
    nameN->editFieldPtr()->setValue("XManipulator");
    addAttachment(nameN);

    // make the axis lines
    NodeUnrecPtr pNode = makeCoordAxis(getLength()[0], 2.0, false);
    setAxisLinesN(pNode);

    // make the red x-axis transform and handle

    pNode = Node::create();
    setTransXNode(pNode);
    OSG::ComponentTransformUnrecPtr transHandleXC = ComponentTransform::create();

    pNode = makeHandleGeo();
    setHandleXNode(pNode);
    pMat = SimpleMaterial::create();
    setMaterialX  (pMat );

    getTransXNode()->setCore (transHandleXC   );
    getTransXNode()->addChild(getHandleXNode());

    transHandleXC->setTranslation(Vec3f(getLength()[0], 0, 0)                   );
    transHandleXC->setRotation   (Quaternion(Vec3f(0, 0, 1), osgDegree2Rad(-90)));

    pMat->setDiffuse(Color3f(1, 0, 0));
    pMat->setLit    (true            );

    geo = dynamic_cast<Geometry *>(getHandleXNode()->getCore());
    geo->setMaterial(pMat);

    //
    // make the green y-axis transform and handle

    pNode = Node::create();
    setTransYNode(pNode);
    OSG::ComponentTransformUnrecPtr transHandleYC = ComponentTransform::create();
    pNode = makeHandleGeo();
    setHandleYNode(pNode);
    pMat = SimpleMaterial::create();
    setMaterialY(pMat);

    getTransYNode()->setCore (transHandleYC   );
    getTransYNode()->addChild(getHandleYNode());

    transHandleYC->setTranslation(Vec3f(0, getLength()[1], 0)                    );
//    transHandleYC->setRotation   ( Quaternion(Vec3f(0, 0, 1), osgDegree2Rad(-90)));

    pMat->setDiffuse(Color3f(0, 1, 0));
    pMat->setLit    (true            );

    geo = dynamic_cast<Geometry *>(getHandleYNode()->getCore());
    geo->setMaterial(pMat);

    //
    // make the blue z-axis transform and handle

    pNode = Node::create();
    setTransZNode(pNode);
    OSG::ComponentTransformUnrecPtr transHandleZC = ComponentTransform::create();
    pNode = makeHandleGeo();
    setHandleZNode(pNode);
    pMat = SimpleMaterial::create();
    setMaterialZ  (pMat);

    getTransZNode()->setCore (transHandleZC   );
    getTransZNode()->addChild(getHandleZNode());

    transHandleZC->setTranslation(Vec3f(0, 0, getLength()[2])                  );
    transHandleZC->setRotation   (Quaternion(Vec3f(1, 0, 0), osgDegree2Rad(90)));

    pMat->setDiffuse(Color3f(0, 0, 1));
    pMat->setLit    (true            );

    geo = dynamic_cast<Geometry *>(getHandleZNode()->getCore());
    geo->setMaterial(pMat);

    //
    // make the yellow pivot transform and handle

    pNode = Node::create();
    setPivotNode(pNode);
    OSG::ComponentTransformUnrecPtr transHandlePivotC = ComponentTransform::create();
    pNode = makeSphere(2, 0.05f);
    setHandlePNode(pNode);
    pMat = SimpleMaterial::create();
    setMaterialPivot  (pMat);

    getPivotNode()->setCore (transHandlePivotC   );
    getPivotNode()->addChild(getHandlePNode());

    transHandlePivotC->setTranslation(Vec3f(0, 0, 0));

    pMat->setDiffuse(Color3f(1, 1, 0));
    pMat->setLit    (true            );

    geo = dynamic_cast<Geometry *>(getHandlePNode()->getCore());
    geo->setMaterial(pMat);

    if (!getEnablePivot())
    {
        getPivotNode()->setTravMask(0x0);
    }

    commitChanges();
}