Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

Drawing a grid

Started by sumit381 Mar 2, 2007 at 7:45 AM 0 replies 350+ views
Original Post
sumit381
sumit381
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.