void globeDispEvent_AfterDraw(ISceneViewer pViewer) { double obsLat; double obsLon; double obsAlt; double tarLat; double tarLon; double tarAlt; globeCamera.GetObserverLatLonAlt(out obsLat, out obsLon, out obsAlt); globeCamera.GetTargetLatLonAlt(out tarLat, out tarLon, out tarAlt); //set the observer and target of the secondary viewer to be the same as main viewer if top-down view = false if (topDownView == false || globeCamera.OrientationMode == esriGlobeCameraOrientationMode.esriGlobeCameraOrientationGlobal) { viewerGlobeCamera.OrientationMode = globeCamera.OrientationMode; viewerGlobeCamera.SetObserverLatLonAlt(obsLat, obsLon, obsAlt); viewerGlobeCamera.SetTargetLatLonAlt(tarLat, tarLon, tarAlt); } //set the observer top down view for the secondary viewer else if (topDownView == true && globeCamera.OrientationMode == esriGlobeCameraOrientationMode.esriGlobeCameraOrientationLocal) { viewerGlobeCamera.OrientationMode = esriGlobeCameraOrientationMode.esriGlobeCameraOrientationLocal; tarLat = obsLat + 0.0000001; tarLon = obsLon + 0.0000001; viewerGlobeCamera.SetTargetLatLonAlt(tarLat, tarLon, tarAlt); } }
public static void AutoSwitchGlobeCameraOrientationMode(IGlobe pGlobe) { try { ESRI.ArcGIS.Analyst3D.ISceneViewer sceneViewer = pGlobe.GlobeDisplay.ActiveViewer; ESRI.ArcGIS.Analyst3D.ICamera camera = sceneViewer.Camera; ESRI.ArcGIS.GlobeCore.IGlobeCamera globeCamera = (ESRI.ArcGIS.GlobeCore.IGlobeCamera)camera; double xTarget; double yTarget; ESRI.ArcGIS.Geometry.IPoint targetCls = (globeCamera as ICamera).Target; targetCls.QueryCoords(out xTarget, out yTarget); double zTarget = targetCls.Z; // Calculate the current azimuth and inclination of the camera. //azimuth = Math.Atan2(xTarget, yTarget) * 180 / Math.PI; double inclination = (180 / Math.PI) * (Math.Asin(zTarget / Math.Sqrt(xTarget * xTarget + yTarget * yTarget + zTarget * zTarget))) - 10.0; if (inclination > 88 | inclination < -88 | double.IsNaN(inclination)) { double targetLatitude; double targetLongitude; double targetAltitude; globeCamera.GetTargetLatLonAlt(out targetLatitude, out targetLongitude, out targetAltitude); double observerLatitude; double obsLongitude; double obsAltitude; globeCamera.GetObserverLatLonAlt(out observerLatitude, out obsLongitude, out obsAltitude); //// Set the GlobeCamera to global navigation mode. globeCamera.OrientationMode = ESRI.ArcGIS.GlobeCore.esriGlobeCameraOrientationMode.esriGlobeCameraOrientationGlobal; globeCamera.NavigationType = ESRI.ArcGIS.GlobeCore.esriGlobeNavigationType.esriGlobeNavigationAttached; globeCamera.SetObserverLatLonAlt(targetLatitude, targetLongitude, obsAltitude); } else { globeCamera.OrientationMode = ESRI.ArcGIS.GlobeCore.esriGlobeCameraOrientationMode.esriGlobeCameraOrientationLocal; globeCamera.NavigationType = ESRI.ArcGIS.GlobeCore.esriGlobeNavigationType.esriGlobeNavigationFree; } } catch { } }
//function for creating specified number of graphics per second public void generatePathPerSecond() { //set animation duration if (theCamForm.animDurationTextBox.Text != "" & theCamForm.animDurationTextBox.Text != "Optional") { animEnv.AnimationDuration = Convert.ToDouble(theCamForm.animDurationTextBox.Text); } else { MessageBox.Show("Please enter animation duration", "Error"); return; } animationDuration = animEnv.AnimationDuration; int numPtsPerSecond = 0; if (theCamForm.numPtsPerSecTextBox.Text != "") { numPtsPerSecond = Convert.ToInt32(theCamForm.numPtsPerSecTextBox.Text); } addGraphicLayer(); string selectedTrack = theCamForm.animTracksListBox.SelectedItem.ToString(); animationTracks.FindTrack(selectedTrack, out animationTrack); IAGAnimationTrackKeyframes kFrames = (IAGAnimationTrackKeyframes)animationTrack; int kFrameCount = kFrames.KeyframeCount; //total number of points to be created int totalPts = (int)(numPtsPerSecond * animationDuration); //this is the from point for the lines connecting the interpolated point graphics IPoint previousPt = new PointClass(); IZAware prevPtZAware = (IZAware)previousPt; prevPtZAware.ZAware = true; previousPt.PutCoords(0, 0); //this is the line connecting the interpolated camera positions IPolyline connectingLine = new PolylineClass(); IZAware lineZAware = (IZAware)connectingLine; lineZAware.ZAware = true; //disable all buttons theCamForm.playButton.Enabled = false; theCamForm.stopButton.Enabled = false; theCamForm.generatePathButton.Enabled = false; //loop over the keyframes in the selected camera track for (int i = 0; i < kFrameCount; i++) { IAGKeyframe currentKeyframe = kFrames.get_Keyframe(i); IAGKeyframe prevKeyframe; IAGKeyframe nextKeyframe; IAGKeyframe afterNextKeyframe; //if else statements to determine the keyframe arguments to the interpolate method //this is needed because the first, second-last and the last keyframes should be handled differently //than the middle keyframes if (i > 0) { prevKeyframe = kFrames.get_Keyframe(i - 1); } else { prevKeyframe = kFrames.get_Keyframe(i); } if (i < kFrameCount - 1) { nextKeyframe = kFrames.get_Keyframe(i + 1); } else { nextKeyframe = kFrames.get_Keyframe(i); } if (i < kFrameCount - 2) { afterNextKeyframe = kFrames.get_Keyframe(i + 2); } else { //this should be equal to the nextKeyFrame for the last keyframe afterNextKeyframe = nextKeyframe;//kFrames.get_Keyframe(i); } double origCamLat, origCamLong, origCamAlt; double interLat, interLong, interAlt; double tarLat, tarLong, tarAlt; double interTarLat, interTarLong, interTarAlt; globeCamera.GetObserverLatLonAlt(out origCamLat, out origCamLong, out origCamAlt); globeCamera.GetTargetLatLonAlt(out tarLat, out tarLong, out tarAlt); IAGAnimationContainer pAnimContainer = animationTracks.AnimationObjectContainer; object objToInterpolate = (object)globeCamera; double timeDiff = nextKeyframe.TimeStamp - currentKeyframe.TimeStamp; int numPtsToInterpolateNow; numPtsToInterpolateNow = Convert.ToInt32((timeDiff * totalPts)); //interpolate positions between keyframes and draw the graphics //for 0 to n-1 keyframes if (i < kFrameCount - 1) { for (int j = 0; j < numPtsToInterpolateNow; j++) { double timeToInterpolate; timeToInterpolate = currentKeyframe.TimeStamp + j * (timeDiff / (numPtsToInterpolateNow)); currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 1, timeToInterpolate, nextKeyframe, prevKeyframe, afterNextKeyframe); currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 2, timeToInterpolate, nextKeyframe, prevKeyframe, afterNextKeyframe); currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 3, timeToInterpolate, nextKeyframe, prevKeyframe, afterNextKeyframe); currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 4, timeToInterpolate, nextKeyframe, prevKeyframe, afterNextKeyframe); currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 5, timeToInterpolate, nextKeyframe, prevKeyframe, afterNextKeyframe); currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 6, timeToInterpolate, nextKeyframe, prevKeyframe, afterNextKeyframe); //get observer and target lat, long, alt after interpolation globeCamera.GetObserverLatLonAlt(out interLat, out interLong, out interAlt); globeCamera.GetTargetLatLonAlt(out interTarLat, out interTarLong, out interTarAlt); //set observer and target lat, long, alt to original values before interpolation globeCamera.SetObserverLatLonAlt(origCamLat, origCamLong, origCamAlt); globeCamera.SetTargetLatLonAlt(tarLat, tarLong, tarAlt); IPoint pObs = new PointClass(); IZAware obsZAware = (IZAware)pObs; obsZAware.ZAware = true; pObs.X = interLong; pObs.Y = interLat; pObs.Z = interAlt * 1000; double symbolSize = 10000; //change the symbol size based on distance to ground if (pObs.Z >= 10000) { symbolSize = 10000 + pObs.Z / 10; } else { symbolSize = pObs.Z; } //add graphics - keyframes (j=0) are colored differently if (j == 0) { addPointGraphicElements(pObs, 2552550, symbolSize); } else { addPointGraphicElements(pObs, 16732415, symbolSize); } connectingLine.FromPoint = previousPt; connectingLine.ToPoint = pObs; //barring the first keyframe, create the line connecting the interpolated points if (i == 0 & j == 0) { } else { addLineGraphicElements(connectingLine, 150150150); } //update the previous point previousPt.PutCoords(pObs.X, pObs.Y); previousPt.Z = pObs.Z; //add camera to target direction if (theCamForm.camToTargetDirectionCheckBox.Checked == true) { cameraToTargetDirection(interLat, interLong, interAlt, interTarLat, interTarLong, interTarAlt); } globeDisplay.RefreshViewers(); } } //for last keyframe if (i == kFrameCount - 1) { currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 4, 1, nextKeyframe, prevKeyframe, afterNextKeyframe); currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 5, 1, nextKeyframe, prevKeyframe, afterNextKeyframe); currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 6, 1, nextKeyframe, prevKeyframe, afterNextKeyframe); currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 1, 1, nextKeyframe, prevKeyframe, afterNextKeyframe); currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 2, 1, nextKeyframe, prevKeyframe, afterNextKeyframe); currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 3, 1, nextKeyframe, prevKeyframe, afterNextKeyframe); globeCamera.GetObserverLatLonAlt(out interLat, out interLong, out interAlt); globeCamera.GetTargetLatLonAlt(out interTarLat, out interTarLong, out interTarAlt); globeCamera.SetObserverLatLonAlt(origCamLat, origCamLong, origCamAlt); globeCamera.SetTargetLatLonAlt(tarLat, tarLong, tarAlt); IPoint pObs = new PointClass(); IZAware obsZAware = (IZAware)pObs; obsZAware.ZAware = true; pObs.X = interLong; pObs.Y = interLat; pObs.Z = interAlt * 1000; double symbolSize = 10000; if (pObs.Z >= 10000) { symbolSize = 10000 + pObs.Z / 10; } else { symbolSize = pObs.Z; } connectingLine.FromPoint = previousPt; connectingLine.ToPoint = pObs; addPointGraphicElements(pObs, 2552550, symbolSize); addLineGraphicElements(connectingLine, 150150150); //add camera to target orientation if (theCamForm.camToTargetDirectionCheckBox.Checked == true) { cameraToTargetDirection(interLat, interLong, interAlt, interTarLat, interTarLong, interTarAlt); } globeDisplay.RefreshViewers(); } } //enable buttons theCamForm.playButton.Enabled = true; theCamForm.generatePathButton.Enabled = true; }