public void StartFlight(double x, double y) { inUse = true; globeDisplay.IsNavigating = true; ESRI.ArcGIS.GlobeCore.esriGlobeCameraOrientationMode camOrientMode = globeCamera.OrientationMode; orbitalFly = (camOrientMode == ESRI.ArcGIS.GlobeCore.esriGlobeCameraOrientationMode.esriGlobeCameraOrientationLocal) ? true : false; IPoint pObs = camera.Observer; IPoint pTar = camera.Target; observer = new GlobeFlyTool.PointZ(pObs.X, pObs.Y, pObs.Z); target = new GlobeFlyTool.PointZ(pTar.X, pTar.Y, pTar.Z); viewVec = target - observer; distance = viewVec.Norm(); //avoid center of globe if (target.Norm() < 0.25) { target = target + viewVec; distance = distance * 2; } currentElevation = Math.Atan(viewVec.z / Math.Sqrt((viewVec.x * viewVec.x) + (viewVec.y + viewVec.y))); currentAzimut = Math.Atan2(viewVec.y, viewVec.x);//2.26892;// //Windows API call to get windows client coordinates System.Drawing.Point pt = new System.Drawing.Point(); bool ans = GetCursorPos(ref pt); Rectangle rect = new Rectangle(); if (GetWindowRect(globeDisplay.ActiveViewer.hWnd, ref rect) == 0) { return; } mouseX = pt.X - rect.Left; mouseY = pt.Y - rect.Top; if (!orbitalFly) { globeCamera.OrientationMode = esriGlobeCameraOrientationMode.esriGlobeCameraOrientationGlobal; } else { globeCamera.OrientationMode = esriGlobeCameraOrientationMode.esriGlobeCameraOrientationLocal; } globeCamera.NavigationType = esriGlobeNavigationType.esriGlobeNavigationFree; globeCamera.RollFactor = 1.0; globeDisplay.IsNavigating = true; globeDisplay.IsNavigating = false; globeDisplay.IsNavigating = true; lastClock = theClock.TickCount; //Windows API call to set cursor SetCursor(moveFlyCur.Handle.ToInt32()); //Continue the flight Flight(); }
public void Flight() { //speed in scene units double motionUnit = (0.000001 + Math.Abs(observer.Norm() - 1.0) / 200.0) * motion; //Get IMessageDispatcher interface IMessageDispatcher pMessageDispatcher; pMessageDispatcher = new MessageDispatcherClass(); //Set the ESC key to be seen as a cancel action pMessageDispatcher.CancelOnClick = false; pMessageDispatcher.CancelOnEscPress = true; bCancel = false; do { //Get the elapsed time long currentClock = theClock.TickCount; double lastFrameDuration = (double)(currentClock - lastClock) / 1000; lastClock = currentClock; if (lastFrameDuration < 0.01) { lastFrameDuration = 0.01; } if (lastFrameDuration > 1) { lastFrameDuration = 0.1; } System.Diagnostics.Debug.Print(lastFrameDuration.ToString()); //Windows API call to get windows client coordinates Rectangle rect = new Rectangle(); if (GetClientRect(globeDisplay.ActiveViewer.hWnd, ref rect) == 0) { return; } //Get normal vectors double dXMouseNormal, dYMouseNormal; dXMouseNormal = 2 * ((double)mouseX / (double)(rect.Right - rect.Left)) - 1; dYMouseNormal = 2 * ((double)mouseY / (double)(rect.Bottom - rect.Top)) - 1; PointZ dir = this.RotateNormal(lastFrameDuration, dXMouseNormal, dYMouseNormal); PointZ visTarget = new PointZ(observer.x + distance * dir.x, observer.y + distance * dir.y, observer.z + distance * dir.z); target.x = visTarget.x; target.y = visTarget.y; target.z = visTarget.z; if (speed != 0) { int speedFactor = (speed > 0) ? (1 << speed) : -(1 << (-speed)); //Move the camera in the viewing directions observer.x = observer.x + (lastFrameDuration * (2 ^ speedFactor) * motionUnit * dir.x); observer.y = observer.y + (lastFrameDuration * (2 ^ speedFactor) * motionUnit * dir.y); observer.z = observer.z + (lastFrameDuration * (2 ^ speedFactor) * motionUnit * dir.z); target.x = target.x + (lastFrameDuration * (2 ^ speedFactor) * motionUnit * dir.x); target.y = target.y + (lastFrameDuration * (2 ^ speedFactor) * motionUnit * dir.y); target.z = target.z + (lastFrameDuration * (2 ^ speedFactor) * motionUnit * dir.z); } ESRI.ArcGIS.GlobeCore.IGlobeViewUtil globeViewUtil = globeCamera as ESRI.ArcGIS.GlobeCore.IGlobeViewUtil; double obsLat; double obsLon; double obsAlt; double tarLat; double tarLon; double tarAlt; globeViewUtil.GeocentricToGeographic(observer.x, observer.y, observer.z, out obsLon, out obsLat, out obsAlt); globeViewUtil.GeocentricToGeographic(target.x, target.y, target.z, out tarLon, out tarLat, out tarAlt); globeCamera.SetObserverLatLonAlt(obsLat, obsLon, obsAlt / 1000); globeCamera.SetTargetLatLonAlt(tarLat, tarLon, tarAlt / 1000); globeCamera.SetAccurateViewDirection(target.x - observer.x, target.y - observer.y, target.z - observer.z); double rollAngle = 0; if (speed > 0) { rollAngle = 10 * dXMouseNormal * Math.Abs(dXMouseNormal); } camera.RollAngle = rollAngle; //Redraw the scene viewer globeDisplay.RefreshViewers(); //Dispatch any waiting messages: OnMouseMove / OnMouseUp / OnKeyUp events object objCancel = bCancel as object; pMessageDispatcher.Dispatch(globeDisplay.ActiveViewer.hWnd, false, out objCancel); //End flight if ESC key pressed if (bCancel == true) { EndFlight(); } }while (inUse == true && bCancel == false); bCancel = false; }
public void StartFlight(double x, double y) { inUse = true; globeDisplay.IsNavigating = true; ESRI.ArcGIS.GlobeCore.esriGlobeCameraOrientationMode camOrientMode = globeCamera.OrientationMode; orbitalFly = (camOrientMode == ESRI.ArcGIS.GlobeCore.esriGlobeCameraOrientationMode.esriGlobeCameraOrientationLocal) ? true : false; IPoint pObs = camera.Observer; IPoint pTar = camera.Target; observer = new GlobeFlyTool.PointZ(pObs.X, pObs.Y, pObs.Z); target = new GlobeFlyTool.PointZ(pTar.X, pTar.Y, pTar.Z); viewVec = target - observer; distance = viewVec.Norm(); //avoid center of globe if (target.Norm() < 0.25) { target = target + viewVec; distance = distance * 2; } currentElevation = Math.Atan(viewVec.z / Math.Sqrt((viewVec.x * viewVec.x) + (viewVec.y + viewVec.y))); currentAzimut = Math.Atan2(viewVec.y, viewVec.x);//2.26892;// //Windows API call to get windows client coordinates System.Drawing.Point pt = new System.Drawing.Point(); bool ans = GetCursorPos(ref pt); Rectangle rect = new Rectangle(); if (GetWindowRect(globeDisplay.ActiveViewer.hWnd, ref rect) == 0) return; mouseX = pt.X - rect.Left; mouseY = pt.Y - rect.Top; if (!orbitalFly) { globeCamera.OrientationMode = esriGlobeCameraOrientationMode.esriGlobeCameraOrientationGlobal; } else { globeCamera.OrientationMode = esriGlobeCameraOrientationMode.esriGlobeCameraOrientationLocal; } globeCamera.NavigationType = esriGlobeNavigationType.esriGlobeNavigationFree; globeCamera.RollFactor = 1.0; globeDisplay.IsNavigating = true; globeDisplay.IsNavigating = false; globeDisplay.IsNavigating = true; lastClock = theClock.TickCount; //Windows API call to set cursor SetCursor(moveFlyCur.Handle.ToInt32()); //Continue the flight Flight(); }