diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index 97f695e6aa..5372292568 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -1305,27 +1305,24 @@ TransformationMatrix ModelInstance::get_trafo_matrix(bool dont_translate) const BoundingBoxf3 ModelInstance::transform_bounding_box(const BoundingBoxf3 &bbox, bool dont_translate) const { - TransformationMatrix - Pointf3 pts[4] = { - bbox.min, - bbox.max, - Pointf3(bbox.min.x, bbox.max.y, bbox.min.z), - Pointf3(bbox.max.x, bbox.min.y, bbox.max.z) + TransformationMatrix trafo = this->get_trafo_matrix(dont_translate); + Pointf3 Poi_min = bbox.min; + Pointf3 Poi_max = bbox.max; + + // all 8 corner points needed because the transformation could be anything + Pointf3 pts[8] = { + Pointf3(Poi_min.x, Poi_min.y, Poi_min.z), + Pointf3(Poi_min.x, Poi_min.y, Poi_max.z), + Pointf3(Poi_min.x, Poi_max.y, Poi_min.z), + Pointf3(Poi_min.x, Poi_max.y, Poi_max.z), + Pointf3(Poi_max.x, Poi_min.y, Poi_min.z), + Pointf3(Poi_max.x, Poi_min.y, Poi_max.z), + Pointf3(Poi_max.x, Poi_max.y, Poi_min.z), + Pointf3(Poi_max.x, Poi_max.y, Poi_max.z) }; BoundingBoxf3 out; - for (int i = 0; i < 4; ++ i) { - Pointf3 &v = pts[i]; - double xold = v.x; - double yold = v.y; - // Rotation around z axis. - v.x = float(c * xold - s * yold); - v.y = float(s * xold + c * yold); - v.scale(this->scaling_factor); - if (!dont_translate) { - v.x += this->offset.x; - v.y += this->offset.y; - } - out.merge(v); + for (int i = 0; i < 8; ++ i) { + out.merge(trafo.transform(pts[i])); } return out; } diff --git a/xs/src/libslic3r/TransformationMatrix.cpp b/xs/src/libslic3r/TransformationMatrix.cpp index cca9b3fecd..b4aa5f6038 100644 --- a/xs/src/libslic3r/TransformationMatrix.cpp +++ b/xs/src/libslic3r/TransformationMatrix.cpp @@ -155,6 +155,15 @@ TransformationMatrix TransformationMatrix::multiplyRight(const TransformationMat return multiply(*this, right); } +Pointf3 TransformationMatrix::transform(const Pointf3 &point, coordf_t w) const +{ + Pointf3 out; + out.x = this->m00 * point.x + this->m01 * point.y + this->m02 * point.z + this->m03 * w; + out.y = this->m10 * point.x + this->m11 * point.y + this->m12 * point.z + this->m13 * w; + out.z = this->m20 * point.x + this->m21 * point.y + this->m22 * point.z + this->m23 * w; + return out; +} + TransformationMatrix TransformationMatrix::multiply(const TransformationMatrix &left, const TransformationMatrix &right) { TransformationMatrix trafo; diff --git a/xs/src/libslic3r/TransformationMatrix.hpp b/xs/src/libslic3r/TransformationMatrix.hpp index a6b6bfa76f..ef0e3422a2 100644 --- a/xs/src/libslic3r/TransformationMatrix.hpp +++ b/xs/src/libslic3r/TransformationMatrix.hpp @@ -77,6 +77,9 @@ class TransformationMatrix /// multiplies the parameter-matrix from the right (out=this*right) TransformationMatrix multiplyRight(const TransformationMatrix &right) const; + /// multiplies the Point from the right (out=this*right) + Pointf3 transform(const Pointf3 &point, coordf_t w = 1.0) const; + /// generates an eye matrix. static TransformationMatrix mat_eye();