virtual void keyPressed(const KeyEventUnrecPtr e)
   {
       if(e->getKey() == KeyEvent::KEY_Q && e->getModifiers() & KeyEvent::KEY_MODIFIER_COMMAND)
       {
           TutorialWindow->closeWindow();
       }

       switch(e->getKey())
       {
       case KeyEvent::KEY_SPACE:
           TheAnimationGroup->pause(!TheAnimationGroup->isPaused());
           break;
       case KeyEvent::KEY_ENTER:
           TheAnimationGroup->attachUpdateProducer(TutorialWindow->editEventProducer());
           TheAnimationGroup->start();
           break;
       case KeyEvent::KEY_MINUS:
           TheAnimationGroup->setScale(osgMax(TheAnimationGroup->getScale()-0.1f, 0.0f));
           break;
       case KeyEvent::KEY_PLUS:
       case KeyEvent::KEY_EQUALS:
           TheAnimationGroup->setScale(osgMax(TheAnimationGroup->getScale()+0.1f, 0.0f));
           break;
       }
   }
   virtual void keyPressed(const KeyEventUnrecPtr e)
   {
       if(e->getKey() == KeyEvent::KEY_Q && e->getModifiers() & KeyEvent::KEY_MODIFIER_COMMAND)
       {
           TutorialWindow->closeWindow();
       }

       switch(e->getKey())
       {
       case KeyEvent::KEY_SPACE:
           TheAnimation->pause(!TheAnimation->isPaused());
           break;
       case KeyEvent::KEY_ENTER:
           TheAnimation->attachUpdateProducer(TutorialWindow->editEventProducer());
           TheAnimation->start();
           break;
       case KeyEvent::KEY_1:
                dynamic_pointer_cast<FieldAnimation>(TheAnimation)->setInterpolationType(Animator::STEP_INTERPOLATION);
           break;
       case KeyEvent::KEY_2:
                dynamic_pointer_cast<FieldAnimation>(TheAnimation)->setInterpolationType(Animator::LINEAR_INTERPOLATION);
           break;
       case KeyEvent::KEY_3:
                dynamic_pointer_cast<FieldAnimation>(TheAnimation)->setInterpolationType(Animator::CUBIC_INTERPOLATION);
           break;
       }
   }
