298 { |
298 { |
299 auto p1 = this->unproject({point.x(), point.y(), 0}); |
299 auto p1 = this->unproject({point.x(), point.y(), 0}); |
300 auto p2 = this->unproject({point.x(), point.y(), 1}); |
300 auto p2 = this->unproject({point.x(), point.y(), 1}); |
301 geom::Line line = geom::lineFromPoints(p1, p2); |
301 geom::Line line = geom::lineFromPoints(p1, p2); |
302 std::optional<glm::vec3> result; |
302 std::optional<glm::vec3> result; |
303 // If the dot product between the line direction and plane normal is negative, the point |
303 result = geom::linePlaneIntersection(line, plane, 0.01f); |
304 // of intersection lies behind the camera. |
304 // If the point lies behind the camera, do not return a result. |
305 if (glm::dot(line.direction, plane.normal) > 0) |
305 if (result.has_value() and glm::dot(line.direction, *result - p1) < 0) |
306 { |
306 { |
307 result = geom::linePlaneIntersection(line, plane, 0.01); |
307 result.reset(); |
308 } |
308 } |
309 return result; |
309 return result; |
310 } |
310 } |
311 |
311 |
312 /** |
312 /** |