Jump to content
  • Advertisement
Sign in to follow this  
exextatic

Creating a grid (DX9)

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all,

Looking into creating a grid like in the Valve Hammer editor for use in my map editor.
I'll attach what I've got so far and a snippet of the valve hammer editors grid for reference.
What I have at the moment:
grid.PNG
What I want it to look like:
grid2.PNG
The code Im using is:
void EditorDXHandler::renderGrid()
{
static int GridSize = 10;
static D3DXMATRIX matIdentity;

d3ddev->SetFVF(GRIDFVF);

if(!gridInit)
{
d3ddev->CreateVertexBuffer(sizeof(GRIDVERTEX) * GridSize * 9,
0,
GRIDFVF,
D3DPOOL_MANAGED,
&g_buffer,
0);

GRIDVERTEX* pGridData = 0;
g_buffer->Lock(0, 0, (void**)&pGridData, 0);

int index = 0;
for(; index <= GridSize * 4 + 1; index++)
{
float x = (index % 2) ? GridSize : -GridSize;
float y = index / 2 - GridSize;
float z = 0.0f;

pGridData[index].position = D3DXVECTOR3(x, y, z);
pGridData[index].color = D3DXCOLOR(0.4f, 0.4f, 0.4f, 1.0f);
}

for(; index <= GridSize * 8 + 4; index++)
{
static int half = index;
float x = (index - half) / 2 - GridSize;
float y = (index % 2) ? -GridSize : GridSize;
float z = 0.0f;

pGridData[index].position = D3DXVECTOR3(x, y, z);
pGridData[index].color = D3DXCOLOR(0.4f, 0.4f, 0.4f, 1.0f);
}

g_buffer->Unlock();

D3DXMatrixIdentity(&matIdentity);
gridInit = true;
}

d3ddev->SetTransform(D3DTS_WORLD, &matIdentity);
d3ddev->SetStreamSource(0, g_buffer, 0, sizeof(GRIDVERTEX));
d3ddev->SetTexture(0, NULL);
d3ddev->DrawPrimitive(D3DPT_LINELIST, 0, GridSize * 4 + 2);
}


Thanks,
James Warner

Share this post


Link to post
Share on other sites
Advertisement
You're not really saying what the problem is. We can see what you're getting, and we can assume that what you see in Hammer is what you want (although we don't know that for definite), but I think a little more info is required. What have you tried? What worked? What didn't work?

Share this post


Link to post
Share on other sites
Hidden
First Create a grid that is just made of 4 lines for example with the size of 512x512 which will give you an big quad. Then subdivide that Quad into N Quads Called GridLines. Now Subdivide each gridline into Cells.

Share this post


Link to post
Hidden
First Create a grid that is just made of 4 lines for example with the size of 512x512 which will give you an big quad. Then subdivide that Quad into N Quads Called GridLines. Now Subdivide each gridline into gridUnit.

Share this post


Link to post
First Create a grid that is just made of 4 lines for example with the size of 512x512 which will give you an big quad. Then subdivide that Quad into N Quads Called GridLines. Now Subdivide each gridline into gridUnit. As you can see this is a recursive problem, and you can make the quads as small as you want.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!