void setupAnimation(void)
{
    //Color Keyframe Sequence
    KeyframeColorSequenceUnrecPtr ColorKeyframes = KeyframeColorSequenceColor3f::create();
    ColorKeyframes->addKeyframe(Color4f(1.0f,0.0f,0.0f,1.0f),0.0f);
    ColorKeyframes->addKeyframe(Color4f(0.0f,1.0f,0.0f,1.0f),2.0f);
    ColorKeyframes->addKeyframe(Color4f(0.0f,0.0f,1.0f,1.0f),4.0f);
    ColorKeyframes->addKeyframe(Color4f(1.0f,0.0f,0.0f,1.0f),6.0f);

    //Animator
    KeyframeAnimatorUnrecPtr TheAnimator = KeyframeAnimator::create();
    TheAnimator->setKeyframeSequence(ColorKeyframes);
    
    //Animation
    TheAnimation = FieldAnimation::create();
    TheAnimation->setAnimator(TheAnimator);
    TheAnimation->setInterpolationType(Animator::LINEAR_INTERPOLATION);
    TheAnimation->setCycling(-1);
	TheAnimation->setAnimatedMultiField(TutorialBackground, std::string("color"), 1);

    //Animation Listener
    TheAnimation->addAnimationListener(&TheAnimationListener);

    TheAnimation->attachUpdateProducer(TutorialWindow->editEventProducer());
    TheAnimation->start();
}
void setupAnimation(void)
{
	//Read animation data from XML file
	FCFileType::FCPtrStore NewContainers;
	NewContainers = FCFileHandler::the()->read(BoostPath("./Data/15TestAnimations.xml"));

	FCFileType::FCPtrStore::iterator Itor;
    for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor)
    {
		if( (*Itor)->getType().isDerivedFrom(Animation::getClassType()))
		{
			//Set the animation to the one we just read in
			TheAnimation = (dynamic_pointer_cast<Animation>(*Itor));
		}
		else if( (*Itor)->getType() == (SimpleMaterial::getClassType()))
		{
			//Set torus material
			TheTorusMaterial = (dynamic_pointer_cast<SimpleMaterial>(*Itor));
			
			//Attach torus material to torus geometry
				TorusGeometry->setMaterial(TheTorusMaterial);
		}
    }

    TheAnimation->attachUpdateProducer(TutorialWindow->editEventProducer());
    TheAnimation->start();
}
void initAnimations(FieldContainerUnrecPtr AnimatedObject, std::string AnimatedField)
{
	//Main Animation
	TheAnimation = createColorAnimation(AnimatedObject, AnimatedField);

    TheAnimation->attachUpdateProducer(TutorialWindow->editEventProducer());
    TheAnimation->start();
}
void setupAnimation(void)
{
    std::vector<BoostPath> _ImagePaths;
    _ImagePaths.push_back(BoostPath("./Data/Anim001.jpg"));
    _ImagePaths.push_back(BoostPath("./Data/Anim002.jpg"));
    _ImagePaths.push_back(BoostPath("./Data/Anim003.jpg"));
    _ImagePaths.push_back(BoostPath("./Data/Anim004.jpg"));
    _ImagePaths.push_back(BoostPath("./Data/Anim005.jpg"));

    //Make the textures
    for(UInt32 i(0) ; i<_ImagePaths.size(); ++i)
    {
        ImageUnrecPtr AnimFrameImage = ImageFileHandler::the()->read(_ImagePaths[i].string().c_str());
           
        _Images.push_back(AnimFrameImage);
    }
    
    TextureObjChunkUnrecPtr AnimFrameTexture = TextureObjChunk::create();
    AnimFrameTexture->setImage(_Images.front());

    //Box Material
    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(1.0,1.0,1.0,1.0));

    TheBoxMaterial = ChunkMaterial::create();
    TheBoxMaterial->addChunk(AnimFrameTexture);

    //Texture Keyframe Sequence
    KeyframeFCPtrSequenceUnrecPtr TextureKeyframes = KeyframeFCPtrSequenceImage::create();
    for(UInt32 i(0) ; i<_Images.size(); ++i)
    {
        TextureKeyframes->addKeyframe(_Images[i],static_cast<Real32>(i)*0.5f);
    }
    
    //Animator
    TutorialTextureAnimator = KeyframeAnimator::create();
    TutorialTextureAnimator->setKeyframeSequence(TextureKeyframes);
    
    //Animation
    TutorialTextureAnimation = FieldAnimation::create();
    TutorialTextureAnimation->setAnimator(TutorialTextureAnimator);
    TutorialTextureAnimation->setInterpolationType(Animator::STEP_INTERPOLATION);
    TutorialTextureAnimation->setCycling(-1);
    TutorialTextureAnimation->setAnimatedField(AnimFrameTexture,TextureObjChunk::ImageFieldId);

    //Animation Listener
    TutorialTextureAnimation->addAnimationListener(&TutorialTextureAnimationListener);

    TutorialTextureAnimation->attachUpdateProducer(TutorialWindow->editEventProducer());
    TutorialTextureAnimation->start();
}
void setupAnimation(void)
{
    //Number Keyframe Sequence
    KeyframeNumberSequenceReal32UnrecPtr XTransKeyframes = KeyframeNumberSequenceReal32::create();
    XTransKeyframes->addKeyframe(1.0,0.0f);
    XTransKeyframes->addKeyframe(5.0,2.0f);
    XTransKeyframes->addKeyframe(-5.0,4.0f);
    XTransKeyframes->addKeyframe(1.0,6.0f);
    
    KeyframeNumberSequenceReal32UnrecPtr YRotKeyframes = KeyframeNumberSequenceReal32::create();
    YRotKeyframes->addKeyframe(0.0,0.0f);
    YRotKeyframes->addKeyframe(45.0,2.0f);
    YRotKeyframes->addKeyframe(0.0,4.0f);

    KeyframeNumberSequenceReal32UnrecPtr ZScaleKeyframes = KeyframeNumberSequenceReal32::create();
    ZScaleKeyframes->addKeyframe(1.0,0.0f);
    ZScaleKeyframes->addKeyframe(2.0,2.0f);
    ZScaleKeyframes->addKeyframe(3.0,4.0f);
    ZScaleKeyframes->addKeyframe(1.0,6.0f);

    //Animator
    TransformAnimatorUnrecPtr TheAnimator = TransformAnimator::create();
    TheAnimator->setXTranslationSequence(XTransKeyframes);
    TheAnimator->setXRotationSequence(YRotKeyframes);
    TheAnimator->setYRotationSequence(YRotKeyframes);
    //TheAnimator->setZRotationSequence(YRotKeyframes);
    TheAnimator->setZScaleSequence(ZScaleKeyframes);
    
    //Animation
    TheAnimation = FieldAnimation::create();
    TheAnimation->setAnimator(TheAnimator);
    TheAnimation->setInterpolationType(Animator::LINEAR_INTERPOLATION);
    TheAnimation->setCycling(2);
    TheAnimation->setAnimatedField(TorusNodeTrans, std::string("matrix"));

    //Animation Listener
    TheAnimation->addAnimationListener(&TheAnimationListener);

    TheAnimation->attachUpdateProducer(TutorialWindow->editEventProducer());
    TheAnimation->start();
}
void setupAnimation(void)
{
    //Color Keyframe Sequence
    ColorKeyframes = KeyframeColorSequenceColor3f::create();
    ColorKeyframes->addKeyframe(Color4f(1.0f,0.0f,0.0f,1.0f),0.0f);
    ColorKeyframes->addKeyframe(Color4f(0.0f,1.0f,0.0f,1.0f),2.0f);
    ColorKeyframes->addKeyframe(Color4f(0.0f,0.0f,1.0f,1.0f),4.0f);
    ColorKeyframes->addKeyframe(Color4f(1.0f,0.0f,0.0f,1.0f),6.0f);
    
    //Color Animator
    KeyframeAnimatorUnrecPtr TheColorAnimator = KeyframeAnimator::create();
    TheColorAnimator->setKeyframeSequence(ColorKeyframes);
    
    //Color Animation
    FieldAnimationUnrecPtr TheColorAnimation = FieldAnimation::create();
    TheColorAnimation->setAnimator(TheColorAnimator);
    TheColorAnimation->setInterpolationType(Animator::LINEAR_INTERPOLATION);
    TheColorAnimation->setCycling(2);
    TheColorAnimation->setAnimatedField(TheTorusMaterial, std::string("diffuse"));

	//Vector Keyframe Sequence
    VectorKeyframes = KeyframeVectorSequenceVec3f::create();
    VectorKeyframes->addKeyframe(Vec3f(0.0f,0.0f,0.0f),0.0f);
    VectorKeyframes->addKeyframe(Vec3f(0.0f,1.0f,0.0f),1.0f);
    VectorKeyframes->addKeyframe(Vec3f(1.0f,1.0f,0.0f),2.0f);
    VectorKeyframes->addKeyframe(Vec3f(1.0f,0.0f,0.0f),3.0f);
    VectorKeyframes->addKeyframe(Vec3f(0.0f,0.0f,0.0f),4.0f);
    
    
    //Vector Animator
    KeyframeAnimatorUnrecPtr TheVectorAnimator = KeyframeAnimator::create();
    TheVectorAnimator->setKeyframeSequence(VectorKeyframes);
    
    //Vector Animation
    FieldAnimationUnrecPtr TheVectorAnimation = FieldAnimation::create();
    TheVectorAnimation->setAnimator(TheVectorAnimator);
    TheVectorAnimation->setInterpolationType(Animator::LINEAR_INTERPOLATION);
    TheVectorAnimation->setCycling(2);
	//TheVectorAnimation->setAnimatedField(getFieldContainer("Transform",std::string("TorusNodeVectorCore")), std::string("matrix"));
    
	//Transformation Keyframe Sequence
    TransformationKeyframes = KeyframeTransformationSequenceMatrix4f::create();
	Matrix TempMat;
	TempMat.setTransform(Vec3f(0.0f,0.0f,0.0f), Quaternion(Vec3f(0.0f,1.0f,0.0f), 3.14159f*0.0f));
    TransformationKeyframes->addKeyframe(TempMat,0.0f);
	TempMat.setTransform(Vec3f(0.0f,1.0f,0.0f), Quaternion(Vec3f(0.0f,1.0f,0.0f), 3.14159f*0.5f));
    TransformationKeyframes->addKeyframe(TempMat,1.0f);
	TempMat.setTransform(Vec3f(1.0f,1.0f,0.0f), Quaternion(Vec3f(0.0f,1.0f,0.0f), 3.14159f*1.0f));
    TransformationKeyframes->addKeyframe(TempMat,2.0f);
	TempMat.setTransform(Vec3f(1.0f,0.0f,0.0f), Quaternion(Vec3f(0.0f,1.0f,0.0f), 3.14159f*1.5f));
    TransformationKeyframes->addKeyframe(TempMat,3.0f);
	TempMat.setTransform(Vec3f(0.0f,0.0f,0.0f), Quaternion(Vec3f(0.0f,1.0f,0.0f), 3.14159f*2.0f));
    TransformationKeyframes->addKeyframe(TempMat,4.0f);
    
    //Transformation Animator
    KeyframeAnimatorUnrecPtr TheTransformationAnimator = KeyframeAnimator::create();
    TheTransformationAnimator->setKeyframeSequence(TransformationKeyframes);
    
    //Transformation Animation
    FieldAnimationUnrecPtr TheTransformationAnimation = FieldAnimation::create();
    TheTransformationAnimation->setAnimator(TheTransformationAnimator);
    TheTransformationAnimation->setInterpolationType(Animator::LINEAR_INTERPOLATION);
    TheTransformationAnimation->setCycling(2);
	TheTransformationAnimation->setAnimatedField(TorusNodeTrans, std::string("matrix"));

    TheAnimationGroup = AnimationGroup::create();
    TheAnimationGroup->pushToAnimations(TheColorAnimation);
    TheAnimationGroup->pushToAnimations(TheTransformationAnimation);

    TheAnimationGroup->attachUpdateProducer(TutorialWindow->editEventProducer());
    TheAnimationGroup->start();
}
void setupAnimation(JointUnrecPtr TheJoint, JointUnrecPtr TheChildJoint)
{
	//Create an animation for TheJoint
	//TheJoint Transformation keyframes (we'll animate TheJoint's translation)
	Matrix transform = TheJoint->getJointTransformation();

	KeyframeTransformationSequenceUnrecPtr TheJointTranformationKeyframes = KeyframeTransformationSequenceMatrix4f::create();
	
	transform.setTranslate(0.0f,0.0f,0.0f);
	TheJointTranformationKeyframes->addKeyframe(transform, 0.0f);

	transform.setTranslate(2.0f,0.0f,0.0f);
	TheJointTranformationKeyframes->addKeyframe(transform, 2.0f);

	transform.setTranslate(1.0f,0.0f,0.0f);
	TheJointTranformationKeyframes->addKeyframe(transform, 4.0f);

	transform.setTranslate(3.0f,0.0f,0.0f);
	TheJointTranformationKeyframes->addKeyframe(transform, 6.0f);

	transform = TheJoint->getJointTransformation();
	transform.setTranslate(0.0f,0.0f,0.0f);
	TheJointTranformationKeyframes->addKeyframe(transform, 8.0f);

	//TheJoint Animator
    AnimatorUnrecPtr TheJointAnimator = KeyframeAnimator::create();
    dynamic_pointer_cast<KeyframeAnimator>(TheJointAnimator)->setKeyframeSequence(TheJointTranformationKeyframes);

    //TheJoint Animation
    TheJointAnimation = FieldAnimation::create();
    dynamic_pointer_cast<FieldAnimation>(TheJointAnimation)->setAnimator(TheJointAnimator);
    dynamic_pointer_cast<FieldAnimation>(TheJointAnimation)->setInterpolationType(Animator::CUBIC_INTERPOLATION);
    dynamic_pointer_cast<FieldAnimation>(TheJointAnimation)->setCycling(-1);
    dynamic_pointer_cast<FieldAnimation>(TheJointAnimation)->setAnimatedField(TheJoint, std::string("JointTransformation"));
	
    TheJointAnimation->attachUpdateProducer(TutorialWindow->editEventProducer());
    TheJointAnimation->start();

	//Create an animation for TheChildJoint
	//TheChildJoint Transformation keyframes (we'll animate TheChildJoint's rotation)
	transform = TheChildJoint->getJointTransformation();

	KeyframeTransformationSequenceUnrecPtr TheChildJointTransformationKeyframes = KeyframeTransformationSequenceMatrix4f::create();

	TheChildJointTransformationKeyframes->addKeyframe(transform, 0.0f);

	transform.setRotate(Quaternion(Vec3f(0.0,1.0,0.0),0.0));
	TheChildJointTransformationKeyframes->addKeyframe(transform, 2.0f);

	transform.setRotate(Quaternion(Vec3f(0.0,1.0,0.0),0.5*Pi));
	TheChildJointTransformationKeyframes->addKeyframe(transform, 4.0f);

	transform.setRotate(Quaternion(Vec3f(0.0,1.0,0.0),Pi));
	TheChildJointTransformationKeyframes->addKeyframe(transform, 6.0f);

	transform.setRotate(Quaternion(Vec3f(0.0,1.0,0.0),1.5*Pi));
	TheChildJointTransformationKeyframes->addKeyframe(transform, 8.0f);

	transform.setRotate(Quaternion(Vec3f(0.0,1.0,0.0),2.0*Pi));
	TheChildJointTransformationKeyframes->addKeyframe(transform, 10.0f);

	//TheChildJoint Animator
    AnimatorUnrecPtr TheChildJointAnimator = KeyframeAnimator::create();
    dynamic_pointer_cast<KeyframeAnimator>(TheChildJointAnimator)->setKeyframeSequence(TheChildJointTransformationKeyframes);

	//TheChildJoint Animation
    TheChildJointAnimation = FieldAnimation::create();
    dynamic_pointer_cast<FieldAnimation>(TheChildJointAnimation)->setAnimator(TheChildJointAnimator);
    dynamic_pointer_cast<FieldAnimation>(TheChildJointAnimation)->setInterpolationType(Animator::CUBIC_INTERPOLATION);
    dynamic_pointer_cast<FieldAnimation>(TheChildJointAnimation)->setCycling(-1);
    dynamic_pointer_cast<FieldAnimation>(TheChildJointAnimation)->setAnimatedField(TheChildJoint, std::string("JointTransformation"));

    TheChildJointAnimation->attachUpdateProducer(TutorialWindow->editEventProducer());
    TheChildJointAnimation->start();
}
void setupAnimation(void)
{
    Matrix TempMat;

    //We create an animation and an animator for each joint we wish to animate

    //Left Elbow
    KeyframeTransformationSequenceUnrecPtr LeftElbowKeyframes = KeyframeTransformationSequenceMatrix4f::create();
    //Make keyframes
    TempMat.setTransform(Vec3f(2.0,0.0,0.0),Quaternion(Vec3f(0.0,0.0,1.0),0.0f));
    LeftElbowKeyframes->addKeyframe(TempMat,0.0f);
    TempMat.setTransform(Vec3f(2.0,0.0,0.0),Quaternion(Vec3f(0.0,0.0,1.0),1.57f));
    LeftElbowKeyframes->addKeyframe(TempMat,3.0f);
    TempMat.setTransform(Vec3f(2.0,0.0,0.0),Quaternion(Vec3f(0.0,0.0,1.0),0.0f));
    LeftElbowKeyframes->addKeyframe(TempMat,6.0f);

    //Left Elbow Animator
    KeyframeAnimatorUnrecPtr LeftElbowAnimator = KeyframeAnimator::create();
    LeftElbowAnimator->setKeyframeSequence(LeftElbowKeyframes);

    //Right Elbow
    KeyframeTransformationSequenceUnrecPtr RightElbowKeyframes = KeyframeTransformationSequenceMatrix4f::create();
    //Make keyframes
    TempMat.setTransform(Vec3f(-2.0,0.0,0.0),Quaternion(Vec3f(0.0,0.0,1.0),0.0f));
    RightElbowKeyframes->addKeyframe(TempMat,0.0f);
    TempMat.setTransform(Vec3f(-2.0,0.0,0.0),Quaternion(Vec3f(0.0,0.0,1.0),-1.57f));
    RightElbowKeyframes->addKeyframe(TempMat,3.0f);
    TempMat.setTransform(Vec3f(-2.0,0.0,0.0),Quaternion(Vec3f(0.0,0.0,1.0),0.0f));
    RightElbowKeyframes->addKeyframe(TempMat,6.0f);

    //Right Elbow Animator
    KeyframeAnimatorUnrecPtr RightElbowAnimator = KeyframeAnimator::create();
    RightElbowAnimator->setKeyframeSequence(RightElbowKeyframes);

    //Left Shoulder
    KeyframeTransformationSequenceUnrecPtr LeftShoulderKeyframes = KeyframeTransformationSequenceMatrix4f::create();
    //Make keyframes
    TempMat.setTransform(Vec3f(1.0,-0.5,0.0),Quaternion(Vec3f(0.0,0.0,1.0),0.0f));
    LeftShoulderKeyframes->addKeyframe(TempMat,0.0f);
    TempMat.setTransform(Vec3f(1.0,-0.5,0.0),Quaternion(Vec3f(0.0,0.0,1.0),0.4f));
    LeftShoulderKeyframes->addKeyframe(TempMat,3.0f);
    TempMat.setTransform(Vec3f(1.0,-0.5,0.0),Quaternion(Vec3f(0.0,0.0,1.0),0.0f));
    LeftShoulderKeyframes->addKeyframe(TempMat,6.0f);

    //Left Shoulder Animator
    KeyframeAnimatorUnrecPtr LeftShoulderAnimator = KeyframeAnimator::create();
    LeftShoulderAnimator->setKeyframeSequence(LeftShoulderKeyframes);

    //Right Shoulder
    KeyframeTransformationSequenceUnrecPtr RightShoulderKeyframes = KeyframeTransformationSequenceMatrix4f::create();
    //Make keyframes
    TempMat.setTransform(Vec3f(-1.0,-0.5,0.0),Quaternion(Vec3f(0.0,0.0,1.0),0.0f));
    RightShoulderKeyframes->addKeyframe(TempMat,0.0f);
    TempMat.setTransform(Vec3f(-1.0,-0.5,0.0),Quaternion(Vec3f(0.0,0.0,1.0),-0.4f));
    RightShoulderKeyframes->addKeyframe(TempMat,3.0f);
    TempMat.setTransform(Vec3f(-1.0,-0.5,0.0),Quaternion(Vec3f(0.0,0.0,1.0),0.0f));
    RightShoulderKeyframes->addKeyframe(TempMat,6.0f);

    //Right Shoulder Animator
    KeyframeAnimatorUnrecPtr RightShoulderAnimator = KeyframeAnimator::create();
    RightShoulderAnimator->setKeyframeSequence(RightShoulderKeyframes);

    //Left Hip
    KeyframeTransformationSequenceUnrecPtr LeftHipKeyframes = KeyframeTransformationSequenceMatrix4f::create();
    //Make keyframes
    TempMat.setTransform(Vec3f(1.0,-1.0,0.0),Quaternion(Vec3f(0.0,0.0,1.0),0.0f));
    LeftHipKeyframes->addKeyframe(TempMat,0.0f);
    TempMat.setTransform(Vec3f(1.0,-1.0,0.0),Quaternion(Vec3f(0.0,0.0,1.0),0.4f));
    LeftHipKeyframes->addKeyframe(TempMat,3.0f);
    TempMat.setTransform(Vec3f(1.0,-1.0,0.0),Quaternion(Vec3f(0.0,0.0,1.0),0.0f));
    LeftHipKeyframes->addKeyframe(TempMat,6.0f);

    //Left Hip Animator
    KeyframeAnimatorUnrecPtr LeftHipAnimator = KeyframeAnimator::create();
    LeftHipAnimator->setKeyframeSequence(LeftHipKeyframes);

    //Right Hip
    KeyframeTransformationSequenceUnrecPtr RightHipKeyframes = KeyframeTransformationSequenceMatrix4f::create();
    //Make keyframes
    TempMat.setTransform(Vec3f(-1.0,-1.0,0.0),Quaternion(Vec3f(0.0,0.0,1.0),0.0f));
    RightHipKeyframes->addKeyframe(TempMat,0.0f);
    TempMat.setTransform(Vec3f(-1.0,-1.0,0.0),Quaternion(Vec3f(0.0,0.0,1.0),-0.4f));
    RightHipKeyframes->addKeyframe(TempMat,3.0f);
    TempMat.setTransform(Vec3f(-1.0,-1.0,0.0),Quaternion(Vec3f(0.0,0.0,1.0),0.0f));
    RightHipKeyframes->addKeyframe(TempMat,6.0f);

    //Right Hip Animator
    KeyframeAnimatorUnrecPtr RightHipAnimator = KeyframeAnimator::create();
    RightHipAnimator->setKeyframeSequence(RightHipKeyframes);


    //Clavicle
    KeyframeTransformationSequenceUnrecPtr ClavicleKeyframes = KeyframeTransformationSequenceMatrix4f::create();
    //Make keyframes
    TempMat.setTransform(Vec3f(0.0,5.0,0.0));
    ClavicleKeyframes->addKeyframe(TempMat,0.0f);
    TempMat.setTransform(Vec3f(0.0,3.0,0.0));
    ClavicleKeyframes->addKeyframe(TempMat,2.0f);
    TempMat.setTransform(Vec3f(0.0,3.0,0.0));
    ClavicleKeyframes->addKeyframe(TempMat,4.0f);
    TempMat.setTransform(Vec3f(0.0,5.0,0.0));
    ClavicleKeyframes->addKeyframe(TempMat,6.0f);

    //Clavicle Animator
    KeyframeAnimatorUnrecPtr ClavicleAnimator = KeyframeAnimator::create();
    ClavicleAnimator->setKeyframeSequence(ClavicleKeyframes);

    //Skeleton Animation
    TheSkeletonAnimation = SkeletonAnimation::create();
    //Add the animators we just made to the skeleton animation
    TheSkeletonAnimation->addTransformationAnimator(LeftElbowAnimator, LeftElbow);  //Here we tell the skeleton animation the it should use the animator LeftElbowAnimator to animate the joint LeftElbow
    TheSkeletonAnimation->addTransformationAnimator(RightElbowAnimator, RightElbow);
    TheSkeletonAnimation->addTransformationAnimator(LeftShoulderAnimator, LeftShoulder);
    TheSkeletonAnimation->addTransformationAnimator(RightShoulderAnimator, RightShoulder);
    TheSkeletonAnimation->addTransformationAnimator(LeftHipAnimator, LeftHip);
    TheSkeletonAnimation->addTransformationAnimator(RightHipAnimator, RightHip);
    TheSkeletonAnimation->addTransformationAnimator(ClavicleAnimator, Clavicle);
    TheSkeletonAnimation->setSkeleton(ExampleSkeleton);

    TheSkeletonAnimation->attachUpdateProducer(TutorialWindow->editEventProducer());
    TheSkeletonAnimation->start();
}
// Initialize GLUT & OpenSG and set up the rootNode
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

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

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

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

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

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

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

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

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

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

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

        physicsSpace->setDefaultCollisionParameters(DefaultCollisionParams);

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

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


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


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

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

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

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

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

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

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

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

    osgExit();

    return 0;
}