Beispiel #1
0
        public Point3d MultiplicateF(Point3d vertex, double[,] ar)
        {
            double[,] result = new double[1, 4];
            double[,] a = new double[1, 4];
            double[,] b = ar;
            a[0, 0] = vertex.x;
            a[0, 1] = vertex.y;
            a[0, 2] = vertex.z;
            a[0, 3] = W;

            for (int i = 0; i < 1; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    result[i, j] = 0;
                    for (int q = 0; q < 4; q++)
                        result[i, j] += a[i, q] * b[q, j];
                }
            }

            //for (int i = 0; i < 4; i++)
            //    for (int j = 0; j < 1; j++)
            //    {
            //        result[i, j] = 0;
            //        for (int r = 0; r < 4; r++)
            //            result[i, j] += a[i, r] * b[r, j];
            //    }
            return (new Point3d((float)(result[0, 0]),(float)(result[0, 1]),(float)(result[0, 2])));
        }
Beispiel #2
0
 private void btnbuild_Click(object sender, EventArgs e)
 {
     size = Convert.ToInt32(tbsize.Text);
     basepoint = new Point3d(Convert.ToDouble(tbbasex.Text), Convert.ToDouble(tbbasey.Text), Convert.ToDouble(tbbasez.Text));
     AddSphere();
     DrawSphere(false);
 }
        public GraphicModel(Point3d basepoint,float R,float LOD,Color color)
        {
            double x, y, z, fi, psi;
            Radius = R;
            for (fi = 0; fi < Math.PI; fi += LOD)
            {
                edgelist.Add(new Edge());
                for (psi = 0; psi < 2 * Math.PI + LOD; psi += LOD)
                {
                    x = basepoint.x + R * Math.Sin(psi) * Math.Cos(fi);
                    y = basepoint.y + R * Math.Sin(psi) * Math.Sin(fi);
                    z = basepoint.z + R * Math.Cos(psi);
                    edgelist[edgelist.Count - 1].vertex.Add(new Point3d((float)x, (float)y, (float)z));
                }
            }

            for (psi = 0; psi < Math.PI; psi += LOD)
            {
                edgelist.Add(new Edge());
                for (fi = 0; fi < 2 * Math.PI + LOD; fi += LOD)
                {
                    x = basepoint.x + R * Math.Sin(psi) * Math.Cos(fi);
                    y = basepoint.y + R * Math.Sin(psi) * Math.Sin(fi);
                    z = basepoint.z + R * Math.Cos(psi);
                    edgelist[edgelist.Count - 1].vertex.Add(new Point3d((float)x, (float)y, (float)z));

                }
            }

            ModelColor = color;
        }
Beispiel #4
0
 public Faces(Point3d pt1, Point3d pt2, Point3d pt3, Point3d pt4, Color color)
 {
     this.pt1 = pt1;
     this.pt2 = pt2;
     this.pt3 = pt3;
     this.pt4 = pt4;
     FaceColor = color;
 }
Beispiel #5
0
 public void RobertsSet(Point3d innerPoint)
 {
     _A = pt1.y * (pt3.z - pt4.z) + pt3.y * (pt4.z - pt1.z) + pt4.y * (pt1.z - pt3.z);
     _B = pt1.z * (pt3.x - pt4.x) + pt3.z * (pt4.x - pt1.x) + pt4.z * (pt1.x - pt3.x);
     _C = pt1.x * (pt3.y - pt4.y) + pt3.x * (pt4.y - pt1.y) + pt4.x * (pt1.y - pt3.y);
     _D = -(_A * pt4.x + _B * pt4.y + _C * pt4.z);
     if (innerPoint.x * _A + innerPoint.y * _B + innerPoint.z * _C + _D > 0) return;
     _A = -_A;
     _B = -_B;
     _C = -_C;
     _D = -_D;
 }
