hog Posted December 11, 2003 Posted December 11, 2003 I know the content of this is DirectX but the problem I have is the mechanics of the usage of the array hence posting here:) I don't follow how this code works and hope someone can explain. Here goes; Public Function CreateTextures() As Boolean Dim Verts As CustomVertex() Dim intX As Integer Dim strTexturePath As String Try For intX = 1 To 10 strTexturePath = Application.StartupPath & "\walk" & CStr(intX) & ".bmp" Textures(intX - 1) = TextureLoader.FromFile(m_objDevice, strTexturePath) Next VertBuffer = New VertexBuffer(GetType(CustomVertex), NUM_VERTS, m_objDevice, Usage.WriteOnly, FVF_CUSTOMVERTEX, Pool.Default) Verts = VertBuffer.Lock(0, 0) SquareVertices(Verts) VertBuffer.Unlock() Return True Catch objException As Exception Return False End Try End Function Private Function SquareVertices(ByVal Vertices As CUSTOMVERTEX()) Vertices(0) = CreateFlexVertex(60, 60, 0, 1, 0, 0) Vertices(1) = CreateFlexVertex(240, 60, 0, 1, 1, 0) Vertices(2) = CreateFlexVertex(60, 240, 0, 1, 0, 1) Vertices(3) = CreateFlexVertex(240, 240, 0, 1, 1, 1) End Function Private Function CreateFlexVertex(ByVal X As Single, ByVal Y As Single, ByVal Z As Single, ByVal rhw As Single, _ ByVal tu As Single, ByVal tv As Single) As CUSTOMVERTEX CreateFlexVertex.X = X CreateFlexVertex.Y = Y CreateFlexVertex.Z = Z CreateFlexVertex.rhw = rhw CreateFlexVertex.tu = tu CreateFlexVertex.tv = tv End Function In the procedure CreateTextures() Verts is declared as CUSTOMVERTEX() which is a structure. So Verts is an array of structures? This line, SquareVertices(Verts), passes Verts to the SquareVertices procedure ByVal again an array of structures? In SquareVertices it assigns values to each array element. But how come the redim staement is not required? I spent a lot of time trying to get this to work and by trial and error found if I removed the redim line it work?? Duh.....don't get it :( Quote My website
Administrators PlausiblyDamp Posted December 11, 2003 Administrators Posted December 11, 2003 the lines VertBuffer = New VertexBuffer(GetType(CustomVertex), NUM_VERTS, m_objDevice, Usage.WriteOnly, FVF_CUSTOMVERTEX, Pool.Default) Verts = VertBuffer.Lock(0, are creating the array at the correct size Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.