close

Вход

Забыли?

вход по аккаунту

?

Moya kursovaya (2)

код для вставкиСкачать
???????????? ??????????? ? ????? ?????????? ?????????
??????????? ??????????????? ?????????? ??????????????? ??????????
??????? ????????????????? ???????????
"???????? (???????????) ??????????? ??????????? ????? ?.?. ??????????"
??????? ?????????????? ??????????(???????????? ???????)????????? ???? ????????(???????, ???, ???????? ????????)?????????????????3??????3???????? ?????? ?? ?????????????????????? ????????? ? ????????? ?????????-???????? (???????????? ????)?????? ???????? ? ??????(??????? ????????????)(????)????????, ??? ??????????????? ? ???????? ? ??????????????????? ??. ??????????????.?. ???????(?????????)(???????)(?.,?., ???????)(????)???????????2012
???????????? ??????????? ? ????? ?????????? ?????????
??????????? ??????????????? ?????????? ??????????????? ??????????
??????? ????????????????? ???????????
"???????? (???????????) ??????????? ??????????? ????? ?.?. ??????????"
??????? ?????????????? ??????????(???????????? ???????)??????? ?? ???????? ???????????????????? ????????? ? ??????? (???????????? ??????????)?????????????3?????3???????????????? ???? ?????????(???????, ???, ???????? ????????)????:?????-???????????????? ??????:?????? ???????? ???? ?????? ???? ?????????????? ?""2012 ?. ?? ""2012 ?.
???????????? ???????
??. ????.?.?. ???????(?????????)(???????)(?.?. ???????)
???? ?????????
??????????
????????51 ?????????? ??????72 ???????? ???????????? ??????????102.1 ?????????????? ?????????102.2 ???????? ???????? ????????? ??????112.3 ??????????? ??????? ? ?? ??????? ?????? ? ??????? ??????? ???????122.4 ???????? ??????????? ??????? ? ?????????????? ??????? ?????? ?????????133 ???????? ?????????153.1 ????????? ???? ?????? ? ?? ??????????????153.2 ???????? ?????????? ? ?? ??????????????153.3 ???????? ???????? ???????? ? ??????? 163.4 ???????? ?????????????? ???????? ? ???????174 ???????????? ?????????184.1 ???????? ??????????184.2 ??????????? ?? ????????????? ?????????194.3 ?????????20??????????23?????? ?????????????? ??????????24?????????? ?. ??????? ???????? ???????????25
????????
???????????? ??????? - ??? ??????? ????????????, ? ??????? ?????????? ???????????? ? ???????? ??????????? ???????? ??????????? ? ????????? ?????????? ??????????, ?????????? ?? ????????? ????. ?? ???????? ??????? ??????????? ??????? ????? ????????? ?? ??? ???????? ?????????: ????????? ??????? ? ??????????. ????????? ??????? ? ???? ??????? ??????? ?? ?????????, ????????? ? ??????????? ???????. ????????? ??????? ???????????? ??????????? ??? ????? ?????????????? ??????????. ?????? ? ???????? ??? ?????????? ?????, ??????, ??????????, ??????????????, ? ????? ??? ????? ??????, ?????? ?????????? ???????. ???????? ????????????? ????????? ????????, ????????, ??????? ?????, ???? ??????????. ??????? ???????? ??? ????? ?????????, ???????? ? ?????? ?????, ??????????????? ????? ??????????. ??????????? ? ????????? ??????? ???? ??????? ??? ??????????????. ??????????? ????? ??? ?????? ????????????????, ??????????????, ??????????????? ? ??????????? ?????????? ???????.
????????? ??????? ?????? ????????? ????????? ???????? (????????) ????????. ??????? ??????? ?????????????? ???????? - ???????, ?????, ???????????? - ??? ?????????? ???? ????????. ????????? ????? ????? ????????? ????? ????? ? ????????. ??? ?????? ?????? ????????? ??????????? ????? ?????? ???? ?????????, ???? ????????? ?????? ??????????? ????? ???????? ????????, ??? ????? ? ????????? ?????????????, ??? ?????????? ??????????? ?????????? ?????. ? ????????? ???? ??????????? ????? ???????????, ?????? ???? ?????? ???????? ????? ???? ??????????: ??????? ????? ??????, ??????????? ??? ?????? ? ?????????????, ?????? ??? ??????????????.
? ?????? ??????????? ??????? ????? ??????? ????????, ???????, ????????? ???????? ???????? ????????? ???????? ???????????? ????????. ????????? ????? ????????? ???????? ????????? ???????? ???????? ?????????? ?? ???????? ?????????, ??????? ????? ?????? ????? ????? ???? ??????????? ??????????????? ???????????. ???????? ????????? ????????? ????? ?????? ???????????, ??? ?????????? ???????? ??????? ????????? ???????????? ???? ??????. ? ?????? ???????, ???????? ????? ????????? ? ???????????? ??? ???? ???????.
?????????? ??????? ????????? ? ????????? ? ?????????? ????????????. ?????? ?????????? ???????????? ????? ??????? ????????, ????????. ? ?????????? ???????????? ??????? ??? ??????? ?????? ?????????????? ??? ????? ???????????? ??? ??????. ??????????? ??????????? ???????? ?????????. ? ???????? ???????? ?????? ???????? ????????????. ????? ??????? ????? ??????????? ? ???? ?????? ?? ????????? ??? ??????. ???, ? ???????????? ????? 3 ???????. ?????????? ?????? ??????? ???????????? ????? ?????? (x, y, z). ??????? ?????? ?? ??????????????? ??????? (????????/??????/???????????????), ?? ??????? ????? ??????. ?????? ????? ?????????????? ?? ????? ????????? ????????, ??????? ????? ???????, ? ???????????? ??? ????????, ??????? ????? ??????.? ?????? ?????? ????????? ??????? ?????????? ????? ??????????? Microsoft Visual Studio, ? ?????????? ? ??????? ???????????????? ?? ????? ???????? ?????? C#.
1 ?????????? ??????
? ?????? ?????? ????????? ??????????? ?????-????????, ?? ???? ??????? ?????????? ?????? ???? ?????????: ???? ??????????, ?????? ???. ???? ?????? ??????????? ? ???, ????? ???????? ???????? ???????? ?????????? ???, ? ?????? ??????????? ????????????? ???????? ?????? ?????????? ? ???????? ??????????? ???????? (??? ??? ?????) ?? ????????????.
??????????? ????? ????? ???????? ?? ???? ?????????: ?????????? ?????? ????????? ??????? ? ?????? ????. ?????? ????? ????????? ???? ??????????? ????????, ? ??? - ?????????????. ?????? ??????? ?? 20 ??????? ?????? ? ????? ????????? ???????, ??? ????? ?????? ???? ???????????. ??? - ??????????? ?????????????? ??????, ??????? 6 ??????, ??????????? ? ????? ?????????? ???????????????, ?????????. ?????? ????? ?????? ???????? ?????? ???????????? ? ?????? ?????????.
?????????? ?????????? ?????? ?????? ??????? (??????? 1).
??????? 1 - ?????????? ?????? ?????? ???????
????? ????????????????? ??????????? Y?????????? Z0-50-5001-48-50-152-40-50-303-28-50-424-15-50-4850-50-50615-50-48728-50-42840-50-30 ??????????? ??????? 1
????? ????????????????? ??????????? Y?????????? Z948-50-151050-5001148-50151240-50301328-50421415-5048150-505016-15-504817-28-504218-40-503019-48-501520-60100021-58100-1922-48100-3623-35100-5024-18100-58250100-602618100-582735100-502848100-362958100-19306010003158100193248100363335100503418100583501006036-181005837-351005038-481003639-5810019 ? ?????? ?????? ?????? ??????????? ? ????????, ? ????? ??????? ?????? ? ????? ??????? ??????????. ??????? ?? 0 ?? 19 ?????????? ????????? ???????, ? ??????? ????? ????????? ?????? ???????? ????? ????????? ???????. ??????? ?? 20 ?? 39 ?????????? ??????? ????? ???????, ?? ???????? ??????????? ????? ??????, ????? ?? ???? ?????? ??????? ?? ?????. ? ?????? ??????? ????????????? 20 ??????? ??????, ?????? ????? ???????? ?? ???????? ?????????? ?????? ? ???? ???????, ????????: ???? ?? ??????? ?????? ????? ??????? 0, 20, 21, 1 (????: i, i + 20, i + 21, i + 1). ?????????? ?????????? ?????? ???? ? ?????? 50 (??????? 2).
??????? 2 - ?????????? ?????? ????
????? ????????????????? ??????????? Y?????????? Z????????? ????40-60-50-6541-60-50-11542-10-50-11543-10-50-65??????? ?????44-600-6545-600-11546-100-11547-100-65
?????? ???? ?????????? ?? ???????????? ???????? ????????????? ???????, ??????? ????????? ????? ?????????, ????? ??????? ?????, ? ????? ??????? ??????? ?????. ?????? ????? ???? ???????? 4 ?????????. ??? ??? ??? ??? ?????? ???????? ?????? ?????, ?? ?????????? ????????????? ?? ?????? ???????, ? ????? ?????? ?????? ???????? ?? ???????. ? ?????????? ? ??????????????? ???????? ????? ????? ????????? ???????????? ??????, ???????? ???????????? ? ???????? ????????? ???? ?????.
2 ???????? ???????????? ??????????
2.1 ?????????????? ?????????
? ?????????? ??????? ??? ?????????? ?????????? ???????? ???? ?????? ?????????? ?????? ???????? ? ??????? ??????? ?????????. ?????????? ???????? ?? ???????? ????????? ??????? (? ???????? ??? ????????????? ????????) ??????????. ??? ??????? ????????? ??????? ????????? ????????????? ?????????????? ??? ??????? ??????????????? ???????? ??????????????. ???????, ????? ??????? ?????????? ?????? ??? ????????????? ?????????????? ??????????????, ?? ????? ???????? ??? ?????????? ????? ??????, ??????????? ??-?? ??????? ??????, ?? ???????? ????????????? ??????????????, ?????? ?????? ????????. ???????? ?????????? ?????? ??????? ????? ????, ??? ? ??????? ??????????? ???????? ????????????? ??????????????, ? ?????? ?????? ? ????? ???????? ???? ??????.
// ??????? ??????????
View[i].x = 20 * (int)Math.Round(Vertex[i].x * (-Math.Sin(teta)) + Vertex[i].y * Math.Cos(teta));
View[i].y = 20 * (int)Math.Round(Vertex[i].x * (-Math.Cos(phi) * Math.Cos(teta)) - Vertex[i].y * (Math.Cos(phi) * Math.Sin(teta)) + Vertex[i].z * Math.Sin(phi));
View[i].z = -20 * (int)Math.Round(Vertex[i].x * (-Math.Sin(phi) * Math.Cos(teta)) - Vertex[i].y * (Math.Sin(phi) * Math.Sin(teta)) - Vertex[i].z * (Math.Cos(phi)) + R0);
// ????????????? ??????????????
Perspective[i].X = pictureBox1.Width / 2 + (int)Math.Round(D0 * (View[i].x / View[i].z));
Perspective[i].Y = pictureBox1.Height / 2 + (int)Math.Round(D0 * (View[i].y / View[i].z));
// ????????? ???????? ?????????
Scrn[i].X = (int)Perspective[i].X + pictureBox1.Width / 2;
Scrn[i].Y = (int)Perspective[i].Y + pictureBox1.Height / 2;
??????? 1 - ????????? ???????? ?????????
????? ????????? ???????? ????? ??????? ? ?????????? ?, ??? ?????? ??????? ?????????.
2.2 ???????? ???????? ????????? ??????
??? ??? ? ????????? ???????????? ???????? ?????????? ??????, ?? ??-?? ????? ????????? ?????? ?????????? ??????, ?? ???? ????? ?????????????? ? ????? ? ??? ?? ?????. ????? ????? ????????, ??????? ?????????? ?????? ??????? ?????, ? ????????? ????? ???????. ??? ????? ????????????? ?????????? ?????-??????-?????, ????? ???????????? ???????? ?????????. ???? ????????? ?????????, ??????? ? ???, ???, ????????? ??????????????? ?????? ?? ???????, ????????? ? ????????? ?????, ??????? ? ??????? ??????. ??? ???? ?????, ??????? ????????? ?????, ????????? ????? ????????? ????? ????? ??????? ??????. ????? ????? ?????? ???????? ? ???????????? ???????, ? ????? ? ???????????? ???????????. ?? ????? ???????? ??? ???????????? ????????, ?? ???? ? ?????? ????, ??? ??????????? ????????????? ??????????????. ????? ??????? ?? ???? ???????? ?????:
1. ???????????? ???? ????????? ? ???????????? ? ?? ??????????? z-????????????;
2. ?????????? ???? ?????????????????, ??????? ????????? ??? ?????????? z-???????? ???????????????;
3. ?????????? ??????? ????????, ???????????? ? ??????? ?????????? ?? ?????????? z-??????????.
??? ?????????? ???????? ???????? ?? ?????????? Z, ?????????? ??????? ???????? ?????????? Z ?????? ?? ?????? ???????? ? ???????? ??? ????? ?? ?????????? ??????. ??? ? ????? ??????? ???????? ?????????? Z ????????. ????? ???????? ??????, ?????????? ??? ??????? ????????, ? ??????? ????? ?????????? ??. ???? ?????? ???????? ????? ?????? ???????????, ?? ??????, ??? ??????? ????????? ????? ? ???????????, ? ??????, ????? ?????????? ? ????????? ???????. ????? ???????, ????? ????? ?????????? ? ??????? ?????????? ???????? Z.
?????? ???????? ?????????? ?????????? ????????? ??????????, ?, ??? ?????????, ???????????? ??????????. ? ????? ????, ???? ?????????? ????? ??????? ?? ???????? ?????????? ????????, ? ??????? ???????? ????????? ????? ?? ????? ? ??????? ?????. ? ??????, ?? ??????????? ?? ?????? ? ?? ?????????. ?????????? "????????? ?????????" ??????? ? ???, ??? ???????????? ??? ????????. 2.3 ??????????? ??????? ? ?? ??????? ?????? ? ??????? ??????? ???????
??? ?????????? ????? ????????? ????? ????????? ??? ?????? ????? ?????? ???????, ? ?? ??? ???????? ?????????? ?????, ??????? ????? ?????. ????? ????? ???????? ??, ??? ???? ????? ??????? ?? ??????????? ??????? ? ?????????????, ??????? ??????? ????????????? ?????? ????????.
???? ????????? ??????? ? ???, ??? ?? ???? ????? ???????????? ??????? ? ???????? ? ??????????? ????? ?????????? ???????????? ??????, ??????? ??? ??? ?? ???. ??????? ? ??????????? ????????? ? ??????? ???? ?????, ??? ??? ????? ????? ??? ????? ????? ???????? ?????????. ?????????? ??????? ??????? ?????????: N(Nx, Ny, Nz). ??? ????? ??????????? ????? ????????? ??????????: A(Ax, Ay, Az), B(Bx, By, Bz), C(Cx, Cy, Cz). ????????? ????????? ???????? ? ????: Nx * X + Ny * Y + Nz * Z + d = 0.
? ?????????? ??????? ????????? ??????? ?????????:
??????????? ?????? ??????? ? ??????? ???????? 4?4.
?????? ???????????? ?????? ??????? ?? ?????? ??????. ??? ??? ?????? ??????? ????????? ????? ????????????? ???????, ?? ???????????? ?????? ??????? ????? 0. ? ?????????? ????????:
Nx = , Ny = , Nz = .
???????? d ??? ??????????? ????????? ??????? ?? ?????. ????, ?????????? ??????? ??????? ????? ???:
Nx = Ay(Bz - Cz) + By(Cz - Az) + Cy(Az - Bz);
Ny = Az(Bx - Cx) + Bz(Cx - Ax) + Cz(Ax - Bx);
Nz = Ax(By - Cy) + Bx(Cy - Ay) + Cx(Ay - By).
???????? ???????? ?????? ??????? ? ????????? ?????, ??? ??? ??? ??????????? ???????? ???? ????? ????????? ????? ???????????? ????????? ???????. ??? ????? ????? ?????????? ????? ??????? ? ????????? ?? ??? ?????? ??????????. ??? ?????? ????? ??? ????????????? ??????? ????? ????????? ?????? ???????, ???????? ? ????????? ????? ? ????????? ??? ?????????? ? ????????? ??????????????? ?????. ????? ????, ??? ?????? ???????? ????? ??????? ??????? ????? ???? ????????????? (?? ????????????? ???????? ???????? ?? ???????).
??? ?????????? ??????? ????????? ??? ??????????? ?????? ?????????? Nz. ???????? ??????? ?? ???????: Nz = Nz/ (??????(Nx*Nx + Ny*Ny + Nz*Nz)). ???? Nz > 0, ?? ????? ?? ?????, ???? Nz < 0, ?? ????? ?????. ??? ??? ? ??? ?? ????? ??????? ?????????? ??????, ? ???????? ?????? ??????????????? ??? ?????, ?? ???????? ??? ??????? ?? ???????? ????????? ??????.
2.4 ???????? ??????????? ??????? ? ?????????????? ??????? ?????? ?????????
??? ??? ?????? ???????? ? ????? ????? ?? ??? ???????????, ?? ???????? ????????? ? ????? ???????? ??? ?? ???????? ??????? ???????. ?????? ???????????? ????? ???????????? ??????????? ???????????? ??????????? ????????. ???? ????????? ??????? ? ?????????: ????? ??????????? ?????? ????? ???????, ??????? ???????? ????????? ????????? ?????? (A, R, G, B) ?? ???????? ?????????? Z ??????? ???????. ???? ? ????????? ???????????? ? ???????? ??????, ?? ??????? ?????? ????, ??????? ??????? ?????????????? ???????? ?????-?????? ??? ?????? ???? ????????? ????????????? - 255, ? ??? ?????? ??????? ???????? ????????? ?????????: 80 ??? ??????? ??????, ? 100 ??? ????????? ???????. ??? ?????? ???????? Nz ????? ???????????? ? ???????, ??? ?????? ????? ???? ????? ???????? ? ????? ????? ? ??? ?????????????? ?????? ????? ????????????? ?????.
??? ???????? ????????? ????????????? ??????????? ???????? ???????? - FillPolygon. ?????? ??????? ????????? ?????????? ????? ????????, ????????????? ???????? ?????, ???? ?? ???? ?????????? ?????? ??????? ???????? ?? ???? ????????. ? ????? ???????? ??????????, ?? ????????? ??????? ?????????. 3 ???????? ?????????
3.1 ????????? ???? ?????? ? ?? ??????????????
? ??????? 3 ??????? ??? ???? ??????, ???????????? ? ?????????.
??????? 3 - ???? ??????, ???????????? ? ?????????
??? ????????????????????int???????????? ??? ????????????? ??????????double???????????? ??? ?????? ??????????bool???????????? ??? ?????????? ?????????????? ? ????????int[]???????????? ? ???????? ????????, ???????? ????? ???????? (?????? ?????????, ??????)double[]???????????? ? ???????? ????????, ???????? ???????????? ?????, ???????? ??????, ???????? ??????? ???????? ?????????? Z????????????????????? ??? ???????? ????????? ???????????????????????? ??? ??????????? ?????????? ??????? ? ??????? ?????????
3.2 ???????? ?????????? ? ?? ??????????????
???????? ?????????? ? ?? ?????????????? ??????????? ? ??????? 4.
??????? 4 - ???????? ?????????? ? ?? ???????
????????????? ?????????????b????? Bitmap???????????? ??? ?????? ? ?????????????, ????????????? ??????? ????????g????? Graphics????????????? ??????????? ?????????image????? Image????????? ????????? ??????? ??????????? ??? ??????????? ?????????VertexPoint3D[]?????????? ????????? ????????? ??????ViewPoint3D[]??????? ?????????? ??????ScrnPoint[]?????? ???????? ?????????PerspectivePoint[]?????? ????????????? ?????????NZdouble[]??????, ?????????? ??? ???????? ?????????? Z ??????? ???????Orderint[]??????, ???????? ??????? ??????????? ??????, ?????????? ?????? ?????????Ddouble[]??????, ???????? ??????? ???????? ?? ?????????? Z ?????????Teta, Phidouble??????????, ???????? ???????? ?????nx, ny, nzdouble?????????? ??????? ???????R0int??????????? ??????????????? ?????D0int??????????? ??????????? ?????mousePressbool?????????? ??????????, ????????????? ??????? ?? ?????? ????
3.3 ???????? ???????? ???????? ? ??????? ?????????? ???????? ??????? ? ?????????.
1. ????????? "??????????????". ??????? ?????????, ? ??????? ?????????? ?????????????? ?????????, ???????? ?????????, ?????????? ??????? ???????? ?????????? Z, ???????????? ???????????? ? ???????? ?????? ?????????.
2. ??????? "????????????????". ????????? ????? ?? ??????? ? ????????? ?????? ????????????? ?????? ??? ???????????.
3. ????????? "?????????????????". ????????? ??????? ? ??????????? ? ????????? ?????? ? ??????????? Z ???? ???????.
4. ????????? "?????????????". ?????? ????????? ???????????? ??? ??????????? ?????.
5. ??????? "Flag". ??????????????? ????? ??? ?????????? ??????? "????????????????". ?????????? ????? ??? ?????????.
3.4 ???????? ?????????????? ???????? ? ???????
?????????? ???????? ?????????????? ????????????? ???????? ? ???????. ????????? "?????????????" ?????????? ?????? ??? ??? ????????? ??????????? ?????, ?????? ????????? ???????? ? ????? ???? ???????? ????????? ????????? "???????????????". ????????? "???????????????" ?????? ????? ??????? ???????? ??????? ?? ???????: "????????????????" ? ??????? "?????????????????". ??????? "????????????????" ???????? ? ???? ????? "Flag". ???????? ????? ?????????????? ???????? ? ??????? ???????????? ?? ??????? 2.
??????? 2 - ???????? ????? ?????????????? ????????
? ???????
4 ???????????? ?????????
4.1 ???????? ??????????
??? ??????? ????????? ???????????? ????? ????? ?????: ?????? ? ??? ????? ??? (??????? 3).
??????? 3 - ????????? ?????????
????????? ????? ?????????? ???????? ?????????, ??, ??? ???? ????????, ?? ? ?????????? - ??? ???????: ?????????? ?????? (??????) ? ???????????? (???). ? ????? ??????? ?? ????? ????? "?# Alpha Blending" ??????? ? ???? ??????, ????? ????????. ???? ?????????? ?????? ??????????????, ????? ?????? ????????? ? ???????????. ????????? ???? ?????????? ????? ???? ?????? ? ???????? ??????????.
4.2 ??????????? ?? ????????????? ?????????
?????? ?????????? ????????????? ??? ????????????? ??????? ???, ????? ??? ???????????? ? ??????????????, ? ????? ??? ?????????? ????, ??? ????? ???? ????????, ?????????? ??????? ?????????? ? ???????? ????? ?????. ?? ???? ?????????? ????, ?????????? ????????????, ?????? ????????? ??? ??????????, ? ???????????? ???? ? ???? ??????? ?????? ???????? ????? ??????????? ???? ??? ?????? ???????, ???????????? ? ??? ?? ????? ?????.
???????????? ????? ??????? ?????? ???????? ????? ?? ???????? ??? ???????????????. ????? ????? ??????????? ???? ? ??????? ????, ???? ? ??????? ??????? ??????????. ??????? ?????????? ???????????? ? ??????? 5.
??????? 5 - ?????????? ??????
??????? ????????????????????????????? ???/???????? ????? ?? ???? ???????????????? ??????????????????????? +/-??????? ????????????? ? ???????? ?????????????????????????????? ????? ??????????? ????????????????? ????? ??????????? ????????????????? ????? ? ????? ????????????????????? ????? ? ?????? ???????
?????? ?????????? ???????? ??? ????????? ??????????, ?? ???????? ??????????, ?? ??????????? ???????, ?? ?????????? ????????????? ????????? ??? ???????????? ??????? ??????????? ???????????.
??????????? ????????? ??????????:
- ???????????? ??????? Windows XP, Vista, 7 (????????????? ?Windows 8 ??????????);
- ????????? ? ???????? ???????? 1 ??? ??? ????;
- ??? 512 ?? ??? ????;
- ??????????? 128 ?? ??? ????;
- ??????????, ????.
4.3 ?????????
? ?????????? ?????????? ?????????, ???????? ????????? ??????????, ?????????? ?? ???????? 4-8. ??????? 4 - ????? ??????? ?????? ???????????? ?????
??????? 5 - ????????? ???? ?????? ?????????? ??????
??????? 6 - ??? ????????? ?????? ???????
??????? 7 - ?????? ??????????????? ?? ?????????? ?????
??????? 8 - ?????? ??????????????? ?? ?????????? ?????
??????????
? ?????????? ?????????? ???????????? ??????, ???????? ?????, ????????? ?? ???? ????????? (?????????? ?????? ? ???????????? ???) ?? ????????? ????, ?????????? ??????????? ????????????. ?? ??????? ?????????? ???? ???????? ???????? ?????????? ??? ? ???????? ???????????? ???, ? ????? ????????? ??? ??????? ????? ? ?????????? ?? ??????????????. ? ????? ???????? ??????????? ??????????: ???????????? ??????? ???????? ????? ??????????? ????????, ? ?????? ?????????? ??????? ??? ????? ??????? ????? ???????????? ???????.
??? ????????? ?????? ??????????? ??? ???????? ??? ??????????: ???????? ?????????????? ?????????, ???????? ???????? ????????? ??????, ????????, ???????????? ??????? ? ?? ??????? ????? ? ??????? ??????? ???????, ???????????? ? ???????????, ? ????? ???????? ???????? ??????????? ??????? ? ?????????????? ??????? ?????? ?????????, ?????????? ?? ????? ??????????? ????????? ??????? ???????.
?????? ?????? ????? ?????????? "C# Alpha Blending", ???????? ???????????? ??????? ?????? ?????-????????, ? ????? ???????????? ??????????? ???????? ?????????? ????? ??????????? ???????????????? ?? ????? ???????? ?????? C#.
?????? ?????????????? ??????????
1 ????????? ?.?., ???????? ?.?., ??????? ?.?. ???????????? ???????? ? ?????????? ???????????? ????? ?? ?????????? "???????????? ????????? ? ???????". [?????] - ????????????: " ????????????? ??????????????? ??????????? ???????????", ?. ???????????, 2006 ?. - ???. 36;
2 ????????? - ????????? ????????????. [??????????? ??????] - ????? ???????: http://ru.wikipedia.org/, ?????????;
3 ?????? ?.?., ???????? ?.?. ?????????? ???????????? ???????. [?????] - ????????????: "????? ? ?????", ISBN 5-256-01204-5, ?. ??????, 1995 ?. - ???. 224;
4 ??????? ?., ????? ??. ?????????????? ?????? ???????? ???????. [?????] - ????????????: "???", ??????? ? ???????????, ISBN 5-03-002143-4, ?. ??????, 2001 ?. - ???. 604.
?????????? ?
(????????????)
??????? ???????? ???????????
??????? ?????? Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
// ????????? ?????????
public struct Point3D
{
public double x;
public double y;
public double z;
public Point3D(double x, double y, double z)
{
this.x = x;
this.y = y;
this.z = z;
}
}
public partial class Form1 : Form
{
Bitmap b;
Graphics g;
Image image;
Point3D[] Vertex = new Point3D[48]; // ?????? ????????? ?????? (x, y, z)
Point3D[] View = new Point3D[48]; // ?????? ??????? ?????????
Point[] Scrn = new Point[48]; // ?????? ???????? ?????????
Point[] Perspective = new Point[48]; // ?????? ????????????? ?????????
double[] NZ = new double[27]; // ?????? ???????? ??? ?????????
int[] Order = new int[27]; // ?????? ??????? ??????????? ??????? ??????
double[] D = new double[27]; // ??????, ?????????? ??????? ???????? Z-??????
double Teta = Math.PI / 180; // ???? ???? = 45 ????????
double Phi = Math.PI / 180; // ???? ?? = 45 ???????? bool mousePress = false;
double sX = 0;
double sY = 0;
double nx, ny, nz;
int D0 = 500;
int R0 = 300;
public Form1()
{
InitializeComponent();
this.MouseWheel += new MouseEventHandler(Form1_MouseWheel);
b = new Bitmap("Background.jpg"); // ????????? ?????? Bitmap
image = Image.FromFile("Background.jpg"); // ????????? ??????? ???????????
g = Graphics.FromImage(b); // ?????? ??????????? ??? ?????????
}
// ?????????? ???????? ?????
void ??????????????()
{
g.DrawImage(image, 0, 0);
for (int i = 0; i < 48; i++)
{
// ?????????????? ?? ??????? ? ??????? ??????????
View[i].x = 20 * (int)Math.Round(Vertex[i].x * (-Math.Sin(Teta)) + Vertex[i].y * Math.Cos(Teta));
View[i].y = 20 * (int)Math.Round(Vertex[i].x * (-Math.Cos(Phi) * Math.Cos(Teta)) - Vertex[i].y * (Math.Cos(Phi) * Math.Sin(Teta)) + Vertex[i].z * Math.Sin(Phi));
View[i].z = -20 * (int)Math.Round(Vertex[i].x * (-Math.Sin(Phi) * Math.Cos(Teta)) - Vertex[i].y * (Math.Sin(Phi) * Math.Sin(Teta)) - Vertex[i].z * (Math.Cos(Phi)) + R0);
// ????????????? ?????????????? ??????? ?????????
Perspective[i].X = pictureBox1.Width / 2 + (int)Math.Round(D0 * (View[i].x / View[i].z));
Perspective[i].Y = pictureBox1.Height / 2 + (int)Math.Round(D0 * (View[i].y / View[i].z));
if (View[i].z == 0)
{
Perspective[i].X = 0;
Perspective[i].Y = 0;
}
else
{
Perspective[i].X = (int)(Math.Round(D0 * (View[i].x / View[i].z)));
Perspective[i].Y = (int)(Math.Round(D0 * (View[i].y / View[i].z)));
}
// ????????? ???????? ?????????
Scrn[i].X = (int)Perspective[i].X + pictureBox1.Width / 2;
Scrn[i].Y = (int)Perspective[i].Y + pictureBox1.Height / 2;
}
// ??????? ??????? ???????? ?? ?????????? Z ?????? ?????
for (int i = 0; i < 19; i++)
{
D[i] = (View[i].z + View[i + 20].z + View[i + 21].z + View[i + 1].z) / 4;
}
// ???????? ????? ???????
D[19] = (View[19].z + View[39].z + View[20].z + View[0].z) / 4;
// ????? - ????????? ???????
for (int i = 0; i < 19; i++)
{
D[20] += View[i].z / 20;
}
// ????? ???????-??????? ????
D[21] = (View[40].z + View[41].z + View[42].z + View[43].z) / 4;
D[22] = (View[40].z + View[44].z + View[47].z + View[43].z) / 4;
D[23] = (View[43].z + View[47].z + View[46].z + View[42].z) / 4;
D[24] = (View[42].z + View[46].z + View[45].z + View[41].z) / 4;
D[25] = (View[41].z + View[45].z + View[44].z + View[40].z) / 4;
D[26] = (View[44].z + View[45].z + View[46].z + View[47].z) / 4;
// ????????? ?????? ??????
List<Point[]> Plane = new List<Point[]>();
for (int i = 0; i < 19; i++)
{
Plane.Add(new Point[] { Scrn[i], Scrn[20 + i], Scrn[21 + i], Scrn[1 + i] });
}
Plane.Add(new Point[] { Scrn[19], Scrn[39], Scrn[20], Scrn[0] });
Plane.Add(new Point[] {Scrn[0], Scrn[1], Scrn[2], Scrn[3], Scrn[4], Scrn[5], Scrn[6], Scrn[7], Scrn[8], Scrn[9], Scrn[10], Scrn[11], Scrn[12], Scrn[13], Scrn[14], Scrn[15], Scrn[16], Scrn[17], Scrn[18], Scrn[19]});
// ??? ???????-??????? ?????
Plane.Add(new Point[] { Scrn[40], Scrn[41], Scrn[42], Scrn[43] });
Plane.Add(new Point[] { Scrn[40], Scrn[44], Scrn[47], Scrn[43] });
Plane.Add(new Point[] { Scrn[43], Scrn[47], Scrn[46], Scrn[42] });
Plane.Add(new Point[] { Scrn[42], Scrn[46], Scrn[45], Scrn[41] });
Plane.Add(new Point[] { Scrn[41], Scrn[45], Scrn[44], Scrn[40] });
Plane.Add(new Point[] { Scrn[44], Scrn[45], Scrn[46], Scrn[47] });
// ?????? ?????? ??? ?????? ?????
List<Color> PlaneColor = new List<Color>() {
Color.FromArgb(80, 208, 208, 208), // 1 ????? ???????
Color.FromArgb(80, 208, 208, 208), // 2 ????? ???????
Color.FromArgb(80, 208, 208, 208), // 3 ????? ???????
Color.FromArgb(80, 208, 208, 208), // 4 ????? ???????
Color.FromArgb(80, 208, 208, 208), // 5 ????? ???????
Color.FromArgb(80, 208, 208, 208), // 6 ????? ???????
Color.FromArgb(80, 208, 208, 208), // 7 ????? ???????
Color.FromArgb(80, 208, 208, 208), // 8 ????? ???????
Color.FromArgb(80, 208, 208, 208), // 9 ????? ???????
Color.FromArgb(80, 208, 208, 208), // 10 ????? ???????
Color.FromArgb(80, 208, 208, 208), // 11 ????? ???????
Color.FromArgb(80, 208, 208, 208), // 12 ????? ???????
Color.FromArgb(80, 208, 208, 208), // 13 ????? ???????
Color.FromArgb(80, 208, 208, 208), // 14 ????? ???????
Color.FromArgb(80, 208, 208, 208), // 15 ????? ???????
Color.FromArgb(80, 208, 208, 208), // 16 ????? ???????
Color.FromArgb(80, 208, 208, 208), // 17 ????? ???????
Color.FromArgb(80, 208, 208, 208), // 18 ????? ???????
Color.FromArgb(80, 208, 208, 208), // 19 ????? ???????
Color.FromArgb(80, 208, 208, 208), // 20 ????? ???????
Color.FromArgb(100, 102, 102, 102), // 21 - ????????? ???????
Color.FromArgb(255, 204, 255, 0), // ????? ????
Color.FromArgb(255, 204, 255, 0), // ????? ????
Color.FromArgb(255, 204, 255, 0), // ????? ????
Color.FromArgb(255, 204, 255, 0), // ????? ????
Color.FromArgb(255, 204, 255, 0), // ????? ????
Color.FromArgb(255, 204, 255, 0), // ????? ????
};
????????????????(27, 0); // ?????????? 27 ?????? ?? ???????, ??????? ? 0-?? ?????
?????????????????(); // ?????????? ??????? ? ????????? ?? ???? ??????
for (int i = 0; i < 27; i++) // ?????????? ??? ?????
{
if (NZ[Order[i]] >= 0) // ???? ????? ?? ?????
{
int A = (int)((double)PlaneColor[Order[i]].A); // ????????????
int R = (int)((double)PlaneColor[Order[i]].R * NZ[Order[i]]); // ??????? ???? * ?????????????
int G = (int)((double)PlaneColor[Order[i]].G * NZ[Order[i]]); // ??????? ???? * ?????????????
int B = (int)((double)PlaneColor[Order[i]].B * NZ[Order[i]]); // ????? ???? * ?????????????
Color Glass = Color.FromArgb(A, R, G, B); // ?????? ????
g.FillPolygon(new SolidBrush(Glass), Plane[Order[i]]); // ????????
}
if (NZ[Order[i]] <= 0) // ???? ????? ?????
{
int A = (int)Math.Abs(((double)PlaneColor[Order[i]].A));
int R = (int)Math.Abs(((double)PlaneColor[Order[i]].R * NZ[Order[i]]));
int G = (int)Math.Abs(((double)PlaneColor[Order[i]].G * NZ[Order[i]]));
int B = (int)Math.Abs(((double)PlaneColor[Order[i]].B * NZ[Order[i]]));
Color Glass = Color.FromArgb(A, R, G, B);
g.FillPolygon(new SolidBrush(Glass), Plane[Order[i]]);
}
}
}
// ????????? ?????????? ???????? ? ????????????
void ?????????????????()
{
// ????????? ???????? ? ?????? 19 ?????? ???????
for (int i = 0; i < 19; i++)
{
nx = View[i].y * (View[i + 20].z - View[i + 21].z) + View[i + 20].y * (View[i + 21].z - View[i].z) + View[i + 21].y * (View[i].z - View[i + 20].z);
ny = View[i].z * (View[i + 20].x - View[i + 21].x) + View[i + 20].z * (View[i + 21].x - View[i].x) + View[i + 21].z * (View[i].x - View[i + 20].x);
nz = View[i].x * (View[i + 20].y - View[i + 21].y) + View[i + 20].x * (View[i + 21].y - View[i].y) + View[i + 21].x * (View[i].y - View[i + 20].y);
NZ[i] = nz / Math.Sqrt(nz * nz + ny * ny + nx * nx);
}
// ??????? ? 19-?? ????? (?? ????????? ?????)
nx = View[19].y * (View[39].z - View[20].z) + View[39].y * (View[20].z - View[19].z) + View[20].y * (View[19].z - View[39].z);
ny = View[19].z * (View[39].x - View[20].x) + View[39].z * (View[20].x - View[19].x) + View[20].z * (View[19].x - View[39].x);
nz = View[19].x * (View[39].y - View[20].y) + View[39].x * (View[20].y - View[19].y) + View[20].x * (View[19].y - View[39].y);
NZ[19] = nz / Math.Sqrt(nz * nz + ny * ny + nx * nx);
// ??????? ? ????? (????????? ???????), ????? ????? 10 ??????, ????? 3 (0, 10, 19)
nx = View[0].y * (View[10].z - View[19].z) + View[10].y * (View[19].z - View[0].z) + View[19].y * (View[0].z - View[10].z);
ny = View[0].z * (View[10].x - View[19].x) + View[10].z * (View[19].x - View[0].x) + View[19].z * (View[0].x - View[10].x);
nz = View[0].x * (View[10].y - View[19].y) + View[10].x * (View[19].y - View[0].y) + View[19].x * (View[0].y - View[10].y);
NZ[20] = nz / Math.Sqrt(nz * nz + ny * ny + nx * nx);
// 40, 41, 42
nx = View[40].y * (View[41].z - View[42].z) + View[41].y * (View[42].z - View[40].z) + View[42].y * (View[40].z - View[41].z);
ny = View[40].z * (View[41].x - View[42].x) + View[41].z * (View[42].x - View[40].x) + View[42].z * (View[40].x - View[41].x);
nz = View[40].x * (View[41].y - View[42].y) + View[41].x * (View[42].y - View[40].y) + View[42].x * (View[40].y - View[41].y);
NZ[21] = nz / Math.Sqrt(nz * nz + ny * ny + nx * nx);
// 40, 44, 47
nx = View[40].y * (View[44].z - View[47].z) + View[44].y * (View[47].z - View[40].z) + View[47].y * (View[40].z - View[44].z);
ny = View[40].z * (View[44].x - View[47].x) + View[44].z * (View[47].x - View[40].x) + View[47].z * (View[40].x - View[44].x);
nz = View[40].x * (View[44].y - View[47].y) + View[44].x * (View[47].y - View[40].y) + View[47].x * (View[40].y - View[44].y);
NZ[22] = nz / Math.Sqrt(nz * nz + ny * ny + nx * nx);
// 43, 47, 46
nx = View[43].y * (View[47].z - View[46].z) + View[47].y * (View[46].z - View[43].z) + View[46].y * (View[43].z - View[47].z);
ny = View[43].z * (View[47].x - View[46].x) + View[47].z * (View[46].x - View[43].x) + View[46].z * (View[43].x - View[47].x);
nz = View[43].x * (View[47].y - View[46].y) + View[47].x * (View[46].y - View[43].y) + View[46].x * (View[43].y - View[47].y);
NZ[23] = nz / Math.Sqrt(nz * nz + ny * ny + nx * nx);
// 42, 46, 45
nx = View[42].y * (View[46].z - View[45].z) + View[46].y * (View[45].z - View[42].z) + View[45].y * (View[42].z - View[46].z);
ny = View[42].z * (View[46].x - View[45].x) + View[46].z * (View[45].x - View[42].x) + View[45].z * (View[42].x - View[46].x);
nz = View[42].x * (View[46].y - View[45].y) + View[46].x * (View[45].y - View[42].y) + View[45].x * (View[42].y - View[46].y);
NZ[24] = nz / Math.Sqrt(nz * nz + ny * ny + nx * nx);
// 41, 45, 44
nx = View[41].y * (View[45].z - View[44].z) + View[45].y * (View[44].z - View[41].z) + View[44].y * (View[41].z - View[45].z);
ny = View[41].z * (View[45].x - View[44].x) + View[45].z * (View[44].x - View[41].x) + View[44].z * (View[41].x - View[45].x);
nz = View[41].x * (View[45].y - View[44].y) + View[45].x * (View[44].y - View[41].y) + View[44].x * (View[41].y - View[45].y);
NZ[25] = nz / Math.Sqrt(nz * nz + ny * ny + nx * nx);
// 44, 45, 46
nx = View[44].y * (View[45].z - View[46].z) + View[45].y * (View[46].z - View[44].z) + View[46].y * (View[44].z - View[45].z);
ny = View[44].z * (View[45].x - View[46].x) + View[45].z * (View[46].x - View[44].x) + View[46].z * (View[44].x - View[45].x);
nz = View[44].x * (View[45].y - View[46].y) + View[45].x * (View[46].y - View[44].y) + View[46].x * (View[44].y - View[45].y);
NZ[26] = nz / Math.Sqrt(nz * nz + ny * ny + nx * nx);
}
// ???????? ??????????? ????
void ?????????????()
{
??????????????();
pictureBox1.Image = b;
}
// ?????-????
bool Flag(int i, int PlaneNumber, int[] Order)
{
bool flag = true; // ???? ??????
for (int j = 0; j < PlaneNumber; j++) // ?????????? ????? ?? ?? ???????
if (Order[j] == i) flag = false; // ?????????? ????? ????? ? ??????? ??????? ? ??????? ?????? ?????
return flag; // ?????????? ???????? ?????
}
// ????? ?????????? ??????
void ????????????????(int PlanesCount, int PlaneNumber)
{
double k = 1000; // ?????????? ???????
for (int i = 0; i < 27; i++) // ?????????? ??? ?????
{ if (Flag(i, PlaneNumber, Order)) //
if (D[i] < k) // ???? ??. ????. ?? Z < ?????????? ???????
{ // ??...
k = D[i]; // ?????????? ??????? ????????? ??????????? ????????
Order[PlaneNumber] = i; // ?????????? ??????? ?? ??????? ???????????? ??????
}
}
PlanesCount --; // ????????? ?????????? ?????? ?? 1
PlaneNumber ++; // ??????????? ????? ????? ?? 1
if (PlanesCount > 0) // ???? ?????????? ?????? > 0, ???????? ????????
????????????????(PlanesCount, PlaneNumber);
}
// ???????, ?????????????? ??? ???????? ????? ??????????
private void Form1_Load(object sender, EventArgs e)
{
Teta = 89.549087;
Phi = 134.99817;
Vertex[0] = new Point3D(-50, -50, 0); // A
Vertex[1] = new Point3D(-48, -50, -15); // B
Vertex[2] = new Point3D(-40, -50, -30); // C
Vertex[3] = new Point3D(-28, -50, -42); // D Vertex[4] = new Point3D(-15, -50, -48); // E
Vertex[5] = new Point3D(0, -50, -50); // F
Vertex[6] = new Point3D(15, -50, -48); // G
Vertex[7] = new Point3D(28, -50, -42); // H
Vertex[8] = new Point3D(40, -50, -30); // I Vertex[9] = new Point3D(48, -50, -15); // J
Vertex[10] = new Point3D(50, -50, 0); // K
Vertex[11] = new Point3D(48, -50, 15); // L
Vertex[12] = new Point3D(40, -50, 30); // M
Vertex[13] = new Point3D(28, -50, 42); // N
Vertex[14] = new Point3D(15, -50, 48); // O
Vertex[15] = new Point3D(0, -50, 50); // P
Vertex[16] = new Point3D(-15, -50, 48); // R
Vertex[17] = new Point3D(-28, -50, 42); // S
Vertex[18] = new Point3D(-40, -50, 30); // T
Vertex[19] = new Point3D(-48, -50, 15); // U
// ??????? ????????? ???????
Vertex[20] = new Point3D(-60, 100, 0); // A-1
Vertex[21] = new Point3D(-58, 100, -19); // B-1
Vertex[22] = new Point3D(-48, 100, -36); // C-1
Vertex[23] = new Point3D(-35, 100, -50); // D-1
Vertex[24] = new Point3D(-18, 100, -58); // E-1
Vertex[25] = new Point3D(0, 100, -60); // F-1
Vertex[26] = new Point3D(18, 100, -58); // G-1
Vertex[27] = new Point3D(35, 100, -50); // H-1
Vertex[28] = new Point3D(48, 100, -36); // I-1
Vertex[29] = new Point3D(58, 100, -19); // J-1
Vertex[30] = new Point3D(60, 100, 0); // K-11
Vertex[31] = new Point3D(58, 100, 19); // L-12
Vertex[32] = new Point3D(48, 100, 36); // M-13
Vertex[33] = new Point3D(35, 100, 50); // N-14
Vertex[34] = new Point3D(18, 100, 58); // O-15
Vertex[35] = new Point3D(0, 100, 60); // P-16
Vertex[36] = new Point3D(-18, 100, 58); // R-17
Vertex[37] = new Point3D(-35, 100, 50); // S-18
Vertex[38] = new Point3D(-48, 100, 36); // T-19
Vertex[39] = new Point3D(-58, 100, 19); // U-20
// ???????-?????? ??? (? = 50)
// ?????? ?????
Vertex[40] = new Point3D(-60, -50, -65); // A
Vertex[41] = new Point3D(-60, -50, -115); // B
Vertex[42] = new Point3D(-10, -50, -115); // C
Vertex[43] = new Point3D(-10, -50, -65); // D
// ??????? ?????
Vertex[44] = new Point3D(-60, 0, -65); // A-1
Vertex[45] = new Point3D(-60, 0, -115); // B-1
Vertex[46] = new Point3D(-10, 0, -115); // C-1
Vertex[47] = new Point3D(-10, 0, -65); // D-1
?????????????();
}
// ?????????? ?????? ? ??????? ??????-???????
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Up)
{
Phi = Phi + Math.PI / 128;
?????????????();
}
if (e.KeyCode == Keys.Down)
{
Phi = Phi - Math.PI / 128;
?????????????();
}
if (e.KeyCode == Keys.Right)
{
Teta = Teta + Math.PI / 128;
?????????????();
}
if (e.KeyCode == Keys.Left)
{
Teta = Teta - Math.PI / 128;
?????????????();
}
}
// ?????????? ?????? ? ??????? ????
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (mousePress)
{
if (e.X < sX)
{
Teta = Teta - Math.PI / 128;
sX = e.X;
}
if (e.X > sX)
{
Teta = Teta + Math.PI / 128;
sX = e.X;
}
if (e.Y > sY)
{
Phi = Phi - Math.PI / 128;
sY = e.Y;
}
if (e.Y < sY)
{
Phi = Phi + Math.PI / 128;
sY = e.Y;
}
?????????????();
}
}
// ???????, ??????????? ??? ?????????? ????
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
mousePress = false;
}
// ???????, ??????????? ??? ??????? ????
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
mousePress = true;
if (e.Button == MouseButtons.Right)
{
R0 = 300;
?????????????();
}
}
// ??????? ??? ????????? ?????? ????
void Form1_MouseWheel(object sender, MouseEventArgs e)
{
if ((e.Delta == 120) && (R0 != 150))
{
R0 -= 5;
?????????????();
}
else if ((e.Delta == -120) && (R0 != 800))
{
R0 += 5;
?????????????();
}
}
}
}
2
2
Документ
Категория
Без категории
Просмотров
11
Размер файла
2 556 Кб
Теги
moya_kursovaya
1/--страниц
Пожаловаться на содержимое документа