///<summary>根据planeviewbox和planecameraheight自动调整相机位置</summary> void planeAdjustCamera() { //计算相机位置 System.Windows.Point pnt = new System.Windows.Point(planeViewBox.Width / 2, planeViewBox.Height / 2); System.Windows.Point geopnt = geohelper.planeToGeo(pnt.ToString()); VECTOR3D vc = MapHelper.JWHToPoint(geopnt.Y, geopnt.X, Para.LineHeight, earthpara); float tmp = 1.0f + planeCameraHeight / Para.Radius; earth.camera = new Camera(new Vector3(vc.x, vc.y, vc.z) * tmp, new Vector3(0, 0, 0), Vector3.Up, earth); }
/// <summary> /// 自动调整相机距离以显示指定范围 /// </summary> public void adjustCameraRange(System.Windows.Rect rect) { double minjd, maxjd, minwd, maxwd; minwd = rect.Left; maxwd = rect.Right; minjd = rect.Top; maxjd = rect.Bottom; List <VECTOR3D> corners = new List <VECTOR3D>(); VECTOR3D lefttop, righttop, leftbottom, rightbottom, center; System.Windows.Media.Media3D.Vector3D lt, rt, lb, rb; lefttop = MapHelper.JWHToPoint(minjd, maxwd, 0, earth.earthManager.earthpara); corners.Add(lefttop); lt = Helpler.vecD3DToWpf(lefttop); righttop = MapHelper.JWHToPoint(maxjd, maxwd, 0, earth.earthManager.earthpara); corners.Add(righttop); rt = Helpler.vecD3DToWpf(righttop); leftbottom = MapHelper.JWHToPoint(minjd, minwd, 0, earth.earthManager.earthpara); corners.Add(leftbottom); lb = Helpler.vecD3DToWpf(leftbottom); rightbottom = MapHelper.JWHToPoint(maxjd, minwd, 0, earth.earthManager.earthpara); corners.Add(rightbottom); rb = Helpler.vecD3DToWpf(rightbottom); System.Windows.Media.Media3D.Vector3D cent = new System.Windows.Media.Media3D.Vector3D((corners.Max(p => p.x) + corners.Min(p => p.x)) / 2, (corners.Max(p => p.y) + corners.Min(p => p.y)) / 2, (corners.Max(p => p.z) + corners.Min(p => p.z)) / 2); if (earth.earthManager.earthpara.SceneMode == ESceneMode.地球) { cent = cent * Para.Radius / cent.Length; center = new VECTOR3D(cent.X, cent.Y, cent.Z); } else //zh注:还未验证 { center = new VECTOR3D(cent.X, cent.Y, 0); } double width, height; width = Math.Max((rt - lt).Length, (rb - lb).Length) * 1.5; height = Math.Max((lb - lt).Length, (rb - rt).Length) * 1.5; double distance; if (width / height > earth.global.ScreenWidth / earth.global.ScreenHeight) //以宽度来计算 { distance = width * earth.global.ScreenHeight / earth.global.ScreenWidth / 2 / Math.Atan(FieldOfView / 2); } else //以高度来计算 { distance = height / 2 / Math.Atan(FieldOfView / 2); } aniLook(center); adjustCameraDistance((float)distance); }
///<summary>获取指定经纬高的点在三维场景中的坐标</summary> public VECTOR3D getScene3DCoordinate(double jd, double wd, double hd) { return(MapHelper.JWHToPoint(jd, wd, hd, earth.earthManager.earthpara)); }