游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2734|回复: 6

初探 DirectX (vb2005&vb2008)

[复制链接]

1

主题

7

帖子

9

积分

新手上路

Rank: 1

积分
9
发表于 2009-4-6 00:44:00 | 显示全部楼层 |阅读模式
系统环境:vb2005或者vb2008,Microsoft DirectX 9.0 SDK Update (August 2005).

在form上的背景涂上Aqua 的?色:

Imports Microsoft.DirectX

Imports Microsoft.DirectX.Direct3D

Public Class Form1

    Private device As Device



    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim ppms As New PresentParameters

        With ppms

            .SwapEffect = SwapEffect.Discard

            .Windowed = True

        End With

        device = New Device(0, DeviceType.Hardware, Me, CreateFlags.HardwareVertexProcessing, ppms)

        Me.MinimumSize = SystemInformation.MinimumWindowSize + New Size(0, 1)

    End Sub



    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

        With device

            .Clear(ClearFlags.Target, Color.Aqua, 1, 0)

            .Present()

        End With

    End Sub

End Class

原文联接:http://www.ncis.com.tw/ncis_bbs/viewthread.php?tid=839

1

主题

7

帖子

9

积分

新手上路

Rank: 1

积分
9
 楼主| 发表于 2009-4-6 00:47:00 | 显示全部楼层

Re:初探 DirectX (vb2005&vb2008)_画一??三角形

Option Explicit On

Imports Microsoft.DirectX

Imports Microsoft.DirectX.Direct3D



Public Class Form1



    Private device As Device

    Dim vts(2) As CustomVertex.TransformedColored

  

  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim ppms As New PresentParameters

        With ppms

            .SwapEffect = SwapEffect.Discard

            .Windowed = True

        End With

        device = New Device(0, DeviceType.Hardware, Me, CreateFlags.HardwareVertexProcessing, ppms)  

        Me.MinimumSize = SystemInformation.MinimumWindowSize + New Size(0, 1)

        vts(0) = New CustomVertex.TransformedColored

        With vts(0)

            .Position = New Vector4(200, 50, 0, 1)

            .Color = Color.Chocolate.ToArgb

        End With



        vts(1) = New CustomVertex.TransformedColored

        With vts(1)

            .Position = New Vector4(300, 150, 0, 1)

            .Color = Color.Yellow.ToArgb

        End With

        vts(2) = New CustomVertex.TransformedColored

        With vts(2)

            .Position = New Vector4(100, 150, 0, 1)

            .Color = Color.Green.ToArgb

        End With

    End Sub

  

  Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

        With device

            .Clear(ClearFlags.Target, Color.Aqua, 1, 0)

            .BeginScene()

            .VertexFormat = VertexFormats.Transformed Or VertexFormats.Diffuse

            .DrawUserPrimitives(PrimitiveType.TriangleList, 1, vts)

            .EndScene()

            .Present()

        End With

    End Sub

End Class


原文联接:http://www.ncis.com.tw/ncis_bbs/viewthread.php?tid=839

1

主题

7

帖子

9

积分

新手上路

Rank: 1

积分
9
 楼主| 发表于 2009-4-6 00:49:00 | 显示全部楼层

Re:初探 DirectX (vb2005&vb2008)_可变色三角形

Option Explicit On

Imports Microsoft.DirectX

Imports Microsoft.DirectX.Direct3D

