src/gl/partrenderer.cpp

changeset 206
654661eab7f3
parent 205
1a4342d80de7
child 215
34c6e7bc4ee1
equal deleted inserted replaced
205:1a4342d80de7 206:654661eab7f3
53 } 53 }
54 54
55 static QVector3D calcQVector3DFromQColor(const QColor& color) 55 static QVector3D calcQVector3DFromQColor(const QColor& color)
56 { 56 {
57 return { 57 return {
58 toFloat(color.redF()), 58 float_cast(color.redF()),
59 toFloat(color.greenF()), 59 float_cast(color.greenF()),
60 toFloat(color.blueF()), 60 float_cast(color.blueF()),
61 }; 61 };
62 } 62 }
63 63
64 void PartRenderer::initializeGL() 64 void PartRenderer::initializeGL()
65 { 65 {
302 * the camera, no value is returned. 302 * the camera, no value is returned.
303 * @param point 2D window co-ordinates to convert. 303 * @param point 2D window co-ordinates to convert.
304 * @param plane Plane to raycast against 304 * @param plane Plane to raycast against
305 * @return world co-ordinates, or no value if the point is behind the camera. 305 * @return world co-ordinates, or no value if the point is behind the camera.
306 */ 306 */
307 std::optional<glm::vec3> PartRenderer::screenToModelCoordinates(const QPoint& point, const Plane& plane) const 307 std::optional<glm::vec3> PartRenderer::screenToModelCoordinates(const QPointF& point, const Plane& plane) const
308 { 308 {
309 const Line line = this->cameraLine(point); 309 const Line line = this->cameraLine(point);
310 std::optional<glm::vec3> result; 310 std::optional<glm::vec3> result;
311 result = linePlaneIntersection(line, plane, 0.01f); 311 result = linePlaneIntersection(line, plane, 0.01f);
312 // If the point lies behind the camera, do not return a result. 312 // If the point lies behind the camera, do not return a result.
330 this->projectionMatrix, 330 this->projectionMatrix,
331 this->viewportVector); 331 this->viewportVector);
332 return toQPointF(glm::vec2{projected.x, this->height() - projected.y}); 332 return toQPointF(glm::vec2{projected.x, this->height() - projected.y});
333 } 333 }
334 334
335 Line<3> PartRenderer::cameraLine(const QPoint& point) const 335 Line<3> PartRenderer::cameraLine(const QPointF& point) const
336 { 336 {
337 const glm::vec3 p1 = this->unproject({point.x(), point.y(), 0}); 337 const glm::vec3 p1 = this->unproject({point.x(), point.y(), 0});
338 const glm::vec3 p2 = this->unproject({point.x(), point.y(), 1}); 338 const glm::vec3 p2 = this->unproject({point.x(), point.y(), 1});
339 return lineFromPoints(p1, p2); 339 return lineFromPoints(p1, p2);
340 } 340 }

mercurial