/// <summary> /// Initializes a new instance of the <see cref= "T:WorldWind.Renderable.QuadTile"/> class. /// </summary> /// <param name="south"></param> /// <param name="north"></param> /// <param name="west"></param> /// <param name="east"></param> /// <param name="level"></param> /// <param name="quadTileSet"></param> public QuadTile(double south, double north, double west, double east, int level, QuadTileSet quadTileSet) { this.South = south; this.North = north; this.West = west; this.East = east; CenterLatitude = Angle.FromDegrees(0.5f * (North + South)); CenterLongitude = Angle.FromDegrees(0.5f * (West + East)); LatitudeSpan = Math.Abs(North - South); LongitudeSpan = Math.Abs(East - West); this.Level = level; this.QuadTileSet = quadTileSet; BoundingBox = new BoundingBox((float)south, (float)north, (float)west, (float)east, (float)quadTileSet.LayerRadius, (float)quadTileSet.LayerRadius + 300000f); //localOrigin = BoundingBox.CalculateCenter(); localOrigin = MathEngine.SphericalToCartesianD(CenterLatitude, CenterLongitude, quadTileSet.LayerRadius); // To avoid gaps between neighbouring tiles truncate the origin to // a number that doesn't get rounded. (nearest 10km) localOrigin.X = (float)(Math.Round(localOrigin.X / 10000) * 10000); localOrigin.Y = (float)(Math.Round(localOrigin.Y / 10000) * 10000); localOrigin.Z = (float)(Math.Round(localOrigin.Z / 10000) * 10000); Row = MathEngine.GetRowFromLatitude(South, North - South); Col = MathEngine.GetColFromLongitude(West, North - South); }
private double GetSlope(RasterReader reader, TerrainPoint tp) { double zx = 0, zy = 0, ex = 0; if (tp.col - 1 > 0 && tp.row - 1 > 0 && tp.row + 1 < _terrainTile.GetLength(1) && tp.col + 1 < _terrainTile.GetLength(0)) { iTelluro.GlobeEngine.DataSource.Geometry.Point3d d1 = null, d2 = null; if (reader.IsProjected) { d1 = new Point3d(_terrainTile[tp.col - 1, tp.row].Longitude, tp.Latitude, tp.Altitude); d2 = new Point3d(_terrainTile[tp.col + 1, tp.row].Longitude, tp.Latitude, tp.Altitude); } else { d1 = MathEngine.SphericalToCartesianD( Angle.FromDegrees(tp.Latitude), Angle.FromDegrees(_terrainTile[tp.col - 1, tp.row].Longitude), //lon - demSpan GlobeTools.CurrentWorld.EquatorialRadius + tp.Altitude ); d2 = MathEngine.SphericalToCartesianD( Angle.FromDegrees(tp.Latitude), Angle.FromDegrees(_terrainTile[tp.col + 1, tp.row].Longitude), //lon + demSpan), GlobeTools.CurrentWorld.EquatorialRadius + tp.Altitude ); } iTelluro.GlobeEngine.DataSource.Geometry.Point3d segment = d2 - d1; ex = segment.Length; //zx = (elv[1, 2] - elv[1, 0]) / ex; //zy = (elv[2, 1] - elv[0, 1]) / ex; zx = (_terrainTile[tp.col + 1, tp.row + 0].Altitude - _terrainTile[tp.col - 1, tp.row + 0].Altitude) / ex; zy = (_terrainTile[tp.col + 0, tp.row + 1].Altitude - _terrainTile[tp.col + 0, tp.row - 1].Altitude) / ex; } return(Math.Atan(Math.Sqrt(zx * zx + zy * zy))); }
/// <summary> /// 计算影像数据单元格的投影面积 /// (区分了文件为投影坐标还是地理坐标) /// </summary> /// <param name="reader"></param> /// <param name="_widthNum"></param> /// <param name="_heightNum"></param> /// <returns></returns> private double CaculateCellAera(RasterReader reader, int _widthNum, int _heightNum) { try { int ti, tj; ti = _widthNum / 2; tj = _heightNum / 2; iTelluro.GlobeEngine.DataSource.Geometry.Point3d p00, p01, p10; if (reader.IsProjected) { p00 = new Point3d(_terrainTile[ti, tj].Longitude, _terrainTile[ti, tj].Latitude, _terrainTile[ti, tj].Altitude); p01 = new Point3d(_terrainTile[ti, tj + 1].Longitude, _terrainTile[ti, tj + 1].Latitude, _terrainTile[ti, tj + 1].Altitude); p10 = new Point3d(_terrainTile[ti + 1, tj].Longitude, _terrainTile[ti + 1, tj].Latitude, _terrainTile[ti + 1, tj].Altitude); } else { double r = _globeView.GlobeViewSetting.EquatorialRadius + _terrainTile[ti, tj].Altitude; p00 = MathEngine.SphericalToCartesianD(Angle.FromDegrees(_terrainTile[ti, tj].Latitude), Angle.FromDegrees(_terrainTile[ti, tj].Longitude), r); p01 = MathEngine.SphericalToCartesianD(Angle.FromDegrees(_terrainTile[ti, tj + 1].Latitude), Angle.FromDegrees(_terrainTile[ti, tj + 1].Longitude), r); p10 = MathEngine.SphericalToCartesianD(Angle.FromDegrees(_terrainTile[ti + 1, tj].Latitude), Angle.FromDegrees(_terrainTile[ti + 1, tj].Longitude), r); } double area = (p00 - p01).Length * (p00 - p10).Length; return(area); } catch (Exception ex) { FormOutput.AppendLog(ex.Message); return(0); } }
private void UpdateCartesianPoint() { m_cartesianPoint = MathEngine.SphericalToCartesianD( Angle.FromDegrees(m_latitude), Angle.FromDegrees(m_longitude), m_world.EquatorialRadius + m_distanceAboveSurface * World.Settings.VerticalExaggeration); m_currentVerticalExaggeration = World.Settings.VerticalExaggeration; }
public override void Initialize(DrawArgs drawArgs) { double samplesPerDegree = 50.0 / (drawArgs.WorldCamera.ViewRange.Degrees); double elevation = drawArgs.CurrentWorld.TerrainAccessor.GetElevationAt(m_latitude, m_longitude, samplesPerDegree); double altitude = (World.Settings.VerticalExaggeration * Altitude + World.Settings.VerticalExaggeration * elevation); Position = MathEngine.SphericalToCartesian(m_latitude, m_longitude, altitude + drawArgs.WorldCamera.WorldRadius); m_positionD = MathEngine.SphericalToCartesianD(Angle.FromDegrees(m_latitude), Angle.FromDegrees(m_longitude), altitude + drawArgs.WorldCamera.WorldRadius); Inited = true; }
private void Update() { double altitude; // Altitude is ASL altitude = (World.Settings.VerticalExaggeration * Alt) + DrawArgs.Camera.WorldRadius; Position = MathEngine.SphericalToCartesian(Lat, Lon, altitude); m_positionD = MathEngine.SphericalToCartesianD( Angle.FromDegrees(Lat), Angle.FromDegrees(Lon), altitude); }
/// <summary> /// 初始化Icon对象 /// </summary> /// <param name="drawArgs"></param> public override void Initialize(DrawArgs drawArgs) { double samplesPerDegree = 50.0 / (drawArgs.WorldCamera.ViewRange.Degrees); //计算当前每一度有多少个格网 double elevation = drawArgs.CurrentWorld.TerrainAccessor.GetElevationAt(m_latitude, m_longitude, samplesPerDegree); //计算当前经纬度的海拔系信息 double altitude = (World.Settings.VerticalExaggeration * Altitude + World.Settings.VerticalExaggeration * elevation); //计算Icon的实际显示高度=夸大因子*Altitude+海拔高度 //转换为屏幕向量信息 Position = MathEngine.SphericalToCartesian(m_latitude, m_longitude, altitude + drawArgs.WorldCamera.WorldRadius); //转换到屏幕坐标 m_positionD = MathEngine.SphericalToCartesianD( Angle.FromDegrees(m_latitude), Angle.FromDegrees(m_longitude), altitude + drawArgs.WorldCamera.WorldRadius); isInitialized = true; }
/// <summary> /// 初始化控制点 /// </summary> /// <param name="drawArgs"></param> public override void Initialize(DrawArgs drawArgs) { //计算当前每一度有多少个格网 double samplesPerDegree = 50.0 / (drawArgs.WorldCamera.ViewRange.Degrees); //计算当前经纬度的海拔系信息 double elevation = drawArgs.CurrentWorld.TerrainAccessor.GetElevationAt(m_latitude, m_longitude, samplesPerDegree); //计算GCP的实际显示高度=夸大因子*Altitude+海拔高度 double altitude = (World.Settings.VerticalExaggeration * Altitude + World.Settings.VerticalExaggeration * elevation); //转换为屏幕向量信息 Position = MathEngine.SphericalToCartesian(m_latitude, m_longitude, altitude + drawArgs.WorldCamera.WorldRadius); //转换到屏幕坐标 m_positionD = MathEngine.SphericalToCartesianD( Angle.FromDegrees(m_latitude), Angle.FromDegrees(m_longitude), altitude + drawArgs.WorldCamera.WorldRadius); //注册主窗口事件 QrstGlobe.MouseDown += new System.Windows.Forms.MouseEventHandler(QrstGlobe_MouseDown); QrstGlobe.MouseUp += new System.Windows.Forms.MouseEventHandler(QrstGlobe_MouseUp); IsInitialized = true; }
private double getDistance(Angle startLatitude, Angle startLongitude, Angle endLatitude, Angle endLongitude, double radius) { Angle angularDistance = World.ApproxAngularDistance(startLatitude, startLongitude, endLatitude, endLongitude); int steps = 4; double distance = 0; Point3d d1 = MathEngine.SphericalToCartesianD(startLatitude, startLongitude, radius); for (int i = 1; i < steps; i++) { Angle curLat; Angle curLon; World.IntermediateGCPoint((float)i / (float)(steps - 1), startLatitude, startLongitude, endLatitude, endLongitude, angularDistance, out curLat, out curLon); Point3d d2 = MathEngine.SphericalToCartesianD(curLat, curLon, radius); Point3d segment = d2 - d1; distance += segment.Length; d1 = d2; } return(distance); }
public virtual void ComputeViewMatrix() { ComputeAbsoluteMatrices(); if (World.Settings.ElevateCameraLookatPoint) { targetCameraElevation = TerrainElevation * World.Settings.VerticalExaggeration; curCameraElevation = curCameraElevation + (0.01f * (targetCameraElevation - curCameraElevation)); } else { curCameraElevation = 0; } // needs to be double precsion double radius = WorldRadius + curCameraElevation; double radCosLat = radius * Math.Cos(_latitude.Radians); LookFrom = new Point3d(radCosLat * Math.Cos(_longitude.Radians), radCosLat * Math.Sin(_longitude.Radians), radius * Math.Sin(_latitude.Radians)); // this constitutes a local tri-frame hovering above the sphere Point3d zAxis = LookFrom.normalize(); // on sphere the normal vector and position vector are the same Point3d xAxis = Point3d.cross(cameraUpVector, zAxis).normalize(); Point3d yAxis = Point3d.cross(zAxis, xAxis); ReferenceCenter = MathEngine.SphericalToCartesianD(Angle.FromRadians(Convert.ToSingle(_latitude.Radians)), Angle.FromRadians(Convert.ToSingle(_longitude.Radians)), WorldRadius); // Important step !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // In order to use single precsion rendering, we need to define a local frame (i.e. center of center tile, etc.) // Vector3d LocalCenter should be defined & initialized in the CameraBase class // Each time the camera moves, a new local center could be defined // The local center also has to be subtracted from all the terrain vertices!!!! relCameraPos = LookFrom - ReferenceCenter; // Important step: construct the single precision m_ViewMatrix by hand // We can build the m_ViewMatrix by hand m_ViewMatrix.M11 = (float)xAxis.X; m_ViewMatrix.M21 = (float)xAxis.Y; m_ViewMatrix.M31 = (float)xAxis.Z; m_ViewMatrix.M12 = (float)yAxis.X; m_ViewMatrix.M22 = (float)yAxis.Y; m_ViewMatrix.M32 = (float)yAxis.Z; m_ViewMatrix.M13 = (float)zAxis.X; m_ViewMatrix.M23 = (float)zAxis.Y; m_ViewMatrix.M33 = (float)zAxis.Z; m_ViewMatrix.M41 = -(float)(xAxis.X * relCameraPos.X + xAxis.Y * relCameraPos.Y + xAxis.Z * relCameraPos.Z); m_ViewMatrix.M42 = -(float)(yAxis.X * relCameraPos.X + yAxis.Y * relCameraPos.Y + yAxis.Z * relCameraPos.Z); m_ViewMatrix.M43 = -(float)(zAxis.X * relCameraPos.X + zAxis.Y * relCameraPos.Y + zAxis.Z * relCameraPos.Z); m_ViewMatrix.M14 = (float)0.0; m_ViewMatrix.M24 = (float)0.0; m_ViewMatrix.M34 = (float)0.0; m_ViewMatrix.M44 = (float)1.0; m_ViewMatrix *= Matrix.RotationYawPitchRoll(0, (float)-_tilt.Radians, (float)_heading.Radians); m_ViewMatrix *= Matrix.Translation(0, 0, (float)(-_distance - curCameraElevation)); m_ViewMatrix *= Matrix.RotationZ((float)_bank.Radians); // Extract camera position Matrix cam = Matrix.Invert(m_absoluteViewMatrix); _position = new Vector3(cam.M41, cam.M42, cam.M43); }
/// <summary> /// 导出桥梁,隧道或路基的中线 /// </summary> /// <param name="latlonPoints"></param> /// <param name="TXT"></param> private void exportMiddleLine(CRailwayProject prj, StreamWriter DoubleFile, StreamWriter SingleFile, string prjType) { string fileNameExt = ".max.x"; StreamWriter TXT; OnePrj aprj; List <Vector3d> earthCoreSysPoints = new List <Vector3d>(); List <Vector3d> dsMaxPoints = new List <Vector3d>(); List <int> sIndex = new List <int>(); // 如果工点里程过长,拆分为不超过3.5 KM作为一段生成模型 int startN = 0; // int n = 0; if (!prj.mIsValid) { return; } for (startN = 0; startN < prj.mPath.mPointCount - 350; startN += 300) { sIndex.Add(startN); } sIndex.Add(startN); double[] m, x, y, z, d; bool isDouble; string sp; isDouble = prj.mPath.getMiddleLine(out m, out x, out y, out z, out d); if (isDouble) { TXT = DoubleFile; sp = "d"; } else { TXT = SingleFile; sp = "s"; } for (int j = 0; j < sIndex.Count; j++) { int fromIdx = sIndex[j]; int toIdx; if (j == sIndex.Count - 1) { toIdx = m.Length - 1; } else { toIdx = sIndex[j + 1]; } double prjLength = prj.mPath.mLength; switch (prjType) { case "bridge": if (isDouble) { dbridgeCount++; aprj = new OnePrj(j, prjType, prj.ProjectName, sp + prjType + dbridgeCount + fileNameExt, prjLength, x[sIndex[j]], y[sIndex[j]], z[sIndex[j]]); } else { sbridgeCount++; aprj = new OnePrj(j, prjType, prj.ProjectName, sp + prjType + sbridgeCount + fileNameExt, prjLength, x[sIndex[j]], y[sIndex[j]], z[sIndex[j]]); } projectList.Add(aprj); break; case "road": if (isDouble) { droadCount++; aprj = new OnePrj(j, prjType, prj.ProjectName, sp + prjType + droadCount + fileNameExt, prjLength, x[sIndex[j]], y[sIndex[j]], z[sIndex[j]]); } else { sroadCount++; aprj = new OnePrj(j, prjType, prj.ProjectName, sp + prjType + sroadCount + fileNameExt, prjLength, x[sIndex[j]], y[sIndex[j]], z[sIndex[j]]); } projectList.Add(aprj); break; case "tunnel": if (isDouble) { dtunnelCount++; aprj = new OnePrj(j, prjType, prj.ProjectName, sp + prjType + dtunnelCount + fileNameExt, prjLength, x[sIndex[j]], y[sIndex[j]], z[sIndex[j]]); } else { stunnelCount++; aprj = new OnePrj(j, prjType, prj.ProjectName, sp + prjType + stunnelCount + fileNameExt, prjLength, x[sIndex[j]], y[sIndex[j]], z[sIndex[j]]); } projectList.Add(aprj); break; } TXT.Write(prjLength + " "); TXT.Write(prj.ProjectName + " "); TXT.WriteLine(j); earthCoreSysPoints.Clear(); dsMaxPoints.Clear(); for (int i = fromIdx; i <= toIdx; i++) { double radius = WorldSettings.EquatorialRadius /* 米 */ + z[i]; earthCoreSysPoints.Add(MathEngine.SphericalToCartesianD(y[i], x[i], radius)); // 米 } //foreach (LatLonAl p in latlonPoints) //{ // double radius = WorldSettings.EquatorialRadius/* 米 */ + p.altitude; // earthCoreSysPoints.Add(MathEngine.SphericalToCartesianD(p.latitude, p.longitude, radius)); // 米 //} // 经测试 地球窗口的世界坐标系原点在地球球心,x轴指向0纬0经,右手系,z轴指向北极点,测试语句: // Vector3 latlon_test = MathEngine.CartesianToSpherical(5001,1, 1); Vector3d k_prime = new Vector3d(earthCoreSysPoints[0]); k_prime = k_prime.Normalize(); Vector3d i_prime = Vector3d.Transform(earthCoreSys_YAxis, Matrix4d.RotationZ((prj.mPath.mx[fromIdx] * PI / 180))); Vector3d j_prime = Vector3d.Cross(k_prime, i_prime); j_prime = j_prime.Normalize(); Matrix4d mm = new Matrix4d(); // mm是正交矩阵,求逆就是求转置。 mm.M11 = i_prime.X; mm.M12 = j_prime.X; mm.M13 = k_prime.X; mm.M21 = i_prime.Y; mm.M22 = j_prime.Y; mm.M23 = k_prime.Y; mm.M31 = i_prime.Z; mm.M32 = j_prime.Z; mm.M33 = k_prime.Z; mm.M41 = mm.M42 = mm.M43 = 0; mm.M14 = mm.M24 = mm.M34 = 0; mm.M44 = 1; // 把三维中线(地球球心坐标系)上 起点之外的点 转换为 3ds max世界坐标 (起点作原点) for (int i = 1; i <= toIdx - fromIdx; i++) { Vector3d vv = new Vector3d(earthCoreSysPoints[i].X - earthCoreSysPoints[0].X, earthCoreSysPoints[i].Y - earthCoreSysPoints[0].Y, earthCoreSysPoints[i].Z - earthCoreSysPoints[0].Z); dsMaxPoints.Add(Vector3d.Transform(vv, mm)); } // 输出 List <Vector3d> straight_opt = new List <Vector3d>(); straight_opt.Add(dsMaxPoints[0]); straight_opt.Add(dsMaxPoints[1]); for (int i = 2; i < dsMaxPoints.Count; i++) { Vector3d a = dsMaxPoints[i] - straight_opt[straight_opt.Count - 1]; Vector3d b = straight_opt[straight_opt.Count - 1] - straight_opt[straight_opt.Count - 2]; double costheta = Vector3d.Dot(a, b) / a.Length / b.Length; double sintheta = Math.Sqrt(1 - costheta * costheta); if (sintheta < Threshold) { straight_opt.Last().X = dsMaxPoints[i].X; straight_opt.Last().Y = dsMaxPoints[i].Y; straight_opt.Last().Z = dsMaxPoints[i].Z; } else { straight_opt.Add(dsMaxPoints[i]); } } foreach (Vector3d p in straight_opt) { TXT.Write(p.X); TXT.Write(' '); TXT.Write(p.Y); TXT.Write(' '); TXT.Write(p.Z); TXT.Write(' '); } TXT.WriteLine(); } }
public virtual void Render(DrawArgs drawArgs) { if (this.m_Visible) { if (this.dblLatitude != double.MinValue) { try { drawArgs.device.RenderState.ZBufferEnable = true; Cull cullMode = drawArgs.device.RenderState.CullMode; drawArgs.device.RenderState.CullMode = Cull.None; Point3d pointd = MathEngine.SphericalToCartesianD(Angle.FromDegrees((double)this.dblLatitude), Angle.FromDegrees((double)this.dblLongitude), (this.ww.CurrentWorld.EquatorialRadius + (this.ww.CurrentWorld.TerrainAccessor.GetElevationAt((double)this.dblLatitude, (double)this.dblLongitude, 100.0) * World.Settings.VerticalExaggeration)) + this.dblAltitude); Microsoft.DirectX.Vector3 point = new Microsoft.DirectX.Vector3((float)(pointd.X - drawArgs.WorldCamera.ReferenceCenter.X), (float)(pointd.Y - drawArgs.WorldCamera.ReferenceCenter.Y), (float)(pointd.Z - drawArgs.WorldCamera.ReferenceCenter.Z)); Microsoft.DirectX.Vector3 vector2 = drawArgs.WorldCamera.Project(point); Microsoft.DirectX.Vector3 vector3 = new Microsoft.DirectX.Vector3(); Microsoft.DirectX.Vector3 vector4 = new Microsoft.DirectX.Vector3(); vector3.X = this.m_Location.X + (((float)this.m_Size.Width) / 3f); vector3.Y = this.m_Location.Y + this.m_Size.Height; vector4.X = this.m_Location.X + (2f * (((float)this.m_Size.Width) / 3f)); vector4.Y = this.m_Location.Y + this.m_Size.Height; CustomVertex.TransformedColored[] vertexStreamZeroData = new CustomVertex.TransformedColored[3]; vertexStreamZeroData[0].X = vector3.X; vertexStreamZeroData[0].Y = vector3.Y; vertexStreamZeroData[0].Z = 0f; vertexStreamZeroData[0].Color = this.m_BackgroundColor.ToArgb(); vertexStreamZeroData[1].X = vector2.X; vertexStreamZeroData[1].Y = vector2.Y; vertexStreamZeroData[1].Z = 0f; vertexStreamZeroData[1].Color = this.m_BackgroundColor.ToArgb(); vertexStreamZeroData[2].X = vector4.X; vertexStreamZeroData[2].Y = vector4.Y; vertexStreamZeroData[2].Z = 0f; vertexStreamZeroData[2].Color = this.m_BackgroundColor.ToArgb(); drawArgs.device.TextureState[0].ColorOperation = TextureOperation.Disable; drawArgs.device.VertexFormat = VertexFormats.Diffuse | VertexFormats.Transformed; drawArgs.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, vertexStreamZeroData.Length - 2, vertexStreamZeroData); drawArgs.device.RenderState.CullMode = cullMode; } catch (Exception) { } } if (this.m_TextFont == null) { System.Drawing.Font font = new System.Drawing.Font("Arial", 12f, FontStyle.Italic | FontStyle.Bold); this.m_TextFont = new Microsoft.DirectX.Direct3D.Font(drawArgs.device, font); } if (this.m_WorldWindDingsFont == null) { AddFontResource(Path.Combine(Application.StartupPath, "World Wind Dings 1.04.ttf")); PrivateFontCollection fonts = new PrivateFontCollection(); fonts.AddFontFile(Path.Combine(Application.StartupPath, "World Wind Dings 1.04.ttf")); System.Drawing.Font font2 = new System.Drawing.Font(fonts.Families[0], 12f); this.m_WorldWindDingsFont = new Microsoft.DirectX.Direct3D.Font(drawArgs.device, font2); } if (this.m_Resizeble) { if (((DrawArgs.LastMousePosition.X > (this.AbsoluteLocation.X - this.resizeBuffer)) && (DrawArgs.LastMousePosition.X < (this.AbsoluteLocation.X + this.resizeBuffer))) && ((DrawArgs.LastMousePosition.Y > (this.AbsoluteLocation.Y - this.resizeBuffer)) && (DrawArgs.LastMousePosition.Y < (this.AbsoluteLocation.Y + this.resizeBuffer)))) { DrawArgs.MouseCursor = CursorType.SizeNWSE; } else if (((DrawArgs.LastMousePosition.X > ((this.AbsoluteLocation.X - this.resizeBuffer) + this.ClientSize.Width)) && (DrawArgs.LastMousePosition.X < ((this.AbsoluteLocation.X + this.resizeBuffer) + this.ClientSize.Width))) && ((DrawArgs.LastMousePosition.Y > (this.AbsoluteLocation.Y - this.resizeBuffer)) && (DrawArgs.LastMousePosition.Y < (this.AbsoluteLocation.Y + this.resizeBuffer)))) { DrawArgs.MouseCursor = CursorType.SizeNESW; } else if (((DrawArgs.LastMousePosition.X > (this.AbsoluteLocation.X - this.resizeBuffer)) && (DrawArgs.LastMousePosition.X < (this.AbsoluteLocation.X + this.resizeBuffer))) && ((DrawArgs.LastMousePosition.Y > ((this.AbsoluteLocation.Y - this.resizeBuffer) + this.ClientSize.Height)) && (DrawArgs.LastMousePosition.Y < ((this.AbsoluteLocation.Y + this.resizeBuffer) + this.ClientSize.Height)))) { DrawArgs.MouseCursor = CursorType.SizeNESW; } else if (((DrawArgs.LastMousePosition.X > ((this.AbsoluteLocation.X - this.resizeBuffer) + this.ClientSize.Width)) && (DrawArgs.LastMousePosition.X < ((this.AbsoluteLocation.X + this.resizeBuffer) + this.ClientSize.Width))) && ((DrawArgs.LastMousePosition.Y > ((this.AbsoluteLocation.Y - this.resizeBuffer) + this.ClientSize.Height)) && (DrawArgs.LastMousePosition.Y < ((this.AbsoluteLocation.Y + this.resizeBuffer) + this.ClientSize.Height)))) { DrawArgs.MouseCursor = CursorType.SizeNWSE; } else if ((((DrawArgs.LastMousePosition.X > (this.AbsoluteLocation.X - this.resizeBuffer)) && (DrawArgs.LastMousePosition.X < (this.AbsoluteLocation.X + this.resizeBuffer))) && ((DrawArgs.LastMousePosition.Y > (this.AbsoluteLocation.Y - this.resizeBuffer)) && (DrawArgs.LastMousePosition.Y < ((this.AbsoluteLocation.Y + this.resizeBuffer) + this.ClientSize.Height)))) || (((DrawArgs.LastMousePosition.X > ((this.AbsoluteLocation.X - this.resizeBuffer) + this.ClientSize.Width)) && (DrawArgs.LastMousePosition.X < ((this.AbsoluteLocation.X + this.resizeBuffer) + this.ClientSize.Width))) && ((DrawArgs.LastMousePosition.Y > (this.AbsoluteLocation.Y - this.resizeBuffer)) && (DrawArgs.LastMousePosition.Y < ((this.AbsoluteLocation.Y + this.resizeBuffer) + this.ClientSize.Height))))) { DrawArgs.MouseCursor = CursorType.SizeWE; } else if ((((DrawArgs.LastMousePosition.X > (this.AbsoluteLocation.X - this.resizeBuffer)) && (DrawArgs.LastMousePosition.X < ((this.AbsoluteLocation.X + this.resizeBuffer) + this.ClientSize.Width))) && ((DrawArgs.LastMousePosition.Y > (this.AbsoluteLocation.Y - this.resizeBuffer)) && (DrawArgs.LastMousePosition.Y < (this.AbsoluteLocation.Y + this.resizeBuffer)))) || (((DrawArgs.LastMousePosition.X > (this.AbsoluteLocation.X - this.resizeBuffer)) && (DrawArgs.LastMousePosition.X < ((this.AbsoluteLocation.X + this.resizeBuffer) + this.ClientSize.Width))) && ((DrawArgs.LastMousePosition.Y > ((this.AbsoluteLocation.Y - this.resizeBuffer) + this.ClientSize.Height)) && (DrawArgs.LastMousePosition.Y < ((this.AbsoluteLocation.Y + this.resizeBuffer) + this.ClientSize.Height))))) { DrawArgs.MouseCursor = CursorType.SizeNS; } } if (this.ClientSize.Height > drawArgs.parentControl.Height) { this.ClientSize = new Size(this.ClientSize.Width, drawArgs.parentControl.Height); } if (this.ClientSize.Width > drawArgs.parentControl.Width) { this.ClientSize = new Size(drawArgs.parentControl.Width, this.ClientSize.Height); } if (!this.m_AutoHideHeader || (((DrawArgs.LastMousePosition.X >= this.m_Location.X) && (DrawArgs.LastMousePosition.X <= (this.m_Location.X + this.m_Size.Width))) && ((DrawArgs.LastMousePosition.Y >= this.m_Location.Y) && (DrawArgs.LastMousePosition.Y <= (this.m_Location.Y + this.m_Size.Height))))) { Utilities.DrawBox(this.m_Location.X, this.m_Location.Y, this.m_Size.Width, this.m_HeaderHeight, 0f, this.m_HeaderColor.ToArgb(), drawArgs.device); this.m_WorldWindDingsFont.DrawText(null, "E", new Rectangle((this.m_Location.X + this.m_Size.Width) - 15, this.m_Location.Y + 2, this.m_Size.Width, this.m_Size.Height), DrawTextFormat.NoClip, Color.White.ToArgb()); this.m_OutlineVertsHeader[0].X = this.AbsoluteLocation.X; this.m_OutlineVertsHeader[0].Y = this.AbsoluteLocation.Y + this.m_HeaderHeight; this.m_OutlineVertsHeader[1].X = this.AbsoluteLocation.X; this.m_OutlineVertsHeader[1].Y = this.AbsoluteLocation.Y; this.m_OutlineVertsHeader[2].X = this.AbsoluteLocation.X + this.ClientSize.Width; this.m_OutlineVertsHeader[2].Y = this.AbsoluteLocation.Y; this.m_OutlineVertsHeader[3].X = this.AbsoluteLocation.X + this.ClientSize.Width; this.m_OutlineVertsHeader[3].Y = this.AbsoluteLocation.Y + this.m_HeaderHeight; if (!this.m_HideBorder) { Utilities.DrawLine(this.m_OutlineVertsHeader, this.m_BorderColor.ToArgb(), drawArgs.device); } } Utilities.DrawBox(this.m_Location.X, this.m_Location.Y + this.m_HeaderHeight, this.m_Size.Width, this.m_Size.Height - this.m_HeaderHeight, 0f, this.m_BackgroundColor.ToArgb(), drawArgs.device); for (int i = this.m_ChildWidgets.Count - 1; i >= 0; i--) { IWidget widget = this.m_ChildWidgets[i]; if (widget != null) { if ((widget.ParentWidget == null) || (widget.ParentWidget != this)) { widget.ParentWidget = this; } widget.Render(drawArgs); } } this.m_OutlineVerts[0].X = this.AbsoluteLocation.X + this.ClientSize.Width; this.m_OutlineVerts[0].Y = this.AbsoluteLocation.Y + this.m_HeaderHeight; this.m_OutlineVerts[1].X = this.AbsoluteLocation.X + this.ClientSize.Width; this.m_OutlineVerts[1].Y = this.AbsoluteLocation.Y + this.ClientSize.Height; this.m_OutlineVerts[2].X = this.AbsoluteLocation.X; this.m_OutlineVerts[2].Y = this.AbsoluteLocation.Y + this.ClientSize.Height; this.m_OutlineVerts[3].X = this.AbsoluteLocation.X; this.m_OutlineVerts[3].Y = this.AbsoluteLocation.Y + this.m_HeaderHeight; if (!this.m_HideBorder) { Utilities.DrawLine(this.m_OutlineVerts, this.m_BorderColor.ToArgb(), drawArgs.device); } } }
/// <summary> /// 1.绘制太阳 /// </summary> /// <param name="drawArgs"></param> private void RenderSun(DrawArgs drawArgs) { //根据时间计算太阳的位置 Point3d sunPosition = -SunCalculator.GetGeocentricPosition(TimeKeeper.CurrentTimeUtc); Point3d sunSpherical = MathEngine.CartesianToSphericalD(sunPosition.X, sunPosition.Y, sunPosition.Z); sunPosition = MathEngine.SphericalToCartesianD( Angle.FromRadians(sunSpherical.Y), Angle.FromRadians(sunSpherical.Z), 150000000000); Vector3 sunVector = new Vector3((float)sunPosition.X, (float)sunPosition.Y, (float)sunPosition.Z); Frustum viewFrustum = new Frustum(); float aspectRatio = (float)drawArgs.WorldCamera.Viewport.Width / drawArgs.WorldCamera.Viewport.Height; Matrix projectionMatrix = Matrix.PerspectiveFovRH((float)drawArgs.WorldCamera.Fov.Radians, aspectRatio, 1.0f, 300000000000); viewFrustum.Update( Matrix.Multiply(drawArgs.WorldCamera.AbsoluteWorldMatrix, Matrix.Multiply(drawArgs.WorldCamera.AbsoluteViewMatrix, projectionMatrix))); if (!viewFrustum.ContainsPoint(sunVector)) { return; } Vector3 translationVector = new Vector3( (float)(sunPosition.X - drawArgs.WorldCamera.ReferenceCenter.X), (float)(sunPosition.Y - drawArgs.WorldCamera.ReferenceCenter.Y), (float)(sunPosition.Z - drawArgs.WorldCamera.ReferenceCenter.Z)); Vector3 projectedPoint = drawArgs.WorldCamera.Project(translationVector); if (m_sunTexture == null) { m_sunTexture = ImageHelper.LoadTexture(Path.Combine(((QRSTWorldGlobeControl)drawArgs.parentControl).DataDirectory, @"Space\sun.dds")); m_sunSurfaceDescription = m_sunTexture.GetLevelDescription(0); } if (m_sprite == null) { m_sprite = new Sprite(drawArgs.device); } m_sprite.Begin(SpriteFlags.AlphaBlend); // Render icon float xscale = (float)m_sunWidth / m_sunSurfaceDescription.Width; float yscale = (float)m_sunHeight / m_sunSurfaceDescription.Height; m_sprite.Transform = Matrix.Scaling(xscale, yscale, 0); m_sprite.Transform *= Matrix.Translation(projectedPoint.X, projectedPoint.Y, 0); m_sprite.Draw(m_sunTexture, new Vector3(m_sunSurfaceDescription.Width >> 1, m_sunSurfaceDescription.Height >> 1, 0), Vector3.Empty, System.Drawing.Color.FromArgb(253, 253, 200).ToArgb()); // Reset transform to prepare for text rendering later m_sprite.Transform = Matrix.Identity; m_sprite.End(); }