# rendering a grid problems

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

## Recommended Posts

hi guys my problem is that i have rendered a grid but it starts at the origin (0,0) and goes outwards from there. But how would i make it so that the centre of the grid is at the origin? the code i use is

for(DWORD i = 0; i < m; ++i)
{
float z = i;
for(DWORD j = 0; j < n; ++j)
{
float x = j;

// Graph of this function looks like a mountain range.
float y = 0.0f;

vertices[i*n+j].pos = D3DXVECTOR3(x, y, z);

// Stretch texture over grid.
vertices[i*n+j].texC.x = j*du;
vertices[i*n+j].texC.y = i*dv;

// n = (-df/dx, 1, -df/dz)
D3DXVECTOR3 normal;
normal.x = -0.03f*z*cosf(0.1f*x) - 0.3f*cosf(0.1f*z);
normal.y = 1.0f;
normal.z = -0.3f*sinf(0.1f*x) + 0.03f*x*sinf(0.1f*z);
D3DXVec3Normalize(&vertices[i*n+j].normal, &normal);
}
}



##### Share on other sites
Try something like:
for(float z=-m+1; z < +m; z++) {   for(float x=-m+1; x < +m; x++) {      // do your stuff here   }}

##### Share on other sites
thank you that got it working! :D

1. 1
2. 2
Rutin
22
3. 3
4. 4
frob
18
5. 5

• 33
• 13
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
632562
• Total Posts
3007098

×