Beispiel #6
0
 private void btnFill_Click(object sender, EventArgs e)
 {
     pbMain.Refresh();
     var gM = pbMain.CreateGraphics();
     double viewparam1 = Convert.ToDouble(tbviewparam1.Text);
     double viewparam2 = Convert.ToDouble(tbviewparam2.Text);
     double viewparam3 = Convert.ToDouble(tbviewparam3.Text);
     double viewparam4 = Convert.ToDouble(tbviewparam4.Text);
     double lightx = Convert.ToDouble(tbLightX.Text);
     double lighty = Convert.ToDouble(tbLightY.Text);
     double lightz = Convert.ToDouble(tbLightZ.Text);
     var lightPoint = new Point3d(lightx, lighty, lightz);
     ModelsTree[ModelsTree.Count - 1].Fill(gM, MainViewType, viewparam1, viewparam2, viewparam3, viewparam4,chkLight.Checked,lightPoint);
 }
Beispiel #7
0
 public void LightDiffuse(Point3d vectorLight)
 {
     //var vectorLight = new Point3d(0,200,200);
     var vectorPoint = new Point3d((pt1.x + pt3.x) / 2, (pt1.y + pt3.y) / 2, (pt1.z+pt3.z)/2);
     double cosTetta = (vectorLight.x * vectorPoint.x + vectorLight.y * vectorPoint.y +
                       vectorLight.z * vectorPoint.z) / (
                                                        Math.Sqrt(Math.Pow(vectorLight.x, 2) +
                                                                  Math.Pow(vectorLight.y, 2) +
                                                                  Math.Pow(vectorLight.z, 2)) *
                                                        Math.Sqrt(Math.Pow(vectorPoint.x, 2) +
                                                                  Math.Pow(vectorPoint.y, 2) +
                                                                  Math.Pow(vectorPoint.z, 2)));
     double lighting = 100 + 100 * 0.6 * cosTetta;
     lighting = lighting > 255 ? 255 : lighting;
     lighting = lighting < 0 ? 0 : lighting;
     FaceColor = Color.FromArgb(Convert.ToInt32(lighting), Convert.ToInt32(lighting), Convert.ToInt32(lighting));
 }
Beispiel #8
0
        private void pbMain_MouseMove(object sender, MouseEventArgs e)
        {
            if (checkBox1.Checked)
            {
                pbMain.Refresh();
                var gM = pbMain.CreateGraphics();
                double viewparam1 = Convert.ToDouble(tbviewparam1.Text) + e.Delta;
                double viewparam2 = Convert.ToDouble(tbviewparam2.Text);
                double viewparam3 = Convert.ToDouble(tbviewparam3.Text) + e.Y - rotdelta.Y;
                double viewparam4 = Convert.ToDouble(tbviewparam4.Text) + e.X - rotdelta.X;
                rotdelta.X = e.X;
                rotdelta.Y = e.Y;
                tbviewparam3.Text = Convert.ToString(viewparam3);
                tbviewparam4.Text = Convert.ToString(viewparam4);
                double lightx = Convert.ToDouble(tbLightX.Text);
                double lighty = Convert.ToDouble(tbLightY.Text);
                double lightz = Convert.ToDouble(tbLightZ.Text);
                var lightPoint = new Point3d(lightx, lighty, lightz);
                ModelsTree[ModelsTree.Count - 1].DrawModelFast(gM, VIEWPORT, MainViewType, viewparam1, viewparam2, viewparam3, viewparam4, chkLight.Checked,lightPoint);

            }
        }
