小秋的家

          home

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            1 Posts :: 91 Stories :: 17 Comments :: 0 Trackbacks

          在ArcGIS的接口里,提供了IAnimationTracks,通過它我們可以實現(xiàn)三維動畫軌跡的創(chuàng)建,刪除或在播放當前軌跡的三維場景效果,進而可以生成三維場景的錄像輸出處理方法(這個我在下一篇再給大家介紹),還是看看具體實現(xiàn)代碼吧--

             /// <summary>
             /// 創(chuàng)建動畫軌跡
             /// </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];
                    }
             }

          是不是很簡單呢?記住喲,在播放軌跡的時候,有個時間的處理方法,具體在程序調(diào)試時,多試幾次就知道是怎么回事了,我就不多說了。。。

          當然,還有動畫幀的處理方法,ArcGIS也提供了一個很方便的接口IKeyframe來實現(xiàn)的,再通過動畫軌跡接口IAnimationTrack來實現(xiàn)動畫幀的創(chuàng)建,刪除等功能,代碼實現(xiàn)如下

             /// <summary>
             /// 創(chuàng)建動畫幀
             /// </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 棋劍小秋 閱讀(548) 評論(1)  編輯  收藏 所屬分類: GIS

          Feedback

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

          主站蜘蛛池模板: 巫溪县| 砀山县| 沙洋县| 临漳县| 自贡市| 廉江市| 兴城市| 海丰县| 鹤岗市| 鹤壁市| 巫山县| 周至县| 通辽市| 大连市| 北票市| 华坪县| 鲁甸县| 东安县| 山东省| 大关县| 浮梁县| 洪江市| 高邮市| 门源| 兰州市| 漯河市| 中阳县| 沐川县| 通州市| 铜川市| 牡丹江市| 贵定县| 霍林郭勒市| 安泽县| 田林县| 晋中市| 德惠市| 邳州市| 上饶市| 常德市| 玉林市|