Sign in to follow this  
emforce

generating a Grid

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 this post


Link to post
Share on other sites
Quote:
Original post by emforce
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.
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this