mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-12 21:29:00 +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
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -77,6 +77,9 @@ public:
|
||||
/// 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();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user