# Drawing a Plane

This topic is 2914 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello,

I've been trying to add support for planes, grids, call them what you will, in my engine.

I've been mostly successful, except for the problem illustrated by this screenshot:

I have no idea why this would occur.

 private SurviveMesh ReadPlane(BeginMode primType, SurvivePrimitiveParam par) { SurviveMesh mesh = new SurviveMesh(); Vector3d[] vertex = new Vector3d[4]; Vector3d[] normal = new Vector3d[4]; Vector2d[] texCoord = new Vector2d[4]; int k; for (k = 0; k < 4; k++) { vertex[k] = new Vector3d(); normal[k] = new Vector3d(); texCoord[k] = new Vector2d(); } double xmin = par.param[0]; double xmax = par.param[1]; double step = par.param[2]; uint numVerts = (uint)((xmax - xmin) / step) * 8; mesh.BeginMesh(primType, numVerts + 4); for (double x = xmin; x <= xmax; x += step) { vertex[0] = new Vector3d(x, -0.55, xmax); normal[0] = new Vector3d(0, 1, 0); texCoord[0] = new Vector2d(x / xmax, 1.0); vertex[1] = new Vector3d(x, -0.55, xmin); normal[1] = new Vector3d(0, 1, 0); texCoord[1] = new Vector2d(x / xmax, 0.0); vertex[2] = new Vector3d(xmax, -0.55, x); normal[2] = new Vector3d(0, 1, 0); texCoord[2] = new Vector2d(1.0, x / xmax); vertex[3] = new Vector3d(xmin, -0.55, x); normal[3] = new Vector3d(0, 1, 0); texCoord[3] = new Vector2d(0.0, x / xmax); mesh.AddTriangle(vertex, normal, texCoord); vertex[0] = vertex[1]; normal[0] = normal[1]; texCoord[0] = texCoord[1]; vertex[1] = vertex[3]; normal[1] = normal[3]; texCoord[1] = texCoord[3]; mesh.AddTriangle(vertex, normal, texCoord); } mesh.End(); mesh.Filename = par.filename; logger.FormatLine(SurviveLogger.InfoLogging, "Plane \"{0}\" created successfully.", mesh.Filename); logger.FormatLine(SurviveLogger.DetailedLogging, "\"{0}\" has {1} vertices and {2} faces.", mesh.Filename, mesh.NumVerts, mesh.NumFaces); return mesh; } 

Note: I think I'm telling BeginMesh an excessive amount of vertices, but if I scale by 4 instead of 8 like I think I should, it throws an IndexOutOfRangeException.

##### Share on other sites
You appear to be trying to create a grid by using two sets of intersecting lines. However, you're using triangles instead of line segments. This is why you have those diagonal lines streaking back across the map; those are the third side of each of those triangles.

Second, because you're using triangles, assuming mesh.addTriangle() uses only the first three array elements from the data you pass it and producing a triangle list (as opposed to a triangle strip or fan), you're generating 6 vertices per iteration step, not either 4 or 8.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 12
• 9
• 11
• 15
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!