Hey the code I posted above CAN make rough terrain you just apply random heights to the .y value (height value on the grid for each point) It should also work with that struct. The code creates the grid about 0,0,0 so be sure your camera is around there and also make sure your camer isn''t below it or it won''t show. And draw it like this:
pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, D3DFVF_VERTEX,plane.pTerrainVertices,plane.dwNumTerrainVertices,plane.pTerrainIndices, plane.dwNumTerrainIndices, 0 );}
you don''t need the g_ prefix if you''re using a struct.(not that it matters)
Also what error are you getting?
More terrain blues...
I''m not getting an error - it just doesnt display...Also, if i supply a random y value, it''ll just end up making the ground disjointed.
Solarbeam,
I haven''t checked your code deeply, but I noticed this:
You declare your grid array like:
D3DVECTOR *grid;
this is a one-dimensional array.
Then you ''new'' it twice. I don''t know what happens if you do this, but it won''t make it 2-dimensional.
But when you access the array later you use grid[pos][pos] as it were 2-dim. I think the ''ambiguous bla, bla'' - error lies here.
Either do:
D3DVECTOR **grid;
grid = new (D3DVECTOR *)[dwGridSize];
for(i=0; i = new D3DVECTOR[dwGridSize];
and access it via grid[x][y]
or (better IMHO):
D3DVECTOR *grid;
grid = new D3DVECTOR[dwGridSize * dwGridSize];
and access it via grid[x + y * dwGridSize]
About Indices:
They are used with DrawIndexedPrimitive and allow you to share vertices between triangles. In this way there are less vertices to be transformed.
For example, if you have a quad made of two triangles. If you draw it without indices you need to pass an array of 6 vertices to DrawPrimitive. Using indices, you pass an array of 4 vertices and the 6 indices to this array to DrawIndexedPrimitive. D3D only has to transform 4 vertices now instead of 6. If you do this in a smart way you can save a lot of time transforming duplicate vertices.
I''m also trying a terrain engine now (using binary triangle trees and LOD) and I''ve managed to only transform slightly more than half the vertices as there are triangles in a patch of terrain (if they use the same texture, of course) using indices. If I''d used DrawPrimitive, there were nearly six times as much vertices to be transformed.
Peter
I haven''t checked your code deeply, but I noticed this:
You declare your grid array like:
D3DVECTOR *grid;
this is a one-dimensional array.
Then you ''new'' it twice. I don''t know what happens if you do this, but it won''t make it 2-dimensional.
But when you access the array later you use grid[pos][pos] as it were 2-dim. I think the ''ambiguous bla, bla'' - error lies here.
Either do:
D3DVECTOR **grid;
grid = new (D3DVECTOR *)[dwGridSize];
for(i=0; i = new D3DVECTOR[dwGridSize];
and access it via grid[x][y]
or (better IMHO):
D3DVECTOR *grid;
grid = new D3DVECTOR[dwGridSize * dwGridSize];
and access it via grid[x + y * dwGridSize]
About Indices:
They are used with DrawIndexedPrimitive and allow you to share vertices between triangles. In this way there are less vertices to be transformed.
For example, if you have a quad made of two triangles. If you draw it without indices you need to pass an array of 6 vertices to DrawPrimitive. Using indices, you pass an array of 4 vertices and the 6 indices to this array to DrawIndexedPrimitive. D3D only has to transform 4 vertices now instead of 6. If you do this in a smart way you can save a lot of time transforming duplicate vertices.
I''m also trying a terrain engine now (using binary triangle trees and LOD) and I''ve managed to only transform slightly more than half the vertices as there are triangles in a patch of terrain (if they use the same texture, of course) using indices. If I''d used DrawPrimitive, there were nearly six times as much vertices to be transformed.
Peter
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement