/// <summary> /// Create a Vector3 for the point specified by a given co-ordinate. /// /// This function will also translate the point as necessary to ensure /// that the landscape is symmetric about the origin. /// /// Assuming that the height translates to the y-value. /// </summary> /// <param name="coord"></param> /// <returns></returns> private Vector3 getVector(Tuple coord) { return new Vector3( coord.i - (size / 2), heightMap[coord.i, coord.j], coord.j - (size / 2) ); }
/// <summary> /// Does the given tuple specify a valid (i, j) co-ordinate for the /// current height map? /// </summary> private bool validCoord(Tuple coord) { return coord.i >= 0 && coord.i < size && coord.j >= 0 && coord.j < size; }
/// <summary> /// Generate the two triangles that describe the square whose bottom-left corner is the given coordinate. /// </summary> /// <param name="coord">The coordinates of the bottom-left corner of the square.</param> /// <returns></returns> private Vector3[] getTriangleVertices(Tuple coord) { // if the bottom-left coordinate is at the right or top borders, then there are no triangles here if(coord.i == size - 1 || coord.j == size - 1) { // return an empty array return new Vector3[0]; } // otherwise, return vertices for the two triangles within that square return new Vector3[] { // the first (upper) triangle getVector(new Tuple(coord.i, coord.j)), getVector(new Tuple(coord.i, coord.j + 1)), getVector(new Tuple(coord.i + 1, coord.j + 1)), // the second (lower) triangle getVector(new Tuple(coord.i, coord.j)), getVector(new Tuple(coord.i + 1, coord.j + 1)), getVector(new Tuple(coord.i + 1, coord.j)) }; }