|
|
|
 |
 |
Исходник |
 |
|
 |
 |
|
Автор:
|
|
|
Название:
|
Вращение куба |
|
Дата:
|
11 January 2009 |
|
Описание: |
Ващение куба вокруг любой выбранной оси |
| |
Разместить ссылку на этот исходник в форуме вы можете вставив в текст сообщения
следующую строку:
[CODEPOST ID=243]Вращение куба[/CODEPOST] |
| Оценка: |
Проголосовало 20 посетителей, средняя оценка 3.20 |
| Оценить: |
|
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Text;
7 using System.Windows.Forms;
8
9 namespace _D_rotation
10 {
11 public partial class Form1 : Form
12 {
13 Graphics ET;
14 float[][] coordnew;
15 float[][] coordtmp;
16 float[][] coord;
17 double gradus;
18 int XYZ;
19 public Form1()
20 {
21 XYZ = 1;
22 gradus = 1;
23 coordnew = new float[11][]
24 {
25 new float[2],
26 new float[2],
27 new float[2],
28 new float[2],
29 new float[2],
30 new float[2],
31 new float[2],
32 new float[2],
33 new float[2],
34 new float[2],
35 new float[2],
36
37 };
38 coordtmp = new float[11][]
39 {
40 new float[2],
41 new float[2],
42 new float[2],
43 new float[2],
44 new float[2],
45 new float[2],
46 new float[2],
47 new float[2],
48 new float[2],
49 new float[2],
50 new float[2],
51
52 };
53 coord = new float[11][]
54 {
55 new float[] {-100,100,100},
56 new float[] {100,100,100},
57 new float[] {100,-100,100},
58 new float[] {-100,-100,100},
59 new float[] {-100,100,-100},
60 new float[] {100,100,-100},
61 new float[] {100,-100,-100},
62 new float[] {-100,-100,-100},
63 new float[] {150,0,0},
64 new float[] {0,150,0},
65 new float[] {0,0,150},
66 };
67 InitializeComponent();
68 }
69
70 void paint(Graphics e, float [][] newmas, Color col)
71 {
72 Pen pen = new Pen (col);
73 for (int i = 0; i < 4; i++)
74 {
75 if (i + 1 != 4)
76 e.DrawLine(pen, newmas[i][0], newmas[i][1], newmas[i + 1][0], newmas[i + 1][1]);
77 else
78 e.DrawLine(pen, newmas[3][0], newmas[3][1], newmas[0][0], newmas[0][1]);
79
80 }
81 for (int i = 4; i < 8; i++)
82 {
83 if (i + 1 != 8)
84 e.DrawLine(pen, newmas[i][0], newmas[i][1], newmas[i + 1][0], newmas[i + 1][1]);
85 else
86 e.DrawLine(pen, newmas[7][0], newmas[7][1], newmas[4][0], newmas[4][1]);
87 }
88 e.DrawLine (pen,newmas[0][0],newmas [0][1],newmas [4][0],newmas [4][1]);
89 e.DrawLine (pen,newmas[1][0],newmas [1][1],newmas [5][0],newmas [5][1]);
90 e.DrawLine (pen,newmas[2][0],newmas [2][1],newmas [6][0],newmas [6][1]);
91 e.DrawLine (pen,newmas[3][0],newmas [3][1],newmas [7][0],newmas [7][1]);
92 if(col != Color.White)
93 pen.Color = Color.Red;
94 e.DrawLine(pen, 0, 0, newmas[8][0], newmas[8][1]);
95 if (col != Color.White)
96 pen.Color = Color.Blue;
97 e.DrawLine(pen, 0, 0, newmas[9][0], newmas[9][1]);
98 if (col != Color.White)
99 pen.Color = Color.Green;
100 e.DrawLine(pen, 0, 0, newmas[10][0], newmas[10][1]);
101 }
102
103 void rotation(float[][] coord, double theta, int e)
104 {
105 float[][] tmpcoord = new float[11][]
106 {
107 new float[3],
108 new float[3],
109 new float[3],
110 new float[3],
111 new float[3],
112 new float[3],
113 new float[3],
114 new float[3],
115 new float[3],
116 new float[3],
117 new float[3],
118 };
119 switch (e)
120 {
121 case 1:
122 {
123 for (int i = 0; i < 11; i++)
124 {
125 tmpcoord[i][0] = coord[i][0];
126 tmpcoord[i][1] = coord[i][1] * (float)Math.Cos(theta) - coord[i][2] * (float)Math.Sin(theta);
127 tmpcoord[i][2] = coord[i][1] * (float)Math.Sin(theta) + coord[i][2] * (float)Math.Cos(theta);
128 }
129 break;
130 }
131 case 2:
132 {
133 for (int i = 0; i < 11; i++)
134 {
135 tmpcoord[i][0] = coord[i][0] * (float)Math.Cos(theta) + coord[i][2] * (float)Math.Sin(theta);
136 tmpcoord[i][1] = coord[i][1];
137 tmpcoord[i][2] = - coord[i][0] * (float)Math.Sin(theta) + coord[i][2] * (float)Math.Cos(theta);
138 }
139 break;
140 }
141 case 3:
142 {
143 for (int i = 0; i < 11; i++)
144 {
145 tmpcoord[i][0] = coord[i][0] * (float)Math.Cos(theta) - coord[i][1] * (float)Math.Sin(theta);
146 tmpcoord[i][1] = coord[i][0] * (float)Math.Sin(theta) + coord[i][1] * (float)Math.Cos(theta);
147 tmpcoord[i][2] = coord[i][2];
148 }
149 break;
150 }
151 }
152 for (int i = 0; i < 11; i++)
153 {
154 coord[i][0] = tmpcoord[i][0];
155 coord[i][1] = tmpcoord[i][1];
156 coord[i][2] = tmpcoord[i][2];
157 }
158 }
159
160 private void button1_Click(object sender, EventArgs e)
161 {
162 if (timer1.Enabled == true)
163 {
164 button1.Text = "Запустить";
165 timer1.Enabled = false;
166 }
167 else
168 {
169 button1.Text = "Пауза";
170 timer1.Enabled = true;
171 }
172 }
173
174 private void Form1_Shown(object sender, EventArgs e)
175 {
176 Color col = Color .Black;
177 ET = panel1.CreateGraphics();
178 ET.TranslateTransform(300, 300);
179 paint(ET, coordnew, col);
180 }
181
182 private void timer1_Tick(object sender, EventArgs e)
183 {
184 Color col;
185 double radian = gradus * Math.PI / 180;
186 rotation(coord, radian, XYZ);
187 for (int i = 0; i < 11; i++)
188 {
189 radian = 0 * Math.PI / 180;
190 //поворот плоскости OXY
191 coordtmp[i][0] = coordnew[i][0];
192 coordtmp[i][1] = coordnew[i][1];
193 coordnew[i][0] = coord[i][0] * (float)Math.Cos(radian) - coord[i][1] * (float)Math.Sin(radian);
194 coordnew[i][1] = coord[i][0] * (float)Math.Sin(radian) + coord[i][1] * (float)Math.Cos(radian);
195
196 //поворот плоскости OYZ
197 coordnew[i][1] = coordnew[i][1] * (float)Math.Cos(radian) - coord[i][2] * (float)Math.Sin(radian);
198
199 }
200
201 col = Color.White;
202 paint(ET, coordtmp, col);
203 col = Color.Black;
204 paint(ET, coordnew, col);
205 }
206
207 private void radioButton2_CheckedChanged(object sender, EventArgs e)
208 {
209 if (radioButton2.Checked == true)
210 XYZ = 2;
211 }
212
213 private void radioButton3_CheckedChanged(object sender, EventArgs e)
214 {
215 if (radioButton3.Checked == true)
216 XYZ = 3;
217 }
218
219 private void radioButton1_CheckedChanged(object sender, EventArgs e)
220 {
221 if (radioButton1.Checked == true)
222 XYZ = 1;
223 }
224 }
225 } |
| Вернуться к списку исходников в категории Winforms |
|
|
 |
 |
 |
 |
|
|