src/gl/compiler.cpp

changeset 33
4c41bfe2ec6e
parent 30
1536f23cfab7
child 34
1de2b8d64e9f
equal deleted inserted replaced
32:767592024ec5 33:4c41bfe2ec6e
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()));
210 color = this->colorTable[polygon.color].faceColor; 210 color = this->colorTable[polygon.color].faceColor;
211 } 211 }
212 return color; 212 return color;
213 } 213 }
214 214
215 Point3D gl::Compiler::modelCenter() const 215 glm::vec3 gl::Compiler::modelCenter() const
216 { 216 {
217 return boxCenter(this->boundingBox); 217 return boxCenter(this->boundingBox);
218 } 218 }
219 219
220 double gl::Compiler::modelDistance() const 220 double gl::Compiler::modelDistance() const

mercurial