mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-14 15:05:57 +08:00
rewrite transform_bb
This commit is contained in:
parent
852fb80555
commit
2199d7f99c
@ -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
|
BoundingBoxf3 ModelInstance::transform_bounding_box(const BoundingBoxf3 &bbox, bool dont_translate) const
|
||||||
{
|
{
|
||||||
TransformationMatrix
|
TransformationMatrix trafo = this->get_trafo_matrix(dont_translate);
|
||||||
Pointf3 pts[4] = {
|
Pointf3 Poi_min = bbox.min;
|
||||||
bbox.min,
|
Pointf3 Poi_max = bbox.max;
|
||||||
bbox.max,
|
|
||||||
Pointf3(bbox.min.x, bbox.max.y, bbox.min.z),
|
// all 8 corner points needed because the transformation could be anything
|
||||||
Pointf3(bbox.max.x, bbox.min.y, bbox.max.z)
|
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;
|
BoundingBoxf3 out;
|
||||||
for (int i = 0; i < 4; ++ i) {
|
for (int i = 0; i < 8; ++ i) {
|
||||||
Pointf3 &v = pts[i];
|
out.merge(trafo.transform(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);
|
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
@ -155,6 +155,15 @@ TransformationMatrix TransformationMatrix::multiplyRight(const TransformationMat
|
|||||||
return multiply(*this, right);
|
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 TransformationMatrix::multiply(const TransformationMatrix &left, const TransformationMatrix &right)
|
||||||
{
|
{
|
||||||
TransformationMatrix trafo;
|
TransformationMatrix trafo;
|
||||||
|
@ -77,6 +77,9 @@ public:
|
|||||||
/// multiplies the parameter-matrix from the right (out=this*right)
|
/// multiplies the parameter-matrix from the right (out=this*right)
|
||||||
TransformationMatrix multiplyRight(const TransformationMatrix &right) const;
|
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.
|
/// generates an eye matrix.
|
||||||
static TransformationMatrix mat_eye();
|
static TransformationMatrix mat_eye();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user