diff --git a/fggl/data/heightmap.cpp b/fggl/data/heightmap.cpp index c2a915dcafe2815d44278be7f44f693af0d60e9b..0c7dcf665fa3c8053d84b8667d502677d3d6cd5e 100644 --- a/fggl/data/heightmap.cpp +++ b/fggl/data/heightmap.cpp @@ -15,7 +15,7 @@ namespace fggl::data { const int gridOffset = sizeX * sizeY; // calculate normals for each triangle - math::vec3 triNormals[sizeX * sizeY * 2]; + math::vec3* triNormals = new math::vec3[sizeX * sizeY * 2]; for (int i = 0; i < sizeX - 1; i++) { for (int j = 0; j < sizeY - 1; j++) { // calculate vertex @@ -66,12 +66,15 @@ namespace fggl::data { locations[idx(i, j, sizeY)].normal = glm::normalize(finalNormal) * -1.0f; //FIXME the normals seem wrong. } } + delete[] triNormals; } void generateHeightMesh(const data::HeightMap *heights, data::Mesh &mesh) { // step 1: convert height data into vertex locations - data::Vertex locations[data::heightMaxZ * data::heightMaxZ]; + const int numElms = data::heightMaxX * data::heightMaxZ; + data::Vertex* locations = new data::Vertex[numElms]; + for (std::size_t x = 0; x < data::heightMaxX; x++) { for (std::size_t z = 0; z < data::heightMaxZ; z++) { float level = heights->getValue(x, z); @@ -88,9 +91,10 @@ namespace fggl::data { mesh.restartVertex = data::heightMaxZ * data::heightMaxX; // populate mesh - for (auto & location : locations) { - mesh.pushVertex(location); + for (auto i = 0; i < numElms; i++) { + mesh.pushVertex(locations[i]); } + delete[] locations; for (std::size_t x = 0; x < data::heightMaxX - 1; x++) { for (std::size_t z = 0; z < data::heightMaxZ; z++) {