Public Class Form1

    Private device As Device

    Private vts(2) As CustomVertex.PositionColored

    Private vb As VertexBuffer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim ppms As New PresentParameters

        With ppms

            .SwapEffect = SwapEffect.Discard

            .Windowed = True

        End With

        device = New Device(0, DeviceType.Hardware, Me, CreateFlags.SoftwareVertexProcessing, ppms)

        vb = New VertexBuffer(GetType(CustomVertex.PositionColored), 3, device, _

                Usage.Dynamic, VertexFormats.None, Pool.Default)

        AddHandler vb.Created, AddressOf VertBufferCreated

        With Me

            .SetStyle(ControlStyles.ResizeRedraw Or _

                    ControlStyles.Opaque, True)

            .MinimumSize = SystemInformation.MinimumWindowSize + New Size(0, 1)

            .Text = "DirectXTest"

            .VertBufferCreated(Nothing, EventArgs.Empty)

        End With



    End Sub



    Private Sub VertBufferCreated(ByVal sender As Object, ByVal e As EventArgs)



        Dim rnd As New Random



        With vts(0)

            .Position = New Vector3(1, 0, 1)

            .Color = Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255)).ToArgb

        End With

        With vts(1)

            .Position = New Vector3(-1, 0, 1)

            .Color = Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255)).ToArgb

        End With

        With vts(2)

            .Position = New Vector3(0, 1, 1)

            .Color = Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255)).ToArgb

        End With

        vb.SetData(vts, 0, LockFlags.None)

    End Sub



    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

        With device

            .Clear(ClearFlags.Target, Color.Aqua, 1, 0)

            Me.Camera()

            .VertexFormat = VertexFormats.Position Or VertexFormats.Diffuse

            .BeginScene()

            .SetStreamSource(0, vb, 0)

            .DrawPrimitives(PrimitiveType.TriangleList, 0, 1)

            .EndScene()

            .Present()

        End With

    End Sub

    Private Sub Camera()

        device.Transform.Projection = Matrix.PerspectiveFovLH(Math.PI / 4, _

         CSng(Me.ClientSize.Width / Me.ClientSize.Height), 1, 100)

        device.RenderState.Lighting = False

        device.RenderState.CullMode = Cull.None

        device.Transform.View = Matrix.LookAtLH(New Vector3(0, 0, -5), New Vector3(0, 0, 0), _

             New Vector3(0, 1, 0))

    End Sub

End Class

1

主题

7

帖子

9

积分

新手上路

Rank: 1

积分
9
 楼主| 发表于 2009-4-6 00:51:00 | 显示全部楼层

Re: 初探 DirectX (vb2005&vb2008)_画一??立方体

