МИНИСТЕРСТВО ОБРАЗОВАНИЯ И НАУКИ РОССИЙСКОЙ ФЕДЕРАЦИИ ФЕДЕРАЛЬНОЕ ГОСУДАРСТВЕННОЕ БЮДЖЕТНОЕ ОБРАЗОВАТЕЛЬНОЕ УЧРЕЖДЕНИЕ ВЫСШЕГО ПРОФЕССИОНАЛЬНОГО ОБРАЗОВАНИЯ "РОССИЙСКИЙ ГОСУДАРСТВЕННЫЙ СОЦИАЛЬНЫЙ УНИВЕРСИТЕТ" КУРСКИЙ ИНСТИТУТ СОЦИАЛЬНОГО ОБРАЗОВАНИЯ (ФИЛИАЛ) РГСУ Инженерно-технический факультет Кафедра информационных систем и информационного права ЛАБОРАТОРНАЯ РАБОТА 21271 по дисциплине: "Инженерная и компьютерная графика" на тему: Возвращение контроля над устройством Выполнил студент 3 курса группы ИВТ специальности "Информатика и вычислительная техника" очной формы обучения Умеренков Павел Игоревич Проверила: Королькова Ирина Анатольевна Лабораторная работа зачтена/не зачтена "__"_______20__г. Курск 2013г. Лабораторная работа №7 . Рендеринг объемных фигур: Создание поверхности из нескольких полигонов, вращение объемной фигуры. Цель работы: Приобретение навыков построения объемных фигур в DirectX. Код программы: 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; using Microsoft.DirectX; using Microsoft.DirectX.Direct3D; namespace lab1 { public partial class Form1 : Form { float A = 0f; VertexBuffer Buffer; Device device = null; private CustomVertex.PositionColored[] Vertex = new CustomVertex.PositionColored[36]; public Form1() { this.SetStyle(ControlStyles.AllPaintingInWmPaint|ControlStyles.Opaque,true); this.UpdateStyles(); InitializeComponent(); InitializeDevice(); initializeCamera(); InitializeVericies(); } private void InitializeDevice() { PresentParameters presentParams = new PresentParameters(); presentParams.Windowed = true; presentParams.SwapEffect = SwapEffect.Discard; device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams); } protected override void OnPaint(PaintEventArgs e) { device.Clear(ClearFlags.Target, Color.CornflowerBlue, 0, 1); device.BeginScene(); Draw(); device.EndScene(); device.Present(); this.Invalidate(); A+=0.05f; } private void InitializeVericies() { Buffer = new VertexBuffer(typeof(CustomVertex.PositionColored), 36, device, Usage.WriteOnly, CustomVertex.PositionColored.Format, Pool.Default); //задняя грань 2-0-1(невидимая,левый) Vertex[0] = new CustomVertex.PositionColored(new Vector3(3.0F, 3.0F, 3.0F), Color.Red.ToArgb()); Vertex[1] = new CustomVertex.PositionColored(new Vector3(-3.0F, 3.0F, 3.0F), Color.Red.ToArgb()); Vertex[2] = new CustomVertex.PositionColored(new Vector3(-3.0F, -3.0F, 3.0F), Color.Red.ToArgb()); //задняя грань 2-1-3(невидимая,левый) Vertex[3] = new CustomVertex.PositionColored(new Vector3(3.0F, 3.0F, 3.0F), Color.Red.ToArgb()); Vertex[4] = new CustomVertex.PositionColored(new Vector3(-3.0F, -3.0F, 3.0F), Color.Red.ToArgb()); Vertex[5] = new CustomVertex.PositionColored(new Vector3(3.0F, -3.0F, 3.0F), Color.Red.ToArgb()); //передняя грань 5-6-4 (лицевая,правый) Vertex[6] = new CustomVertex.PositionColored(new Vector3(3.0F, 3.0F, -3.0F), Color.Blue.ToArgb()); Vertex[7] = new CustomVertex.PositionColored(new Vector3(-3.0F, -3.0F, -3.0F), Color.Blue.ToArgb()); Vertex[8] = new CustomVertex.PositionColored(new Vector3(-3.0F, 3.0F, -3.0F), Color.Blue.ToArgb()); //передняя грань 5-7-6(лицевая,правый) Vertex[9] = new CustomVertex.PositionColored(new Vector3(3.0F, 3.0F, -3.0F), Color.Blue.ToArgb()); Vertex[10] = new CustomVertex.PositionColored(new Vector3(3.0F, -3.0F, -3.0F), Color.Blue.ToArgb()); Vertex[11] = new CustomVertex.PositionColored(new Vector3(-3.0F, -3.0F, -3.0F), Color.Blue.ToArgb()); //верхняя грань 0-5-4(лицевая,правый) Vertex[12] = new CustomVertex.PositionColored(new Vector3(-3.0F, 3.0F, 3.0F), Color.Yellow.ToArgb()); Vertex[13] = new CustomVertex.PositionColored(new Vector3(3.0F, 3.0F, -3.0F), Color.Yellow.ToArgb()); Vertex[14] = new CustomVertex.PositionColored(new Vector3(-3.0F, 3.0F, -3.0F), Color.Yellow.ToArgb()); //верхняя грань 0-2-5(лицевая,правый) Vertex[15] = new CustomVertex.PositionColored(new Vector3(-3.0F, 3.0F, 3.0F), Color.Yellow.ToArgb()); Vertex[16] = new CustomVertex.PositionColored(new Vector3(3.0F, 3.0F, 3.0F), Color.Yellow.ToArgb()); Vertex[17] = new CustomVertex.PositionColored(new Vector3(3.0F, 3.0F, -3.0F), Color.Yellow.ToArgb()); //нижняя грань 1-6-7(невидимая,левый) Vertex[18] = new CustomVertex.PositionColored(new Vector3(-3.0F, -3.0F, 3.0F), Color.Black.ToArgb()); Vertex[19] = new CustomVertex.PositionColored(new Vector3(-3.0F, -3.0F, -3.0F), Color.Black.ToArgb()); Vertex[20] = new CustomVertex.PositionColored(new Vector3(3.0F, -3.0F, -3.0F), Color.Black.ToArgb()); //нижняя грань 1-7-3(невидимая,левый) Vertex[21] = new CustomVertex.PositionColored(new Vector3(-3.0F, -3.0F, 3.0F), Color.Black.ToArgb()); Vertex[22] = new CustomVertex.PositionColored(new Vector3(3.0F, -3.0F, -3.0F), Color.Black.ToArgb()); Vertex[23] = new CustomVertex.PositionColored(new Vector3(3.0F, -3.0F, 3.0F), Color.Black.ToArgb()); //левая грань 0-6-1(невидимая,левый) Vertex[24] = new CustomVertex.PositionColored(new Vector3(-3.0F, 3.0F, 3.0F), Color.Gray.ToArgb()); Vertex[25] = new CustomVertex.PositionColored(new Vector3(-3.0F, -3.0F, -3.0F), Color.Gray.ToArgb()); Vertex[26] = new CustomVertex.PositionColored(new Vector3(-3.0F, -3.0F, 3.0F), Color.Gray.ToArgb()); //левая грань 0-4-6(невидимая,левый) Vertex[27] = new CustomVertex.PositionColored(new Vector3(-3.0F, 3.0F, 3.0F), Color.Gray.ToArgb()); Vertex[28] = new CustomVertex.PositionColored(new Vector3(-3.0F, 3.0F, -3.0F), Color.Gray.ToArgb()); Vertex[29] = new CustomVertex.PositionColored(new Vector3(-3.0F, -3.0F, -3.0F), Color.Gray.ToArgb()); //правая грань 2-3-7(лицевая,правый) Vertex[30] = new CustomVertex.PositionColored(new Vector3(3.0F, 3.0F, 3.0F), Color.Green.ToArgb()); Vertex[31] = new CustomVertex.PositionColored(new Vector3(3.0F, -3.0F, 3.0F), Color.Green.ToArgb()); Vertex[32] = new CustomVertex.PositionColored(new Vector3(3.0F, -3.0F, -3.0F), Color.Green.ToArgb()); //правая грань 2-7-5(лицевая,правый) Vertex[33] = new CustomVertex.PositionColored(new Vector3(3.0F, 3.0F, 3.0F), Color.Green.ToArgb()); Vertex[34] = new CustomVertex.PositionColored(new Vector3(3.0F, -3.0F, -3.0F), Color.Green.ToArgb()); Vertex[35] = new CustomVertex.PositionColored(new Vector3(3.0F, 3.0F, -3.0F), Color.Green.ToArgb()); Buffer.SetData(Vertex, 0, LockFlags.None); } private void initializeCamera() { device.Transform.Projection = Matrix.PerspectiveFovLH(3.14f / 4, Width / Height, 1f, 10000f); device.Transform.View= Matrix.LookAtLH(new Vector3(0,0,50),new Vector3(),new Vector3(0,1,0)); device.RenderState.Lighting = false; // device.RenderState.CullMode = Cull.None; } private void Draw() { device.VertexFormat = CustomVertex.PositionColored.Format; device.Transform.World = Matrix.RotationYawPitchRoll(A / (float)Math.PI, A / (float)Math.PI * 2.0F, A / (float)Math.PI); device.SetStreamSource(0, Buffer, 0); device.DrawPrimitives(PrimitiveType.TriangleList, 0, 12); } } }
1/--страниц