Skip to content

Commit

Permalink
rewrite transform_bb
Browse files Browse the repository at this point in the history
  • Loading branch information
Oekn5w authored and lordofhyphens committed Dec 2, 2019
1 parent 852fb80 commit 2199d7f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
35 changes: 16 additions & 19 deletions xs/src/libslic3r/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
9 changes: 9 additions & 0 deletions xs/src/libslic3r/TransformationMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions xs/src/libslic3r/TransformationMatrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 2199d7f

Please sign in to comment.