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(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(); }
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(); }
AnimationTransitPtr setupAnimation(Transform* const TheJoint, Transform* const TheChildJoint) { //Create an animation for TheJoint //TheJoint Transformation keyframes (we'll animate TheJoint's translation) Matrix transform = TheJoint->getMatrix(); 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->getMatrix(); 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 FieldAnimationUnrecPtr TheJointAnimation = FieldAnimation::create(); TheJointAnimation->setAnimator(TheJointAnimator); TheJointAnimation->setInterpolationType(Animator::CUBIC_INTERPOLATION); TheJointAnimation->setCycling(-1); TheJointAnimation->setAnimatedField(TheJoint, std::string("matrix")); //Create an animation for TheChildJoint //TheChildJoint Transformation keyframes (we'll animate TheChildJoint's rotation) transform = TheChildJoint->getMatrix(); 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 FieldAnimationUnrecPtr TheChildJointAnimation = FieldAnimation::create(); TheChildJointAnimation->setAnimator(TheChildJointAnimator); TheChildJointAnimation->setInterpolationType(Animator::CUBIC_INTERPOLATION); TheChildJointAnimation->setCycling(-1); TheChildJointAnimation->setAnimatedField(TheChildJoint, std::string("matrix")); AnimationGroupUnrecPtr TheAnimationGroup = AnimationGroup::create(); TheAnimationGroup->pushToAnimations(TheJointAnimation); TheAnimationGroup->pushToAnimations(TheChildJointAnimation); return AnimationTransitPtr(TheAnimationGroup); }