using System.Windows.Forms; using System.Drawing; using Drawing3d; namespace Sample { public partial class Form1 : Form { MyDevice Device = new MyDevice(); public Form1() { InitializeComponent(); Device.WinControl = this; } } public class MyDevice:OpenGlDevice { CustomSurface MySurface = new CustomSurface(); public override void OnPaint() { base.OnPaint(); PolygonMode = PolygonMode.Line; MySurface.Paint(this); } protected override void OnCreated() { base.OnCreated(); BackColor = Color.White; MySurface.OnGetValue += MySurface_OnGetValue; MySurface.OnGetUDerivation += MySurface_OnGetUDerivation; MySurface.OnGetVDerivation += MySurface_OnGetVDerivation; MySurface.CompileEnable = false; } private xyz MySurface_OnGetVDerivation(object sender, double u, double v) { u = (u - 0.5) * 5; // map 0,1 --> -2.5,2.5 v = (v - 0.5) * 5; // map 0,1 --> -2.5,2.5 return new xyz(0, 1, v); } private xyz MySurface_OnGetUDerivation(object sender, double u, double v) { u = (u - 0.5) * 5; // map 0,1 --> -2.5,2.5 v = (v - 0.5) * 5; // map 0,1 --> -2.5,2.5 return new xyz(1, 0, u); } private xyz MySurface_OnGetValue(object sender, double u, double v) { u = (u - 0.5) * 5; // map 0,1 --> -2.5,2.5 v = (v - 0.5) * 5; // map 0,1 --> -2.5,2.5 return new xyz(u, v, (u * u + v * v) / 2); } } }