src/gl/partrenderer.cpp

changeset 59
60650929dc82
parent 58
b7841cd31fb7
child 60
0f221121849b
--- a/src/gl/partrenderer.cpp	Thu Feb 27 12:23:42 2020 +0200
+++ b/src/gl/partrenderer.cpp	Thu Feb 27 14:38:48 2020 +0200
@@ -300,11 +300,11 @@
 	auto p2 = this->unproject({point.x(), point.y(), 1});
 	geom::Line line = geom::lineFromPoints(p1, p2);
 	std::optional<glm::vec3> result;
-	// If the dot product between the line direction and plane normal is negative, the point
-	// of intersection lies behind the camera.
-	if (glm::dot(line.direction, plane.normal) > 0)
+	result = geom::linePlaneIntersection(line, plane, 0.01f);
+	// If the point lies behind the camera, do not return a result.
+	if (result.has_value() and glm::dot(line.direction, *result - p1) < 0)
 	{
-		result = geom::linePlaneIntersection(line, plane, 0.01);
+		result.reset();
 	}
 	return result;
 }

mercurial