src/layers/edittools.cpp

changeset 323
3c09c937848c
parent 322
a39f454a3d7f
child 324
d9bab5d22c98
equal deleted inserted replaced
322:a39f454a3d7f 323:3c09c937848c
266 { 266 {
267 if (this->inputPolygon.bufferSize() < 3) { 267 if (this->inputPolygon.bufferSize() < 3) {
268 return {}; 268 return {};
269 } 269 }
270 else { 270 else {
271 const glm::vec3 cameravec = glm::normalize(this->renderer->cameraVector(this->localPosition));
272 const glm::vec3 heightvec = glm::normalize(glm::vec3{gridMatrix[2]});
273 const glm::vec3 normal = glm::cross(glm::cross(cameravec, heightvec), heightvec);
271 const Plane plane{ 274 const Plane plane{
272 .normal = glm::normalize(this->renderer->cameraVector(this->localPosition)), 275 .normal = normal,
273 .anchor = this->inputPolygon[0], 276 .anchor = this->inputPolygon[0],
274 }; 277 };
275 const opt<glm::vec3> p = this->renderer->screenToModelCoordinates(this->localPosition, plane); 278 const opt<glm::vec3> p = this->renderer->screenToModelCoordinates(this->localPosition, plane);
276 if (p.has_value()) { 279 if (p.has_value()) {
277 const glm::vec3 heightvec = glm::normalize(glm::vec3{gridMatrix[2]});
278 return std::round(glm::dot(*p - this->inputPolygon[0], heightvec)); 280 return std::round(glm::dot(*p - this->inputPolygon[0], heightvec));
279 } 281 }
280 else { 282 else {
281 return {}; 283 return {};
282 } 284 }

mercurial