using OpenTK.Graphics.OpenGL; namespace Yw.WinFrmUI.Hydro { /// /// 绘制水源2d辅助类 /// internal static class DrawSource2dExtensions { /// /// 绘制水源 /// public static void Draw2d(this SourceL3d source, float zoom) { var radiu = source.Style2d.Normal.Radiu; var color = source.Style2d.Normal.Color; if (source.IsSelected) { radiu = source.Style2d.Selected.Radiu; color = source.Style2d.Selected.Color; } if (source.IsHovered) { radiu = source.Style2d.Hovered.Radiu; color = source.Style2d.Hovered.Color; } radiu *= zoom; float z = source.Position.Z; //计算水池下方矩形的四个顶点相对于中心点的坐标 float left_b = source.Position.X - radiu * 1f; float right_b = source.Position.X + radiu * 1f; float bottom_b = source.Position.Y - radiu * 1.5f; float top_b = source.Position.Y; float left_t = source.Position.X - radiu * 2f; float right_t = source.Position.X + radiu * 2f; float bottom_t = source.Position.Y; float top_t = source.Position.Y + radiu * 1.5f; GL.Color3(color); // 绘制下方矩形 GL.Begin(PrimitiveType.Quads); GL.Vertex3(left_b, bottom_b, z); GL.Vertex3(right_b, bottom_b, z); GL.Vertex3(right_b, top_b, z); GL.Vertex3(left_b, top_b, z); GL.End(); // 绘制水池中的水 GL.Begin(PrimitiveType.Quads); GL.Vertex3(left_t, bottom_t, z); GL.Vertex3(right_t, bottom_t, z); GL.Vertex3(right_t, top_t, z); GL.Vertex3(left_t, top_t, z); GL.End(); } } }