|
 | multiple terrains | |  |
| Poster | : DaveA | | Posts | : 5 | | Country | : Australia | | City | : Perth |
| | | | Posted by DaveA on 12/08/2008 at 21:35:23
| | Hi,
Great tutorials thanks.
I am writing a 3d Cad type application, and I would like to be able to create several terrains such as the indexed one in this tutorial. While I can create the vertices for the separate surfaces and display them as points, I cant figure out how to create the index buffer(s).
The example I would like to see is this tutorial with the texture replicated at different heights with one vertex buffer and one index buffer. Any help would be greatly appreciated.
Regards,
Dave A | |
|
| | | | | | Poster | : riemer | | Posts | : 1392 | | Country | : Belgium | | City | : Antwerp |
| | | | Posted by riemer on 13/08/2008 at 14:54:34
| | | I'm not really sure what you're asking here, your second-last sentance was not that clear to me. Did you try the first series? That should give you some basic understanding how indices, vertices, buffers and terrains are related to each other. | |
|
| | | | | | Poster | : daveA | | Posts | : 5 | | Country | : Australia | | City | : Perth |
| | | | Posted by daveA on 13/08/2008 at 21:39:35
| | Hi Riemer,
Sorry that I was not clear, I meant terrain not texture. I have worked through the first series up to and including this tutorial and they are great, I have learned a great deal (even though I program in VB).
I have a program that produces grids (cols and rows) of points with x,y and z values. I can import these files individually into my DX9 application and produce a terrain using an index buffer and a vertex buffer, as per the tutorial. I have also imported a second file (similar X & Y values as the first file, but different Z values), using the same vertex buffer and plotted both surfaces as points.
My question is with the second grid, how do I create the indices and add them to the existing index buffer, or do I have to create a new index buffer, so that I can display both grids as triangle lists.
Thanks again, I very much appreciate your time.
Regards,
Dave A | |
|
| | | | | | Poster | : Rich_Zap | | Posts | : 103 | | Country | : UK | | City | : Leeds |
| | | | Posted by Rich_Zap on 14/08/2008 at 05:31:19
| | So you're wanting to combine 2 terrains in 1 vertex buffer and index buffer.
It actually shouldnt be too hard, assuming you load ALL of 1 terrain then the other.
If we assume both terrains are 64x64 then each terrain has 4096 verts. The number of indices per terrain is 3x2x(64-1)^2, but that doesnt really matter. Load in all your indices for terrain 1 as normal, then do exactly the same for terrain 2 except all the indices numbers need to have 4095 added to them. This is an offset which is equal to one minus the number of verts in the first terrain.
Personally though i would just create 2 separate sets of buffers, i think its easier to understand code wise and you can build objects and classes around that sort of system. | |
|
| | | | | | Poster | : DaveA | | Posts | : 5 | | Country | : Australia | | City | : Perth |
| | | | Posted by DaveA on 15/08/2008 at 02:32:13
| | Hi from the Land down under,
Thanks Rich_Zap for your reply. I work in the mining industry and the surfaces I'm importing are our mining plans before and after mining. Our mine is in the order of 60 km long so I have a lot of surfaces. I've looked at both methods you suggest.I'd started down the path of multiple buffer sets. The problem is that I need to create them at run time and I want to give them the name of the file I import eg vbSurf01, ibSurf01 etc. A problem I ran into here was trying to declare a buffer with a name derived from a string (part of the imported file name).
I've just about sorted out the approach of one set of buffers. The trick as you point out is to add the number of verts - 1 from the first terrain, however I've now discovered that you have to add them not only to the index number but also to the WIDTH in Riemer's formula, otherwise the indices work OK but you start back at 1 with the Verts, which was the problem I was having.
Thanks again for your time. If anyone has any suggestions as to how I can create buffers with names from strings at runtime I'd love to hear them.
Regards,
Dave A | |
|
| | | | | | Poster | : riemer | | Posts | : 1392 | | Country | : Belgium | | City | : Antwerp |
| | | | Posted by riemer on 18/08/2008 at 13:59:15
| | Hi Dave,
I'm not too sure what you mean with a buffer from strings? Are you referring to creating buffers on-the-fly from image files? | |
|
| | | | | | Poster | : DaveA | | Posts | : 5 | | Country | : Australia | | City | : Perth |
| | | | Posted by DaveA on 04/09/2008 at 21:20:47
| | Hi Reimer,
In my application I use an open file dialog to import a terrain points file (x, y, z) into my application.
I put the points into a custom vertex,create a vertex buffer,calculate the indices and create an index buffer.
I need to do this each time I open a new file, and I want to open a lot of points files.
An example of my code for the first 2 files is as follows:
'Custom Vertex's
Public vx01() As CustomVertex.PositionColored = Nothing
Public vx02() As CustomVertex.PositionColored = Nothing
'Vertex Buffers
Public vb01 As VertexBuffer = Nothing
Public vb02 As VertexBuffer = Nothing
'Number of vertices
Public numVx01 As Integer = Nothing
Public numVx02 As Integer = Nothing
'Indexes
Public ix01() As Integer = Nothing
Public ix02() As Integer = Nothing
'Indices
Public numix01 As Integer = Nothing
Public numix02 As Integer = Nothing
'Index Buffers
Public ib01 As IndexBuffer = Nothing
Public ib02 As IndexBuffer = Nothing
Public Sub InitBuffer01()
If vb01 Is Nothing Then
vb01 = New VertexBuffer(GetType(CustomVertex.PositionColored), numVx01, device, _
Usage.Dynamic Or Usage.[WriteOnly], CustomVertex.PositionColored.Format, Pool.[Default])
ib01 = New IndexBuffer(GetType(Integer), numIx01, device, Usage.[WriteOnly], Pool.[Default])
ReDim vx01(numVx01)
ReDim ix01(numIx01)
End If
End Sub
Public Sub InitBuffer02()
If vb02 Is Nothing Then
vb02 = New VertexBuffer(GetType(CustomVertex.PositionColored), numVx01, device, _
Usage.Dynamic Or Usage.[WriteOnly], CustomVertex.PositionColored.Format, Pool.[Default])
ib02 = New IndexBuffer(GetType(Integer), numIx02, device, Usage.[WriteOnly], Pool.[Default])
ReDim vx02(numVx02)
ReDim ix02(numIx02)
End If
End Sub
|
At this stage I have hardcoded for 100 surfaces, but instead of writing all this code I would like to create the buffers as I open a new file. I've discovered that I can create an array of vertices: Public vx1 As CustomVertex.PositionColored()(), which I populate as required. Is there any way to create an array of buffers? Is there any other way to create this at runtime?
Thanks again for you site.
Regards,
Dave A
| |
|
|
 | | |  |
|
|
|
If you appreciate the amount of time I spend creating and updating these pages, feel free to donate -- any amount is welcome !
|
- Website design & DirectX code : Riemer Grootjans - ©2006 Riemer Grootjans
|
|