1st installment of ModelInstance 3D rotation components

This commit is contained in:
Enrico Turri
2018-09-20 15:00:40 +02:00
parent f1e0dc2dd7
commit 07274589a3
20 changed files with 533 additions and 12 deletions

View File

@@ -1054,6 +1054,29 @@ size_t ModelVolume::split(unsigned int max_extruders)
return idx;
}
#if ENABLE_MODELINSTANCE_3D_ROTATION
void ModelInstance::set_rotation(const Vec3d& rotation)
{
set_rotation(X, rotation(0));
set_rotation(Y, rotation(1));
set_rotation(Z, rotation(2));
}
void ModelInstance::set_rotation(Axis axis, double rotation)
{
static const double TWO_PI = 2.0 * (double)PI;
while (rotation < 0.0)
{
rotation += TWO_PI;
}
while (TWO_PI < rotation)
{
rotation -= TWO_PI;
}
m_rotation(axis) = rotation;
}
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
void ModelInstance::transform_mesh(TriangleMesh* mesh, bool dont_translate) const
{
mesh->transform(world_matrix(dont_translate).cast<float>());
@@ -1098,7 +1121,12 @@ Vec3d ModelInstance::transform_vector(const Vec3d& v, bool dont_translate) const
void ModelInstance::transform_polygon(Polygon* polygon) const
{
#if ENABLE_MODELINSTANCE_3D_ROTATION
// CHECK_ME -> Is the following correct or it should take in account all three rotations ?
polygon->rotate(this->m_rotation(2)); // rotate around polygon origin
#else
polygon->rotate(this->rotation); // rotate around polygon origin
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
polygon->scale(this->scaling_factor); // scale around polygon origin
}
@@ -1114,7 +1142,15 @@ Transform3d ModelInstance::world_matrix(bool dont_translate, bool dont_rotate, b
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
if (!dont_rotate)
#if ENABLE_MODELINSTANCE_3D_ROTATION
{
m.rotate(Eigen::AngleAxisd(m_rotation(2), Vec3d::UnitZ()));
m.rotate(Eigen::AngleAxisd(m_rotation(1), Vec3d::UnitY()));
m.rotate(Eigen::AngleAxisd(m_rotation(0), Vec3d::UnitX()));
}
#else
m.rotate(Eigen::AngleAxisd(rotation, Vec3d::UnitZ()));
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
if (!dont_scale)
m.scale(scaling_factor);