src/ui/canvas.cpp

changeset 164
8305e2f968fb
parent 157
869fe95c4e5e
child 165
f6eab2bd46c2
--- a/src/ui/canvas.cpp	Sat Mar 05 13:32:58 2022 +0200
+++ b/src/ui/canvas.cpp	Sat Mar 05 13:38:22 2022 +0200
@@ -228,19 +228,23 @@
 }
 
 /**
+ * @brief Draws a polyline to where the specified vector of 3D points would appear on the screen.
+ * @param painter Painter to use to draw with
+ * @param points 3D points to render
+ */
+void Canvas::drawWorldPolyline(QPainter *painter, const std::vector<glm::vec3> &points)
+{
+	painter->drawPolyline(QPolygonF{this->convertWorldPointsToScreenPoints(points)});
+}
+
+/**
  * @brief Draws a polygon to where the specified vector of 3D points would appear on the screen.
  * @param painter Painter to use to draw with
  * @param points 3D points to render
  */
 void Canvas::drawWorldPolygon(QPainter* painter, const std::vector<glm::vec3> &points)
 {
-	QVector<QPointF> points2d;
-	points2d.reserve(points.size());
-	for (const glm::vec3& point : points)
-	{
-		points2d.push_back(this->modelToScreenCoordinates(point));
-	}
-	painter->drawPolygon(QPolygonF{points2d});
+	painter->drawPolygon(QPolygonF{this->convertWorldPointsToScreenPoints(points)});
 }
 
 /**
@@ -329,6 +333,17 @@
 	return std::abs(dot) < threshold;
 }
 
+QVector<QPointF> Canvas::convertWorldPointsToScreenPoints(const std::vector<glm::vec3> &worldPoints)
+{
+	QVector<QPointF> points2d;
+	points2d.reserve(worldPoints.size());
+	for (const glm::vec3& point : worldPoints)
+	{
+		points2d.push_back(this->modelToScreenCoordinates(point));
+	}
+	return points2d;
+}
+
 /**
  * @brief Clears the selection.
  */

mercurial