From 1f2f04e4e837f4b094487d4a95e59605c8da2dba Mon Sep 17 00:00:00 2001 From: cilix42 Date: Mon, 20 Aug 2007 18:55:18 +0000 Subject: [PATCH] Enable center-dragging of boxes in Z direction by using Shift --- src/box3d.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++ src/box3d.h | 2 ++ src/object-edit.cpp | 6 +++++- 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/box3d.cpp b/src/box3d.cpp index dcbe5b531..f822a1b20 100644 --- a/src/box3d.cpp +++ b/src/box3d.cpp @@ -181,6 +181,7 @@ sp_3dbox_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr box->old_corner0 = box->corners[0]; box->old_corner3 = box->corners[3]; box->old_corner5 = box->corners[5]; + box->old_corner7 = box->corners[7]; } static void @@ -292,6 +293,7 @@ static Inkscape::XML::Node *sp_3dbox_write(SPObject *object, Inkscape::XML::Node box->old_corner0 = box->corners[0]; box->old_corner3 = box->corners[3]; box->old_corner5 = box->corners[5]; + box->old_corner7 = box->corners[7]; } if (((SPObjectClass *) (parent_class))->write) { @@ -783,6 +785,55 @@ sp_3dbox_new_midpoints (Box3D::Perspective3D *persp, Box3D::Axis axis, NR::Point return std::make_pair (A_new, B_new); } +void sp_3dbox_recompute_Z_corners_from_new_center (SP3DBox *box, NR::Point const new_center) +{ + // TODO: Clean this function up + + Box3D::Perspective3D *persp = sp_desktop_document (inkscape_active_desktop())->get_persp_of_box (box); + NR::Point old_center = box->old_center; + + Box3D::PerspectiveLine aux_line1 (old_center, Box3D::Z, persp); + Box3D::PerspectiveLine aux_line2 (new_center, Box3D::Y, persp); + NR::Point Z1 = aux_line1.meet (aux_line2); + + NR::Point A0 (sp_3dbox_get_midpoint_in_axis_direction (box->old_corner2, box->old_corner0, Box3D::Y, persp)); + NR::Point B0 (sp_3dbox_get_midpoint_in_axis_direction (box->old_corner7, box->old_corner5, Box3D::Y, persp)); + Box3D::PerspectiveLine aux_line3 (A0, Box3D::X, persp); + Box3D::PerspectiveLine aux_line4 (B0, Box3D::X, persp); + + NR::Point C0 = aux_line3.meet (aux_line1); + NR::Point D0 = aux_line4.meet (aux_line1); + + std::pair new_midpts = sp_3dbox_new_midpoints (persp, Box3D::Z, old_center, Z1, C0, D0); + NR::Point C1 (new_midpts.first); + NR::Point D1 (new_midpts.second); + Box3D::PerspectiveLine aux_line5 (C1, Box3D::X, persp); + Box3D::PerspectiveLine aux_line6 (D1, Box3D::X, persp); + + Box3D::PerspectiveLine aux_line7 (A0, Box3D::Z, persp); + Box3D::PerspectiveLine aux_line8 (B0, Box3D::Z, persp); + + NR::Point A1 = aux_line5.meet (aux_line7); + NR::Point B1 = aux_line6.meet (aux_line8); + + Box3D::PerspectiveLine aux_line9 (box->old_corner2, Box3D::Z, persp); + Box3D::PerspectiveLine aux_line10 (box->old_corner5, Box3D::Z, persp); + + Box3D::PerspectiveLine aux_line11 (A1, Box3D::Y, persp); + Box3D::PerspectiveLine aux_line12 (B1, Box3D::Y, persp); + + NR::Point new_corner2 = aux_line9.meet (aux_line11); + NR::Point new_corner5 = aux_line10.meet (aux_line12); + + Box3D::PerspectiveLine aux_line13 (A1, Box3D::X, persp); + NR::Point E1 = aux_line13.meet (aux_line8); + Box3D::PerspectiveLine aux_line14 (E1, Box3D::Y, persp); + + NR::Point new_corner1 = aux_line10.meet (aux_line14); + + sp_3dbox_set_shape_from_points (box, new_corner2, new_corner1, new_corner5); +} + void sp_3dbox_recompute_XY_corners_from_new_center (SP3DBox *box, NR::Point const new_center) { // TODO: Clean this function up diff --git a/src/box3d.h b/src/box3d.h index a47b06663..e1b90c3f9 100644 --- a/src/box3d.h +++ b/src/box3d.h @@ -54,6 +54,7 @@ struct SP3DBox : public SPGroup { NR::Point old_corner0; NR::Point old_corner3; NR::Point old_corner5; + NR::Point old_corner7; gint my_counter; // for testing only }; @@ -80,6 +81,7 @@ void sp_3dbox_reshape_after_VP_toggling (SP3DBox *box, Box3D::Axis axis); NR::Maybe sp_3dbox_get_center (SP3DBox *box); NR::Maybe sp_3dbox_get_midpoint_between_corners (SP3DBox *box, guint id_corner1, guint id_corner2); void sp_3dbox_recompute_XY_corners_from_new_center (SP3DBox *box, NR::Point const new_center); +void sp_3dbox_recompute_Z_corners_from_new_center (SP3DBox *box, NR::Point const new_center); NR::Point sp_3dbox_get_midpoint_in_axis_direction (NR::Point const &C, NR::Point const &D, Box3D::Axis axis, Box3D::Perspective3D *persp); void sp_3dbox_update_perspective_lines(); diff --git a/src/object-edit.cpp b/src/object-edit.cpp index 2ebb2a065..bb98c6b68 100644 --- a/src/object-edit.cpp +++ b/src/object-edit.cpp @@ -652,7 +652,11 @@ static void sp_3dbox_knot_set(SPItem *item, guint knot_id, NR::Point const &new_ static void sp_3dbox_knot_center_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state) { NR::Matrix const i2d (sp_item_i2d_affine (item)); - sp_3dbox_recompute_XY_corners_from_new_center (SP_3DBOX (item), new_pos * i2d); + if (state & GDK_SHIFT_MASK) { + sp_3dbox_recompute_Z_corners_from_new_center (SP_3DBOX (item), new_pos * i2d); + } else { + sp_3dbox_recompute_XY_corners_from_new_center (SP_3DBOX (item), new_pos * i2d); + } sp_3dbox_update_curves (SP_3DBOX(item)); } -- 2.30.2