I'm trying to construct a plane out of triangles in WebGL. My code for the constructor looks like this:
function plane( points_transform )
{
shape.call(this); // Inherit class shape’s array members by calling parent constructor
if( !arguments.length) return; // Pass no arguments if you just want to make an empty dummy object that inherits everything, for populating other shapes
this.populate( this, points_transform ); // Otherwise, a new triangle immediately populates its own arrays with triangle points,
this.init_buffers(); // Then sends its arrays to the graphics card into new buffers
}
inherit(plane, shape);
plane.prototype.populate = function( recipient, points_transform)
{
var offset = recipient.vertices.length;
var index_offset = recipient.indices.length; // Recipient's previous size
recipient.vertices.push( vec3(0,0,0), vec3(1,1,0), vec3(0,1,0), vec3(1,0,0), vec3(2,1,0), vec3(2,0,0) );
recipient.normals.push( vec3(0,0,1), vec3(0,0,1), vec3(0,0,1), vec3(0,0,1), vec3(0,0,1), vec3(0,0,1) );
// recipient.texture_coords.push( vec2(0,0), vec2(0,1), vec2(1,0), vec2(1,1), vec2(2,0), vec2(2,1) );
recipient.indices.push( offset + 0, offset + 1, offset + 2, offset + 3, offset + 4, offset + 5 );
gl.drawArrays(gl.TRIANGLE_STRIP, 0, recipient.vertices);
}
However when I draw it, it looks disjointed like this:
I was wondering how to fix that issue and how to make a generalized function that could take an arbitrary amount of rows / columns and compute the necessary vertices to generate an MxN grid.
I was looking at this site specifically but I can't figure out where the trianglestrip variable comes from.