src/gldraw.cpp

changeset 501
8f314f3f5054
parent 500
cad8cdc42a64
child 503
bebe09014dd6
equal deleted inserted replaced
500:cad8cdc42a64 501:8f314f3f5054
1322 overlaysFromObjects(); 1322 overlaysFromObjects();
1323 } 1323 }
1324 1324
1325 // ============================================================================= 1325 // =============================================================================
1326 // ----------------------------------------------------------------------------- 1326 // -----------------------------------------------------------------------------
1327 matrix GLRenderer::getCircleDrawMatrix (double scale)
1328 { matrix transform = g_circleDrawTransforms[camera() % 3];
1329
1330 for (int i = 0; i < 9; ++i)
1331 { if (transform[i] == 2)
1332 transform[i] = scale;
1333 elif (transform[i] == 1 && camera() >= 3)
1334 transform[i] = -1;
1335 }
1336
1337 return transform;
1338 }
1339
1340 // =============================================================================
1341 // -----------------------------------------------------------------------------
1327 void GLRenderer::endDraw (bool accept) 1342 void GLRenderer::endDraw (bool accept)
1328 { (void) accept; 1343 { (void) accept;
1329 1344
1330 // Clean the selection and create the object 1345 // Clean the selection and create the object
1331 List<vertex>& verts = m_drawedVerts; 1346 List<vertex>& verts = m_drawedVerts;
1381 1396
1382 case CircleMode: 1397 case CircleMode:
1383 { const int segs = lores, divs = lores; // TODO: make customizable 1398 { const int segs = lores, divs = lores; // TODO: make customizable
1384 double dist0 = circleDrawDist (0), 1399 double dist0 = circleDrawDist (0),
1385 dist1 = circleDrawDist (1); 1400 dist1 = circleDrawDist (1);
1386 enum {Circle, Ring, Disc, CustomRing} type = Ring; 1401 LDFile* refFile = null;
1387 int num = 0; 1402 matrix transform;
1388 double scale; 1403 bool circleOrDisc = false;
1389 1404
1390 if (dist1 < dist0) 1405 if (dist1 < dist0)
1391 std::swap<double> (dist0, dist1); 1406 std::swap<double> (dist0, dist1);
1392 1407
1393 if (dist0 == dist1) 1408 if (dist0 == dist1)
1394 { scale = dist0; 1409 { refFile = getFile ("4-4edge.dat");
1395 type = Circle; 1410 transform = getCircleDrawMatrix (dist0);
1396 } elif (dist0 == 0 || dist1 == 0) 1411 circleOrDisc = true;
1397 { scale = (dist0 != 0) ? dist0 : dist1;
1398 type = Disc;
1399 } else
1400 { /* scale = |r1 - r0|
1401 number = r0 / scale */
1402 scale = abs (dist1 - dist0);
1403 assert (scale != 0);
1404
1405 if (!isInteger (dist0) || !isInteger (scale) || (((int) dist0) % ((int) scale)) != 0)
1406 type = CustomRing; // Non-integer ring number - make a custom ring
1407 else
1408 num = ((int) dist0) / ((int) scale);
1409 } 1412 }
1410 1413 elif (dist0 == 0 || dist1 == 0)
1411 if (type == CustomRing) 1414 { refFile = getFile ("4-4disc.dat");
1415 transform = getCircleDrawMatrix ((dist0 != 0) ? dist0 : dist1);
1416 circleOrDisc = true;
1417 }
1418 elif (g_RingFinder (dist0, dist1) /* && g_RingFinder.solution().size() <= 3 */)
1419 { for (const RingFinder::SolutionComponent& cmp : g_RingFinder.solution())
1420 { if ((refFile = getFile (radialFileName (::Ring, lores, lores, cmp.num))) == null)
1421 { refFile = generatePrimitive (::Ring, lores, lores, cmp.num);
1422 refFile->setImplicit (false);
1423 }
1424
1425 LDSubfile* ref = new LDSubfile;
1426 ref->setFileInfo (refFile);
1427 ref->setTransform (getCircleDrawMatrix (cmp.scale));
1428 ref->setPosition (m_drawedVerts[0]);
1429 ref->setColor (maincolor);
1430 objs << ref;
1431 }
1432 }
1433 else
1412 { // Last resort: draw the ring with quads 1434 { // Last resort: draw the ring with quads
1413 List<QLineF> c0, c1; 1435 List<QLineF> c0, c1;
1414 1436
1415 makeCircle (segs, divs, dist0, c0); 1437 makeCircle (segs, divs, dist0, c0);
1416 makeCircle (segs, divs, dist1, c1); 1438 makeCircle (segs, divs, dist1, c1);
1417 1439
1418 for (int i = 0; i < 16; ++i) 1440 for (int i = 0; i < 16; ++i)
1419 { 1441 {
1420 } 1442 }
1421 } 1443 }
1422 else 1444
1423 { matrix transform = g_circleDrawTransforms[camera() % 3]; 1445 if (circleOrDisc)
1424 LDFile* refFile = null; 1446 { LDSubfile* ref = new LDSubfile;
1425 1447 ref->setFileInfo (refFile);
1426 for (int i = 0; i < 9; ++i) 1448 ref->setTransform (transform);
1427 { if (transform[i] == 2) 1449 ref->setPosition (m_drawedVerts[0]);
1428 transform[i] = scale; 1450 ref->setColor (maincolor);
1429 elif (transform[i] == 1 && camera() >= 3) 1451 objs << ref;
1430 transform[i] = -1;
1431 }
1432
1433 switch (type)
1434 { case Circle:
1435 { refFile = getFile ("4-4edge.dat");
1436 } break;
1437
1438 case Disc:
1439 { refFile = getFile ("4-4disc.dat");
1440 } break;
1441
1442 case Ring:
1443 { if ((refFile = getFile (radialFileName (::Ring, lores, lores, num))) == null)
1444 { refFile = generatePrimitive (::Ring, lores, lores, num);
1445 refFile->setImplicit (false);
1446 }
1447 } break;
1448 }
1449
1450 if (refFile)
1451 { LDSubfile* ref = new LDSubfile;
1452 ref->setFileInfo (refFile);
1453 ref->setTransform (transform);
1454 ref->setPosition (m_drawedVerts[0]);
1455 ref->setColor (maincolor);
1456 objs << ref;
1457 }
1458 } 1452 }
1459 } break; 1453 } break;
1460 1454
1461 case Select: 1455 case Select:
1462 { assert (false); 1456 { assert (false);

mercurial