- Код: Выделить всё
Public Sub InitializeGraphics()
Dim presentParams As New PresentParameters
presentParams.Windowed = True
presentParams.SwapEffect = SwapEffect.Discard
presentParams.AutoDepthStencilFormat = DepthFormat.D16
presentParams.EnableAutoDepthStencil = True
device = New Device(0, DeviceType.Hardware, PictureBox1,_
CreateFlags.SoftwareVertexProcessing, presentParams)
Dim Vecta As Vector3
Dim Vectb As Vector3
Dim Vectc As Vector3
Dim Vectn As Vector3
Dim Vectnn As Vector3
vertexBuffer = New VertexBuffer(GetType(CustomVertex.PositionNormal), 6, _
device, Usage.Dynamic Or Usage.WriteOnly, CustomVertex.PositionNormal.Format, Pool.Default)
Dim verts(6) As CustomVertex.PositionNormal
verts(0).SetPosition(New Vector3(-1.0F, 0.0F, 0))
Vecta.X = -1.0F : Vecta.Y = 0.0F : Vecta.Z = 0.0F
'
verts(1).SetPosition(New Vector3(1.0F, 0.0F, 0))
Vectb.X = 1.0F : Vectb.Y = 0.0F : Vectb.Z = 0.0F
'
verts(2).SetPosition(New Vector3(0.0F, 1.0F, -1))
Vectc.X = 0.0F : Vectc.Y = 1.0F : Vectc.Z = -1.0F
'
Vector3.Subtract(Vectb, Vecta)
Vector3.Subtract(Vectc, Vecta)
Vectn = Vector3.Cross(Vector3.Subtract(Vectb, Vecta), Vector3.Subtract(Vectc, Vecta))
Vectnn = Vector3.Normalize(Vectn)
verts(0).Nx = Vectnn.X : verts(0).Ny = Vectnn.Y : verts(0).Nz = Vectnn.Z
verts(1).Nx = Vectnn.X : verts(1).Ny = Vectnn.Y : verts(1).Nz = Vectnn.Z
verts(2).Nx = Vectnn.X : verts(2).Ny = Vectnn.Y : verts(2).Nz = Vectnn.Z
'
verts(3).SetPosition(New Vector3(-1.0F, 0.0F, 0))
Vecta.X = -1.0F : Vecta.Y = 0.0F : Vecta.Z = 0.0F
'
verts(4).SetPosition(New Vector3(1.0F, 0.0F, 0))
Vectb.X = 1.0F : Vectb.Y = 0.0F : Vectb.Z = 0.0F
'
verts(5).SetPosition(New Vector3(0.0F, -1.0F, -1))
Vectc.X = 0.0F : Vectc.Y = -1 : Vectc.Z = -1
'
Vectn = Vector3.Cross(Vector3.Subtract(Vectb, Vecta), Vector3.Subtract(Vectc, Vecta))
Vectnn = Vector3.Normalize(Vectn)
verts(3).Nx = Vectnn.X : verts(3).Ny = Vectnn.Y : verts(3).Nz = Vectnn.Z
verts(4).Nx = Vectnn.X : verts(4).Ny = Vectnn.Y : verts(4).Nz = Vectnn.Z
verts(5).Nx = Vectnn.X : verts(5).Ny = Vectnn.Y : verts(5).Nz = Vectnn.Z
vertexBuffer.SetData(verts, 0, LockFlags.None)
'
device.RenderState.ZBufferEnable = True
'
device.RenderState.CullMode = Cull.None
'
device.RenderState.Lighting = True
End Sub
Сначала вб ругался на
"verts(1).SetPosition(New Vector3(1.0F, 0.0F, 0))".
Поменял "SetPosition" на "Position" (у меня почему-то
не окзалось св-ва "SetPosition" у "CustomVertex.PositionNormal"). Теперь он пишет "Error 1 Property access must assign to the property or use its value."
Никто не знает почему так?
Заранее спасибо!
VS 2005, DX9 sdk