From 12a6316ffa897b4ce4205f545b88359195b386d6 Mon Sep 17 00:00:00 2001 From: duheng <2784771470@qq.com> Date: 星期三, 25 九月 2024 17:34:24 +0800 Subject: [PATCH] Merge branch 'master' of http://47.103.154.90:83/r/HStation/XHS.V1.0 --- WinFrmUI/Yw.WinFrmUI.Hydro.L3d.Core/01-network/02-node/Junction.cs | 135 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 135 insertions(+), 0 deletions(-) diff --git a/WinFrmUI/Yw.WinFrmUI.Hydro.L3d.Core/01-network/02-node/Junction.cs b/WinFrmUI/Yw.WinFrmUI.Hydro.L3d.Core/01-network/02-node/Junction.cs index bd751ed..387cae6 100644 --- a/WinFrmUI/Yw.WinFrmUI.Hydro.L3d.Core/01-network/02-node/Junction.cs +++ b/WinFrmUI/Yw.WinFrmUI.Hydro.L3d.Core/01-network/02-node/Junction.cs @@ -5,6 +5,10 @@ /// </summary> public class Junction : Node { + /// <summary> + /// 闀垮害 + /// </summary> + public float? Length { get; set; } /// <summary> /// 瀹藉害 @@ -22,6 +26,11 @@ public Color? FillColor { get; set; } /// <summary> + /// 鎮仠闀垮害 + /// </summary> + public float? HoveredLength { get; set; } + + /// <summary> /// 鎮仠瀹藉害 /// </summary> public float? HoveredWidth { get; set; } @@ -37,6 +46,11 @@ public Color? HoveredFillColor { get; set; } /// <summary> + /// 閫夋嫨闀垮害 + /// </summary> + public float? SelectedLength { get; set; } + + /// <summary> /// 閫夋嫨瀹藉害 /// </summary> public float? SelectedWidth { get; set; } @@ -51,6 +65,127 @@ /// </summary> public Color? SelectedFillColor { get; set; } + //鍖呭洿鐩� + private BoundingBox3d _boundingBox = null; + + //鑾峰彇鍖呭洿鐩� + private BoundingBox3d GetBoundingBox() + { + var length = this.Length.HasValue ? this.Length.Value : CacheHelper.HydroL3d.Junction.Size.Length; + var width = this.Width.HasValue ? this.Width.Value : CacheHelper.HydroL3d.Junction.Size.Width; + var height = this.Height.HasValue ? this.Height.Value : CacheHelper.HydroL3d.Junction.Size.Height; + return new BoundingBox3d() + { + Min = new Point3d() + { + X = this.Position.X - length / 2f, + Y = this.Position.Y - width / 2f, + Z = this.Position.Z - height / 2f + }, + Max = new Point3d() + { + X = this.Position.X + length / 2f, + Y = this.Position.Y + width / 2f, + Z = this.Position.Z + height / 2f + } + }; + } + + /// <summary> + /// 缁樺埗 + /// </summary> + public override void Draw(SharpGL.OpenGL gl) + { + _boundingBox = GetBoundingBox(); + if (this.Hovered) + { + var length = this.HoveredLength.HasValue ? this.HoveredLength.Value : CacheHelper.HydroL3d.Junction.HoveredSize.Length; + var width = this.HoveredWidth.HasValue ? this.HoveredWidth.Value : CacheHelper.HydroL3d.Junction.HoveredSize.Width; + var height = this.HoveredHeight.HasValue ? this.HoveredHeight.Value : CacheHelper.HydroL3d.Junction.HoveredSize.Height; + var fillColor = this.HoveredFillColor.HasValue ? this.HoveredFillColor.Value : ColorTranslator.FromHtml(CacheHelper.HydroL3d.Junction.HoveredFill.Color); + DrawJunction(gl, length / 2f, width / 2f, height / 2f, fillColor); + } + else if (this.Selected) + { + var length = this.SelectedLength.HasValue ? this.SelectedLength.Value : CacheHelper.HydroL3d.Junction.SelectedSize.Length; + var width = this.SelectedWidth.HasValue ? this.SelectedWidth.Value : CacheHelper.HydroL3d.Junction.SelectedSize.Width; + var height = this.SelectedHeight.HasValue ? this.SelectedHeight.Value : CacheHelper.HydroL3d.Junction.SelectedSize.Height; + var fillColor = this.SelectedFillColor.HasValue ? this.SelectedFillColor.Value : ColorTranslator.FromHtml(CacheHelper.HydroL3d.Junction.SelectedFill.Color); + DrawJunction(gl, length / 2f, width / 2f, height / 2f, fillColor); + } + else + { + var length = this.Length.HasValue ? this.Length.Value : CacheHelper.HydroL3d.Junction.Size.Length; + var width = this.Width.HasValue ? this.Width.Value : CacheHelper.HydroL3d.Junction.Size.Width; + var height = this.Height.HasValue ? this.Height.Value : CacheHelper.HydroL3d.Junction.Size.Height; + var fillColor = this.FillColor.HasValue ? this.FillColor.Value : ColorTranslator.FromHtml(CacheHelper.HydroL3d.Junction.Fill.Color); + DrawJunction(gl, length / 2f, width / 2f, height / 2f, fillColor); + } + } + + //缁樺埗鑺傜偣 + private void DrawJunction(OpenGL gl, float halfLength, float halfWidth, float halfHeight, Color fillColor) + { + const int stacks = 32; + const int slices = 32; + + // 璁剧疆妞悆浣撶殑涓績鐐瑰潗鏍� + float x0 = this.Position.X; + float y0 = this.Position.Y; + float z0 = this.Position.Z; + + // 璁剧疆妞悆浣撶殑鍗婅酱闀� + float a = halfLength; + float b = halfWidth; + float c = halfHeight; + + gl.Color(fillColor.R / 255f, fillColor.G / 255f, fillColor.B / 255f); + + + for (int i = 0; i < stacks; i++) + { + float lat0 = ((float)i / (float)stacks - 0.5f) * (float)MathF.PI; + float z0_ = (float)MathF.Sin(lat0); + float zr0 = (float)MathF.Cos(lat0); + + float lat1 = ((float)(i + 1) / (float)stacks - 0.5f) * (float)MathF.PI; + float z1_ = (float)MathF.Sin(lat1); + float zr1 = (float)MathF.Cos(lat1); + + gl.Begin(SharpGL.OpenGL.GL_TRIANGLE_STRIP); + for (int j = 0; j <= slices; j++) + { + float lng = ((float)j / (float)slices) * 2.0f * (float)MathF.PI; + + // 鏍规嵁妞悆浣撴柟绋嬭绠楅《鐐瑰潗鏍囧苟鍔犱笂涓績鐐瑰潗鏍� + float x = a * (float)MathF.Cos(lng) * zr0 + x0; + float y = b * (float)MathF.Sin(lng) * zr0 + y0; + float z = c * z0_ + z0; + gl.Color(1.0f, 0.0f, 0.0f); + gl.Vertex(x, y, z); + + x = a * (float)MathF.Cos(lng) * zr1 + x0; + y = b * (float)MathF.Sin(lng) * zr1 + y0; + z = c * z1_ + z0; + gl.Color(1.0f, 0.0f, 0.0f); + gl.Vertex(x, y, z); + } + gl.End(); + } + } + + + /// <summary> + /// 鍖呭惈 + /// </summary> + public override bool Contains(Point3d pt) + { + if (_boundingBox == null) + { + return false; + } + return _boundingBox.Contains(pt); + } -- Gitblit v1.9.3