Option Strict On
Option Explicit On
Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D
Public Class Form1
    Private device As Device
    Private vb As VertexBuffer
    Private angle As Single = 0
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim ppms As New PresentParameters
        With ppms
            .SwapEffect = SwapEffect.Discard
            .Windowed = True
        End With
        device = New Device(0, DeviceType.Hardware, Me, CreateFlags.SoftwareVertexProcessing, ppms)
        vb = New VertexBuffer(GetType(CustomVertex.PositionColored), 36, device, _
                Usage.Dynamic, VertexFormats.None, Pool.Default)
        AddHandler vb.Created, AddressOf VertBufferCreated
        With Me
            .SetStyle(ControlStyles.ResizeRedraw Or _
                    ControlStyles.Opaque, True)
            .MinimumSize = SystemInformation.MinimumWindowSize + New Size(0, 1)
            .Text = "初探 DirectX_一??立方?"
            .VertBufferCreated(vb, EventArgs.Empty)
        End With
    End Sub

    Private Sub VertBufferCreated(ByVal sender As Object, ByVal e As EventArgs)
        Dim vts(35) As CustomVertex.PositionColored
        '前
        With vts(0)
            .Position = New Vector3(1, 1, 1)
            .Color = Color.Green.ToArgb
        End With
        With vts(1)
            .Position = New Vector3(-1, -1, 1)
            .Color = Color.Green.ToArgb
        End With
        With vts(2)
            .Position = New Vector3(1, -1, 1)
            .Color = Color.Green.ToArgb
        End With
        With vts(3)
            .Position = New Vector3(-1, -1, 1)
            .Color = Color.Green.ToArgb
        End With
        With vts(4)
            .Position = New Vector3(1, 1, 1)
            .Color = Color.Green.ToArgb
        End With
        With vts(5)
            .Position = New Vector3(-1, 1, 1)
            .Color = Color.Green.ToArgb
        End With
        '後
        With vts(6)
            .Position = New Vector3(1, 1, -1)
            .Color = Color.Yellow.ToArgb
        End With
        With vts(7)
            .Position = New Vector3(-1, -1, -1)
            .Color = Color.Yellow.ToArgb
        End With
        With vts(8)
            .Position = New Vector3(-1, 1, -1)
            .Color = Color.Yellow.ToArgb
        End With
        With vts(9)
            .Position = New Vector3(-1, -1, -1)
            .Color = Color.Yellow.ToArgb
        End With
        With vts(10)
            .Position = New Vector3(1, 1, -1)
            .Color = Color.Yellow.ToArgb
        End With
        With vts(11)
            .Position = New Vector3(1, -1, -1)
            .Color = Color.Yellow.ToArgb
        End With
        '右
        With vts(12)
            .Position = New Vector3(1, -1, -1)
            .Color = Color.Red.ToArgb
        End With
        With vts(13)
            .Position = New Vector3(1, 1, 1)
            .Color = Color.Red.ToArgb
        End With
        With vts(14)
            .Position = New Vector3(1, -1, 1)
            .Color = Color.Red.ToArgb
        End With
        With vts(15)
            .Position = New Vector3(1, 1, 1)
            .Color = Color.Red.ToArgb
        End With
        With vts(16)
            .Position = New Vector3(1, -1, -1)
            .Color = Color.Red.ToArgb
        End With
        With vts(17)
            .Position = New Vector3(1, 1, -1)
            .Color = Color.Red.ToArgb
        End With

        '左
        With vts(18)
            .Position = New Vector3(-1, 1, 1)
            .Color = Color.Blue.ToArgb
        End With
        With vts(19)
            .Position = New Vector3(-1, -1, -1)
            .Color = Color.Blue.ToArgb
        End With
        With vts(20)
            .Position = New Vector3(-1, -1, 1)
            .Color = Color.Blue.ToArgb
        End With
        With vts(21)
            .Position = New Vector3(-1, -1, -1)
            .Color = Color.Blue.ToArgb
        End With
        With vts(22)
            .Position = New Vector3(-1, 1, 1)
            .Color = Color.Blue.ToArgb
        End With
        With vts(23)
            .Position = New Vector3(-1, 1, -1)
            .Color = Color.Blue.ToArgb
        End With

        '上
        With vts(24)
            .Position = New Vector3(1, 1, 1)
            .Color = Color.Orange.ToArgb
        End With
        With vts(25)
            .Position = New Vector3(1, 1, -1)
            .Color = Color.Orange.ToArgb
        End With
        With vts(26)
            .Position = New Vector3(-1, 1, -1)
            .Color = Color.Orange.ToArgb
        End With
        With vts(27)
            .Position = New Vector3(1, 1, 1)
            .Color = Color.Orange.ToArgb
        End With
        With vts(28)
            .Position = New Vector3(-1, 1, -1)
            .Color = Color.Orange.ToArgb
        End With
        With vts(29)
            .Position = New Vector3(-1, 1, 1)
            .Color = Color.Orange.ToArgb
        End With

        '下
        With vts(30)
            .Position = New Vector3(1, -1, 1)
            .Color = Color.Pink.ToArgb
        End With
        With vts(31)
            .Position = New Vector3(-1, -1, 1)
            .Color = Color.Pink.ToArgb
        End With
        With vts(32)
            .Position = New Vector3(-1, -1, -1)
            .Color = Color.Pink.ToArgb
        End With
        With vts(33)
            .Position = New Vector3(1, -1, 1)
            .Color = Color.Pink.ToArgb
        End With
        With vts(34)
            .Position = New Vector3(-1, -1, -1)
            .Color = Color.Pink.ToArgb
        End With
        With vts(35)
            .Position = New Vector3(1, -1, -1)
            .Color = Color.Pink.ToArgb
        End With
        vb.SetData(vts, 0, LockFlags.None)
    End Sub
    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Me.Camera()
        With device
            .Clear(ClearFlags.Target, Color.Aqua, 1, 0)
            .VertexFormat = VertexFormats.Position Or VertexFormats.Diffuse
            .BeginScene()
            .SetStreamSource(0, vb, 0)
            .DrawPrimitives(PrimitiveType.TriangleList, 0, 12)
            .EndScene()
            .Present()
        End With
        Me.Invalidate()
    End Sub
    Private Sub Camera()
        angle += 3
        If angle > 360 Then angle = 0

        With device
            .Transform.Projection = Matrix.PerspectiveFovLH(Math.PI / 4, _
                 CSng(Me.ClientSize.Width / Me.ClientSize.Height), 1, 100)
            .RenderState.Lighting = False
            .Transform.World = Matrix.RotationAxis(New Vector3(1, 1, 0), CSng(angle * Math.PI / 180))
            .Transform.View = Matrix.LookAtLH(New Vector3(0, 0, 10), New Vector3(0, 0, 0), _
                 New Vector3(0, 1, 0))
        End With

    End Sub
