Esempio n. 1
0
        public virtual void Draw_without_colors(Graphics3D graphics)
        {
            //foreach(var vertex in Vertices)
            //{
            //    graphics.DrawPoint(vertex, Color.Black);
            //}

            foreach (var verge in Verges)
            {
                Vector p1 = Vertices[verge[0]];
                Vector p2 = Vertices[verge[1]];
                Vector p3 = Vertices[verge[2]];

                double[,] matrix = new double[2, 3];
                matrix[0, 0]     = p2.X - p1.X;
                matrix[0, 1]     = p2.Y - p1.Y;
                matrix[0, 2]     = p2.Z - p1.Z;
                matrix[1, 0]     = p3.X - p1.X;
                matrix[1, 1]     = p3.Y - p1.Y;
                matrix[1, 2]     = p3.Z - p1.Z;

                double ni = matrix[0, 1] * matrix[1, 2] - matrix[0, 2] * matrix[1, 1];
                double nj = matrix[0, 2] * matrix[1, 0] - matrix[0, 0] * matrix[1, 2];
                double nk = matrix[0, 0] * matrix[1, 1] - matrix[0, 1] * matrix[1, 0];
                double d  = -(ni * p1.X + nj * p1.Y + nk * p1.Z);

                Vector pp   = new Vector(p1.X + ni, p1.Y + nj, p1.Z + nk);
                double val1 = ni * pp.X + nj * pp.Y + nk * pp.Z + d;
                double val2 = ni * Center.X + nj * Center.Y + nk * Center.Z + d;

                if (val1 * val2 > 0)
                {
                    ni = -ni;
                    nj = -nj;
                    nk = -nk;
                }

                if (ni * 1 + nj * 1 + nk * 1 > 0)
                {
                    graphics.DrawPoint(Vertices[verge[0]], Color.Black);
                    for (int i = 1; i < verge.Length; ++i)
                    {
                        graphics.DrawPoint(Vertices[verge[i]], Color.Black);
                        graphics.DrawLine(Vertices[verge[i - 1]], Vertices[verge[i]]);
                    }
                    graphics.DrawLine(Vertices[verge[verge.Length - 1]], Vertices[verge[0]]);
                }
            }
        }
Esempio n. 2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            if (current_primitive == null)
            {
                return;
            }
            e.Graphics.Clear(SystemColors.Control);
            e.Graphics.DrawLines(Pens.Black, new Point[]
            {
                new Point(1, 1),
                new Point(1, Height - 1),
                new Point(Width - 1, Height - 1),
                new Point(Width - 1, 1),
                new Point(1, 1)
            });

            if (current_primitive == null)
            {
                return;
            }

            var graphics3D = new Graphics3D(e.Graphics, ViewCamera.ViewProjection, Width, Height);


            if (without_colors)
            {
                current_primitive.Draw_without_colors(graphics3D);
            }
            else
            {
                var x = new Vector(0.8, 0, 0);
                var y = new Vector(0, 0.8, 0);
                var z = new Vector(0, 0, 0.8);
                graphics3D.DrawLine(new Vector(0, 0, 0), x, new Pen(Color.Red, 2));
                graphics3D.DrawPoint(x, Color.Red);
                graphics3D.DrawLine(new Vector(0, 0, 0), y, new Pen(Color.Green, 2));
                graphics3D.DrawPoint(y, Color.Green);
                graphics3D.DrawLine(new Vector(0, 0, 0), z, new Pen(Color.Blue, 2));
                graphics3D.DrawPoint(z, Color.Blue);
                current_primitive.Draw(graphics3D);
            }

            e.Graphics.DrawImage(graphics3D.ColorBuffer, 0, 0);
        }
Esempio n. 3
0
        public virtual void Draw(Graphics3D graphics)
        {
            Random r = new Random(256);

            foreach (var verge in Verges)
            {
                int k  = r.Next(0, 256);
                int k2 = r.Next(0, 256);
                int k3 = r.Next(0, 256);

                for (int i = 1; i < verge.Length - 1; ++i)
                {
                    var a = new Vertex(Vertices[verge[0]], new Vector(), Color.FromArgb(k2, k, k3));
                    var b = new Vertex(Vertices[verge[i]], new Vector(), Color.FromArgb(k2, k, k3));
                    var c = new Vertex(Vertices[verge[i + 1]], new Vector(), Color.FromArgb(k2, k, k3));
                    graphics.DrawTriangle(a, b, c);
                }
            }
        }
Esempio n. 4
0
        private void PictureBox1_Paint(object sender, PaintEventArgs e)
        {
            //e.Graphics.Clear(Color.White);
            if (current_primitive == null)
            {
                return;
            }

            var graphics3D = new Graphics3D(e.Graphics, camera.ViewProjection, pictureBox1.Width, pictureBox1.Height, camera.Position);

            /*var x = new Vector(1, 0, 0);
             * var y = new Vector(0, 1, 0);
             * var z = new Vector(0, 0, 1);
             * graphics3D.DrawLine(new Vector(0, 0, 0), x, new Pen(Color.Red, 2));
             * graphics3D.DrawPoint(x, Color.Red);
             * graphics3D.DrawLine(new Vector(0, 0, 0), y, new Pen(Color.Green, 2));
             * graphics3D.DrawPoint(y, Color.Green);
             * graphics3D.DrawLine(new Vector(0, 0, 0), z, new Pen(Color.Blue, 2));
             * graphics3D.DrawPoint(z, Color.Blue);*/

            if (without_colors)
            {
                current_primitive.Draw_without_colors(graphics3D);
            }
            else if (moreThanOneObj)
            {
                foreach (var obj in objects)
                {
                    obj.Draw(graphics3D);
                }
            }
            else
            {
                current_primitive.Draw(graphics3D);
            }

            e.Graphics.DrawImage(graphics3D.ColorBuffer, 0, 0);
        }