From fab5d6e30b9a42a1f94524fca74ef227d2c963e4 Mon Sep 17 00:00:00 2001 From: cloudflight <cloudflight@126.com> Date: 星期六, 20 七月 2024 11:12:32 +0800 Subject: [PATCH] 1 --- Hydraulic/Hydro.MapUI/Map/MapViewer.Draw.cs | 168 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 153 insertions(+), 15 deletions(-) diff --git a/Hydraulic/Hydro.MapUI/Map/MapViewer.Draw.cs b/Hydraulic/Hydro.MapUI/Map/MapViewer.Draw.cs index a8af967..c5840c8 100644 --- a/Hydraulic/Hydro.MapUI/Map/MapViewer.Draw.cs +++ b/Hydraulic/Hydro.MapUI/Map/MapViewer.Draw.cs @@ -1,4 +1,6 @@ -锘縰sing Hydro.MapView; +锘縰sing DevExpress.XtraPrinting.Native; +using Hydro.MapView; +using Hydro.MapView.Base; using Hydro.MapView.Common; using System; using System.Collections.Generic; @@ -130,7 +132,7 @@ if (template == null) return; var _Nodes = template.network.Nodes.ViewNodes; var _Links = template.network.Links.ViewLinks; - + var _Areas = template.network.Areas; var Cpoints = getCurclePoints(64).ToList(); var r = 1.73f / zoom; @@ -161,6 +163,52 @@ Pen penClosed = new Pen(Color.OrangeRed, 2 * r); Pen penHovered = new Pen(Color.DeepSkyBlue, 5 * r); + + //缁樺埗闈� + using (Pen pen0 = new Pen(Color.FromArgb(0, 0, 255), 2 * r)) + { + foreach (var area in _Areas) + { + + if (!area.Visible) continue; + if (!IsFaceVisibleToCamera(area, GetCameraPosition())) continue; + if (area.Elev < minElve || area.Elev >= maxElve) continue; + + var p = new List<PointF>(); + foreach (var node in area.InnerNodes) + { + p.Add(CubeWorldPointToMapPoint(node, template.OffSet)); + } + if (p.Count < 3) continue; + pen0.Color = penClosed.Color = area.color; + Pen pen = pen0; + if (area.Hovered) pen = penHovered; + bufferG.FillPolygon(pen.Brush, p.ToArray()); + bufferG.DrawPolygon(pen, p.ToArray()); + //鏄剧ずarea鐨勫悕绉� + var c = new PointF(p.Average(p0 => p0.X), p.Average(p0 => p0.Y)); + var brush=new SolidBrush(Color.White); + + + + + var gs = bufferG.Save(); + // 搴旂敤鐭╅樀鍙樻崲浠ユ姷娑堜箣鍓嶇殑缈昏浆鏁堟灉 + bufferG.ScaleTransform(1 / Zoom.X, 1 / Zoom.Y); + + Font font = new Font(FontFamily.GenericSansSerif, 10*10*zoom); + + SizeF textSize = bufferG.MeasureString(area.Name, font); + var center = new PointF(c.X * Zoom.X, c.Y * Zoom.Y); + float textLeft = center.X - textSize.Width / 2; + float textTop = center.Y - textSize.Height / 2; + PointF pd = new PointF(textLeft, textTop); + + bufferG.DrawString(area.Name, font, brush, pd); + // 鎭㈠涔嬪墠淇濆瓨鐨勭粯鍥剧姸鎬� + bufferG.Restore(gs); + } + } // 缁樺埗绾� @@ -768,17 +816,18 @@ // 鏍规嵁鏃嬭浆瑙掑害璁$畻鏃嬭浆鍚庣殑鍧愭爣 - private PointF Get骞抽潰鏃嬭浆Point(PointF p) + private PointF Get骞抽潰鏃嬭浆Point(PointF p, PointF MapC) { - PointF center = MapCenter; + + PointF center = MapC ; double radian = Rotation * Math.PI / 180; // 瑙掑害杞姬搴� float x = (float)(Math.Cos(radian) * (p.X - center.X) - Math.Sin(radian) * (p.Y - center.Y) + center.X); float y = (float)(Math.Sin(radian) * (p.X - center.X) + Math.Cos(radian) * (p.Y - center.Y) + center.Y); return new PointF(x, y); } - private PointF Get骞抽潰杩樺師Point(PointF p) + private PointF Get骞抽潰杩樺師Point(PointF p, PointF MapC) { - PointF center = MapCenter; + PointF center = MapC; double radian = -Rotation * Math.PI / 180; // 瑙掑害杞姬搴� float x = (float)(Math.Cos(radian) * (p.X - center.X) - Math.Sin(radian) * (p.Y - center.Y) + center.X); float y = (float)(Math.Sin(radian) * (p.X - center.X) + Math.Cos(radian) * (p.Y - center.Y) + center.Y); @@ -787,9 +836,9 @@ - private PointF Get淇瑙掓棆杞琍oint(PointF p, float z) + private PointF Get淇瑙掓棆杞琍oint(PointF p, float z, PointF MapC) { - PointF center = MapCenter; + PointF center = MapC; double radian_fushi = 淇寮у害; float sin = (float)Math.Sin(radian_fushi); float cos = (float)Math.Cos(radian_fushi); @@ -797,9 +846,9 @@ float y = (float)(sin * (p.Y - center.Y) + center.Y) + cos * z; return new PointF(x, y); } - private PointF Get淇瑙掕繕鍘烶oint(PointF p, float z) + private PointF Get淇瑙掕繕鍘烶oint(PointF p, float z, PointF MapC) { - PointF center = MapCenter; + PointF center = MapC; double radian_fushi = 淇寮у害; float sin = (float)Math.Sin(radian_fushi); float cos = (float)Math.Cos(radian_fushi); @@ -828,9 +877,9 @@ if (offset == null) offset = new PointF3D(0, 0, 0); point = new PointF(point.X + offset.X, point.Y + offset.Y); - var pointR = Get骞抽潰鏃嬭浆Point(point); + var pointR = Get骞抽潰鏃嬭浆Point(point, MapCenter); - var pointT = Get淇瑙掓棆杞琍oint(pointR, z + offset.Z); + var pointT = Get淇瑙掓棆杞琍oint(pointR, z + offset.Z, MapCenter); //var n=new PointF((float)pointR.X - Z(z).X, (float)(pointR.Y - Z(z).Y)); return pointT; @@ -846,7 +895,19 @@ if (junction == null) return new PointF(0, 0); p = WorldPointToMapPoint(junction.Position, junction.Elev, offset); return p; - + } + private PointF CubeWorldPointToMapPoint(NodeViewModel junction, PointF3D offset = null) + { + PointF p; + if (junction == null) return new PointF(0, 0); + var point = junction.Position; + var z = junction.Elev; + if (offset == null) offset = new PointF3D(0, 0, 0); + point = new PointF(point.X + offset.X, point.Y + offset.Y); + var pointR = Get骞抽潰鏃嬭浆Point(point, new PointF(0, 0)); + var pointT = Get淇瑙掓棆杞琍oint(pointR, z + offset.Z, new PointF(0, 0)); + //var n=new PointF((float)pointR.X - Z(z).X, (float)(pointR.Y - Z(z).Y)); + return pointT; } private List<PointF> WorldPointToMapPoint(LinkViewModel pipe, PointF3D offset = null) { @@ -945,8 +1006,8 @@ /// <returns></returns> public PointF MapPointToWorldPoint(PointF point, float z = 0) { - var pointT = Get淇瑙掕繕鍘烶oint(point, z); - pointT = Get骞抽潰杩樺師Point(pointT); + var pointT = Get淇瑙掕繕鍘烶oint(point, z,MapCenter); + pointT = Get骞抽潰杩樺師Point(pointT, MapCenter); //var n=new PointF((float)pointR.X - Z(z).X, (float)(pointR.Y - Z(z).Y)); return pointT; @@ -963,7 +1024,84 @@ #endregion + #region 璁$畻涓夌淮鐩告満 + public PointF3D GetCameraPosition( float distance=1) + { + // 灏嗚搴﹁浆鎹负寮у害 + float rotationRadians = (float)Rotation * (float)Math.PI / 180; + float rotationFRadians = (float)RotationF * (float)Math.PI / 180; + // 璁$畻鐩告満鐨勭悆鍧愭爣绯讳綅缃� + float x = distance * (float)Math.Sin(rotationFRadians) * (float)Math.Cos(rotationRadians); + float y = distance * (float)Math.Sin(rotationFRadians) * (float)Math.Sin(rotationRadians); + float z = distance * (float)Math.Cos(rotationFRadians); + + return new PointF3D(x, y, z); + } + public bool IsFaceVisibleToCamera(AreaViewModel area, PointF3D cameraPosition) + { + + //姝i潰鏄�2锛屽彸闈㈡槸1锛屽乏闈㈡槸3锛岃儗闈㈡槸4 + //Rotation涓�0鏃讹紝鍙樉绀烘闈紝Rotation涓�90鏃讹紝鍙樉绀哄彸闈紝Rotation涓�180鏃讹紝鍙樉绀鸿儗闈紝Rotation涓�270鏃讹紝鍙樉绀哄乏闈� + int delta = 5; + bool flag = false; + switch (area.Name) + { + case "宸�": + //Rotation涓�0~180鏃舵樉绀� + if (RotationF<=90-delta && Rotation >= 0 + delta && Rotation <= 180 - delta) + flag = true; + break; + case "鍓�": + //Rotation涓�0~180鏃舵樉绀� + if (RotationF <= 90 - delta && Rotation >= -90 + delta && Rotation <= 90 - delta) + flag = true; + break; + case "鍙�": + //Rotation涓�0~180鏃舵樉绀� + if (RotationF <= 90 - delta && Rotation >= -180 + delta && Rotation <= 0 - delta) + flag = true; + break; + case "鍚�": + //Rotation涓�0~180鏃舵樉绀� + if (RotationF <= 90 - delta && ((Rotation >= 90 + delta && Rotation<=180)||( Rotation>=-180 && Rotation <= -90 - delta))) + flag = true; + break; + case "涓�": + if (RotationF >= 0 + delta) + flag = true; + break; + case "涓�": + if (RotationF <= 0 - delta) + flag = true; + break; + } + return flag; + + var faceVertices = area.InnerNodes; + if (faceVertices.Count < 3) return false; + PointF3D faceVertexA = faceVertices[0].Position3D; + PointF3D faceVertexB = faceVertices[1].Position3D; + PointF3D faceVertexC = faceVertices[2].Position3D; + + // 璁$畻娉曞悜閲� + PointF3D AB = faceVertexB - faceVertexA; + PointF3D AC = faceVertexC - faceVertexA; + PointF3D normal = AB ^ AC; + + // 璁$畻浠庣浉鏈轰綅缃埌闈㈢殑鍚戦噺 + PointF3D PD = faceVertexA - cameraPosition; + + // 璁$畻鐐圭Н + float dotProduct = normal * PD; + + // 鍒ゆ柇闈㈡槸鍚︽湞鍚戠浉鏈� + bool isFacingCamera = dotProduct > 0; + return isFacingCamera; + } + + + #endregion #region 鍒ゆ柇鍙鎬� private float Get_dist(PointF A, PointF B) -- Gitblit v1.9.3