From 17b67713b60e9940ddb0d3f9ea35bea04d99cea8 Mon Sep 17 00:00:00 2001
From: lixiaojun <1287241240@qq.com>
Date: 星期三, 25 九月 2024 01:49:46 +0800
Subject: [PATCH] l3d修改

---
 WinFrmUI/Yw.WinFrmUI.Hydro.L3d.Core/01-network/00-core/Network_Method.cs |  115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 111 insertions(+), 4 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 325afdc..f3be91b 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>
     /// 
@@ -46,8 +43,118 @@
             };
         }
 
+        /// <summary>
+        /// 鑾峰彇涓績鐐�
+        /// </summary>
+        public Point3d GetCenter(BoundingBox3d boundingBox)
+        {
+            if (boundingBox == null)
+            {
+                boundingBox = GetBoundingBox();
+            }
+            return boundingBox.GetCenter();
+        }
 
+        /// <summary>
+        /// 鑾峰彇瑙傚療淇℃伅
+        /// </summary>
+        public LookAt3d GetLookAt()
+        {
+            return new LookAt3d()
+            {
+                Eye = new Point3d(0, 0, 0),
+                Center = new Point3d(0, 0, 0),
+                Up = new Point3d(0, 1, 0)
+            };
+        }
 
+        /// <summary>
+        /// 鑾峰彇閫忚淇℃伅
+        /// </summary>
+        public Perspective3d GetPerspective(LookAt3d lookAt, SharpGL.OpenGLControl openglControl = null)
+        {
+            if (lookAt == null)
+            {
+                lookAt = GetLookAt();
+            }
+            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 bufferFactor = 1.2f;
+            var aspect = 1.25f;
+            if (openglControl != null)
+            {
+                aspect = (float)openglControl.Width / (float)openglControl.Height;
+            }
+            var near = minDistance * bufferFactor;
+            var far = maxDistance * bufferFactor;
+            return new Perspective3d()
+            {
+                Fovy = 45f,
+                Aspect = aspect,
+                Near = near,
+                Far = far
+            };
+        }
+
+        /// <summary>
+        /// 鑾峰彇鏃嬭浆淇℃伅
+        /// </summary>
+        /// <returns></returns>
+        public Point3d GetRotation()
+        {
+            return new Point3d();
+        }
+
+        /// <summary>
+        /// 鑾峰彇杞崲
+        /// </summary>
+        public Point3d GetTranslation(BoundingBox3d boudingBox, Point3d center)
+        {
+            if (boudingBox == null)
+            {
+                boudingBox = GetBoundingBox();
+            }
+            if (center == null)
+            {
+                center = GetCenter(boudingBox);
+            }
+            var zBufferFactor = 3f;
+            return new Point3d()
+            {
+                X = -center.X,
+                Y = -center.Y,
+                Z = -boudingBox.Max.Z * zBufferFactor
+            };
+        }
+
+        /// <summary>
+        /// 鑾峰彇鍙傛暟
+        /// </summary>
+        /// <returns></returns>
+        public NetworkParas GetParas(SharpGL.OpenGLControl openglControl = null)
+        {
+            var boundingBox = GetBoundingBox();
+            var center = boundingBox.GetCenter();
+            var lookAt = GetLookAt();
+            var perspective = GetPerspective(lookAt, openglControl);
+            var rotation = GetRotation();
+            var translation = GetTranslation(boundingBox, center);
+            return new NetworkParas()
+            {
+                BoundingBox = boundingBox,
+                Ceneter = center,
+                Perspective = perspective,
+                LookAt = lookAt,
+                Rotation = rotation,
+                Translation = translation
+            };
+        }
 
 
 

--
Gitblit v1.9.3