Fix normal of the plane used to find cylinder height

Sun, 03 Jul 2022 21:47:44 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Sun, 03 Jul 2022 21:47:44 +0300
changeset 323
3c09c937848c
parent 322
a39f454a3d7f
child 324
d9bab5d22c98

Fix normal of the plane used to find cylinder height

src/layers/edittools.cpp file | annotate | diff | comparison | revisions
--- a/src/layers/edittools.cpp	Sun Jul 03 20:18:34 2022 +0300
+++ b/src/layers/edittools.cpp	Sun Jul 03 21:47:44 2022 +0300
@@ -268,13 +268,15 @@
 		return {};
 	}
 	else {
+		const glm::vec3 cameravec = glm::normalize(this->renderer->cameraVector(this->localPosition));
+		const glm::vec3 heightvec = glm::normalize(glm::vec3{gridMatrix[2]});
+		const glm::vec3 normal = glm::cross(glm::cross(cameravec, heightvec), heightvec);
 		const Plane plane{
-			.normal = glm::normalize(this->renderer->cameraVector(this->localPosition)),
+			.normal = normal,
 			.anchor = this->inputPolygon[0],
 		};
 		const opt<glm::vec3> p = this->renderer->screenToModelCoordinates(this->localPosition, plane);
 		if (p.has_value()) {
-			const glm::vec3 heightvec = glm::normalize(glm::vec3{gridMatrix[2]});
 			return std::round(glm::dot(*p - this->inputPolygon[0], heightvec));
 		}
 		else {

mercurial