Forum
Contact





DirectX using C#
DirectX using C++
DirectX using Visual Basic



Latest Forum posts

 Tutorial 3 for Windows Phone 7
  Posted by: Anonymous
  When: 19/05/2013 at 11:27:50

 No download link for 2d series: shooter
  Posted by: zaboleq
  When: 07/05/2013 at 15:46:28

 Collision Class?
  Posted by: Anonymous
  When: 05/05/2013 at 19:03:59

 stack overflow
  Posted by: cityguy
  When: 07/04/2013 at 01:58:38

 Meshes looks strange.
  Posted by: ab_saratov
  When: 01/04/2013 at 04:31:08

 Lamppost Not loaded
  Posted by: Anonymous
  When: 22/03/2013 at 06:43:52

 Collision Class?
  Posted by: Da_Boom
  When: 21/03/2013 at 01:23:09

 Math boggles me
  Posted by: cityguy
  When: 17/03/2013 at 03:44:48

 Collision Class?
  Posted by: Da_Boom
  When: 16/03/2013 at 03:44:42

 Tree update
  Posted by: Anonymous
  When: 15/03/2013 at 21:11:22

 XNA 4.0
  Posted by: Anonymous
  When: 15/03/2013 at 19:43:57

 Error when I try to run.
  Posted by: Anonymous
  When: 15/03/2013 at 19:21:06

 Error With the Effect File
  Posted by: Anonymous
  When: 15/03/2013 at 18:21:01

 Can only get shadowmap
  Posted by: Anonymous
  When: 15/03/2013 at 15:48:52

 Vertex and Pixel Shader Versions?
  Posted by: Anonymous
  When: 15/03/2013 at 15:07:16

 Unsupported properties
  Posted by: Anonymous
  When: 15/03/2013 at 14:23:00

 Problem Loading Skybox
  Posted by: Rana
  When: 15/03/2013 at 10:34:45

 Black Screen Of Death - Help!
  Posted by: Anonymous
  When: 15/03/2013 at 03:43:43

 2.0 anyone?
  Posted by: Anonymous
  When: 15/03/2013 at 02:19:48

 Defitinition of tha rotation axis
  Posted by: Anonymous
  When: 15/03/2013 at 00:55:14




Topic: multiple terrains



  
Goto parent category
  
Create a new user account


   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

  
Post a new reply
 





Google
 
Web www.riemers.net
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


News
Home
Forum
XNA 2.0 Recipes Book (8)
XNA 3.0 Recipes Book (8)
Downloads
Extra Reading (3)
Matrices: geometrical
Matrix Mathematics
Homogenous matrices
Community Projects (1)
Tutorials (160)
XNA 4.0 using C# (89)
DirectX using C# (54)
Series 1:Terrain (14)
Opening a window
Linking to the Device
Drawing a triangle
Camera
Rotation - Translation
Indices
Terrain creation
Terrain from file
DirectInput
Importing bmp files
Colored vertices
DirectX Light basics
Mesh creation
Mesh lighting
Series 2: Flightsim (19)
Series 3: HLSL (19)
Short Tuts (2)
Resizing problem
Checking Device caps
DirectX using C++ (15)
DirectX using VB (2)