164 std::vector<GLfloat>& normalsBuffer = vboData[gl::vboIndex({vboClass, gl::VboSubclass::Normals})]; |
164 std::vector<GLfloat>& normalsBuffer = vboData[gl::vboIndex({vboClass, gl::VboSubclass::Normals})]; |
165 auto vertexRing = iter::ring(polygon.vertices, polygon.numPolygonVertices()); |
165 auto vertexRing = iter::ring(polygon.vertices, polygon.numPolygonVertices()); |
166 reserveMore(normalsBuffer, polygon.numPolygonVertices() * 3_z); |
166 reserveMore(normalsBuffer, polygon.numPolygonVertices() * 3_z); |
167 for (unsigned int i = 0; i < polygon.numPolygonVertices(); i += 1) |
167 for (unsigned int i = 0; i < polygon.numPolygonVertices(); i += 1) |
168 { |
168 { |
169 const Point3D& v1 = vertexRing[i - 1]; |
169 const glm::vec3& v1 = vertexRing[i - 1]; |
170 const Point3D& v2 = vertexRing[i]; |
170 const glm::vec3& v2 = vertexRing[i]; |
171 const Point3D& v3 = vertexRing[i + 1]; |
171 const glm::vec3& v3 = vertexRing[i + 1]; |
172 const QVector3D normal = QVector3D::crossProduct(v3 - v2, v1 - v2).normalized(); |
172 const QVector3D normal = QVector3D::crossProduct(v3 - v2, v1 - v2).normalized(); |
173 for (const GLfloat coord : {normal.x(), normal.y(), normal.z()}) |
173 for (const GLfloat coord : {normal.x(), normal.y(), normal.z()}) |
174 normalsBuffer.push_back(coord); |
174 normalsBuffer.push_back(coord); |
175 } |
175 } |
176 */ |
176 */ |
177 reserveMore(vertexBuffer, polygon.numPolygonVertices() * 7); |
177 reserveMore(vertexBuffer, polygon.numPolygonVertices() * 7); |
178 const QColor color = this->getColorForPolygon(polygon); |
178 const QColor color = this->getColorForPolygon(polygon); |
179 // Transform vertices so that they're suitable for GL rendering |
179 // Transform vertices so that they're suitable for GL rendering |
180 for (unsigned int i = 0; i < polygon.numPolygonVertices(); i += 1) |
180 for (unsigned int i = 0; i < polygon.numPolygonVertices(); i += 1) |
181 { |
181 { |
182 Point3D& point = polygon.vertices[i]; |
182 glm::vec3& point = polygon.vertices[i]; |
183 this->boundingBox.consider(polygon.vertices[i]); |
183 this->boundingBox.consider(polygon.vertices[i]); |
184 vertexBuffer.push_back(static_cast<GLfloat>(point.x)); |
184 vertexBuffer.push_back(static_cast<GLfloat>(point.x)); |
185 vertexBuffer.push_back(static_cast<GLfloat>(point.y)); |
185 vertexBuffer.push_back(static_cast<GLfloat>(point.y)); |
186 vertexBuffer.push_back(static_cast<GLfloat>(point.z)); |
186 vertexBuffer.push_back(static_cast<GLfloat>(point.z)); |
187 vertexBuffer.push_back(static_cast<GLfloat>(color.redF())); |
187 vertexBuffer.push_back(static_cast<GLfloat>(color.redF())); |