src/gl/partrenderer.cpp

changeset 201
5d201ee4a9c3
parent 200
ca23936b455b
child 205
1a4342d80de7
equal deleted inserted replaced
200:ca23936b455b 201:5d201ee4a9c3
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 geom::Plane& plane) const 307 std::optional<glm::vec3> PartRenderer::screenToModelCoordinates(const QPoint& point, const Plane& plane) const
308 { 308 {
309 const geom::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 = geom::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.
313 if (result.has_value() and glm::dot(line.direction, *result - line.anchor) < 0) 313 if (result.has_value() and glm::dot(line.direction, *result - line.anchor) < 0)
314 { 314 {
315 result.reset(); 315 result.reset();
316 } 316 }
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 geom::Line<3> PartRenderer::cameraLine(const QPoint& point) const 335 Line<3> PartRenderer::cameraLine(const QPoint& 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 geom::lineFromPoints(p1, p2); 339 return lineFromPoints(p1, p2);
340 } 340 }
341 341
342 /** 342 /**
343 * @brief Unprojects the specified window coordinates to model coordinates 343 * @brief Unprojects the specified window coordinates to model coordinates
344 * @param win Window coordinates to project. Z-coordinate indicates depth 344 * @param win Window coordinates to project. Z-coordinate indicates depth

mercurial