Sign in to follow this  
emforce

rendering a grid problems

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

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