| | |
| | | namespace Yw.WinFrmUI.Hydro |
| | |  |
| | | using OpenTK.Mathematics; |
| | | |
| | | namespace Yw.WinFrmUI.Hydro |
| | | { |
| | | /// <summary> |
| | | /// |
| | |
| | | return boundingBox.GetCenter(); |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// ç»å¶2d |
| | | /// </summary> |
| | | public void Draw2d() |
| | | { |
| | | this.Links?.ForEach(x => x.Draw2d()); |
| | | this.Nodes?.ForEach(x => x.Draw2d()); |
| | | } |
| | | |
| | | |
| | | |
| | |
| | | /// </summary> |
| | | public VisualL3d(VisualL3d rhs) : base(rhs) { } |
| | | |
| | | /// <summary> |
| | | /// ç¶æ |
| | | /// </summary> |
| | | internal eVisualState State { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 2dç»å¶ |
| | | /// </summary> |
| | | public abstract void Draw2d(); |
| | | |
| | | |
| | | |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | namespace Yw.WinFrmUI.Hydro |
| | | { |
| | | /// <summary> |
| | | /// å¯è§ç¶æ |
| | | /// </summary> |
| | | internal enum eVisualState |
| | | { |
| | | /// <summary> |
| | | /// æ£å¸¸ |
| | | /// </summary> |
| | | Normal, |
| | | |
| | | /// <summary> |
| | | /// æ¬æµ® |
| | | /// </summary> |
| | | Hovered, |
| | | |
| | | /// <summary> |
| | | /// éæ© |
| | | /// </summary> |
| | | Selected |
| | | } |
| | | } |
| | |
| | | /// </summary> |
| | | public PointL3d Position { get; set; } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public override void Draw2d() |
| | | { |
| | | switch (this.State) |
| | | { |
| | | case eVisualState.Normal: DrawPoint2dHelper.Draw(5f, Color.Red, this.Position); break; |
| | | case eVisualState.Hovered: DrawPoint2dHelper.Draw(6f, ColorTranslator.FromHtml("#00BFFF"), this.Position); break; |
| | | case eVisualState.Selected: DrawPoint2dHelper.Draw(7f, ColorTranslator.FromHtml("#008000"), this.Position); break; |
| | | default: break; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | } |
| | |
| | | namespace Yw.WinFrmUI.Hydro |
| | | using OpenTK.Graphics.OpenGL; |
| | | |
| | | namespace Yw.WinFrmUI.Hydro |
| | | { |
| | | /// <summary> |
| | | /// è¿æ¥èç¹ |
| | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ç»å¶ |
| | | /// </summary> |
| | | public override void Draw2d() |
| | | { |
| | | switch (this.State) |
| | | { |
| | | case eVisualState.Normal: DrawLine2dHelper.Draw(2f, Color.Blue, this.StartPosition, this.EndPosition); break; |
| | | case eVisualState.Hovered: DrawLine2dHelper.Draw(3f, ColorTranslator.FromHtml("#00BFFF"), this.StartPosition, this.EndPosition); break; |
| | | case eVisualState.Selected: DrawLine2dHelper.Draw(3.5f, ColorTranslator.FromHtml("#800080"), this.StartPosition, this.EndPosition); break; |
| | | default: break; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using OpenTK.Graphics.OpenGL; |
| | | using System.Numerics; |
| | | |
| | | namespace Yw.WinFrmUI.Hydro |
| | | { |
| | | /// <summary> |
| | | /// ç»å¶2d线è¾
å©ç±» |
| | | /// </summary> |
| | | internal class DrawLine2dHelper |
| | | { |
| | | |
| | | /// <summary> |
| | | /// ç»å¶ |
| | | /// </summary> |
| | | /// <param name="width">线宽</param> |
| | | /// <param name="color">线è²</param> |
| | | /// <param name="spt">å¼å§ç¹</param> |
| | | /// <param name="ept">ç»æç¹</param> |
| | | public static void Draw(float width, Color color, PointL3d spt, PointL3d ept) |
| | | { |
| | | GL.LineWidth(width); |
| | | GL.Begin(PrimitiveType.Lines); |
| | | GL.Color3(color); |
| | | GL.Vertex3(spt.X, spt.Y, spt.Z); |
| | | GL.Vertex3(ept.X, ept.Y, ept.Z); |
| | | GL.End(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ç»å¶ |
| | | /// </summary> |
| | | /// <param name="width">线宽</param> |
| | | /// <param name="color">线è²</param> |
| | | /// <param name="spt">å¼å§ç¹</param> |
| | | /// <param name="ept">ç»æç¹</param> |
| | | public static void Draw(float width, Color color, Vector3 spt, Vector3 ept) |
| | | { |
| | | GL.LineWidth(width); |
| | | GL.Begin(PrimitiveType.Lines); |
| | | GL.Color3(color); |
| | | GL.Vertex3(spt.X, spt.Y, spt.Z); |
| | | GL.Vertex3(ept.X, ept.Y, ept.Z); |
| | | GL.End(); |
| | | } |
| | | |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using OpenTK.Graphics.OpenGL; |
| | | using OpenTK.Mathematics; |
| | | |
| | | namespace Yw.WinFrmUI.Hydro |
| | | { |
| | | /// <summary> |
| | | /// ç»å¶2dç¹è¾
å©ç±» |
| | | /// </summary> |
| | | internal class DrawPoint2dHelper |
| | | { |
| | | /// <summary> |
| | | /// ç»å¶ |
| | | /// </summary> |
| | | /// <param name="size">ç¹å¤§å°</param> |
| | | /// <param name="color">ç¹é¢è²</param> |
| | | /// <param name="pt">ç¹ä½ç½®</param> |
| | | public static void Draw(float size, Color color, PointL3d pt) |
| | | { |
| | | GL.PointSize(size); |
| | | GL.Begin(PrimitiveType.Points); |
| | | GL.Color3(Color.Red); |
| | | GL.Vertex3(pt.X, pt.Y, pt.Z); |
| | | GL.End(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ç»å¶ |
| | | /// </summary> |
| | | /// <param name="size">ç¹å¤§å°</param> |
| | | /// <param name="color">ç¹é¢è²</param> |
| | | /// <param name="pt">ç¹ä½ç½®</param> |
| | | public static void Draw(float size, Color color, Vector3 pt) |
| | | { |
| | | GL.PointSize(size); |
| | | GL.Begin(PrimitiveType.Points); |
| | | GL.Color3(Color.Red); |
| | | GL.Vertex3(pt.X, pt.Y, pt.Z); |
| | | GL.End(); |
| | | } |
| | | |
| | | } |
| | | } |
ÎļþÃû´Ó Yw.WinFrmUI.Hydro.L3d.Core/02-helper/OrthoCameraHelper.cs ÐÞ¸Ä |
| | |
| | | _radius = (_bx.Max - _bx.Min).Length / 2f; |
| | | } |
| | | |
| | | |
| | | //æ´æ°æ¨¡åç©éµ |
| | | private void UpdateModelMatrix() |
| | | { |
| | |
| | | //æ´æ°è§å¾ç©éµ |
| | | private void UpdateViewMatrix() |
| | | { |
| | | var eye = new Vector3(_mc.X, _mc.Y + _radius * this.Zoom * 2, _mc.Z); |
| | | var eye = new Vector3(_mc.X, _mc.Y, _mc.Z + this.Radius * 2); |
| | | var target = _mc; |
| | | var up = -Vector3.UnitZ; |
| | | var up = Vector3.UnitY; |
| | | var matrix = Matrix4.CreateFromQuaternion(_rotationQua); |
| | | matrix.Invert(); |
| | | eye = Vector3.TransformPosition(eye, matrix); |
| | | up = Vector3.TransformPosition(up, matrix); |
| | | _viewMatrix = Matrix4.LookAt(eye, target, up); |
| | | } |
| | | |
| | | //æ´æ°æå½±ç©éµ |
| | | public void UpdateProjectionMatrix() |
| | | private void UpdateProjectionMatrix() |
| | | { |
| | | var size = _radius * 2; |
| | | _pw = size; |
| | |
| | | _ph /= _aspect; |
| | | } |
| | | |
| | | _projectionMatrix = Matrix4.CreateOrthographic(_pw * this.Zoom, _ph * this.Zoom, _radius * this.Zoom, _radius * this.Zoom * 3); |
| | | _projectionMatrix = Matrix4.CreateOrthographic(_pw * this.Zoom, _ph * this.Zoom, _radius, _radius * 3); |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// æ´æ°è§å£ |
| | |
| | | _lastMousePos = e.Location; |
| | | gl.Invalidate(); |
| | | } |
| | | |
| | | |
| | | #endregion |
| | | |
ÎļþÃû´Ó Yw.WinFrmUI.Hydro.L3d.Core/03-control/OrthoDrawer2d.cs ÐÞ¸Ä |
| | |
| | | RenderGL(); |
| | | } |
| | | |
| | | //è·åèç¹ |
| | | private void DrawNodes() |
| | | { |
| | | if (_nw == null) |
| | | { |
| | | return; |
| | | } |
| | | GL.PointSize(5f); |
| | | GL.Begin(PrimitiveType.Points); |
| | | |
| | | foreach (NodeL3d node in _nw.Nodes) |
| | | { |
| | | // æ ¹æ®é«åº¦è®¾ç½®ä¸åé¢è² |
| | | GL.Color3(Color.Red); |
| | | GL.Vertex3(node.Position.X, node.Position.Y, node.Position.Z); |
| | | } |
| | | |
| | | GL.End(); |
| | | } |
| | | |
| | | //ç»å¶ç®¡æ®µ |
| | | private void DrawLinks() |
| | | { |
| | | GL.LineWidth(2.5f); |
| | | GL.Begin(PrimitiveType.Lines); |
| | | GL.Color3(Color.Blue); // 管éé¢è² |
| | | |
| | | foreach (var link in _nw.Links) |
| | | { |
| | | // ç»å¶ç®¡éèµ·ç¹åç»ç¹ |
| | | GL.Vertex3(link.StartPosition.X, link.StartPosition.Y, link.StartPosition.Z); |
| | | GL.Vertex3(link.EndPosition.X, link.EndPosition.Y, link.EndPosition.Z); |
| | | } |
| | | |
| | | GL.End(); |
| | | } |
| | | |
| | | // æ·»å åæ è½´æ¾ç¤º |
| | | private void DrawAxes() |
| | | { |
| | | var mc = _orthoHelper.MC; |
| | | var radius = _orthoHelper.Radius; |
| | | |
| | | GL.Begin(PrimitiveType.Lines); |
| | | |
| | | // Xè½´ï¼çº¢è²ï¼ |
| | | GL.Color3(Color.Red); |
| | | GL.Vertex3(mc); |
| | | GL.Vertex3(mc + Vector3.UnitX * radius); |
| | | // Yè½´ï¼ç»¿è²ï¼ |
| | | GL.Color3(Color.Green); |
| | | GL.Vertex3(mc); |
| | | GL.Vertex3(mc + Vector3.UnitY * radius); |
| | | // Zè½´ï¼èè²ï¼ |
| | | GL.Color3(Color.Blue); |
| | | GL.Vertex3(mc); |
| | | GL.Vertex3(mc + Vector3.UnitZ * radius); |
| | | GL.End(); |
| | | } |
| | | |
| | | private void DrawRotationCenter() |
| | | { |
| | | GL.Color3(Color.Red); |
| | | GL.Begin(PrimitiveType.Lines); |
| | | GL.Vertex3(_orthoHelper.MC - Vector3.UnitX * 0.5f); |
| | | GL.Vertex3(_orthoHelper.MC + Vector3.UnitX * 0.5f); |
| | | GL.Vertex3(_orthoHelper.MC - Vector3.UnitY * 0.5f); |
| | | GL.Vertex3(_orthoHelper.MC + Vector3.UnitY * 0.5f); |
| | | GL.End(); |
| | | } |
| | | |
| | | // 渲æ |
| | | private void RenderGL() |
| | |
| | | GL.LoadMatrix(ref viewMatrix); |
| | | |
| | | |
| | | DrawLinks(); |
| | | DrawNodes(); |
| | | |
| | | |
| | | //DrawAxes(); |
| | | |
| | | DrawRotationCenter(); |
| | | _nw.Draw2d(); |
| | | var code = GL.GetError(); |
| | | |
| | | this.glControl1.SwapBuffers(); |
| | | } |
| | |
| | | <Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
| | | <PropertyGroup /> |
| | | <ItemGroup> |
| | | <Compile Update="03-control\OrthoDrawer2d.cs"> |
| | | <Compile Update="04-control\OrthoDrawer2d.cs"> |
| | | <SubType>UserControl</SubType> |
| | | </Compile> |
| | | </ItemGroup> |