void VisualToolRotateZ::Draw() { if (!active_line) return; DrawAllFeatures(); float radius = (pos - org->pos).Len(); float oRadius = radius; if (radius < 50) radius = 50; // Set up the projection gl.SetOrigin(org->pos); gl.SetRotation(rotation_x, rotation_y, 0); gl.SetScale(scale); // Draw the circle gl.SetLineColour(colour[0]); gl.SetFillColour(colour[1], 0.3f); gl.DrawRing(Vector2D(0, 0), radius + 4, radius - 4); // Draw markers around circle int markers = 6; float markStart = -90.f / markers; float markEnd = markStart + (180.f / markers); for (int i = 0; i < markers; ++i) { float angle = i * (360.f / markers); gl.DrawRing(Vector2D(0, 0), radius+30, radius+12, 1.0, angle+markStart, angle+markEnd); } // Draw the baseline through the origin showing current rotation Vector2D angle_vec(Vector2D::FromAngle(angle * deg2rad)); gl.SetLineColour(colour[3], 1, 2); gl.DrawLine(angle_vec * -radius, angle_vec * radius); if (org->pos != pos) { Vector2D rotated_pos = Vector2D::FromAngle(angle * deg2rad - (pos - org->pos).Angle()) * oRadius; // Draw the line from origin to rotated position gl.DrawLine(Vector2D(), rotated_pos); // Draw the line under the text gl.DrawLine(rotated_pos - angle_vec * 20, rotated_pos + angle_vec * 20); } // Draw the fake features on the ring gl.SetLineColour(colour[0], 1.f, 1); gl.SetFillColour(colour[1], 0.3f); gl.DrawCircle(angle_vec * radius, 4); gl.DrawCircle(angle_vec * -radius, 4); // Clear the projection gl.ResetTransform(); // Draw line to mouse if it isn't over the origin feature if (mouse_pos && (mouse_pos - org->pos).SquareLen() > 100) { gl.SetLineColour(colour[0]); gl.DrawLine(org->pos, mouse_pos); } }
void VisualToolDrag::Draw() { DrawAllFeatures(); // Draw connecting lines for (feature_iterator cur = features.begin(); cur != features.end(); ++cur) { if (cur->type == DRAG_START) continue; feature_iterator p2 = cur; feature_iterator p1 = cur->parent; // Move end marker has an arrow; origin doesn't bool has_arrow = p2->type == DRAG_END; int arrow_len = has_arrow ? 10 : 0; // Don't show the connecting line if the features are very close Vector2D direction = p2->pos - p1->pos; if (direction.SquareLen() < (20 + arrow_len) * (20 + arrow_len)) continue; direction = direction.Unit(); // Get the start and end points of the line Vector2D start = p1->pos + direction * 10; Vector2D end = p2->pos - direction * (10 + arrow_len); if (has_arrow) { gl.SetLineColour(colour[3], 0.8f, 2); // Arrow line gl.DrawLine(start, end); // Arrow head Vector2D t_half_base_w = Vector2D(-direction.Y(), direction.X()) * 4; gl.DrawTriangle(end + direction * arrow_len, end + t_half_base_w, end - t_half_base_w); } // Draw dashed line else { gl.SetLineColour(colour[3], 0.5f, 2); gl.DrawDashedLine(start, end, 6); } } }
void VisualToolRotateXY::Draw() { if (!active_line) return; DrawAllFeatures(); // Transform grid gl.SetOrigin(org->pos); gl.SetRotation(angle_x, angle_y, angle_z); gl.SetShear(fax, fay); // Draw grid gl.SetLineColour(colour[0], 0.5f, 2); gl.SetModeLine(); float r = colour[0].Red() / 255.f; float g = colour[0].Green() / 255.f; float b = colour[0].Blue() / 255.f; // Number of lines on each side of each axis static const int radius = 15; // Total number of lines, including center axis line static const int line_count = radius * 2 + 1; // Distance between each line in pixels static const int spacing = 20; // Length of each grid line in pixels from axis to one end static const int half_line_length = spacing * (radius + 1); static const float fade_factor = 0.9f / radius; std::vector<float> colors(line_count * 8 * 4); for (int i = 0; i < line_count * 8; ++i) { colors[i * 4 + 0] = r; colors[i * 4 + 1] = g; colors[i * 4 + 2] = b; colors[i * 4 + 3] = (i + 3) % 4 > 1 ? 0 : (1.f - abs(i / 8 - radius) * fade_factor); } std::vector<float> points(line_count * 8 * 2); for (int i = 0; i < line_count; ++i) { int pos = spacing * (i - radius); points[i * 16 + 0] = pos; points[i * 16 + 1] = half_line_length; points[i * 16 + 2] = pos; points[i * 16 + 3] = 0; points[i * 16 + 4] = pos; points[i * 16 + 5] = 0; points[i * 16 + 6] = pos; points[i * 16 + 7] = -half_line_length; points[i * 16 + 8] = half_line_length; points[i * 16 + 9] = pos; points[i * 16 + 10] = 0; points[i * 16 + 11] = pos; points[i * 16 + 12] = 0; points[i * 16 + 13] = pos; points[i * 16 + 14] = -half_line_length; points[i * 16 + 15] = pos; } gl.DrawLines(2, points, 4, colors); // Draw vectors gl.SetLineColour(colour[3], 1.f, 2); float vectors[] = { 0.f, 0.f, 0.f, 50.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 50.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 50.f, }; gl.DrawLines(3, vectors, 6); // Draw arrow tops float arrows[] = { 60.f, 0.f, 0.f, 50.f, -3.f, -3.f, 50.f, 3.f, -3.f, 50.f, 3.f, 3.f, 50.f, -3.f, 3.f, 50.f, -3.f, -3.f, 0.f, 60.f, 0.f, -3.f, 50.f, -3.f, 3.f, 50.f, -3.f, 3.f, 50.f, 3.f, -3.f, 50.f, 3.f, -3.f, 50.f, -3.f, 0.f, 0.f, 60.f, -3.f, -3.f, 50.f, 3.f, -3.f, 50.f, 3.f, 3.f, 50.f, -3.f, 3.f, 50.f, -3.f, -3.f, 50.f, }; gl.DrawLines(3, arrows, 18); gl.ResetTransform(); }