add function to center around bb

This commit is contained in:
Michael Kirsch 2019-06-29 00:29:54 +02:00 committed by Joseph Lenox
parent f8c6c630ff
commit d7c1f8bad8
2 changed files with 26 additions and 0 deletions

View File

@ -724,6 +724,13 @@ ModelObject::center_around_origin()
} }
} }
TransformationMatrix
ModelObject::get_trafo_to_center() const
{
BoundingBoxf3 raw_bb = this->raw_bounding_box();
return TransformationMatrix::mat_translation(raw_bb.center().negative());
}
void void
ModelObject::translate(const Vectorf3 &vector) ModelObject::translate(const Vectorf3 &vector)
{ {
@ -782,6 +789,17 @@ ModelObject::rotate(double angle, const Axis &axis)
this->invalidate_bounding_box(); this->invalidate_bounding_box();
} }
void
ModelObject::rotate(double angle, const Vectorf3 &axis)
{
if (angle == 0) return;
TransformationMatrix trafo = TransformationMatrix::mat_rotation(angle, axis);
this->apply_transformation(trafo);
this->origin_translation = Pointf3(0,0,0);
this->invalidate_bounding_box();
}
void void
ModelObject::rotate(const Vectorf3 &origin, const Vectorf3 &target) ModelObject::rotate(const Vectorf3 &origin, const Vectorf3 &target)
{ {

View File

@ -358,6 +358,9 @@ class ModelObject
/// Center the current ModelObject to origin by translating the ModelVolumes /// Center the current ModelObject to origin by translating the ModelVolumes
void center_around_origin(); void center_around_origin();
/// Get the matrix, that, when applied, centers the bounding box in all 3 coordinate directions
TransformationMatrix get_trafo_to_center() const;
/// Translate the current ModelObject by translating ModelVolumes with (x,y,z) units. /// Translate the current ModelObject by translating ModelVolumes with (x,y,z) units.
/// This function calls translate(coordf_t x, coordf_t y, coordf_t z) to translate every TriangleMesh in each ModelVolume. /// This function calls translate(coordf_t x, coordf_t y, coordf_t z) to translate every TriangleMesh in each ModelVolume.
/// \param vector Vectorf3 the translation vector /// \param vector Vectorf3 the translation vector
@ -388,6 +391,11 @@ class ModelObject
/// \param axis Axis the axis to be rotated around /// \param axis Axis the axis to be rotated around
void rotate(double angle, const Axis &axis); void rotate(double angle, const Axis &axis);
/// Rotate the current ModelObject by rotating ModelVolumes.
/// \param angle double the angle in radians
/// \param axis Axis the axis to be rotated around
void rotate(double angle, const Vectorf3 &axis);
/// Rotate the current ModelObject by rotating ModelVolumes to align the given vectors /// Rotate the current ModelObject by rotating ModelVolumes to align the given vectors
/// \param origin Vectorf3 /// \param origin Vectorf3
/// \param target Vectorf3 /// \param target Vectorf3