小秋的家

          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 棋劍小秋 閱讀(547) 評論(1)  編輯  收藏 所屬分類: GIS

          Feedback

          # re: 三維動畫軌跡 2012-05-12 16:53 assss
          ssdsdvsdvaavadvadsvasvasv  回復  更多評論
            

          主站蜘蛛池模板: 佛坪县| 来宾市| 三穗县| 江陵县| 景谷| 会东县| 盈江县| 璧山县| 龙游县| 扎兰屯市| 乐东| 沙坪坝区| 邓州市| 始兴县| 汽车| 盐源县| 枣阳市| 寿阳县| 望奎县| 罗定市| 江永县| 山阴县| 临澧县| 西吉县| 体育| 郓城县| 龙井市| 阳信县| 海丰县| 富川| 手游| 三明市| 广丰县| 开远市| 麻江县| 英超| 克东县| 延津县| 台前县| 河源市| 达州市|