238{
239 currType = MeshType::Plane;
240 maxHeight = -100;
241 minHeight = 100;
242 res = resolution;
243 sc = scale;
244 texSc = textureScale;
245 Vert *vertices =
new Vert[resolution * resolution];
246 int *inds = new int[(resolution-1) * (resolution-1) * 6];
247 int triIndex = 0;
248
249 for (int y = 0; y < resolution; y++)
250 {
251 for (int x = 0; x < resolution; x++)
252 {
253 int i = x + y * resolution;
254 glm::vec2 percent = glm::vec2(x, y) / ((float)resolution - 1);
255 glm::vec3 pointOnPlane = (percent.x - .5f) * 2 * right + (percent.y - .5f) * 2 * front;
256 pointOnPlane *= scale;
257 vertices[i] =
Vert();
258 vertices[i].position = glm::vec4(0.0f);
259 vertices[i].position.x = (float)pointOnPlane.x;
260 vertices[i].position.y = (float)pointOnPlane.y;
261 vertices[i].position.z = (float)pointOnPlane.z;
262 vertices[i].texCoord = glm::vec2(percent.x, percent.y)*textureScale;
263 vertices[i].normal = glm::vec4(0.0f);
264
265 if (x != resolution - 1 && y != resolution - 1)
266 {
267 inds[triIndex] = i;
268 inds[triIndex + 1] = i + resolution + 1;
269 inds[triIndex + 2] = i + resolution;
270 inds[triIndex + 3] = i;
271 inds[triIndex + 4] = i + 1;
272 inds[triIndex + 5] = i + resolution + 1;
273 triIndex += 6;
274 }
275
276 vertices[i].extras1 = glm::vec4(0.0f);
277 }
278 }
279
280 if (vert)
281 {
282 delete vert;
283 }
284
285 if (indices)
286 {
287 delete indices;
288 }
289
290 vertexCount = resolution * resolution;
291 vert =
new Vert[resolution * resolution];
292 memset(vert, 0,
sizeof(
Vert) * vertexCount);
293 memcpy(vert, vertices,
sizeof(
Vert)*vertexCount);
294 indexCount = (resolution - 1) * (resolution - 1) * 6;
295 indices = new int[(resolution - 1) * (resolution - 1) * 6];
296 memset(indices, 0, indexCount);
297 memcpy(indices, inds, sizeof(int) * indexCount);
298 delete vertices;
299 delete inds;
300}