Sign in to follow this  

Drawing a grid

Recommended Posts

Hi, I was wonder what would be the best way to draw a grid in directX? The size of the grid will be determined by data that is passed into the program by an xml file. This data will contain data points that have x, y, z values. Below is the code I am current using. I don't know if it seems to be too efficient. lineList = new VertexBuffer(typeof(CustomVertex.PositionColored), numOfVerts, d3dDevice, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionColored.Format, Pool.Default); CustomVertex.PositionColored[] verts = new CustomVertex.PositionColored[numOfVerts]; // x-axis verts[0].Position = new Vector3(-2.0f, 0.0f, 0.0f); verts[1].Position = new Vector3(7.0f, 0.0f, 0.0f); // y-axis verts[2].Position = new Vector3(7.0f, 9.0f, 0.0f); verts[3].Position = new Vector3(7.0f, 0.0f, 0.0f); // z-axis verts[4].Position = new Vector3(7.0f, 0.0f, 0.0f); verts[5].Position = new Vector3(7.0f, 0.0f, 9.0f); // loop creates the grid lines on the x-z plane int counter = 0; for (int v = 0; v < numOfGridVerts; v += 2) { if (v == 0) { verts[v + 6].Position = new Vector3(-2.0f, 0.0f, v + 1f); verts[v + 7].Position = new Vector3(7.0f, 0.0f, v + 1f); } else { verts[v + 6].Position = new Vector3(-2.0f, 0.0f, (float)v - counter); verts[v + 7].Position = new Vector3(7.0f, 0.0f, (float)v - counter); } counter++; } for (int i = 0; i <= numOfVerts - 1; i++) { verts[i].Color = Color.Red.ToArgb(); } lineList.SetData(verts, 0, LockFlags.None); Anyway, please help if you can, thank you.

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