VERSION 5.00 Begin VB.Form Form1 Caption = "Form1" ClientHeight = 8055 ClientLeft = 60 ClientTop = 345 ClientWidth = 8880.001 LinkTopic = "Form1" ScaleHeight = 8055 ScaleWidth = 8880.001 StartUpPosition = 3 'Windows Default Begin VB.Timer Timer1 Interval = 40 Left = 3720 Top = 2760 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Dim bRunning As Boolean ' Variabile per definire l'usica dal ciclo di rendering Dim Rot As Single ' Tipo di vertici utilizzati Private Type CUSTOMVERTEX X As Single 'x Y As Single 'y Z As Single 'z. Nx As Single ' coordinate delle normali Ny As Single Nz As Single tU As Single ' coordinate di mappatura tV As Single End Type ' Crea un vettore Private Function MakeVector(ByVal X As Single, ByVal Y As Single, ByVal Z As Single) As D3DVECTOR MakeVector.X = X MakeVector.Y = Y MakeVector.Z = Z End Function ' Crea un vertice Private Function MakeVertex(ByVal X As Single, ByVal Y As Single, ByVal Z As Single, _ ByVal Nx As Single, ByVal Ny As Single, ByVal Nz As Single, _ ByVal U As Single, ByVal V As Single) As CUSTOMVERTEX MakeVertex.X = X MakeVertex.Y = Y MakeVertex.Z = Z MakeVertex.Nx = Nx MakeVertex.Ny = Ny MakeVertex.Nz = Nz MakeVertex.tU = U MakeVertex.tV = 1 - V End Function ' Attivata quando l'utente clicca sulla finestra, per chiudere l'applicazione Private Sub Form_Click() bRunning = False End Sub ' Programma vero e prorpio! Private Sub Form_Load() ' Inizializzazione della libreria ''''''''''''''''''''''''''''''''' ' Dichiarazioni variabili per le DirectX Dim Dx As DirectX8 Dim D3D As Direct3D8 Dim D3DDevice As Direct3DDevice8 Dim DispMode As D3DDISPLAYMODE Dim D3DWindow As D3DPRESENT_PARAMETERS ' Dichiarazioni variabili per l'applicazione Dim Light As D3DLIGHT8 Dim Material As D3DMATERIAL8 Dim V(23) As CUSTOMVERTEX Dim I(35) As Integer ' Dichiarazioni variabili per il ciclo di rendering Dim matView As D3DMATRIX Dim matProj As D3DMATRIX Dim matWorld As D3DMATRIX Dim matTemp As D3DMATRIX ' Variabili per la texutre Dim D3DX As D3DX8 '//A helper library Dim texture As Direct3DTexture8 ' Si collega con le DirectX Set Dx = New DirectX8 Set D3D = Dx.Direct3DCreate() ' Imposta la modalita' video in finsetra D3D.GetAdapterDisplayMode D3DADAPTER_DEFAULT, DispMode D3DWindow.Windowed = 1 D3DWindow.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC D3DWindow.BackBufferFormat = DispMode.Format ' Imposta lo Z-Buffere D3DWindow.AutoDepthStencilFormat = D3DFMT_D16 D3DWindow.EnableAutoDepthStencil = 1 ' Crea l'applicazione Set D3DDevice = D3D.CreateDevice(D3DADAPTER_DEFAULT, _ D3DDEVTYPE_HAL, hWnd, _ D3DCREATE_SOFTWARE_VERTEXPROCESSING, _ D3DWindow) ' Definisce il tipo di vertici utilizzati D3DDevice.SetVertexShader D3DFVF_XYZ Or D3DFVF_NORMAL Or _ D3DFVF_TEX1 ' Abilita l'illuminazione D3DDevice.SetRenderState D3DRS_LIGHTING, True ' Abilita lo Z-Buffer D3DDevice.SetRenderState D3DRS_ZENABLE, True ' Inizializzazione dell'applicazione '''''''''''''''''''''''''''''''''''' ' Mostra la finestra Me.Show ' Imposta la cinepresa D3DXMatrixLookAtLH matView, MakeVector(0, 2.5, 5), _ MakeVector(0, 0, 0), MakeVector(0, 1, 0) D3DDevice.SetTransform D3DTS_VIEW, matView D3DXMatrixPerspectiveFovLH matProj, 3.1416 / 4, 1, 0.1, 500 D3DDevice.SetTransform D3DTS_PROJECTION, matProj ' Imposta la luce Light.Type = D3DLIGHT_POINT Light.Position = MakeVector(3, 5, 9) Light.diffuse.r = 1 Light.diffuse.g = 1 Light.diffuse.b = 1 Light.Range = 100 Light.Attenuation1 = 0.05 D3DDevice.SetLight 0, Light D3DDevice.LightEnable 0, 1 ' Imposta il materiale Material.diffuse.r = 1 Material.diffuse.g = 1 Material.diffuse.b = 1 D3DDevice.SetMaterial Material ' Crea la geometria V(0) = MakeVertex(-0.5, -0.5, 0.5, -1, 0, 0, 0.2649840117, 0.252863884) V(1) = MakeVertex(-0.5, -0.5, 0.5, 0, -1, 0, 0.2649840117, 1.24887979) V(2) = MakeVertex(-0.5, -0.5, 0.5, 0, 0, 1, 0.2649840117, 0.252863884) V(3) = MakeVertex(0.5, -0.5, 0.5, 0, 0, 1, 0.4995146096, 0.252863884) V(4) = MakeVertex(0.5, -0.5, 0.5, 0, -1, 0, 0.4995146096, 1.24887979) V(5) = MakeVertex(0.5, -0.5, 0.5, 1, 0, 0, 0.5016660094, 0.4914968312) V(6) = MakeVertex(-0.5, 0.5, 0.5, 0, 0, 1, 0.2649840117, 0.5018678904) V(7) = MakeVertex(-0.5, 0.5, 0.5, 0, 1, 0, 0.2649840117, 0.5018678904) V(8) = MakeVertex(-0.5, 0.5, 0.5, -1, 0, 0, 0.2649840117, 0.5018678904) V(9) = MakeVertex(0.5, 0.5, 0.5, 1, 0, 0, 0.7506700158, 0.4914968312) V(10) = MakeVertex(0.5, 0.5, 0.5, 0, 1, 0, 0.4995146096, 0.5018678904) V(11) = MakeVertex(0.5, 0.5, 0.5, 0, 0, 1, 0.4995146096, 0.5018678904) V(12) = MakeVertex(-0.5, 0.5, -0.5, -1, 0, 0, 0.01597999781, 0.5018678904) V(13) = MakeVertex(-0.5, 0.5, -0.5, 0, 1, 0, 0.2649840117, 0.7508718967) V(14) = MakeVertex(-0.5, 0.5, -0.5, 0, 0, -1, 0.2649840117, 0.7508718967) V(15) = MakeVertex(0.5, 0.5, -0.5, 0, 0, -1, 0.4995146096, 0.7508718967) V(16) = MakeVertex(0.5, 0.5, -0.5, 0, 1, 0, 0.4995146096, 0.7508718967) V(17) = MakeVertex(0.5, 0.5, -0.5, 1, 0, 0, 0.7506700158, 0.2487154156) V(18) = MakeVertex(-0.5, -0.5, -0.5, 0, 0, -1, 0.2649840117, 0.9998759031) V(19) = MakeVertex(-0.5, -0.5, -0.5, 0, -1, 0, 0.2649840117, 0.9998759031) V(20) = MakeVertex(-0.5, -0.5, -0.5, -1, 0, 0, 0.01597999781, 0.252863884) V(21) = MakeVertex(0.5, -0.5, -0.5, 1, 0, 0, 0.5016660094, 0.2487154156) V(22) = MakeVertex(0.5, -0.5, -0.5, 0, -1, 0, 0.4995146096, 0.9998759031) V(23) = MakeVertex(0.5, -0.5, -0.5, 0, 0, -1, 0.4995146096, 0.9998759031) I(0) = 2: I(1) = 3: I(2) = 6 I(3) = 3: I(4) = 11: I(5) = 6 I(6) = 7: I(7) = 10: I(8) = 13 I(9) = 10: I(10) = 16: I(11) = 13 I(12) = 14: I(13) = 15: I(14) = 18 I(15) = 15: I(16) = 23: I(17) = 18 I(18) = 19: I(19) = 22: I(20) = 1 I(21) = 22: I(22) = 4: I(23) = 1 I(24) = 5: I(25) = 21: I(26) = 9 I(27) = 21: I(28) = 17: I(29) = 9 I(30) = 20: I(31) = 0: I(32) = 12 I(33) = 0: I(34) = 8: I(35) = 12 ' carica la texture Set D3DX = New D3DX8 Set texture = D3DX.CreateTextureFromFileEx(D3DDevice, _ "texture.bmp", D3DX_DEFAULT, D3DX_DEFAULT, _ 1, 0, D3DFMT_UNKNOWN, _ D3DPOOL_MANAGED, D3DX_FILTER_POINT, _ D3DX_FILTER_POINT, &HFF000000, _ ByVal 0, ByVal 0) ' Inizializza la variabile di permanenza nel ciclo di rendering bRunning = True ' Ciclo di rendering '''''''''''''''''''' ' Ripete fino a quando bRunning vale falso Do While bRunning ' Cancella lo schermo D3DDevice.Clear 0, ByVal 0, _ D3DCLEAR_TARGET Or D3DCLEAR_ZBUFFER, _ &H0, 1#, 0 ' Inizia a disegnare su video D3DDevice.BeginScene ' Imposta le trasformazioni dell'oggetto D3DXMatrixIdentity matWorld D3DXMatrixRotationY matTemp, Rot * (3.1416 / 180) D3DXMatrixMultiply matWorld, matWorld, matTemp D3DDevice.SetTransform D3DTS_WORLD, matWorld ' Imposta la texture D3DDevice.SetTexture 0, texture D3DDevice.SetTextureStageState 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR ' Disegna l'oggetto D3DDevice.DrawIndexedPrimitiveUP D3DPT_TRIANGLELIST, 0, 24, 12, _ I(0), D3DFMT_INDEX16, V(0), Len(V(0)) ' Finisce la fase di disegno D3DDevice.EndScene ' Trasferisce il contenuto del Doppio Buffer sullo schermo D3DDevice.Present ByVal 0, ByVal 0, 0, ByVal 0 ' Restituisce il controllo a Windows per dargli la possibilita' di gestire altri eventi DoEvents Loop ' Rilascio delle risorse '''''''''''''''''''''''' Set D3DDevice = Nothing Set D3D = Nothing Set Dx = Nothing ' Chiude l'applicazione Unload Me End Sub Private Sub Timer1_Timer() Rot = Rot + 2 If Rot = 360 Then Rot = 0 End If End Sub