void showAll(PerspectiveCameraRefPtr TheCamera, NodeRefPtr Scene, Vec3f Up)
{
    //Make sure the volume is up to date for the Scene
    Scene->updateVolume();

    //Get the Minimum and Maximum bounds of the volume
    Vec3f min,max;
    Scene->getVolume().getBounds( min, max );
    Vec3f d = max - min;

    if(d.length() < Eps) //The volume is 0
    {
        //Default to a 1x1x1 box volume
        min.setValues(-0.5f,-0.5f,-0.5f);
        max.setValues( 0.5f, 0.5f, 0.5f);
        d = max - min;
    }

    Real32 dist = osgMax(d[0],d[1]) / (2 * osgTan(TheCamera->getFov() / 2.f));

    Pnt3f at((min[0] + max[0]) * .5f,(min[1] + max[1]) * .5f,(min[2] + max[2]) * .5f);
    Pnt3f from=at;
    from[2]+=(dist+fabs(max[2]-min[2])*0.5f); 

    //If the Camera Beacon is a node with a transfrom core
    if(TheCamera->getBeacon() != NULL &&
       TheCamera->getBeacon()->getCore() != NULL &&
       TheCamera->getBeacon()->getCore()->getType().isDerivedFrom(Transform::getClassType()))
    {
        Matrix m;

        if(!MatrixLookAt(m, from, at, Up))
        {
            dynamic_cast<Transform*>(TheCamera->getBeacon()->getCore())->setMatrix(m);
        }
    }

    //Set the camera to go from 1% of the object to 10 times its size
    Real32 diag = osgMax(osgMax(d[0], d[1]), d[2]);
    TheCamera->setNear (diag / 100.f);
    TheCamera->setFar  (10 * diag);
}
void ApplicationStartScreen::attachApplication(void)
{
    Inherited::attachApplication();

    //Camera Transformation Node
    Matrix CameraTransformMatrix;
    CameraTransformMatrix.setTranslate(0.0f,0.0f, 5.0f);
    TransformRefPtr CameraBeaconTransform = Transform::create();
    CameraBeaconTransform->setMatrix(CameraTransformMatrix);

    NodeRefPtr CameraBeaconNode = Node::create();
    CameraBeaconNode->setCore(CameraBeaconTransform);

    // Make Torus Node (creates Torus in background of scene)
    NodeRefPtr TorusGeometryNode = NULL;
    //BoostPath TorusKnotFile(MainApplication::the()->getSettings()->getDataDirectory() / std::string("Models") / std::string("TorusKnot.osb"));
    //SLOG << "Loading Torus Knot from: " << TorusKnotFile.string() << std::endl;
    //if(boost::filesystem::exists(TorusKnotFile))
    //{
        //TorusGeometryNode = SceneFileHandler::the()->read(TorusKnotFile.native_file_string().c_str());
    //}
    //if(TorusGeometryNode == NULL)
    //{
        //SWARNING << "Could not load Torus Knot from: "
                 //<< TorusKnotFile.string() << " because this file doesn't exist."  << std::endl;
        TorusGeometryNode = makeTorus(.5, 2, 64, 64);
    //}

    //Scene Transformation
    TransformRefPtr SceneTransformCore = Transform::create();

    NodeRefPtr SceneTransformNode = Node::create();
    SceneTransformNode->setCore(SceneTransformCore);
    SceneTransformNode->addChild(TorusGeometryNode);

    //Light
    NodeRefPtr LightBeaconNode = Node::create();
    LightBeaconNode->setCore(Transform::create());

    DirectionalLightRefPtr SceneLightCore = DirectionalLight::create();
    SceneLightCore->setDirection(1.0,0.0,0.0);
    SceneLightCore->setBeacon(LightBeaconNode);

    NodeRefPtr SceneLightNode = Node::create();
    SceneLightNode->setCore(SceneLightCore);
    SceneLightNode->addChild(SceneTransformNode);


    // Make Main Scene Node and add the Torus
    NodeRefPtr DefaultRootNode = OSG::Node::create();
    DefaultRootNode->setCore(OSG::Group::create());
    DefaultRootNode->addChild(CameraBeaconNode);
    DefaultRootNode->addChild(SceneLightNode);
    DefaultRootNode->addChild(LightBeaconNode);

    //Camera
    PerspectiveCameraRefPtr DefaultCamera = PerspectiveCamera::create();
    DefaultCamera->setBeacon(CameraBeaconNode);
    DefaultCamera->setFov   (osgDegree2Rad(60.f));
    DefaultCamera->setNear  (0.1f);
    DefaultCamera->setFar   (10000.f);

    //Background
    GradientBackgroundRefPtr DefaultBackground = GradientBackground::create();
    DefaultBackground->addLine(Color3f(0.0f,0.0f,0.0f), 0.0f);
    DefaultBackground->addLine(Color3f(0.0f,0.0f,0.5f), 1.0f);

    //Animation
    //KeyFrames
    KeyframeTransformationSequenceRefPtr TransformationKeyframes = KeyframeTransformationSequenceMatrix4f::create();
    OSG::Matrix TempMat;

    TransformationKeyframes->addKeyframe(TempMat,0.0f);
    TempMat.setRotate(Quaternion(Vec3f(0.0f,1.0f,0.0f), 3.14159f*0.5));
    TransformationKeyframes->addKeyframe(TempMat,4.0f);
    TempMat.setRotate(Quaternion(Vec3f(0.0f,1.0f,0.0f), 3.14159f*1.0));
    TransformationKeyframes->addKeyframe(TempMat,8.0f);
    TempMat.setRotate(Quaternion(Vec3f(0.0f,1.0f,0.0f), 3.14159f*1.5));
    TransformationKeyframes->addKeyframe(TempMat,12.0f);
    TempMat.setRotate(Quaternion(Vec3f(0.0f,1.0f,0.0f), 0.0f));
    TransformationKeyframes->addKeyframe(TempMat,16.0f);

    //Animator
    KeyframeAnimatorRefPtr TorusAnimator = OSG::KeyframeAnimator::create();
    TorusAnimator->setKeyframeSequence(TransformationKeyframes);

    //Animation
    _TorusAnimation = FieldAnimation::create();
    _TorusAnimation->setAnimator(TorusAnimator);
    _TorusAnimation->setInterpolationType(Animator::LINEAR_INTERPOLATION);
    _TorusAnimation->setCycling(-1);
    _TorusAnimation->setAnimatedField(SceneTransformCore, std::string("matrix"));
    _TorusAnimation->attachUpdateProducer(MainApplication::the()->getMainWindow()->editEventProducer());
    _TorusAnimation->start();

    //Foreground
    //ImageForegroundRefPtr LogoForeground = ImageForeground::create();
    //BoostPath LogoPath(MainApplication::the()->getSettings()->getDataDirectory() / "Images/Logo.png");
    //ImageRefPtr LoadedImage = ImageFileHandler::the().read(LogoPath.string().c_str());

    //	LogoForeground->addImage( LoadedImage, Pnt2f( 0,0 ) );

    ForegroundRefPtr UserInterfaceForeground = createInterface();
    _TheUIDrawingSurface->setEventProducer(MainApplication::the()->getMainWindow());

    if(MainApplication::the()->getMainWindow() != NULL &&
       MainApplication::the()->getMainWindow()->getMFPort()->size() == 0)
    {
        ViewportRefPtr DefaultViewport = Viewport::create();
        DefaultViewport->setCamera                  (DefaultCamera);
        DefaultViewport->setRoot                    (DefaultRootNode);
        DefaultViewport->setSize                    (0.0f,0.0f, 1.0f,1.0f);
        DefaultViewport->setBackground              (DefaultBackground);
        DefaultViewport->addForeground              (UserInterfaceForeground);

        MainApplication::the()->getMainWindow()->addPort(DefaultViewport);
    }

    MainApplication::the()->getMainWindow()->addKeyListener(&_StartScreenKeyListener);
    MainApplication::the()->getMainWindow()->addUpdateListener(&_ScreenUpdateListener);

}