可根据数学计算得出当前观测点是否在目标点正上方或正下方,如果在,则设置适当设置摄像机和地球模式即可。我把代码用C#写成了静态函数,很方便调用。如果大家还有别的什么更好的方法,请指教。
//根据当前摄像机姿态决定应该为Global模式还是Local模式,解决调整Camera之后地球抖动问题 public static void AutoSwitchGlobeCameraOrientationMode(IGlobe pGlobe) { 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; } }