Beispiel #9
0
        private void pbFront_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                Point3d radpoint = new Point3d(e.X, e.Y, 0);
                size = Convert.ToInt32(Math.Sqrt((radpoint.x - basepoint.x) * (radpoint.x - basepoint.x) + (radpoint.y - basepoint.y) * (radpoint.y - basepoint.y)));
                basepoint.x -= VIEWPORT;
                basepoint.y -= VIEWPORT;
                AddSphere();
                DrawSphere(false);
            }
            if (e.Button == MouseButtons.Right)
            {
                float scrollangley = delta.X - e.X;   // need to fix
                float scrollanglex = delta.Y - e.Y;
                tbanglex.Text = Convert.ToString(scrollanglex);
                tbangley.Text = Convert.ToString(scrollangley);
                if (ModelsTree.Count != 0)
                UpdateSphere(ModelsTree[ModelsTree.Count - 1]);
            }
            if (e.Button == MouseButtons.Middle)
            {

                float scrollzoom = delta.Y - e.Y;  // need to fix
                scrollzoom=1+scrollzoom/70;
                tbScaleX.Text = Convert.ToString(scrollzoom);
                tbScaleY.Text = Convert.ToString(scrollzoom);
                tbScaleZ.Text = Convert.ToString(scrollzoom);
                if (ModelsTree.Count != 0)
                UpdateSphere(ModelsTree[ModelsTree.Count - 1]);
            }
        }
Beispiel #10
0
 private void pbFront_MouseDown(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     basepoint = new Point3d(e.X, e.Y, 0);
     if (e.Button == MouseButtons.Right)
         delta = e.Location;
     if (e.Button == MouseButtons.Middle)
         delta = e.Location;
 }
Beispiel #11
0
        private void mainForm_KeyDown(object sender, KeyEventArgs e)
        {
            if (checkBox1.Checked)
            {
                pbMain.Refresh();
                var gM = pbMain.CreateGraphics();

                double viewparam1 = Convert.ToDouble(tbviewparam1.Text) ;
                double viewparam2 = Convert.ToDouble(tbviewparam2.Text);
                double viewparam3 = Convert.ToDouble(tbviewparam3.Text);
                double viewparam4 = Convert.ToDouble(tbviewparam4.Text);
                double lightx = Convert.ToDouble(tbLightX.Text);
                double lighty = Convert.ToDouble(tbLightY.Text);
                double lightz = Convert.ToDouble(tbLightZ.Text);
                var lightPoint = new Point3d(lightx, lighty, lightz);
                switch ( e.KeyData)
                {
                    case Keys.W:
                        viewparam1 += 5;
                        break;
                    case Keys.S:
                        viewparam1 -= 5;
                        break;
                }
                tbviewparam1.Text = Convert.ToString(viewparam1);

                ModelsTree[ModelsTree.Count - 1].DrawModelFast(gM, VIEWPORT, MainViewType, viewparam1, viewparam2, viewparam3, viewparam4,chkLight.Checked,lightPoint);

            }
        }
Beispiel #12
0
 // Draws main view
 private void Draw2D(Graphics g,
     Point3d pt1,
     Point3d pt2,
     byte MainViewType,
     double viewparam1,
     double viewparam2,
     double viewparam3,
     double viewparam4)
 {
     var pen = new Pen(ModelColor, 1);
     Point3d point1=null;
     Point3d point2=null;
     switch (MainViewType)
     {
         case 0: point1 = pt1.Aksonometrik(viewparam1, viewparam2); point2 = pt2.Aksonometrik(viewparam1, viewparam2); break;
         case 1: point1 = pt1.Kosougol(viewparam1, viewparam2); point2 = pt2.Kosougol(viewparam1, viewparam2); break;
         case 2: point1 = pt1.Perspect(viewparam1, viewparam2, viewparam3, viewparam4); point2 = pt2.Perspect(viewparam1, viewparam2, viewparam3, viewparam4); break;
     }
     g.DrawLine(pen, point1.ToPoitntFxy(), point2.ToPoitntFxy());
 }
