From 00ab1b5282ada6ffdc78b3dd46f0ce08726a51e6 Mon Sep 17 00:00:00 2001
From: qin <a@163.com>
Date: 星期四, 20 三月 2025 13:47:24 +0800
Subject: [PATCH] 优化IBox界面

---
 WinFrmUI/Yw.WinFrmUI.Hydro.L3d.Core/01-network/00-core/Network_Method.cs |  238 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 224 insertions(+), 14 deletions(-)

diff --git a/WinFrmUI/Yw.WinFrmUI.Hydro.L3d.Core/01-network/00-core/Network_Method.cs b/WinFrmUI/Yw.WinFrmUI.Hydro.L3d.Core/01-network/00-core/Network_Method.cs
index 527a3ae..d343157 100644
--- a/WinFrmUI/Yw.WinFrmUI.Hydro.L3d.Core/01-network/00-core/Network_Method.cs
+++ b/WinFrmUI/Yw.WinFrmUI.Hydro.L3d.Core/01-network/00-core/Network_Method.cs
@@ -1,7 +1,4 @@
-锘縰sing DevExpress.CodeParser;
-using DevExpress.DataAccess.MongoDB;
-
-namespace Yw.WinFrmUI.HydroL3d
+锘縩amespace Yw.WinFrmUI.HydroL3d
 {
     /// <summary>
     /// 
@@ -22,28 +19,241 @@
         /// </summary>
         public BoundingBox3d GetBoundingBox()
         {
-            var bd = new BoundingBox3d();
-            bd.Min = new Point3d();
-            bd.Max = new Point3d();
+            var minX = float.MaxValue;
+            var minY = float.MaxValue;
+            var minZ = float.MaxValue;
+            var maxX = float.MinValue;
+            var maxY = float.MinValue;
+            var maxZ = float.MinValue;
 
             foreach (var node in this.Nodes)
             {
-                bd.Min.X = Math.Min(bd.Min.X, node.Position.X);
-                bd.Max.X = Math.Max(bd.Max.X, node.Position.X);
-                bd.Min.Y = Math.Min(bd.Min.Y, node.Position.Y);
-                bd.Max.Y = Math.Max(bd.Max.Y, node.Position.Y);
-                bd.Min.Z = Math.Min(bd.Min.Z, node.Position.Z);
-                bd.Max.Z = Math.Max(bd.Max.Z, node.Position.Z);
+                minX = Math.Min(minX, node.Position.X);
+                minY = Math.Min(minY, node.Position.Y);
+                minZ = Math.Min(minZ, node.Position.Z);
+                maxX = Math.Max(maxX, node.Position.X);
+                maxY = Math.Max(maxY, node.Position.Y);
+                maxZ = Math.Max(maxZ, node.Position.Z);
             }
 
-            return bd;
+            return new BoundingBox3d()
+            {
+                Min = new Point3d(minX, minY, minZ),
+                Max = new Point3d(maxX, maxY, maxZ)
+            };
+        }
+
+        /// <summary>
+        /// 鑾峰彇涓績鐐�
+        /// </summary>
+        public Point3d GetCenter(BoundingBox3d boundingBox)
+        {
+            if (boundingBox == null)
+            {
+                boundingBox = GetBoundingBox();
+            }
+            return boundingBox.GetCenter();
+        }
+
+        /// <summary>
+        /// 鑾峰彇杞崲
+        /// </summary>
+        public Point3d GetTranslation(BoundingBox3d boundingBox, Point3d center)
+        {
+            if (boundingBox == null)
+            {
+                boundingBox = GetBoundingBox();
+            }
+            if (center == null)
+            {
+                center = GetCenter(boundingBox);
+            }
+            return new Point3d()
+            {
+                X = -center.X,
+                Y = -center.Y,
+                Z = -center.Z
+            };
+        }
+
+        /// <summary>
+        /// 鑾峰彇鏃嬭浆淇℃伅
+        /// </summary>
+        /// <returns></returns>
+        public Point3d GetRotation()
+        {
+            return new Point3d();
+        }
+
+        /// <summary>
+        /// 缂╂斁
+        /// </summary>
+        public Point3d GetScale()
+        {
+            return new Point3d() { X = 1f, Y = 1f, Z = 1f };
+        }
+
+        /// <summary>
+        /// 鑾峰彇瑙傚療淇℃伅
+        /// </summary>
+        public LookAt3d GetLookAt(BoundingBox3d boundingBox, Point3d center)
+        {
+            if (boundingBox == null)
+            {
+                boundingBox = GetBoundingBox();
+            }
+            if (center == null)
+            {
+                center = boundingBox.GetCenter();
+            }
+            return new LookAt3d()
+            {
+                Eye = new Point3d(0, 0, 3 * boundingBox.Max.Z),
+                Center = new Point3d(0, 0, 0),
+                Up = new Point3d(0, 1, 0)
+            };
+        }
+
+        /// <summary>
+        /// 鑾峰彇閫忚淇℃伅
+        /// </summary>
+        public Perspective3d GetPerspective(BoundingBox3d boundingBox, Point3d center, LookAt3d lookAt, SharpGL.OpenGLControl openglControl = null)
+        {
+            if (boundingBox == null)
+            {
+                boundingBox = GetBoundingBox();
+            }
+            if (center == null)
+            {
+                center = boundingBox.GetCenter();
+            }
+            if (lookAt == null)
+            {
+                lookAt = GetLookAt(boundingBox, center);
+            }
+            var minDistance = float.MaxValue;
+            var maxDistance = float.MinValue;
+            foreach (var node in this.Nodes)
+            {
+                var distance = lookAt.Eye.Distance(node.Position);
+                minDistance = MathF.Min(minDistance, distance);
+                maxDistance = MathF.Max(maxDistance, distance);
+            }
+            var fovy = 45f;
+            var aspect = 1.25f;
+            if (openglControl != null)
+            {
+                aspect = (float)openglControl.Width / (float)openglControl.Height;
+            }
+            var bufferFactor = 1.2f;
+            var near = minDistance / 100f;
+            var far = maxDistance * 5f * bufferFactor;
+            return new Perspective3d()
+            {
+                Fovy = fovy,
+                Aspect = aspect,
+                Near = near,
+                Far = far
+            };
         }
 
 
+        /// <summary>
+        /// 鑾峰彇鍙傛暟
+        /// </summary>
+        /// <returns></returns>
+        public NetworkParas GetParas(SharpGL.OpenGLControl openglControl = null)
+        {
+            var boundingBox = GetBoundingBox();
+            var center = boundingBox.GetCenter();
+            var translation = GetTranslation(boundingBox, center);
+            var scale = GetScale();
+            var rotation = GetRotation();
+            var lookAt = GetLookAt(boundingBox, center);
+            var perspective = GetPerspective(boundingBox, center, lookAt, openglControl);
 
+            return new NetworkParas()
+            {
+                BoundingBox = boundingBox,
+                Ceneter = center,
+                Translation = translation,
+                Rotation = rotation,
+                Scale = scale,
+                LookAt = lookAt,
+                Perspective = perspective,
+            };
+        }
 
+        /// <summary>
+        /// 缁樺埗
+        /// </summary>
+        public void Draw(SharpGL.OpenGL gl)
+        {
+            foreach (var link in this.Links)
+            {
+                link.Draw(gl);
+            }
+            foreach (var node in this.Nodes)
+            {
+                node.Draw(gl);
+            }
+        }
 
+        /// <summary>
+        /// 閫夋嫨
+        /// </summary>
+        public List<Parter> Select(Point3d pt)
+        {
+            int i = 0;
+            foreach (var node in this.Nodes)
+            {
+                node.Selected = node.Contains(pt);
+                if (node.Selected)
+                {
+                    i++;
+                }
+            }
 
+            if (i > 0)
+            {
+                this.Links.ForEach(x => x.Selected = false);
+                return this.Nodes.Where(x => x.Selected).Select(x => x as Parter).ToList();
+            }
+
+            foreach (var link in this.Links)
+            {
+                link.Selected = link.Contains(pt);
+            }
+            return this.Links.Where(x => x.Selected).Select(x => x as Parter).ToList();
+        }
+
+        /// <summary>
+        /// 鎮仠
+        /// </summary>
+        public List<Parter> Hover(Point3d pt)
+        {
+            int i = 0;
+            foreach (var node in this.Nodes)
+            {
+                node.Hovered = node.Contains(pt);
+                if (node.Hovered)
+                {
+                    i++;
+                }
+            }
+
+            if (i > 0)
+            {
+                this.Links.ForEach(x => x.Hovered = false);
+                return this.Nodes.Where(x => x.Hovered).Select(x => x as Parter).ToList();
+            }
+
+            foreach (var link in this.Links)
+            {
+                link.Hovered = link.Contains(pt);
+            }
+            return this.Links.Where(x => x.Hovered).Select(x => x as Parter).ToList();
+        }
 
 
 

--
Gitblit v1.9.3