This document is archived and information here might be outdated.  Recommended version.


Create Animation from Keyframes Snippet (ArcObjects .NET 10.6 SDK)
ArcObjects Library Reference

Create Animation from Keyframes Snippet

Creates an animation by changing and applying the keyframe in globe. The animation rotates the globe by changing the GlobeCamera keyframe and applying it in globe.

[C#]
///<summary>Creates an animation by changing and applying the keyframe in globe. The  animation rotates the globe by changing the GlobeCamera keyframe and applying it in globe.</summary>
/// 
///<param name="globe">An IGlobe interface</param>
///  
///<remarks></remarks>
public void CreateAnimationFromKeyframes(ESRI.ArcGIS.GlobeCore.IGlobe globe)
{
  // get Globe Camera in the globe display
  ESRI.ArcGIS.GlobeCore.IGlobeDisplay globeDisplay=globe.GlobeDisplay;

  ESRI.ArcGIS.Analyst3D.ISceneViewer sceneViewer=globeDisplay.ActiveViewer;
  ESRI.ArcGIS.Analyst3D.ICamera camera=sceneViewer.Camera;
  ESRI.ArcGIS.GlobeCore.IGlobeCamera globeCamera=(ESRI.ArcGIS.GlobeCore.IGlobeCamera)camera; // Explicit Cast

  // create keyframe
  ESRI.ArcGIS.Animation.IAGKeyframe agKeyframe=new ESRI.ArcGIS.GlobeCore.GlobeCameraKeyframeClass();

  // set active properties
  ESRI.ArcGIS.esriSystem.ILongArray longArray=new ESRI.ArcGIS.esriSystem.LongArrayClass();
  longArray.Add(4); // Observer Lat.
  longArray.Add(5); // Observer Lon.
  longArray.Add(6); // Observer Alt.
  agKeyframe.ActiveProperties=longArray;

  ESRI.ArcGIS.Animation.IAGAnimationType agAnimationType=new ESRI.ArcGIS.GlobeCore.AnimationTypeGlobeCameraClass();
  ESRI.ArcGIS.Animation.IAGAnimationTrack agAnimationTrack=new ESRI.ArcGIS.Animation.AGAnimationTrackClass();
  agAnimationTrack.AnimationType=agAnimationType;
  ESRI.ArcGIS.Animation.IAGAnimationContainer AGAnimationContainer=(ESRI.ArcGIS.Animation.IAGAnimationContainer)globe; // Explicit Cast

  // animation loop
  System.Double longitude;
  for (longitude=0; longitude <= 360; longitude++)
  {
    agKeyframe.set_PropertyValue(4, 0.0); // set latitude
    agKeyframe.set_PropertyValue(5, longitude); // set longitude
    agKeyframe.set_PropertyValue(6, 20000.0); // set altitude
    agKeyframe.Apply(agAnimationTrack, AGAnimationContainer, globeCamera); // apply it
    globeDisplay.RefreshViewers();
  }
}
[Visual Basic .NET]
'''<summary>Creates an animation by changing and applying the keyframe in globe. The  animation rotates the globe by changing the GlobeCamera keyframe and applying it in globe.</summary>
''' 
'''<param name="globe">An IGlobe interface</param>
'''  
'''<remarks></remarks>
Public Sub CreateAnimationFromKeyframes(ByVal globe As ESRI.ArcGIS.GlobeCore.IGlobe)

  ' get Globe Camera in the globe display
  Dim globeDisplay As ESRI.ArcGIS.GlobeCore.IGlobeDisplay=globe.GlobeDisplay

  Dim sceneViewer As ESRI.ArcGIS.Analyst3D.ISceneViewer=globeDisplay.ActiveViewer
  Dim camera As ESRI.ArcGIS.Analyst3D.ICamera=sceneViewer.Camera
  Dim globeCamera As ESRI.ArcGIS.GlobeCore.IGlobeCamera=CType(camera, ESRI.ArcGIS.GlobeCore.IGlobeCamera) ' Explicit Cast

  ' create keyframe
  Dim agKeyframe As ESRI.ArcGIS.Animation.IAGKeyframe=New ESRI.ArcGIS.GlobeCore.GlobeCameraKeyframeClass

  ' set active properties
  Dim longArray As ESRI.ArcGIS.esriSystem.ILongArray=New ESRI.ArcGIS.esriSystem.LongArrayClass
  LongArray.Add(4) ' Observer Lat.
  LongArray.Add(5) ' Observer Lon.
  LongArray.Add(6) ' Observer Alt.
  agKeyframe.ActiveProperties=LongArray

  Dim agAnimationType As ESRI.ArcGIS.Animation.IAGAnimationType=New ESRI.ArcGIS.GlobeCore.AnimationTypeGlobeCameraClass
  Dim agAnimationTrack As ESRI.ArcGIS.Animation.IAGAnimationTrack=New ESRI.ArcGIS.Animation.AGAnimationTrackClass
  agAnimationTrack.AnimationType=agAnimationType
  Dim agAnimationContainer As ESRI.ArcGIS.Animation.IAGAnimationContainer=CType(globe, ESRI.ArcGIS.Animation.IAGAnimationContainer) ' Explict Cast

  ' animation loop
  Dim longitude As System.Double

  For longitude=0 To 360

    agKeyframe.PropertyValue(4)=0 ' set latitude
    agKeyframe.PropertyValue(5)=longitude ' set longitude
    agKeyframe.PropertyValue(6)=20000 ' set altitude
    agKeyframe.Apply(agAnimationTrack, agAnimationContainer, globeCamera) ' apply it
    globeDisplay.RefreshViewers()

  Next longitude

End Sub

Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.3DAnalyst
  • ESRI.ArcGIS.Animation
  • ESRI.ArcGIS.Display
  • ESRI.ArcGIS.GlobeCore
  • ESRI.ArcGIS.System