|
Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D
Public Class Form1
Private ReadOnly m_DataNormals As Single(,) = New Single(,) _
{{0.0!, 0.0!, 1.0!}, {0.0!, 0.0!, 1.0!}, {0.0!, 0.0!, -1.0!}, _
{1.0!, 0.0!, -1.0!}, {0.0!, 1.0!, 0.0!}, {0.0!, 1.0!, 0.0!}, _
{0.0!, -1.0!, 0.0!}, {0.0!, -1.0!, 0.0!}, {-1.0!, 0.0!, 0.0!}, _
{-1.0!, 0.0!, 0.0!}, {1.0!, 0.0!, 0.0!}, {1.0!, 0.0!, 0.0!}}
Private ReadOnly m_DataTriangle As Single(,) = New Single(,) _
{{-1.0!, 1.0!, 1.0!}, {-1.0!, -1.0!, 1.0!}, {1.0!, 1.0!, 1.0!}, _
{-1.0!, -1.0!, 1.0!}, {1.0!, -1.0!, 1.0!}, {1.0!, 1.0!, 1.0!}, _
{-1.0!, 1.0!, -1.0!}, {1.0!, 1.0!, -1.0!}, {-1.0!, -1.0!, _
-1.0!}, {-1.0!, -1.0!, -1.0!}, {1.0!, 1.0!, -1.0!}, {1.0!, _
-1.0!, -1.0!}, {-1.0!, 1.0!, 1.0!}, {1.0!, 1.0!, -1.0!}, _
{-1.0!, 1.0!, -1.0!}, {-1.0!, 1.0!, 1.0!}, {1.0!, 1.0!, 1.0!}, _
{1.0!, 1.0!, -1.0!}, {-1.0!, -1.0!, 1.0!}, {-1.0!, -1.0!, _
-1.0!}, {1.0!, -1.0!, -1.0!}, {-1.0!, -1.0!, 1.0!}, {1.0!, _
-1.0!, -1.0!}, {1.0!, -1.0!, 1.0!}, {-1.0!, 1.0!, 1.0!}, _
{-1.0!, -1.0!, -1.0!}, {-1.0!, -1.0!, 1.0!}, {-1.0!, 1.0!, _
-1.0!}, {-1.0!, -1.0!, -1.0!}, {-1.0!, 1.0!, 1.0!}, {1.0!, _
1.0!, 1.0!}, {1.0!, -1.0!, 1.0!}, {1.0!, -1.0!, -1.0!}, {1.0!, _
1.0!, -1.0!}, {1.0!, 1.0!, 1.0!}, {1.0!, -1.0!, -1.0!}}
Private _pp As PresentParameters
Private _dev As Device, _angel As Single
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
_pp = New PresentParameters
With _pp
.Windowed = True
.SwapEffect = SwapEffect.Discard
.EnableAutoDepthStencil = True
.AutoDepthStencilFormat = DepthFormat.D16
End With
_dev = New Device(0, DeviceType.Hardware, Panel1.Handle, _
CreateFlags.SoftwareVertexProcessing, _pp)
Timer1.Enabled = True
Button1.Enabled = False
Button2.Enabled = True
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
If Button2.Text = "Anhalten" Then
Button2.Text = "Weiter"
Timer1.Enabled = False
Else
Button2.Text = "Anhalten"
Timer1.Enabled = True
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button3.Click
Me.Close()
End Sub
Private Function GetPositionColored() As _
CustomVertex.PositionNormalColored()
Dim verts As CustomVertex.PositionNormalColored() = _
New CustomVertex.PositionNormalColored(36) {}
For vertCounter As Integer = 0 To 35
verts(vertCounter) = New
CustomVertex.PositionNormalColored(m_DataTriangle(vertCounter, _
0), m_DataTriangle(vertCounter, 1), _
m_DataTriangle(vertCounter, 2), _
m_DataNormals((vertCounter \ 3), 0), _
m_DataNormals((vertCounter \ 3), 1), _
m_DataNormals((vertCounter \ 3), 2), 0)
Next
Return verts
End Function
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e _
As System.EventArgs) Handles Timer1.Tick
With _dev
.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, _
Color.LightBlue, 1, 0)
.Transform.Projection = Matrix.PerspectiveFovLH(Math.PI / 4, _
1, 1, 10)
.Transform.View = Matrix.LookAtLH(New Vector3(0, 0, 5), _
New Vector3(), New Vector3(0, 1, 0))
.RenderState.Lighting = False
.BeginScene()
.Transform.World = Matrix.RotationYawPitchRoll(_angel, _
_angel, _angel)
_angel = _angel + 0.2!
.VertexFormat = CustomVertex.PositionColored.Format
.DrawUserPrimitives(PrimitiveType.TriangleList, 12, _
GetPositionColored)
.EndScene()
.Present()
End With
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e _
As System.Windows.Forms.FormClosingEventArgs) _
Handles Me.FormClosing
' Prozedur zum Formschließen
Timer1.Enabled = False
' Device aus dem Speicher löschen
_dev.Dispose()
End Sub
End Class
|
|