src/glCompiler.cpp

changeset 1122
795d1c3554b9
parent 1121
be0b5ad128ea
child 1123
15e46ea3151f
equal deleted inserted replaced
1121:be0b5ad128ea 1122:795d1c3554b9
332 332
333 333
334 void GLCompiler::compilePolygon (LDPolygon& poly, LDObject* topobj, ObjectVBOInfo* objinfo) 334 void GLCompiler::compilePolygon (LDPolygon& poly, LDObject* topobj, ObjectVBOInfo* objinfo)
335 { 335 {
336 SurfaceVboType surface; 336 SurfaceVboType surface;
337 int numverts; 337 int vertexCount;
338 338
339 switch (poly.num) 339 switch (poly.num)
340 { 340 {
341 case 2: surface = LinesVbo; numverts = 2; break; 341 case 2: surface = LinesVbo; vertexCount = 2; break;
342 case 3: surface = TrianglesVbo; numverts = 3; break; 342 case 3: surface = TrianglesVbo; vertexCount = 3; break;
343 case 4: surface = QuadsVbo; numverts = 4; break; 343 case 4: surface = QuadsVbo; vertexCount = 4; break;
344 case 5: surface = ConditionalLinesVbo; numverts = 2; break; 344 case 5: surface = ConditionalLinesVbo; vertexCount = 2; break;
345 default: return; 345 default: return;
346 } 346 }
347 347
348 // Determine the normals for the polygon. 348 // Determine the normals for the polygon.
349 Vertex normals[4]; 349 Vertex normals[4];
350 for (int i = 0; i < numverts; ++i) 350 auto vertexRing = ring(poly.vertices, vertexCount);
351 { 351
352 const Vertex& v1 = poly.vertices[(i - 1 + numverts) % numverts]; 352 for (int i = 0; i < vertexCount; ++i)
353 const Vertex& v2 = poly.vertices[i]; 353 {
354 const Vertex& v3 = poly.vertices[(i + 1) % numverts]; 354 const Vertex& v1 = vertexRing[i - 1];
355 const Vertex& v2 = vertexRing[i];
356 const Vertex& v3 = vertexRing[i + 1];
355 normals[i] = Vertex::crossProduct(v3 - v2, v1 - v2).normalized(); 357 normals[i] = Vertex::crossProduct(v3 - v2, v1 - v2).normalized();
356 } 358 }
357 359
358 for (ComplementVboType complement : iterateEnum<ComplementVboType>()) 360 for (ComplementVboType complement : iterateEnum<ComplementVboType>())
359 { 361 {
360 const int vbonum = vboNumber (surface, complement); 362 const int vbonum = vboNumber (surface, complement);
361 QVector<GLfloat>& vbodata = objinfo->data[vbonum]; 363 QVector<GLfloat>& vbodata = objinfo->data[vbonum];
362 const QColor color = getColorForPolygon (poly, topobj, complement); 364 const QColor color = getColorForPolygon (poly, topobj, complement);
363 365
364 for (int vert = 0; vert < numverts; ++vert) 366 for (int vert = 0; vert < vertexCount; ++vert)
365 { 367 {
366 if (complement == SurfacesVboComplement) 368 if (complement == SurfacesVboComplement)
367 { 369 {
368 // Write coordinates. Apparently Z must be flipped too? 370 // Write coordinates. Apparently Z must be flipped too?
369 vbodata << poly.vertices[vert].x() 371 vbodata << poly.vertices[vert].x()

mercurial