Unify place of transformation

This commit is contained in:
Filip Sykala 2022-02-21 16:12:26 +01:00
parent 7f73a0e73d
commit 5ffa19b529
4 changed files with 26 additions and 25 deletions

View File

@ -639,6 +639,19 @@ ExPolygons Emboss::text2shapes(FontFile & font,
return Private::dilate_to_unique_points(result);
}
void Emboss::apply_transformation(const FontProp &font_prop,
Transform3d &transformation)
{
if (font_prop.angle.has_value()) {
double angle_z = *font_prop.angle;
transformation *= Eigen::AngleAxisd(angle_z, Vec3d::UnitZ());
}
if (font_prop.distance.has_value()) {
Vec3d translate = Vec3d::UnitZ() * (*font_prop.distance);
transformation.translate(translate);
}
}
bool Emboss::is_italic(FontFile &font) {
std::optional<stbtt_fontinfo> font_info_opt =
Private::load_font_info(font);

View File

@ -134,6 +134,15 @@ public:
const char * text,
const FontProp &font_prop);
/// <summary>
/// Use data from font property to modify transformation
/// </summary>
/// <param name="font_prop">Z-move as surface distance(FontProp::distance)
/// Z-rotation as angle to Y axis(FontProp::angle)</param>
/// <param name="transformation"></param>
static void apply_transformation(const FontProp &font_prop,
Transform3d &transformation);
/// <summary>
/// Read information from naming table of font file
/// search for italic (or oblique), bold italic (or bold oblique)

View File

@ -274,21 +274,11 @@ bool GLGizmoEmboss::on_mouse_for_translate(const wxMouseEvent &mouse_event)
// hide common dragging of object
m_parent.toggle_model_objects_visibility(false, m_volume->get_object(), gl_volume->instance_idx(), m_volume);
// Show temporary position
// TODO: store z-rotation and aply after transformation matrix
// Calculate temporary position
Transform3d object_trmat = m_raycast_manager.get_transformation(hit->tr_key);
Transform3d trmat = Emboss::create_transformation_onto_surface(hit->position, hit->normal);
const FontProp& font_prop = m_volume->text_configuration->font_item.prop;
if (font_prop.angle.has_value()) {
double angle_z = *font_prop.angle;
trmat *= Eigen::AngleAxisd(angle_z, Vec3d::UnitZ());
}
if (font_prop.distance.has_value()) {
Vec3d translate = Vec3d::UnitZ() * (*font_prop.distance);
trmat.translate(translate);
}
Emboss::apply_transformation(font_prop, trmat);
m_temp_transformation = object_trmat * trmat;
} else if (mouse_event.LeftUp()) {
// TODO: Disable apply common transformation after draggig

View File

@ -140,24 +140,13 @@ void EmbossCreateJob::process(Ctl &ctl) {
} else {
//m_transformation = Emboss::create_transformation_onto_surface(hit->position, hit->normal);
assert(m_input->hit_vol_tr.has_value());
if (m_input->hit_vol_tr.has_value()) {
Transform3d object_trmat = m_input->raycast_manager->get_transformation(hit->tr_key);
const FontProp &font_prop = m_input->text_configuration.font_item.prop;
if (font_prop.angle.has_value()) {
double angle_z = *font_prop.angle;
object_trmat *= Eigen::AngleAxisd(angle_z, Vec3d::UnitZ());
}
if (font_prop.distance.has_value()) {
Vec3d translate = Vec3d::UnitZ() * (*font_prop.distance);
object_trmat.translate(translate);
}
Transform3d surface_trmat = Emboss::create_transformation_onto_surface(hit->position, hit->normal);
Emboss::apply_transformation(font_prop, surface_trmat);
m_transformation = m_input->hit_vol_tr->inverse() * object_trmat * surface_trmat;
}
}
}
}