Sorry, I don't understand what your variables mean. Are they suppose to represent the endpoints of each line in the grid If that is the case, it might be easier to break into 2 loops, 1 loop to calculate the endpoints for the vertical lines, and 2nd look to calculate the end points for the horizontal lines. Something like (psuedo code), modify accordingly if you don't want border
counter = 0;
for (x=0; x<width; x+=space_between_vert_lines) {
end_point[counter][top].x = x;
end_point[counter][top].y = 0;
end_point[counter][bottom].x = x;
end_point[counter][bottom].y = (height-1);
// draw_line( end_point[counter][top].x, end_point[counter][top].y, end_point[counter][bottom].x, end_point[counter][bottom].y );
++counter;
}
counter = 0;
for (y=0; y<height; y+=space_between_horiz_lines) {
end_point[counter][left].x = 0;
end_point[counter][left].y = y;
end_point[counter][right].x = (width-1);
end_point[counter][right].y = y;
// draw_line( end_point[counter][left].x, end_point[counter][left].y, end_point[counter][right].x, end_point[counter][right].y );
++counter;
}
One thing that struck me was the creation of the Vector3:
new Vector3(i - size, 0, j - size)
perhaps you meant to do:
new Vector3(i - size, j - size, 0)
If that's not the problem I can take a further look at it (unless someone else beats me to it
)