src/glcompiler.cpp

changeset 1371
b8df4748d04e
parent 1332
1fffb24d4ffe
child 1372
641060842b92
equal deleted inserted replaced
1370:c6d5ba08c62c 1371:b8df4748d04e
329 if (m_objectInfo.contains(index)) 329 if (m_objectInfo.contains(index))
330 { 330 {
331 // If we have data relating to this object, remove it. 331 // If we have data relating to this object, remove it.
332 // The VBOs have changed now and need to be merged. 332 // The VBOs have changed now and need to be merged.
333 m_objectInfo.remove(index); 333 m_objectInfo.remove(index);
334 this->needBoundingBoxRebuild = true;
334 needMerge(); 335 needMerge();
335 } 336 }
336 } 337 }
337 338
338 /* 339 /*
435 const Vertex& v2 = vertexRing[i]; 436 const Vertex& v2 = vertexRing[i];
436 const Vertex& v3 = vertexRing[i + 1]; 437 const Vertex& v3 = vertexRing[i + 1];
437 normals[i] = QVector3D::crossProduct(v3 - v2, v1 - v2).normalized(); 438 normals[i] = QVector3D::crossProduct(v3 - v2, v1 - v2).normalized();
438 } 439 }
439 440
441 if (not this->needBoundingBoxRebuild)
442 {
443 for (int i = 0; i < vertexCount; i += 1)
444 this->boundingBox.consider(poly.vertices[i]);
445 }
446
440 for (VboSubclass complement : iterateEnum<VboSubclass>()) 447 for (VboSubclass complement : iterateEnum<VboSubclass>())
441 { 448 {
442 const int vbonum = vboNumber (surface, complement); 449 const int vbonum = vboNumber (surface, complement);
443 QVector<GLfloat>& vbodata = objectInfo.data[vbonum]; 450 QVector<GLfloat>& vbodata = objectInfo.data[vbonum];
444 const QColor color = getColorForPolygon (poly, polygonOwnerIndex, complement); 451 const QColor color = getColorForPolygon (poly, polygonOwnerIndex, complement);
471 << ((GLfloat) color.blue()) / 255.0f 478 << ((GLfloat) color.blue()) / 255.0f
472 << ((GLfloat) color.alpha()) / 255.0f; 479 << ((GLfloat) color.alpha()) / 255.0f;
473 } 480 }
474 } 481 }
475 } 482 }
483 }
484
485 /*
486 * Returns the center point of the model.
487 */
488 Vertex GLCompiler::modelCenter()
489 {
490 // If the bounding box is invalid, rebuild it now.
491 if (this->needBoundingBoxRebuild)
492 {
493 // If there's something still queued for compilation, we need to build those first so
494 // that they get into the bounding box.
495 this->compileStaged();
496 this->boundingBox = {};
497 QMapIterator<QPersistentModelIndex, ObjectVboData> iterator {m_objectInfo};
498
499 while (iterator.hasNext())
500 {
501 iterator.next();
502
503 for (VboClass vboclass : {VboClass::Triangles, VboClass::Quads})
504 {
505 // Read in the surface vertices and add them to the bounding box.
506 int vbonum = vboNumber(vboclass, VboSubclass::Surfaces);
507 const auto& vector = iterator.value().data[vbonum];
508
509 for (int i = 0; i + 2 < countof(vector); i += 3)
510 this->boundingBox.consider({vector[i], vector[i + 1], vector[i + 2]});
511 }
512 }
513
514 this->needBoundingBoxRebuild = false;
515 }
516
517 if (not this->boundingBox.isEmpty())
518 return this->boundingBox.center();
519 else
520 return {};
476 } 521 }
477 522
478 int GLCompiler::vboNumber (VboClass surface, VboSubclass complement) 523 int GLCompiler::vboNumber (VboClass surface, VboSubclass complement)
479 { 524 {
480 return (static_cast<int>(surface) * EnumLimits<VboSubclass>::Count) + static_cast<int>(complement); 525 return (static_cast<int>(surface) * EnumLimits<VboSubclass>::Count) + static_cast<int>(complement);
527 572
528 void GLCompiler::handleDataChange(const QModelIndex& topLeft, const QModelIndex& bottomRight) 573 void GLCompiler::handleDataChange(const QModelIndex& topLeft, const QModelIndex& bottomRight)
529 { 574 {
530 for (int row = topLeft.row(); row <= bottomRight.row(); row += 1) 575 for (int row = topLeft.row(); row <= bottomRight.row(); row += 1)
531 m_staged.insert(m_renderer->model()->index(row)); 576 m_staged.insert(m_renderer->model()->index(row));
577
578 this->needBoundingBoxRebuild = true;
532 } 579 }
533 580
534 void GLCompiler::handleObjectHighlightingChanged( 581 void GLCompiler::handleObjectHighlightingChanged(
535 const QModelIndex& oldIndex, 582 const QModelIndex& oldIndex,
536 const QModelIndex& newIndex 583 const QModelIndex& newIndex

mercurial