小秋的家

home

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  1 Posts :: 91 Stories :: 17 Comments :: 0 Trackbacks

在ArcGIS的接口里,提供了IAnimationTracks,通过它我们可以实现三维动画轨迹的创建,删除或在播放当前轨迹的三维场景效果,进而可以生成三维场景的录像输出处理方法(这个我在下一篇再给大家介绍),还是看看具体实现代码吧--

   /// <summary>
   /// 创建动画轨迹
   /// </summary>
   public void CreateAnimationTrack( string trackName )
   {
          IAnimationTrack pAnimationTrack = new AnimationTrackClass();
          IAnimationType pAnimationType = new AnimationTypeCameraClass();
          pAnimationTrack.AnimationType = pAnimationType;

          pAnimationTrack.Name = trackName;
          pAnimationTrack.AttachObject( pSceneGraph.ActiveViewer.Camera );
          pAnimationTrack.ApplyToAllViewers = true;
          pAnimationTrack.EvenTimeStamps = false;

          pAnimationTracks.AddTrack( pAnimationTrack );
   }

   /// <summary>
   /// 删除动画轨迹
   /// </summary>
   public void RemoveAnimationTrack( string trackName )
   {
          IAnimationTrack pAnimationTrack;
          pAnimationTracks.FindTrack( trackName, out pAnimationTrack );
          pAnimationTracks.RemoveTrack( pAnimationTrack );
   }

   /// <summary>
   /// 播放当前动画轨迹
   /// </summary>
   public void PlayAnimationTrack( string trackName )
   {
          Hashtable htKeyTime = null;

          bool[] TracksEnable = new Boolean[pAnimationTracks.TrackCount];
          IAnimationTrack pAnimationTrack;
          for( int index = 0; index < pAnimationTracks.TrackCount; index++ )
          {
                 pAnimationTrack = pAnimationTracks.Tracks.get_Element( index ) as IAnimationTrack;
                 TracksEnable[index] = pAnimationTrack.IsEnabled;
                 if( pAnimationTrack.Name == trackName )
                 {
                        pAnimationTrack.IsEnabled = true;
                        htKeyTime = ClsAnimationTracks.GetKeyTimeTable( pAnimationTrack.Name );
                 }
                 else
                        pAnimationTrack.IsEnabled = false;

          }

   
          int sumTime = 0;
          foreach( object obj in htKeyTime.Values )
          {
                 sumTime += Convert.ToInt32( obj );
          }

          double duration = (double)sumTime / 1000;

          TimeSpan timeSpan;
          double elapsedTime;

   
          DateTime startTime = DateTime.Now;
          int j = 0;
          do
          {
                 timeSpan = (DateTime.Now).Subtract(startTime);
                 elapsedTime = timeSpan.TotalSeconds;
                 if (elapsedTime > duration) elapsedTime = duration;
                 pAnimationTracks.ApplyTracks(pSceneGraph.ActiveViewer, elapsedTime, duration);
                 pSceneGraph.RefreshViewers();
                 j = j + 1;
         }

          for( int index = 0; index < pAnimationTracks.TrackCount; index++ )
          {
                 pAnimationTrack = pAnimationTracks.Tracks.get_Element( index ) as IAnimationTrack;
                 pAnimationTrack.IsEnabled = TracksEnable[index];
          }
   }

是不是很简单呢?记住哟,在播放轨迹的时候,有个时间的处理方法,具体在程序调试时,多试几次就知道是怎么回事了,我就不多说了。。。

当然,还有动画帧的处理方法,ArcGIS也提供了一个很方便的接口IKeyframe来实现的,再通过动画轨迹接口IAnimationTrack来实现动画帧的创建,删除等功能,代码实现如下

   /// <summary>
   /// 创建动画帧
   /// </summary>
   public void CreateKeyFrame( IAnimationTrack pAnimationTrack, string keyName, int timeSpan )
   {
         IKeyframe pKeyframe = new Bookmark3DClass();
         pKeyframe.Name = keyName;
         pKeyframe.CaptureProperties( pScene, pSceneGraph.ActiveViewer.Camera );

         pAnimationTrack.InsertKeyframe( pKeyframe, pAnimationTrack.KeyframeCount );

         Hashtable htKeyTime = ClsAnimationTracks.GetKeyTimeTable( pAnimationTrack.Name );
         int sumTime = 0;
         foreach( object obj in htKeyTime.Values )
         {
               sumTime += Convert.ToInt32( obj );
          }

         double dblTime = 0;
         for( int index = 0; index < pAnimationTrack.KeyframeCount; index++ )
         {
               pKeyframe = pAnimationTrack.get_Keyframe( index );
               dblTime += Convert.ToDouble( htKeyTime[pKeyframe.Name] ) / sumTime;
               pKeyframe.TimeStamp = dblTime;
         }
   }

   /// <summary>
   /// 删除动画帧
   /// </summary>
   public void RemoveKeyFrame( IAnimationTrack pAnimationTrack, string keyName )
   {
         for( int index = 0; index < pAnimationTrack.KeyframeCount; index++ )
         {
               if( pAnimationTrack.get_Keyframe( index ).Name == keyName )
               {
                     pAnimationTrack.RemoveKeyframe( index );
                     break;
               }
         }   
   }

   /// <summary>
   /// 删除当前轨迹的所有帧
   /// </summary>
   public void RemoveAllKeyFrame( IAnimationTrack pAnimationTrack )
   {
         pAnimationTrack.RemoveAllKeyframes();  
   }

posted on 2008-06-24 19:50 棋剑小秋 阅读(539) 评论(1)  编辑  收藏 所属分类: GIS

Feedback

# re: 三维动画轨迹 2012-05-12 16:53 assss
ssdsdvsdvaavadvadsvasvasv  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: