lixiaojun
6 天以前 fba4613d6b8dcbcaea6c7dc83bda14ed49d2f6de
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using OpenTK.Graphics.OpenGL;
using OpenTK.Mathematics;
using OpenTK.Windowing.Common;
using System.Drawing;
 
namespace Yw.WinFrmUI.Hydro
{
    /// <summary>
    /// 绘制水泵2d辅助类
    /// </summary>
    internal static class DrawPump2dExtensions
    {
        /// <summary>
        /// 绘制水源
        /// </summary>
        public static void Draw2d(this PumpL3d pump, float zoom)
        {
            var width = pump.Style2d.Normal.Width;
            var color = pump.Style2d.Normal.Color;
            if (pump.IsSelected)
            {
                width = pump.Style2d.Selected.Width;
                color = pump.Style2d.Selected.Color;
            }
            if (pump.IsHovered)
            {
                width = pump.Style2d.Hovered.Width;
                color = pump.Style2d.Hovered.Color;
            }
 
            Draw2dHelper.DrawLine(width, color, pump.StartPosition, pump.EndPosition);
 
            var start = new Vector3(pump.StartPosition.X, pump.StartPosition.Y, pump.StartPosition.Z);
            var end = new Vector3(pump.EndPosition.X, pump.EndPosition.Y, pump.EndPosition.Z);
            var middle = (start + end) / 2f;
            var direction = (start - middle).Normalized();
            var circle = middle + direction * (width * zoom * 2f);
            Draw2dHelper.DrawPoint(width * 4f, color, circle);
 
 
            direction = (end - circle).Normalized();
 
            var rect = circle + direction * (width * zoom * 4f);
 
            // 选择一个辅助向量(这里选择 Y 轴正方向)
            Vector3 up = Vector3.UnitY;
            if (MathHelper.Abs(Vector3.Dot(direction, up)) > 0.99f)
            {
                up = Vector3.UnitZ;
            }
 
            // 计算垂直于线段方向的向量(即左侧方向)
            Vector3 leftDirection = Vector3.Cross(direction, up).Normalized();
 
            // 计算矩形的四个顶点
            Vector3 rectTopLeft = circle + leftDirection * (width * zoom);
            Vector3 rectTopRight = rect + leftDirection * (width * zoom);
            Vector3 rectBottomLeft = circle;
            Vector3 rectBottomRight = rect;
 
            // 绘制矩形
            Draw2dHelper.DrawRectangle(rectTopLeft, rectTopRight, rectBottomRight, rectBottomLeft, color);
 
 
        }
 
 
 
 
 
 
 
 
 
 
 
 
    }
 
 
}