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
    {
        Texture T = new Texture();
        Line MyLine = new Line(new xy(0, 0), new xy(2.5, 2));
        Arc MyArc = new Arc(new xy(0, 0), 2, System.Math.PI / 3, 0, true);
        Bezier MyBezier = new Bezier(new xy(0, 0), new xy(1, 1), new xy(2, -1), new xy(3, 0));
        QSpline MyQSpline = new QSpline(new xy(0, 0), new xy(3, 0), new xy(2.5, 2), 1.5);
        BSpline MyBSpline = new BSpline();
        Nurbs2d MyNurbs = new Nurbs2d();
        public override void OnPaint()
        {
           base.OnPaint();
            
            LightEnabled = false;
            PolygonMode = PolygonMode.Line;
        
            //     Line
            PushMatrix();
             Translate(-5, 1, 0);
            drawCurve(MyLine);
         xyArray   Pts = new xyArray(2);
            Pts[0] = MyLine.A;
            Pts[1] = MyLine.B;
            DrawPoints(Pts);
            drawText(Font,new xyz(1, 2, 0), "Line", 0);
            PopMatrix();
            //     Arc
            PushMatrix();
            Translate(-1, 1, 0);
            drawCurve(MyArc);
            Pts[0] = MyArc.A;
            Pts[1] = MyArc.B;
            DrawPoints(Pts);
            drawText(Font,new xyz(1, 2, 0), "Arc", 0);
            PopMatrix();
            // Bezier
            PushMatrix();
            Translate(3, 1, 0);
            drawCurve(MyBezier);
            drawText(Font,new xyz(1, 2, 0), "Bezier", 0);
            Pts = new xyArray(4);
            Pts.FromArray(MyBezier.Points);
            DrawPoints(Pts);
            PopMatrix();
            // QSpline
            PushMatrix();
            Translate(-5, -1.5, 0);
            drawCurve(MyQSpline);
            drawText(Font,new xyz(1, 2, 0), "QSpline", 0);
            Pts = new xyArray(3);
            Pts[0] = MyQSpline.A;
            Pts[1] = MyQSpline.ControlPoint;
            Pts[2] = MyQSpline.B;
            DrawPoints(Pts);
            // BSpline
            PopMatrix();
            PushMatrix();
            Translate(-1, -1.5, 0);
            drawCurve(MyBSpline);
            drawText(Font,new xyz(1, 2, 0), "BSpline", 0);
            DrawPoints(MyBSpline.ControlPoints);
            PopMatrix();
            // Nurbs
            PushMatrix();
            Translate(3, -1.5, 0);
            drawCurve(MyNurbs);
            drawText(Font,new xyz(1, 2, 0), "Nurbs", 0);
            DrawPoints(MyBSpline.ControlPoints);
            PopMatrix();
            LightEnabled = true;
        }
        void DrawPoints(xyArray Pts)
        {
            LightEnabled = false;
            for (int i = 0; i < Pts.Count; i++)
                drawPoint(Pts[i].toXYZ(), 0.2, true);
             LightEnabled = true;
        }
        Drawing3d.Font Font = new Drawing3d.Font("Modern");
        protected override void OnCreated()
        {
           
            base.OnCreated();
            BackColor = Color.White;
            Font.FontSize = 0.5;
          
            // Initialization of MyBspline & MyNurbs
            xyArray ControlPoints = new xyArray(10);
            ControlPoints[0] = new xy(0, 0);
            ControlPoints[1] = new xy(0.25, 3 / 3f);
            ControlPoints[2] = new xy(3 / 3f, 5 / 3f);
            ControlPoints[3] = new xy(4 / 3f, 1 / 3f);
            ControlPoints[4] = new xy(5 / 3f, 0);
            ControlPoints[5] = new xy(7 / 3f, 0);
            ControlPoints[6] = new xy(8 / 3f, -1 / 3f);
            ControlPoints[7] = new xy(9 / 3f, 3 / 3f);
            ControlPoints[8] = new xy(10 / 3f, 5 / 3f);
            ControlPoints[9] = new xy(11 / 3f, 1 / 3f);
            // Interpolationdegree
            MyBSpline.Degree = 2;
            MyBSpline.ControlPoints = ControlPoints;
            // The same Controlpoints
            MyNurbs.ControlPoints = ControlPoints;
            // Interpolationdegree
            MyNurbs.Degree = 3;
            MyNurbs.Weights = new double[] { 1, 0.3, 1, 0.2, 4, 1, 1.3, 1, 2, 1 };
        }
    }
}