src/ui/canvas.cpp

changeset 164
8305e2f968fb
parent 157
869fe95c4e5e
child 165
f6eab2bd46c2
equal deleted inserted replaced
163:36ea1a8aee33 164:8305e2f968fb
226 } 226 }
227 } 227 }
228 } 228 }
229 229
230 /** 230 /**
231 * @brief Draws a polyline to where the specified vector of 3D points would appear on the screen.
232 * @param painter Painter to use to draw with
233 * @param points 3D points to render
234 */
235 void Canvas::drawWorldPolyline(QPainter *painter, const std::vector<glm::vec3> &points)
236 {
237 painter->drawPolyline(QPolygonF{this->convertWorldPointsToScreenPoints(points)});
238 }
239
240 /**
231 * @brief Draws a polygon to where the specified vector of 3D points would appear on the screen. 241 * @brief Draws a polygon to where the specified vector of 3D points would appear on the screen.
232 * @param painter Painter to use to draw with 242 * @param painter Painter to use to draw with
233 * @param points 3D points to render 243 * @param points 3D points to render
234 */ 244 */
235 void Canvas::drawWorldPolygon(QPainter* painter, const std::vector<glm::vec3> &points) 245 void Canvas::drawWorldPolygon(QPainter* painter, const std::vector<glm::vec3> &points)
236 { 246 {
237 QVector<QPointF> points2d; 247 painter->drawPolygon(QPolygonF{this->convertWorldPointsToScreenPoints(points)});
238 points2d.reserve(points.size());
239 for (const glm::vec3& point : points)
240 {
241 points2d.push_back(this->modelToScreenCoordinates(point));
242 }
243 painter->drawPolygon(QPolygonF{points2d});
244 } 248 }
245 249
246 /** 250 /**
247 * @brief Gets the current position of the cursor in the model 251 * @brief Gets the current position of the cursor in the model
248 * @return 3D vector 252 * @return 3D vector
327 // and the grid is perpendicular to the screen. 331 // and the grid is perpendicular to the screen.
328 const float dot = glm::dot(glm::normalize(this->gridPlane.normal), glm::normalize(cameraDirection)); 332 const float dot = glm::dot(glm::normalize(this->gridPlane.normal), glm::normalize(cameraDirection));
329 return std::abs(dot) < threshold; 333 return std::abs(dot) < threshold;
330 } 334 }
331 335
336 QVector<QPointF> Canvas::convertWorldPointsToScreenPoints(const std::vector<glm::vec3> &worldPoints)
337 {
338 QVector<QPointF> points2d;
339 points2d.reserve(worldPoints.size());
340 for (const glm::vec3& point : worldPoints)
341 {
342 points2d.push_back(this->modelToScreenCoordinates(point));
343 }
344 return points2d;
345 }
346
332 /** 347 /**
333 * @brief Clears the selection. 348 * @brief Clears the selection.
334 */ 349 */
335 void Canvas::clearSelection() 350 void Canvas::clearSelection()
336 { 351 {

mercurial