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/Tank.cs | 152 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 151 insertions(+), 1 deletions(-) diff --git a/WinFrmUI/Yw.WinFrmUI.Hydro.L3d.Core/01-network/02-node/Tank.cs b/WinFrmUI/Yw.WinFrmUI.Hydro.L3d.Core/01-network/02-node/Tank.cs index 8eea4b3..449ca79 100644 --- a/WinFrmUI/Yw.WinFrmUI.Hydro.L3d.Core/01-network/02-node/Tank.cs +++ b/WinFrmUI/Yw.WinFrmUI.Hydro.L3d.Core/01-network/02-node/Tank.cs @@ -5,7 +5,10 @@ /// </summary> public class Tank : Source { - + /// <summary> + /// 闀垮害 + /// </summary> + public float? Length { get; set; } /// <summary> /// 瀹藉害 @@ -18,6 +21,16 @@ public float? Height { get; set; } /// <summary> + /// 濉厖棰滆壊 + /// </summary> + public Color? FillColor { get; set; } + + /// <summary> + /// 鎮仠闀垮害 + /// </summary> + public float? HoveredLength { get; set; } + + /// <summary> /// 鎮仠瀹藉害 /// </summary> public float? HoveredWidth { get; set; } @@ -28,6 +41,16 @@ public float? HoveredHeight { get; set; } /// <summary> + /// 鎮仠濉厖棰滆壊 + /// </summary> + public Color? HoveredFillColor { get; set; } + + /// <summary> + /// 閫夋嫨闀垮害 + /// </summary> + public float? SelectedLength { get; set; } + + /// <summary> /// 閫夋嫨瀹藉害 /// </summary> public float? SelectedWidth { get; set; } @@ -37,6 +60,133 @@ /// </summary> public float? SelectedHeight { get; set; } + /// <summary> + /// 閫夋嫨濉厖棰滆壊 + /// </summary> + public Color? SelectedFillColor { get; set; } + + //鍖呭洿鐩� + private BoundingBox3d _boundingBox = null; + + //鑾峰彇鍖呭洿鐩� + private BoundingBox3d GetBoundingBox() + { + var length = this.Length.HasValue ? this.Length.Value : CacheHelper.HydroL3d.Tank.Size.Length; + var width = this.Width.HasValue ? this.Width.Value : CacheHelper.HydroL3d.Tank.Size.Width; + var height = this.Height.HasValue ? this.Height.Value : CacheHelper.HydroL3d.Tank.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.Tank.HoveredSize.Length; + var width = this.HoveredWidth.HasValue ? this.HoveredWidth.Value : CacheHelper.HydroL3d.Tank.HoveredSize.Width; + var height = this.HoveredHeight.HasValue ? this.HoveredHeight.Value : CacheHelper.HydroL3d.Tank.HoveredSize.Height; + var fillColor = this.HoveredFillColor.HasValue ? this.HoveredFillColor.Value : ColorTranslator.FromHtml(CacheHelper.HydroL3d.Tank.HoveredFill.Color); + DrawEllipsoid(gl, length / 2f, width / 2f, height / 2f, fillColor); + } + else if (this.Selected) + { + var length = this.SelectedLength.HasValue ? this.SelectedLength.Value : CacheHelper.HydroL3d.Tank.SelectedSize.Length; + var width = this.SelectedWidth.HasValue ? this.SelectedWidth.Value : CacheHelper.HydroL3d.Tank.SelectedSize.Width; + var height = this.SelectedHeight.HasValue ? this.SelectedHeight.Value : CacheHelper.HydroL3d.Tank.SelectedSize.Height; + var fillColor = this.SelectedFillColor.HasValue ? this.SelectedFillColor.Value : ColorTranslator.FromHtml(CacheHelper.HydroL3d.Tank.SelectedFill.Color); + DrawEllipsoid(gl, length / 2f, width / 2f, height / 2f, fillColor); + } + else + { + var length = this.Length.HasValue ? this.Length.Value : CacheHelper.HydroL3d.Tank.Size.Length; + var width = this.Width.HasValue ? this.Width.Value : CacheHelper.HydroL3d.Tank.Size.Width; + var height = this.Height.HasValue ? this.Height.Value : CacheHelper.HydroL3d.Tank.Size.Height; + var fillColor = this.FillColor.HasValue ? this.FillColor.Value : ColorTranslator.FromHtml(CacheHelper.HydroL3d.Tank.Fill.Color); + DrawEllipsoid(gl, length / 2f, width / 2f, height / 2f, fillColor); + } + } + + //缁樺埗妞悆浣� + private void DrawEllipsoid(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, fillColor.G, fillColor.B); + + + 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