End Class

1

主题

7

帖子

9

积分

新手上路

Rank: 1

积分
9
 楼主| 发表于 2009-4-6 00:53:00 | 显示全部楼层

Re: 初探 DirectX (vb2005&vb2008)_贴上材质的立方体

Option Explicit On

Imports Microsoft.DirectX

Imports Microsoft.DirectX.Direct3D

Public Class Form1

    Private device As Device

    Private vb As VertexBuffer

    Private angle As Single = 0

    Private bmp As Bitmap

    Private texture As Texture



    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim ppms As New PresentParameters

        With ppms

            .SwapEffect = SwapEffect.Copy

            .Windowed = True

        End With

        device = New Device(Manager.Adapters.Default.Adapter, DeviceType.Hardware, _

                Me, CreateFlags.HardwareVertexProcessing, ppms)

        vb = New VertexBuffer(GetType(CustomVertex.PositionTextured), 36, device, _

                Usage.Dynamic Or Usage.WriteOnly, VertexFormats.None, Pool.Default)

        AddHandler vb.Created, AddressOf VertBufferCreated

        bmp = DirectCast(Image.FromFile("1.jpg").Clone, Bitmap)

        With Me

            .SetStyle(ControlStyles.Opaque, True)

            .MinimumSize = SystemInformation.MinimumWindowSize + New Size(0, 1)

            .Text = "DirectXTest"

            .VertBufferCreated(Nothing, EventArgs.Empty)

        End With

    End Sub



    Private Sub VertBufferCreated(ByVal sender As Object, ByVal e As EventArgs)

        Dim vts(35) As CustomVertex.PositionTextured

        '前

        With vts(0)

            .Position = New Vector3(1, 1, 1)

            .Tu = 1

            .Tv = 0

        End With

        With vts(1)

            .Position = New Vector3(-1, -1, 1)

            .Tu = 0

            .Tv = 1

        End With

        With vts(2)

            .Position = New Vector3(1, -1, 1)

            .Tu = 1

            .Tv = 1

        End With

        With vts(3)

            .Position = New Vector3(-1, -1, 1)

            .Tu = 0

            .Tv = 1

        End With

        With vts(4)

            .Position = New Vector3(1, 1, 1)

            .Tu = 1

            .Tv = 0

        End With

        With vts(5)

            .Position = New Vector3(-1, 1, 1)

            .Tu = 0

            .Tv = 0

        End With

        '後

        With vts(6)

            .Position = New Vector3(1, 1, -1)

            .Tu = 1

            .Tv = 0

        End With

        With vts(7)

            .Position = New Vector3(-1, -1, -1)

            .Tu = 0

            .Tv = 1

        End With

        With vts(8)

            .Position = New Vector3(-1, 1, -1)

            .Tu = 0

            .Tv = 0

        End With

        With vts(9)

            .Position = New Vector3(-1, -1, -1)

            .Tu = 0

            .Tv = 1

        End With

        With vts(10)

            .Position = New Vector3(1, 1, -1)

            .Tu = 1

            .Tv = 0

        End With

        With vts(11)

            .Position = New Vector3(1, -1, -1)

            .Tu = 1

            .Tv = 1

        End With

        '右

        With vts(12)

            .Position = New Vector3(1, -1, -1)

            .Tu = 0

            .Tv = 1

        End With

        With vts(13)

            .Position = New Vector3(1, 1, 1)

            .Tu = 1

            .Tv = 0

        End With

        With vts(14)

            .Position = New Vector3(1, -1, 1)

            .Tu = 1

            .Tv = 1

        End With

        With vts(15)

            .Position = New Vector3(1, 1, 1)

            .Tu = 1

            .Tv = 0

        End With

        With vts(16)

            .Position = New Vector3(1, -1, -1)

            .Tu = 0

            .Tv = 1

        End With

        With vts(17)

            .Position = New Vector3(1, 1, -1)

            .Tu = 0

            .Tv = 0

        End With



        '左

        With vts(18)

            .Position = New Vector3(-1, 1, 1)

            .Tu = 1

            .Tv = 0

        End With

        With vts(19)

            .Position = New Vector3(-1, -1, -1)

            .Tu = 0

            .Tv = 1

        End With

        With vts(20)

            .Position = New Vector3(-1, -1, 1)

            .Tu = 1

            .Tv = 1

        End With

        With vts(21)

            .Position = New Vector3(-1, -1, -1)

            .Tu = 0

            .Tv = 1

        End With

        With vts(22)

            .Position = New Vector3(-1, 1, 1)

            .Tu = 1

            .Tv = 0

        End With

        With vts(23)

            .Position = New Vector3(-1, 1, -1)

            .Tu = 0

            .Tv = 0

        End With

        '上

        With vts(24)

            .Position = New Vector3(1, 1, 1)

            .Tu = 1

            .Tv = 0

        End With

        With vts(25)

            .Position = New Vector3(1, 1, -1)

            .Tu = 1

            .Tv = 1

        End With

        With vts(26)

            .Position = New Vector3(-1, 1, -1)

            .Tu = 0

            .Tv = 1

        End With

        With vts(27)

            .Position = New Vector3(1, 1, 1)

            .Tu = 1

            .Tv = 0

        End With

        With vts(28)

            .Position = New Vector3(-1, 1, -1)

            .Tu = 0

            .Tv = 1

        End With

        With vts(29)

            .Position = New Vector3(-1, 1, 1)

            .Tu = 0

            .Tv = 0

        End With



        '下

        With vts(30)

            .Position = New Vector3(1, -1, 1)

            .Tu = 1

            .Tv = 0

        End With

        With vts(31)

            .Position = New Vector3(-1, -1, 1)

            .Tu = 0

            .Tv = 0

        End With

        With vts(32)

            .Position = New Vector3(-1, -1, -1)

            .Tu = 0

            .Tv = 1

        End With

        With vts(33)

            .Position = New Vector3(1, -1, 1)

            .Tu = 1

            .Tv = 0

        End With

        With vts(34)

            .Position = New Vector3(-1, -1, -1)

            .Tu = 0

            .Tv = 1

        End With

        With vts(35)

            .Position = New Vector3(1, -1, -1)

            .Tu = 1

            .Tv = 1

        End With

        vb.SetData(vts, 0, LockFlags.Discard)

        texture = New Texture(device, bmp, Usage.Dynamic, Pool.Default)

    End Sub

    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

        Me.Camera()

        With device

            .Clear(ClearFlags.Target, Color.Aqua, 1, 0)

            .VertexFormat = VertexFormats.Position Or VertexFormats.Texture1

            .BeginScene()

            .SetStreamSource(0, vb, 0)

            .SetTexture(0, texture)

            .DrawPrimitives(PrimitiveType.TriangleList, 0, 12)

            .EndScene()

            .Present()

        End With

        Me.Invalidate()

    End Sub

    Private Sub Camera()

        angle += 3

        If angle >= 360 Then angle = 0

        With device

            .Transform.Projection = Matrix.PerspectiveFovLH(Math.PI / 4, _

                 CSng(Me.ClientSize.Width / Me.ClientSize.Height), 1, 100)

            .RenderState.Lighting = False

            .Transform.World = Matrix.RotationAxis(New Vector3(1, 1, 0), CSng(angle * Math.PI / 180))

            .Transform.View = Matrix.LookAtLH(New Vector3(0, 0, 10), New Vector3(0, 0, 0), _

                 New Vector3(0, 1, 0))

        End With

    End Sub

