public Form1()
        {
            InitializeComponent();
            ProjectionBox.SelectedItem = ProjectionBox.Items[0];
            current_primitive          = Plot.get_plot(-0.8, 0.8, 0.1, -0.8, 0.8, 0.1);
            Matrix projection = Transformations.PerspectiveProjection(-0.1, 0.1, -0.1, 0.1, 0.1, 20);

            camera            = new Camera(new Vector(1, 1, 1), Math.PI / 4, -Math.Atan(1 / Math.Sqrt(3)), projection);
            sceneView1.Camera = camera;
        }
        //Rotate current primitive
        private void Rotate()
        {
            double rotatingX = DegreesToRadians((double)numericUpDown4.Value);
            double rotatingY = DegreesToRadians((double)numericUpDown5.Value);
            double rotatingZ = DegreesToRadians((double)numericUpDown6.Value);

            current_primitive.Apply(Transformations.RotateX(rotatingX)
                                    * Transformations.RotateY(rotatingY)
                                    * Transformations.RotateZ(rotatingZ));
            sceneView1.Refresh();
        }
        //Change current view to Plot
        private void ApplyProjection_Click(object sender, EventArgs e)
        {
            switch (ProjectionBox.SelectedItem.ToString())
            {
            case ("Перспективная"):
            {
                Matrix projection = Transformations.PerspectiveProjection(-0.1, 0.1, -0.1, 0.1, 0.1, 20);
                camera            = new Camera(new Vector(1, 1, 1), Math.PI / 4, -Math.Atan(1 / Math.Sqrt(3)), projection);
                sceneView1.Camera = camera;
                break;
            }

            case ("Ортографическая XY"):
            {
                camera            = new Camera(new Vector(0, 0, 0), 0, 0, Transformations.OrthogonalProjection());
                sceneView1.Camera = camera;
                break;
            }

            case ("Ортографическая XZ"):
            {
                camera            = new Camera(new Vector(0, 0, 0), 0, 0, Transformations.RotateX(Math.PI / 2) * Transformations.OrthogonalProjection());
                sceneView1.Camera = camera;
                break;
            }

            case ("Ортографическая YZ"):
            {
                camera            = new Camera(new Vector(0, 0, 0), 0, 0, Transformations.RotateY(-Math.PI / 2) * Transformations.OrthogonalProjection());
                sceneView1.Camera = camera;
                break;
            }

            default:
            {
                Matrix projection = Transformations.PerspectiveProjection(-0.1, 0.1, -0.1, 0.1, 0.1, 20);
                camera            = new Camera(new Vector(1, 1, 1), Math.PI / 4, -Math.Atan(1 / Math.Sqrt(3)), projection);
                sceneView1.Camera = camera;
                break;
            }
            }
            sceneView1.Refresh();
        }
Exemple #4
0
        public static Mesh get_plot(
            double x0, double x1, double dx, double z0, double z1, double dz,
            double AngleX = Math.PI / 4, double AngleY = Math.PI / 2, double AngleZ = Math.PI / 4)
        {
            int nx       = (int)((x1 - x0) / dx);
            int nz       = (int)((z1 - z0) / dz);
            var vertices = new Vector[nx * nz];
            var indices  = new int[(nx - 1) * (nz - 1)][];

            for (int i = 0; i < nx; ++i)
            {
                for (int j = 0; j < nz; ++j)
                {
                    var x = x0 + dx * i;
                    var z = z0 + dz * j;
                    vertices[i * nz + j] = new Vector(x, Func(x, z), z);
                }
            }
            for (int i = 0; i < nx - 1; ++i)
            {
                for (int j = 0; j < nz - 1; j++)
                {
                    indices[i * (nz - 1) + j] = new int[4] {
                        i *nz + j,
                        (i + 1) * nz + j,
                        (i + 1) * nz + j + 1,
                        i *nz + j + 1
                    };
                }
            }

            Mesh m = new Mesh(vertices, indices);

            m.Apply(Transformations.RotateX(-AngleX) *
                    Transformations.RotateY(0) *
                    Transformations.RotateZ(0));

            m.Apply(Transformations.RotateX(0) *
                    Transformations.RotateY(0) *
                    Transformations.RotateZ(-AngleZ));

            m.Apply(Transformations.RotateX(0) *
                    Transformations.RotateY(-AngleY) *
                    Transformations.RotateZ(0));

            int[][] del_y = DelBadY(vertices, indices, nz, nx);

            m = new Mesh(vertices, del_y);


            m.Apply(Transformations.RotateX(0) *
                    Transformations.RotateY(AngleY) *
                    Transformations.RotateZ(0));

            m.Apply(Transformations.RotateX(0) *
                    Transformations.RotateY(0) *
                    Transformations.RotateZ(AngleZ));

            m.Apply(Transformations.RotateX(AngleX) *
                    Transformations.RotateY(0) *
                    Transformations.RotateZ(0));

            return(m);
        }