ArcGlobe组件开发之动画5——播放动画

在动画开发中,录制的一个动画可能只有一个Track也可能有多个Track。前面的博文提到动画的实现方式有两种,这里采用基于Camera的动画。这里我做的比较简单,首先来看实现效果图:


下面,我们来看,如何在Globe下实现动画的播放。来看下面的OMD图,从这张图里我们可以看出,Globe包含多个Track(轨迹),Track包含多个KeyFrame(关键帧);动画类型主要有基于Camera的和基于Layer,再有就是前面提到的基于关键帧的三种类型。那么具体如何做呢?我们一步一步来看:


(1)AnimationExtension

The AnimationExtension object is the access point for other animation objects in ArcMap, Scene, and Globe. Typically, when you work with animation objects, the AnimationExtension object needs to be obtained as the first step before other actions are performed.The animation environment and animation track container objects can be accessed through the IAnimationExtension interface.
之前的博文提到了 IAnimationExtension 接口,这个地方说在操作动画对象前必须要首先获得AnimationExtension对象,通过该对象获得动画参数设置对象和动画轨迹容器对象。接口如下图所示:


代码如下:
IGlobe globe = globecontrol.Globe;
            IBasicScene2 basicscene = globe as IBasicScene2;
            IAnimationExtension animationEx = basicscene.AnimationExtension;
            agAnimationEnv = animationEx.AnimationEnvironment;
(2)获取AGAnimationEnvironment 对象后就可以设置播放的参数,比如播放模式,持续时间等参数
代码如下:
        //设置动画播放参数
        private void SetAnimationEnv ()
        {
            //获取AGAnimationEnvironment对象
            IGlobe globe = globecontrol.Globe;
            IBasicScene2 basicscene = globe as IBasicScene2;
            IAnimationExtension animationEx = basicscene.AnimationExtension;
            agAnimationEnv = animationEx.AnimationEnvironment;
            
            agAnimationEnv.AnimationDuration = Convert.ToDouble(textBox_AnimationDuration.Text);//持续时间
            agAnimationEnv.PlayType=esriAnimationPlayType.esriAnimationPlayTypeDuration; //播放模式
            Set_Animation_PlayMode();
            agAnimationEnv.PlayMode = animationPlayMode;
        }

        //设置播放模式
        private void Set_Animation_PlayMode ()
        {
            switch (comboBox_PlayMode.Text)
            {
                case "正向播放一次":
                animationPlayMode = esriAnimationPlayMode.esriAnimationPlayOnceForward;
            	break;
                case "反向播放一次":
                animationPlayMode = esriAnimationPlayMode.esriAnimationPlayOnceReverse;
                break;
                case "正向循环":
                animationPlayMode = esriAnimationPlayMode.esriAnimationPlayLoopForward;
                break;
                case "正反循环":
                animationPlayMode = esriAnimationPlayMode.esriAnimationPlayLoopReverse;
                break;
                default:
                break;
            }
            
        }

(3)设置完播放参数,下一步就应该是播放了,动画的播放主要用到IAGAnimationPlayer 接口,通过该接口可以播放,暂停,停止和录制动画。如下图所示:

 


代码如下:
IAGAnimationPlayer agAnimationPlayer new AGAnimationEnvironmentClass();
 agAnimationPlayer.PlayAnimation(agAnimationTracks,agAnimationEnv,null);

(4)PlayAnimation方法需要三个参数:
[C#]public void PlayAnimation (
    IAGAnimationTrackspTracks,
    IAGAnimationEnvironmentpEnvironment,
    IStatusBarpStatusBar);
第一个参数是Tracks,就是动画所包含的轨迹,这里动画可能包含多条轨迹,如果要播放其中的一条指定轨迹则需要对轨迹进行处理:
 //选中播放轨迹可见,其余不可见
        private void enableSelectedTrack ()
        {
            string selectedTrackName = agAnimationTrack.Name;
            IArray tracksArray = agAnimationTracks.AGTracks;
            int trackCount = tracksArray.Count;
            if (trackCount>0)
            {
                for(int i = 0;i < trackCount;i++)
                {
                    IAGAnimationTrack track_temp = tracksArray.get_Element(i) as IAGAnimationTrack;
                    if(track_temp.Name==selectedTrackName)
                    {
                        track_temp.IsEnabled = true;
                        
                    }
                    else if (track_temp.Name!=selectedTrackName)
                    {
                        IAGAnimationTrack track2Disabled;
                        agAnimationTracks.FindTrack(track_temp.Name,out track2Disabled);
                        track2Disabled.IsEnabled = false;
                    }
                    
                }
            
            }


        }

通过以上步骤就可以实现对动画的操作,至此,ArcGlobe组件开发之动画篇就结束了,希望对需要的童鞋有所帮助。










posted @ 2014-04-08 23:21  奔跑的鸡丝  阅读(332)  评论(0编辑  收藏  举报