1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
| Public Sub OnResetDevice(ByVal sender As Object, ByVal e As EventArgs)
Dim dev As Device = CType(sender, Device)
dev.RenderState.Lighting = False
End Sub 'OnResetDevice
Public Sub New()
InitializeComponent()
Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.Opaque, True)
End Sub 'New
Public Sub InitializeGraphics(ByVal pic As String)
' Set our presentation parameters
Dim presentParams As New PresentParameters
presentParams.Windowed = True
presentParams.SwapEffect = SwapEffect.Discard
presentParams.AutoDepthStencilFormat = DepthFormat.D16
presentParams.EnableAutoDepthStencil = True
' Create our device
device = New Device(0, DeviceType.Hardware, Me, CreateFlags.SoftwareVertexProcessing, presentParams)
device.RenderState.CullMode = Cull.CounterClockwise
vb = New VertexBuffer(GetType(CustomVertex.PositionTextured), Tlist * 3, device, Usage.Dynamic Or Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default)
AddHandler vb.Created, AddressOf Me.OnVertexBufferCreate
OnVertexBufferCreate(vb, Nothing)
tex = TextureLoader.FromFile(device, pic) ', 512, 512, 0, Usage.Dynamic, Format.Unknown, Pool.Default, Filter.Point, Filter.None, 0)
End Sub 'InitializeGraphics
Private Sub OnVertexBufferCreate(ByVal sender As Object, ByVal e As EventArgs)
'Dim vb As VertexBuffer = CType(sender, VertexBuffer)
Dim verts((Tlist * 3) - 1) As CustomVertex.PositionTextured
Dim d As Integer
For d = 0 To Checkedlist.Count - 1
Dim d3dFile As String = Checkedlist(d)
Pes3DFile.lire(d3dFile, False)
Dim p As Integer = 0
Dim i As Integer
'********************** Affectation des vertices **********************************
For i = 0 To ((Pes3DFile.my_index01.Count) - 1) Step 2
Dim v1, v2, v3, v4, v5, v6 As Integer
v1 = CType(Pes3DFile.my_index01(i), Integer)
v2 = CType(Pes3DFile.my_index02(i), Integer)
v3 = CType(Pes3DFile.my_index03(i), Integer)
v6 = CType(Pes3DFile.my_index01(i + 1), Integer)
v5 = CType(Pes3DFile.my_index02(i + 1), Integer)
v4 = CType(Pes3DFile.my_index03(i + 1), Integer)
verts(p) = New CustomVertex.PositionTextured((my_tabx(v1)), (my_taby(v1)), (my_tabz(v1)), (my_tu(v1)), my_tv(v1))
p += 1
verts(p) = New CustomVertex.PositionTextured((my_tabx(v2)), (my_taby(v2)), (my_tabz(v2)), (my_tu(v2)), my_tv(v2))
p += 1
verts(p) = New CustomVertex.PositionTextured((my_tabx(v3)), (my_taby(v3)), (my_tabz(v3)), (my_tu(v3)), my_tv(v3))
p += 1
verts(p) = New CustomVertex.PositionTextured((my_tabx(v4)), (my_taby(v4)), (my_tabz(v4)), (my_tu(v4)), my_tv(v4))
p += 1
verts(p) = New CustomVertex.PositionTextured((my_tabx(v5)), (my_taby(v5)), (my_tabz(v5)), (my_tu(v5)), my_tv(v5))
p += 1
verts(p) = New CustomVertex.PositionTextured((my_tabx(v6)), (my_taby(v6)), (my_tabz(v6)), (my_tu(v6)), my_tv(v6))
p += 1
Next i
'***************** Fin d'affectation des vertices **********************************
Next d
vb.SetData(verts, 0, LockFlags.None)
End Sub 'OnVertexBufferCreate
Private Sub SetupCamera()
device.Transform.View = Matrix.LookAtLH(New Vector3(0.0F, CameraPosl, VZoom_z), New Vector3(CameraPosLR, CameraPosHW, 0.0F), New Vector3(0, 1, 0))
device.Transform.Projection = Matrix.PerspectiveFovLH(CSng(Math.PI / 4), 1.0F, -10000.0F, 500.0F)
device.RenderState.ZBufferEnable = True
device.RenderState.Lighting = False
End Sub 'SetupCamera
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
device.Clear(ClearFlags.ZBuffer Or ClearFlags.Target, Color.CornflowerBlue, 1.0F, 0)
device.BeginScene()
SetupCamera()
If _wireFrame Then
device.RenderState.FillMode = FillMode.Solid
Else
device.RenderState.FillMode = FillMode.WireFrame
End If
device.VertexFormat = CustomVertex.PositionTextured.Format
device.SetStreamSource(0, vb, 0)
device.SetTexture(0, tex)
device.DrawPrimitives(PrimitiveType.TriangleList, 0, Tlist)
device.EndScene()
device.Present()
Me.Invalidate()
End Sub 'OnPaint |
Partager