44 #include "misc/ringFinder.h" |
44 #include "misc/ringFinder.h" |
45 #include "glCompiler.h" |
45 #include "glCompiler.h" |
46 |
46 |
47 static const LDFixedCameraInfo g_FixedCameras[6] = |
47 static const LDFixedCameraInfo g_FixedCameras[6] = |
48 { |
48 { |
49 {{ 1, 0, 0 }, X, Z, false, false }, |
49 {{ 1, 0, 0 }, X, Z, false, false, false }, // top |
50 {{ 0, 0, 0 }, X, Y, false, true }, |
50 {{ 0, 0, 0 }, X, Y, false, true, false }, // front |
51 {{ 0, 1, 0 }, Z, Y, true, true }, |
51 {{ 0, 1, 0 }, Z, Y, true, true, false }, // left |
52 {{ -1, 0, 0 }, X, Z, false, true }, |
52 {{ -1, 0, 0 }, X, Z, false, true, true }, // bottom |
53 {{ 0, 0, 0 }, X, Y, true, true }, |
53 {{ 0, 0, 0 }, X, Y, true, true, true }, // back |
54 {{ 0, -1, 0 }, Z, Y, false, true }, |
54 {{ 0, -1, 0 }, Z, Y, false, true, true }, // right |
55 }; |
55 }; |
56 |
56 |
57 // Matrix templates for circle drawing. 2 is substituted with |
57 // Matrix templates for circle drawing. 2 is substituted with |
58 // the scale value, 1 is inverted to -1 if needed. |
58 // the scale value, 1 is inverted to -1 if needed. |
59 static const Matrix g_circleDrawMatrixTemplates[3] = |
59 static const Matrix g_circleDrawMatrixTemplates[3] = |
1019 m_addpick = (m_keymods & Qt::ControlModifier); |
1022 m_addpick = (m_keymods & Qt::ControlModifier); |
1020 |
1023 |
1021 if (m_totalmove < 10 || m_rangepick) |
1024 if (m_totalmove < 10 || m_rangepick) |
1022 pick (ev->x(), ev->y()); |
1025 pick (ev->x(), ev->y()); |
1023 } |
1026 } |
1024 } break; |
1027 break; |
|
1028 } |
1025 } |
1029 } |
1026 |
1030 |
1027 m_rangepick = false; |
1031 m_rangepick = false; |
1028 } |
1032 } |
1029 |
1033 |
1030 if (wasMid && editMode() != ESelectMode && m_drawedVerts.size() < 4 && m_totalmove < 10) |
1034 if (wasMid && editMode() != ESelectMode && m_drawedVerts.size() < 4 && m_totalmove < 10) |
1031 { |
1035 { |
1032 // Find the closest vertex to our cursor |
1036 // Find the closest vertex to our cursor |
1033 double mindist = 1024.0f; |
1037 double minimumDistance = 1024.0; |
1034 Vertex closest; |
1038 const Vertex* closest = null; |
1035 bool valid = false; |
1039 Vertex cursorPosition = coordconv2_3 (m_pos, false); |
1036 |
1040 QPoint cursorPosition2D (m_pos); |
1037 QPoint curspos = coordconv3_2 (m_hoverpos); |
1041 const Axis relZ = getRelativeZ(); |
|
1042 QList<Vertex> vertices; |
1038 |
1043 |
1039 for (auto it = document()->vertices().begin(); it != document()->vertices().end(); ++it) |
1044 for (auto it = document()->vertices().begin(); it != document()->vertices().end(); ++it) |
1040 { |
1045 vertices << it.key(); |
1041 QPoint pos2d = coordconv3_2 (it.key()); |
1046 |
1042 |
1047 // Sort the vertices in order of distance to camera |
1043 // Measure squared distance |
1048 std::sort (vertices.begin(), vertices.end(), [&](const Vertex& a, const Vertex& b) -> bool |
1044 const double dx = abs (pos2d.x() - curspos.x()), |
1049 { |
1045 dy = abs (pos2d.y() - curspos.y()), |
1050 if (g_FixedCameras[camera()].negatedDepth) |
1046 distsq = (dx * dx) + (dy * dy); |
1051 return a[relZ] > b[relZ]; |
1047 |
1052 |
1048 if (distsq >= 1024.0f) // 32.0f ** 2 |
1053 return a[relZ] < b[relZ]; |
1049 continue; // too far away |
1054 }); |
1050 |
1055 |
1051 if (distsq < mindist) |
1056 for (const Vertex& vrt : vertices) |
1052 { |
1057 { |
1053 mindist = distsq; |
1058 // If the vertex in 2d space is very close to the cursor then we use |
1054 closest = it.key(); |
1059 // it regardless of depth. |
1055 valid = true; |
1060 QPoint vect2d = coordconv3_2 (vrt) - cursorPosition2D; |
1056 |
1061 const double distance2DSquared = std::pow (vect2d.x(), 2) + std::pow (vect2d.y(), 2); |
1057 // If it's only 4 pixels away, I think we found our vertex now. |
1062 if (distance2DSquared < 16.0 * 16.0) |
1058 if (distsq <= 16.0f) // 4.0f ** 2 |
1063 { |
1059 break; |
1064 closest = &vrt; |
1060 } |
1065 break; |
1061 } |
1066 } |
1062 |
1067 |
1063 if (valid) |
1068 // Check if too far away from the cursor. |
1064 addDrawnVertex (closest); |
1069 if (distance2DSquared > 64.0 * 64.0) |
|
1070 continue; |
|
1071 |
|
1072 // Not very close to the cursor. Compare using true distance, |
|
1073 // including depth. |
|
1074 const double distanceSquared = (vrt - cursorPosition).lengthSquared(); |
|
1075 |
|
1076 if (distanceSquared < minimumDistance) |
|
1077 { |
|
1078 minimumDistance = distanceSquared; |
|
1079 closest = &vrt; |
|
1080 } |
|
1081 } |
|
1082 |
|
1083 if (closest != null) |
|
1084 addDrawnVertex (*closest); |
1065 } |
1085 } |
1066 |
1086 |
1067 if (wasRight && not m_drawedVerts.isEmpty()) |
1087 if (wasRight && not m_drawedVerts.isEmpty()) |
1068 { |
1088 { |
1069 // Remove the last vertex |
1089 // Remove the last vertex |