0

私は2Dグリッドを動かそうとしています。ゲームマップ用です。残念ながら、グリッドはあるべき姿ではありません。そして、私はその理由を理解できません。誰にもアイデアがありますか?

Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D

Public Class clsIsometric

'==================================
' SETTINGS
'==================================

Private tile_size As New Point(64, 64) 'Size of one tile in pixels
Private map_size As New Point(25, 25) 'Amount of tiles in total

Private gDevice As Device
Private bufVertex As VertexBuffer
Private bufIndex As IndexBuffer
Private gVertices() As CustomVertex.TransformedColored
Private gIndices() As Integer

'==================================
' CONSTRUCTOR
'==================================

Public Sub New(vDevice As Device)

    gDevice = vDevice

End Sub

Public Sub dispose()

    bufVertex.Dispose()
    bufIndex.Dispose()
    bufVertex = Nothing
    bufIndex = Nothing

End Sub

'==================================
' RENDERING
'==================================

Public Sub buildMap()

    ' Recreate buffers to fit the map size
    ReDim gVertices((map_size.X + 1) * (map_size.Y + 1))    ' x+1 * y+1
    ReDim gIndices(map_size.X * map_size.Y * 6)             ' x * y * 6
    Dim k As Integer

    For cX = 0 To map_size.X - 1 'Rows
        For cY = 0 To map_size.Y - 1 'Columns

            'VERTEX
            k = cX * map_size.X + cY
            gVertices(k) = New CustomVertex.TransformedColored(cX * tile_size.X, cY * tile_size.Y, 0, 1, Color.Blue.ToArgb)

        Next cY
    Next cX

    Dim vertexPerCol As Integer = map_size.Y + 1

    k = 0
    For ccX = 0 To map_size.X - 1
        For ccY = 0 To map_size.Y - 1

            gIndices(k) = ccX * vertexPerCol + ccY                  ' 0
            gIndices(k + 1) = (ccX + 1) * vertexPerCol + (ccY + 1)  ' 1
            gIndices(k + 2) = (ccX + 1) * vertexPerCol + ccY        ' 2

            gIndices(k + 3) = ccX * vertexPerCol + ccY              ' 3
            gIndices(k + 4) = ccX * vertexPerCol + (ccY + 1)        ' 4
            gIndices(k + 5) = (ccX + 1) * vertexPerCol + (ccY + 1)  ' 5

            k += 6 'Each tile has 6 indices. Increase for next tile

        Next
    Next

    bufVertex = New VertexBuffer(GetType(CustomVertex.TransformedColored), gVertices.Length, gDevice, Usage.Dynamic Or Usage.WriteOnly, CustomVertex.TransformedColored.Format, Pool.Default)
    bufIndex = New IndexBuffer(GetType(Integer), gIndices.Length, gDevice, Usage.WriteOnly, Pool.Default)

End Sub

Public Sub render()

    'RENDER THE MAP

    bufVertex.SetData(gVertices, 0, LockFlags.ReadOnly)
    bufIndex.SetData(gIndices, 0, LockFlags.None)

    gDevice.VertexFormat = CustomVertex.TransformedColored.Format
    gDevice.SetStreamSource(0, bufVertex, 0)
    gDevice.Indices = bufIndex
    gDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, gVertices.Length, 0, CInt(gIndices.Length / 3))

End Sub

End Class

これにより、25 x 25 タイルの完全な正方形グリッドが出力されます。しかし、ワイヤーフレームは次のようになります。

http://i43.tinypic.com/2whf51c.jpg

4

1 に答える 1

0

各行/列に n+1 個の頂点があるため、頂点を構築するループが終了するのが早すぎるようです。これは配列を最前列までしか埋めず、頂点のシフトにつながります。

For cX = 0 To map_size.X 'Rows
    For cY = 0 To map_size.Y 'Columns

        'VERTEX
        k = cX * (map_size.X + 1) + cY
        gVertices(k) = New CustomVertex.TransformedColored(cX * tile_size.X, cY * tile_size.Y, 0, 1, Color.Blue.ToArgb)

    Next cY
Next cX
于 2013-08-21T12:01:33.733 に答える