| | |
| | | using DevExpress.CodeParser; |
| | | using DevExpress.DataAccess.MongoDB; |
| | | |
| | | namespace Yw.WinFrmUI.HydroL3d |
| | | namespace Yw.WinFrmUI.HydroL3d |
| | | { |
| | | /// <summary> |
| | | /// |
| | |
| | | /// </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 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 |
| | | }; |
| | | } |
| | | |
| | | |
| | | |