Beispiel #13
0
        public void Fill(Graphics eGraphics,
            byte mainViewType,
            double viewparam1,
            double viewparam2,
            double viewparam3,
            double viewparam4,
            bool light,
            Point3d lightPoint)
        {
            faceslist.Clear();

            for (var i = edgelist.Count/2; i < edgelist.Count; i++)
            {
                for (var j = 0; j < edgelist[0].vertex.Count; j++)
                {
                    Point3d point1=null;
                    Point3d point2=null;
                    Point3d point3=null;
                    Point3d point4=null;
                    var jNext = (j != edgelist[0].vertex.Count-1) ? j + 1 : 0;
                    var iNext = i + 1;
                    if (i == edgelist.Count / 2)
                    {
                        point1 = edgelist[edgelist.Count / 2].vertex[0];
                        point2 = point1;
                        point3 = edgelist[iNext].vertex[j];
                        point4 = edgelist[iNext].vertex[jNext];
                    }
                    else
                    if (i != edgelist.Count - 1)
                    {

                        point1 = edgelist[i].vertex[j];
                        point2 = edgelist[i].vertex[jNext];
                        point3 = edgelist[iNext].vertex[jNext];
                        point4 = edgelist[iNext].vertex[j];
                    }
                    else
                    {
                        point1 = edgelist[i].vertex[j];
                        point2 = edgelist[i].vertex[jNext];
                        point3 = new Point3d(edgelist[0].vertex[0].x, edgelist[0].vertex[0].y, edgelist[0].vertex[0].z-2*Radius);
                        point4 = point3;
                    }
                    //var iNext = (i != edgelist.Count - 1) ? i + 1 : i ;

                    //Point3d point1 = edgelist[i].vertex[j];
                    //Point3d point2 = edgelist[i].vertex[jNext];
                    //Point3d point3 = edgelist[iNext].vertex[jNext];
                    //Point3d point4 = edgelist[iNext].vertex[j];
                    var f = new Faces(point1, point2, point3, point4, ModelColor);
                    if (light) f.LightDiffuse(lightPoint);
                    switch (mainViewType)
                    {
                        case 0:
                            f.pt1 = f.pt1.Aksonometrik(viewparam1, viewparam2);
                            f.pt2 = f.pt2.Aksonometrik(viewparam1, viewparam2);
                            f.pt3 = f.pt3.Aksonometrik(viewparam1, viewparam2);
                            f.pt4 = f.pt4.Aksonometrik(viewparam1, viewparam2);
                            break;
                        case 1:
                            f.pt1 = f.pt1.Kosougol(viewparam1, viewparam2);
                            f.pt2 = f.pt2.Kosougol(viewparam1, viewparam2);
                            f.pt3 = f.pt3.Kosougol(viewparam1, viewparam2);
                            f.pt4 = f.pt4.Kosougol(viewparam1, viewparam2);
                            break;
                        case 2:
                            f.pt1 = f.pt1.Perspect(viewparam1, viewparam2, viewparam3, viewparam4);
                            f.pt2 = f.pt2.Perspect(viewparam1, viewparam2, viewparam3, viewparam4);
                            f.pt3 = f.pt3.Perspect(viewparam1, viewparam2, viewparam3, viewparam4);
                            f.pt4 = f.pt4.Perspect(viewparam1, viewparam2, viewparam3, viewparam4);
                            break;
                    }

                    f.RobertsSet(new Point3d(0,0,0));
                    if (f.RobertsCheck())
                        f.DrawIt(eGraphics, light);
                    //faceslist.Add(f);
                }
            }
            //foreach (var f in faceslist)
            //{

            //    f.DrawIt(eGraphics, light);
            //}
        }
Beispiel #14
0
 // Draws model
 public void DrawModelFast(
     Graphics MainView,
     float size,
     byte MainViewType,
     double viewparam1,
     double viewparam2,
     double viewparam3,
     double viewparam4,
     bool light,
     Point3d lightPoint)
 {
     this.Fill(MainView,MainViewType,viewparam1,viewparam2,viewparam3,viewparam4,light,lightPoint);
 }