// Create octahedron private void button3_Click(object sender, EventArgs e) { figure = new Polyhedron(); figure.make_octahedron(); if (bmp != null) { bmp.Dispose(); } rgbValues = getRGBValues(out bmp, out bmpData, out ptr, out bytes); figure.ApplyTexture(bmp, bmpData, rgbValues, texture, bmpDataTexture, rgbValuesTexture); System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes); bmp.UnlockBits(bmpData); pictureBox1.Image = bmp; }
private void button_exec_Click(object sender, EventArgs e) { if (figure == null) { MessageBox.Show("Сначала создайте фигуру", "Нет фигуры", MessageBoxButtons.OK); } else { check_all_textboxes(); // масштабируем и переносим относительно начала координат (сдвигом центра в начало) // if (scaling_x.Text != "1" || scaling_y.Text != "1" || scaling_z.Text != "1" || trans_x.Text != "0" || trans_y.Text != "0" || trans_z.Text != "0") { // сначала переносим в начало // left fig float old_x = figure.Center.X, old_y = figure.Center.Y, old_z = figure.Center.Z; figure.translate(-old_x, -old_y, -old_z); // делаем, что нужно if (scaling_x.Text != "1" || scaling_y.Text != "1" || scaling_z.Text != "1") { float x = float.Parse(scaling_x.Text, CultureInfo.CurrentCulture), y = float.Parse(scaling_y.Text, CultureInfo.CurrentCulture), z = float.Parse(scaling_z.Text, CultureInfo.CurrentCulture); figure.scale(x, y, z); } if (trans_x.Text != "0" || trans_y.Text != "0" || trans_z.Text != "0") { int dx = int.Parse(trans_x.Text, CultureInfo.CurrentCulture), dy = int.Parse(trans_y.Text, CultureInfo.CurrentCulture), dz = int.Parse(trans_z.Text, CultureInfo.CurrentCulture); figure.translate(dx, dy, dz); } // переносим обратно figure.translate(old_x, old_y, old_z); } // поворачиваем относительно нужной прямой if (rot_angle.Text != "0") { if (line_mode != Axis.OTHER) { float old_x = figure.Center.X, old_y = figure.Center.Y, old_z = figure.Center.Z; figure.translate(-old_x, -old_y, -old_z); double angle = double.Parse(rot_angle.Text, CultureInfo.CurrentCulture); figure.rotate(angle, line_mode); figure.translate(old_x, old_y, old_z); } else { Edge rot_line = new Edge( new Point3d( int.Parse(rot_line_x1.Text, CultureInfo.CurrentCulture), int.Parse(rot_line_y1.Text, CultureInfo.CurrentCulture), int.Parse(rot_line_z1.Text, CultureInfo.CurrentCulture)), new Point3d( int.Parse(rot_line_x2.Text, CultureInfo.CurrentCulture), int.Parse(rot_line_y2.Text, CultureInfo.CurrentCulture), int.Parse(rot_line_z2.Text, CultureInfo.CurrentCulture))); float Ax = rot_line.P1.X, Ay = rot_line.P1.Y, Az = rot_line.P1.Z; figure.translate(-Ax, -Ay, -Az); double angle = double.Parse(rot_angle.Text, CultureInfo.CurrentCulture); figure.rotate(angle, line_mode, rot_line); figure.translate(Ax, Ay, Az); } } bmp.Dispose(); rgbValues = getRGBValues(out bmp, out bmpData, out ptr, out bytes); figure.ApplyTexture(bmp, bmpData, rgbValues, texture, bmpDataTexture, rgbValuesTexture); System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes); bmp.UnlockBits(bmpData); pictureBox1.Image = bmp; } }