src/primitives.cpp

changeset 1408
0d6162662040
parent 1407
22bc5862cb56
child 1411
b48f3fd2664b
equal deleted inserted replaced
1407:22bc5862cb56 1408:0d6162662040
372 segment->setVertex(1, {circle[i].x2(), 0.0, circle[i].y2()}); 372 segment->setVertex(1, {circle[i].x2(), 0.0, circle[i].y2()});
373 segment->setVertex(2, {circle[i].x1(), 0.0, circle[i].y1()}); 373 segment->setVertex(2, {circle[i].x1(), 0.0, circle[i].y1()});
374 } 374 }
375 } 375 }
376 376
377 void PrimitiveModel::generateChord(Model& model) const
378 {
379 QVector<QLineF> circle = makeCircle(segments, divisions, 1);
380
381 for (int i = 1; i < segments; ++i)
382 {
383 LDTriangle* segment = model.emplace<LDTriangle>();
384 segment->setColor(MainColor);
385 segment->setVertex(0, {circle[0].x1(), 0.0, circle[0].y1()});
386 segment->setVertex(1, {circle[i].x1(), 0.0, circle[i].y1()});
387 segment->setVertex(2, {circle[i].x2(), 0.0, circle[i].y2()});
388 }
389 }
390
377 void PrimitiveModel::generateBody(Model& model, bool deep) const 391 void PrimitiveModel::generateBody(Model& model, bool deep) const
378 { 392 {
379 switch (type) 393 switch (type)
380 { 394 {
381 case Cylinder: 395 case Cylinder:
415 model.emplace<LDCircularPrimitive>(Cylinder, segments, divisions, QMatrix4x4 {}); 429 model.emplace<LDCircularPrimitive>(Cylinder, segments, divisions, QMatrix4x4 {});
416 model.emplace<LDCircularPrimitive>(Circle, segments, divisions, QMatrix4x4 {}); 430 model.emplace<LDCircularPrimitive>(Circle, segments, divisions, QMatrix4x4 {});
417 model.emplace<LDCircularPrimitive>(Circle, segments, divisions, endCircleMatrix); 431 model.emplace<LDCircularPrimitive>(Circle, segments, divisions, endCircleMatrix);
418 } 432 }
419 } 433 }
434 return;
435
436 case Chord:
437 generateChord(model);
420 return; 438 return;
421 439
422 default: 440 default:
423 break; 441 break;
424 } 442 }
471 if (type == Cylinder or type == Cone) 489 if (type == Cylinder or type == Cone)
472 conditionalLineSegments.append(i); 490 conditionalLineSegments.append(i);
473 } 491 }
474 break; 492 break;
475 493
494 case Chord:
476 case Disc: 495 case Disc:
477 case DiscNegative: 496 case DiscNegative:
478 case Circle: 497 case Circle:
479 case Cylinder: 498 case Cylinder:
480 case CylinderClosed: 499 case CylinderClosed:
527 "Disc", 546 "Disc",
528 "Disc Negative", 547 "Disc Negative",
529 "Ring", 548 "Ring",
530 "Cone", 549 "Cone",
531 "Cylinder Closed", 550 "Cylinder Closed",
532 "Cylinder Open" 551 "Cylinder Open",
552 "Chord"
533 }; 553 };
534 554
535 if (type >= 0 and type < countof(names)) 555 if (type >= 0 and type < countof(names))
536 return names[type]; 556 return names[type];
537 else 557 else
555 } 575 }
556 576
557 // Compose some general information: prefix, fraction, root, ring number 577 // Compose some general information: prefix, fraction, root, ring number
558 QString prefix = (divisions == MediumResolution) ? "" : format ("%1\\", divisions); 578 QString prefix = (divisions == MediumResolution) ? "" : format ("%1\\", divisions);
559 QString frac = format ("%1-%2", numerator, denominator); 579 QString frac = format ("%1-%2", numerator, denominator);
560 static const char* roots[] = {"edge", "cyli", "disc", "ndis", "ring", "con"}; 580 static const char* roots[] = {"edge", "cyli", "disc", "ndis", "ring", "con", "chrd"};
561 QString root = roots[type]; 581 QString root = roots[type];
562 QString numberString = (type == Ring or type == Cone) ? format ("%1", ringNumber) : ""; 582 QString numberString = (type == Ring or type == Cone) ? format ("%1", ringNumber) : "";
563 583
564 // Truncate the root if necessary (7-16rin4.dat for instance). 584 // Truncate the root if necessary (7-16rin4.dat for instance).
565 // However, always keep the root at least 2 characters. 585 // However, always keep the root at least 2 characters.

mercurial