• Advertisement
Sign in to follow this  

Drawing a grid

This topic is 4010 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, 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.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
Advertisement
Sign in to follow this  

  • Advertisement