Public Group

# generating a Grid

This topic is 3328 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hi guys could someone give me the basic pseudocode for generating a flat plane. It seems simple but the solution evades me :( For instance if i had 2 variables mNumRows mNumCols i know i would use something like this for(DWORD i = 0; i < mNumRows; ++i) { for(DWORD j = 0; j < mNumCols; ++j) { } } but how would i make this into a formula which generates a flat plane. [Edited by - emforce on August 13, 2009 5:36:16 PM]

##### Share on other sites
Quote:
 Original post by emforcehi guys could someone give me the basic pseudocode for generating a flat plane. It seems simple but the solution evades me :( For instance if i had 2 variablesmNumRowsmNumColsi know i would use something like thisfor(DWORD i = 0; i < mNumRows; ++i) { for(DWORD j = 0; j < mNumCols; ++j) { } }but how would i make this into a formula which generates a flat plane.
I assume you mean a grid? (A plane is infinite, and does not have distinguishing characteristics such as grid lines).

Also, is this 2-d or 3-d? And what are you using for rendering?

##### Share on other sites
ok its a grid like you would see in 3dsmax or blender. So it is in 3d and i am using directx 10. What do you mean by what am i using for rendering?

##### Share on other sites
Quote:
 What do you mean by what am i using for rendering?
Quote:
 ...i am using directx 10.
:)

Ok, to render a grid, you'll need to do the following:

1. Generate local-space coordinates for the grid vertices. A straightforward way to do this would be to use the nested loop you posted earlier, and for each iteration of the inner loop, generate a vertex with x equal to i and y equal to j (or vice versa).

2. Render the geometry, using an appropriate transform (scale, rotation, and translation).

Strictly speaking, you only need the vertices around the perimeter of the grid (assuming you'll be rendering it in wireframe), but it might be easier just to go ahead and generate all the intermediate vertices as well.

If there are particular parts of this that you're unsure about, post back with any specific question you have.

##### Share on other sites
ok so i managed to render a grid but how to i render it with quad? topology because right now it renders a square grid but made with triangles. On msdn it doesn't show any thing like quadlist but does that mean i will have to use a line list? Oh and thanks for your help :D

##### Share on other sites
Quote:
 ok so i managed to render a grid but how to i render it with quad? topology because right now it renders a square grid but made with triangles. On msdn it doesn't show any thing like quadlist but does that mean i will have to use a line list?
Not quite sure what you mean - are you asking how to render the grid in wireframe? If that's what you're asking, I'm not familiar enough with DX10 to give you a specific answer, but if DX offers line primitives (which I assume it does), then that would probably be the most straightforward way to proceed.

Maybe someone who's more familiar with DX10 can provide some more details.
Quote:
 Oh and thanks for your help :D
You're welcome :)

##### Share on other sites
no i have the wireframe down its just it renders it all in triangles because my primitive topology is a trianglelist but i was wondering if i would have to use a linelist to render the grid in squares.

thanks

##### Share on other sites
I maybe totally misunderstood your problem but:
for( int i = 0; i < GRID_NUM_X; i++ ){    line(i*GRID_SIZE-GRID_NUM_X*GRID_SIZE/2,i*GRID_SIZE-GRID_NUM_X*GRID_SIZE/2,         -GRID_NUM_Y*GRID_SIZE/2,GRID_NUM_Y*GRID_SIZE/2);    ////line(x1,x2,y1,y2), I dunno the syntax in DX}for( int j = 0; i < GRID_NUM_Y; j++ ){    line(-GRID_NUM_X*GRID_SIZE/2,GRID_NUM_X*GRID_SIZE/2,         j*GRID_SIZE-GRID_NUM_Y*GRID_SIZE/2,j*GRID_SIZE-GRID_NUM_Y*GRID_SIZE/2,         );}
It's the X-Y plane (z = 0). Haven't tested it. If you only want to display the grid, I think that's the simplest method.
You draw it after the View transformations, of course.

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 9
• 23
• 9
• 32
• ### Forum Statistics

• Total Topics
632624
• Total Posts
3007505
• ### Who's Online (See full list)

There are no registered users currently online

×