End Class

1

主题

7

帖子

9

积分

新手上路

Rank: 1

积分
9
 楼主| 发表于 2009-4-6 00:55:00 | 显示全部楼层

Re: 初探 DirectX (vb2005&vb2008)_灯光

Option Strict On

Imports System

Imports System.Drawing

Imports System.Windows.Forms

Imports Microsoft.DirectX

Imports Microsoft.DirectX.Direct3D



Public Class LightsTest



    Private Device As Device = Nothing

    Private ppms As PresentParameters

    Private vertexBuffer As VertexBuffer = Nothing

  

    Private Const VertexCount As Int32 = 100

    Private angle As Single = 0

    Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)

        ppms = New PresentParameters

        With ppms

            .Windowed = True

            .SwapEffect = SwapEffect.Discard

            .EnableAutoDepthStencil = True

            .AutoDepthStencilFormat = DepthFormat.D16

        End With

        Device = New Device(0, DeviceType.Hardware, Me, CreateFlags.SoftwareVertexProcessing, ppms)

        AddHandler Device.DeviceReset, AddressOf OnResetDevice

        vertexBuffer = New VertexBuffer(GetType(CustomVertex.PositionNormal), _

                100, Device, Usage.WriteOnly, CustomVertex.PositionNormal.Format, Pool.Default)

        AddHandler vertexBuffer.Created, AddressOf Me.OnCreateVertexBuffer

        Me.OnCreateVertexBuffer(Nothing, Nothing)

        With Me

            .MinimumSize = SystemInformation.MinimumWindowSize + New Size(0, 1)

            .Text = "初探 DirectX_3D 灯光"

            .SetStyle(ControlStyles.Opaque, True)

            .OnResetDevice(Nothing, Nothing)

        End With



    End Sub



    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)

        Me.Carera()

        With Device

            .Clear(ClearFlags.Target Or ClearFlags.ZBuffer, System.Drawing.Color.Aqua, 1.0F, 0)

            .BeginScene()

            .SetStreamSource(0, vertexBuffer, 0)

            .DrawPrimitives(PrimitiveType.TriangleStrip, 0, 4 * 25 - 2)

            .EndScene()

            .Present()

        End With

        Me.Invalidate()

    End Sub

    Public Sub OnResetDevice(ByVal sender As Object, ByVal e As EventArgs)

        With Device

            .RenderState.CullMode = Cull.None

            .RenderState.ZBufferEnable = True

            .RenderState.Lighting = True

            .VertexFormat = CustomVertex.PositionNormal.Format

        End With

        Me.SetupLights()

    End Sub

    Public Sub OnCreateVertexBuffer(ByVal sender As Object, ByVal e As EventArgs)

        Dim vts() As CustomVertex.PositionNormal = _

                DirectCast(Me.vertexBuffer.Lock(0, LockFlags.None), CustomVertex.PositionNormal())

        For i As Int32 = 0 To 49

            Dim theta As Single = CSng((2 * Math.PI * i) / 49)

            vts(2 * i).Position = New Vector3(CSng(Math.Sin(theta)), -1, CSng(Math.Cos(theta)))

            vts(2 * i).Normal = New Vector3(CSng(Math.Sin(theta)), 0, CSng(Math.Cos(theta)))

            vts(2 * i + 1).Position = New Vector3(CSng(Math.Sin(theta)), 1, CSng(Math.Cos(theta)))

            vts(2 * i + 1).Normal = New Vector3(CSng(Math.Sin(theta)), 0, CSng(Math.Cos(theta)))

        Next i

        vertexBuffer.Unlock()

    End Sub

    Private Sub SetupLights()

        Dim material As New Material

        With material

            .Diffuse = Color.SpringGreen

            .Ambient = Color.SpringGreen

        End With

        Device.Material = material

        With Device

            .Lights(0).Type = LightType.Directional

            .Lights(0).Diffuse = System.Drawing.Color.DarkTurquoise

            .Lights(0).Direction = New Vector3(1, 1, 0)

            .Lights(0).Enabled = True

            .RenderState.Ambient = Color.Green

        End With

    End Sub



    Private Sub Carera()

        If angle >= 2 * Math.PI Then angle = 0

        angle = angle + 0.1F

        Device.Transform.World = Matrix.RotationAxis(New Vector3(1, 1, 0), angle)

        Device.Transform.View = Matrix.LookAtLH(New Vector3(0.0F, 0, 5.0F), New Vector3(0.0F, 0.0F, 0.0F), New Vector3(0.0F, 1.0F, 0.0F))

        Device.Transform.Projection = Matrix.PerspectiveFovLH(Math.PI / 4.0F, _

                CSng(Me.ClientSize.Width / Me.ClientSize.Height), 1.0F, 100.0F)

    End Sub

End Class

原文联接:http://www.ncis.com.tw/ncis_bbs/viewthread.php?tid=839

12

主题

733

帖子

734

积分

高级会员

Rank: 4

积分
734
发表于 2009-4-13 10:26:00 | 显示全部楼层

Re:初探 DirectX (vb2005&vb2008)

好贴,难道见技术贴,顶了,虽然我知道此贴必会变成口水贴
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-12-20 14:17

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表