Структура и назначение программного кода программы по созданию 3D-графики средствами языка программирования Visual Basic. Элементы управления "Окно формы" и "Таймер", выполняемые ими функции и основные свойства, значение в работе программного кода.
Аннотация к работе
КАФЕДРА: АСОИиУ Лабораторная работа по программированию Создание 3D-графики средствами языка программирования Visual Basic Душанбе, 2009 год Интерфейс Рабочей Формы Интерфейс программы (в действии) Исходный (программный код) Private FPS As Long Private all_stop As Boolean Private cube As Object3D Private Sub Form_Load() Call LoadObject(cube) all_stop = False End Sub Private Sub Form_Unload (Cancel As Integer) all_stop = True End Sub Private Sub Timer1_Timer() Dim temp As Object3D Dim ang As Single Timer1. Enabled = False Do temp = cube Me. Cls Call ScaleObject (10, 10, 10, temp) Call RotateObject (ang, -0.5, 0, temp) Call TranslateObject (0, 0, 50, temp) Call ProjectObject (temp, Me) Call DisplayObject (temp, Me) FPS = FPS 1 ang = ang 0.02: If ang > 6.282 Then ang = 0 DoEvents Loop Until all_stop End Sub Private Sub Timer2_Timer() Me. Caption = «VB/3D - Tutorial #1 - FPS =» Str$(FPS) FPS = 0 End Sub Private Type Vertex3D x As Single y As Single z As Single sx As Long sy As Long End Type Private Type Polygon3D v_pointer(2) As Long colr As Long End Type Public Type Object3D vertex() As Vertex3D polygon() As Polygon3D End Type Public Sub LoadObject (obj As Object3D) ReDim obj.vertex(7), obj.polygon(11) obj.vertex(0).x = -1: obj.vertex(0).y = -1: obj.vertex(0).z = -1 obj.vertex(1).x = -1: obj.vertex(1).y = -1: obj.vertex(1).z = 1 obj.vertex(2).x = 1: obj.vertex(2).y = -1: obj.vertex(2).z = 1 obj.vertex(3).x = 1: obj.vertex(3).y = -1: obj.vertex(3).z = -1 obj.vertex(4).x = -1: obj.vertex(4).y = 1: obj.vertex(4).z = -1 obj.vertex(5).x = -1: obj.vertex(5).y = 1: obj.vertex(5).z = 1 obj.vertex(6).x = 1: obj.vertex(6).y = 1: obj.vertex(6).z = 1 obj.vertex(7).x = 1: obj.vertex(7).y = 1: obj.vertex(7).z = -1 obj.polygon(0).v_pointer(0) = 0: obj.polygon(0).v_pointer(1) = 2: obj.polygon(0).v_pointer(2) = 1 obj.polygon(0).colr = RGB (255, 0, 0) obj.polygon(1).v_pointer(0) = 0: obj.polygon(1).v_pointer(1) = 3: obj.polygon(1).v_pointer(2) = 2 obj.polygon(1).colr = RGB (255, 0, 0) obj.polygon(2).v_pointer(0) = 4: obj.polygon(2).v_pointer(1) = 0: obj.polygon(2).v_pointer(2) = 1 obj.polygon(2).colr = RGB (255, 0, 0) obj.polygon(3).v_pointer(0) = 4: obj.polygon(3).v_pointer(1) = 1: obj.polygon(3).v_pointer(2) = 5 obj.polygon(3).colr = RGB (255, 0, 0) obj.polygon(4).v_pointer(0) = 5: obj.polygon(4).v_pointer(1) = 1: obj.polygon(4).v_pointer(2) = 2 obj.polygon(4).colr = RGB (255, 0, 0) obj.polygon(5).v_pointer(0) = 5: obj.polygon(5).v_pointer(1) = 2: obj.polygon(5).v_pointer(2) = 6 obj.polygon(5).colr = RGB (255, 0, 0) obj.polygon(6).v_pointer(0) = 7: obj.polygon(6).v_pointer(1) = 2: obj.polygon(6).v_pointer(2) = 3 obj.polygon(6).colr = RGB (255, 0, 0) obj.polygon(7).v_pointer(0) = 7: obj.polygon(7).v_pointer(1) = 6: obj.polygon(7).v_pointer(2) = 2 obj.polygon(7).colr = RGB (255, 0, 0) obj.polygon(8).v_pointer(0) = 4: obj.polygon(8).v_pointer(1) = 5: obj.polygon(8).v_pointer(2) = 6 obj.polygon(8).colr = RGB (255, 0, 0) obj.polygon(9).v_pointer(0) = 4: obj.polygon(9).v_pointer(1) = 6: obj.polygon(9).v_pointer(2) = 7 obj.polygon(9).colr = RGB (255, 0, 0) obj.polygon(10).v_pointer(0) = 4: obj.polygon(10).v_pointer(1) = 3: obj.polygon(10).v_pointer(2) = 0 obj.polygon(10).colr = RGB (255, 0, 0) obj.polygon(11).v_pointer(0) = 4: obj.polygon(11).v_pointer(1) = 7: obj.polygon(11).v_pointer(2) = 3 obj.polygon(11).colr = RGB (255, 0, 0) End Sub Public Sub DisplayObject (obj As Object3D, frm As Object) Dim poly As Long For poly = 0 To UBound (obj.polygon()) Call DrawTriangle (obj, poly, frm) Next End Sub Private Sub DrawTriangle (obj As Object3D, poly As Long, frm As Object) Dim x0 As Long, y0 As Long Dim x1 As Long, y1 As Long Dim x2 As Long, y2 As Long x0 = obj.vertex (obj.polygon(poly).v_pointer(0)).sx y0 = obj.vertex (obj.polygon(poly).v_pointer(0)).sy x1 = obj.vertex (obj.polygon(poly).v_pointer(1)).sx y1 = obj.vertex (obj.polygon(poly).v_pointer(1)).sy x2 = obj.vertex (obj.polygon(poly).v_pointer(2)).sx y2 = obj.vertex (obj.polygon(poly).v_pointer(2)).sy frm.