Skip to main content
gamedev.net
🔒 Locked

Making a grid

Started by Programmer16 Jul 4, 2004 at 12:37 AM 1 replies 700+ views
Original Post
Programmer16
Programmer16
Hey everybody, I was wondering if you could help me figure out an algorithm to fill a vertexbuffer with transformed vertices, forming a grid. I have a few specifications: I want each grid square to be equilateral I want the grid to be CxR big I want each square to consist of 2 tris I think I have part of it, but I can't get the code to work:

for(int iRow = 0; iRow < iMaxRows; iRow+=2)
{
for(int iCol = 0; iCol < iMaxCols; iCol+=2)
{
int iSector = iRow * iMaxCols + iCol;
Vertices[iSector].x = iCol * iTileSize;
Vertices[iSector].y = iRow * iTileSize;
Vertices[iSector].z = 0.0f;
Vertices[iSector].diffuse = D3DCOLOR_XRGB(255, 255, 255);
Vertices[iSector].u = 0.0f;
Vertices[iSector].v = 0.0f;

iSector = iRow * iMaxCols + (iCol + 1);
Vertices[iSector].x = (iCol+1) * iTileSize;
Vertices[iSector].y = iRow * iTileSize;
Vertices[iSector].z = 0.0f;
Vertices[iSector].diffuse = D3DCOLOR_XRGB(255, 255, 255);
Vertices[iSector].u = 1.0f;
Vertices[iSector].v = 0.0f;

iSector = (iRow + 1) * iMaxCols + iCol;
Vertices[iSector].x = iCol * iTileSize;
Vertices[iSector].y = (iRow+1) * iTileSize;
Vertices[iSector].z = 0.0f;
Vertices[iSector].diffuse = D3DCOLOR_XRGB(255, 255, 255);
Vertices[iSector].u = 0.0f;
Vertices[iSector].v = 1.0f;

iSector = (iRow + 1) * iMaxCols + (iCol + 1);
Vertices[iSector].x = (iCol+1) * iTileSize;
Vertices[iSector].y = (iRow+1) * iTileSize;
Vertices[iSector].z = 0.0f;
Vertices[iSector].diffuse = D3DCOLOR_XRGB(255, 255, 255);
Vertices[iSector].u = 1.0f;
Vertices[iSector].v = 1.0f;
}
}
But that doesn't seem to work for me. Am I doing something wrong, or is some other part of my code messed up (I'm not getting any errors, it just doesn't render)? (Note: It might help if I put them as two tris and not a quad, huh?) My other stuff renders just fine I think part of my problem is that I'm trying to make the vertex array into a grid, when I should just make each one in order. Thanks!
stevie56
stevie56
Where is your camera? My guess it’s still at 0,0,0.

You set your grid vertices at Z=0, therefore your camera will be on the grid, looking through it.

Either move the camera to Z<>0, try -10 to start, or set the vertices of the grid so the Z component isn’t = 0.

StevieDon't follow me, I'm lost.
Programmer16
Programmer16
Its in transformed vertices so I don't have a "camera" or z axis.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.