implement returning trafo matrix

This commit is contained in:
Michael Kirsch 2019-04-06 16:15:38 +02:00 committed by Joseph Lenox
parent 287948a2f8
commit 91f12b5574
2 changed files with 18 additions and 2 deletions

View File

@ -1050,11 +1050,11 @@ ModelVolume::assign_unique_material()
ModelInstance::ModelInstance(ModelObject *object) ModelInstance::ModelInstance(ModelObject *object)
: rotation(0), x_rotation(0), y_rotation(0), scaling_factor(1),scaling_vector(Pointf3(1,1,1)), z_translation(0), object(object) : rotation(0), scaling_factor(1), object(object)
{} {}
ModelInstance::ModelInstance(ModelObject *object, const ModelInstance &other) ModelInstance::ModelInstance(ModelObject *object, const ModelInstance &other)
: rotation(other.rotation), x_rotation(other.x_rotation), y_rotation(other.y_rotation), scaling_factor(other.scaling_factor), scaling_vector(other.scaling_vector), offset(other.offset), z_translation(other.z_translation), object(object) : rotation(other.rotation), scaling_factor(other.scaling_factor), offset(other.offset), object(object)
{} {}
ModelInstance& ModelInstance::operator= (ModelInstance other) ModelInstance& ModelInstance::operator= (ModelInstance other)
@ -1083,6 +1083,18 @@ ModelInstance::transform_mesh(TriangleMesh* mesh, bool dont_translate) const
} }
TransformationMatrix ModelInstance::get_trafo_matrix(bool dont_translate) const
{
TransformationMatrix trafo = TransformationMatrix();
trafo.scale(this->scaling_factor);
trafo.rotate(this->rotation, Axis::Z);
if(!dont_translate)
{
trafo.translate(this->offset.x, this->offset.y, 0);
}
return trafo;
}
BoundingBoxf3 ModelInstance::transform_mesh_bounding_box(const TriangleMesh* mesh, bool dont_translate) const BoundingBoxf3 ModelInstance::transform_mesh_bounding_box(const TriangleMesh* mesh, bool dont_translate) const
{ {
// rotate around mesh origin // rotate around mesh origin

View File

@ -543,6 +543,10 @@ class ModelInstance
/// \param dont_translate bool whether to translate the mesh or not /// \param dont_translate bool whether to translate the mesh or not
void transform_mesh(TriangleMesh* mesh, bool dont_translate = false) const; void transform_mesh(TriangleMesh* mesh, bool dont_translate = false) const;
/// Returns the TransformationMatrix defined by the instance's Transform an external TriangleMesh to the returned TriangleMesh object
/// \param dont_translate bool whether to translate the mesh or not
TransformationMatrix get_trafo_matrix(bool dont_translate = false) const;
/// Calculate a bounding box of a transformed mesh. To be called on an external mesh. /// Calculate a bounding box of a transformed mesh. To be called on an external mesh.
/// \param mesh TriangleMesh* pointer to the the mesh /// \param mesh TriangleMesh* pointer to the the mesh
/// \param dont_translate bool whether to translate the bounding box or not /// \param dont_translate bool whether to translate the bounding box or not