• Advertisement
Sign in to follow this  

rendering a grid problems

This topic is 3116 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 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 this post


Link to post
Share on other sites
Advertisement
Try something like:

for(float z=-m+1; z < +m; z++) {
for(float x=-m+1; x < +m; x++) {
// do your stuff here
}
}

Share this post


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

  • Advertisement