X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=inline;f=src%2Fperspective3d.cpp;h=489e88dfc859d46786ec28cb4872b229b2f90fca;hb=713ffe6438216a16f37590dfcb78715b42906843;hp=0d4877f37ec83f406f8913e832b9df2093545b10;hpb=209527815f6ad1b81d21bb3188947aef3d845010;p=inkscape.git diff --git a/src/perspective3d.cpp b/src/perspective3d.cpp index 0d4877f37..489e88dfc 100644 --- a/src/perspective3d.cpp +++ b/src/perspective3d.cpp @@ -49,7 +49,7 @@ NR::Point perspective_line_snap (NR::Point line_pt, Box3D::Axis dir, NR::Point ext_pt, Perspective3D *persp) { return PerspectiveLine(line_pt, dir, persp).closest_to(ext_pt); -} +} Perspective3D::Perspective3D (VanishingPoint const &pt_x, VanishingPoint const &pt_y, VanishingPoint const &pt_z, SPDocument *doc) : boxes (NULL), @@ -174,12 +174,48 @@ Perspective3D::set_vanishing_point (Box3D::Axis const dir, VanishingPoint const case Z: (*vp_z) = pt; break; - case NONE: + default: // no vanishing point to set break; } } +void +Perspective3D::set_infinite_direction (Box3D::Axis axis, NR::Point const dir) +{ + Box3D::Axis axis1 = Box3D::get_remaining_axes (axis).first; + Box3D::Axis axis2 = Box3D::get_remaining_axes (axis).second; + Box3D::VanishingPoint *vp1 = get_vanishing_point (axis1); + Box3D::VanishingPoint *vp2 = get_vanishing_point (axis2); + if (fabs (Box3D::determinant (vp1->v_dir, dir)) < Box3D::epsilon || + fabs (Box3D::determinant (vp2->v_dir, dir)) < Box3D::epsilon) { + // This is an ad-hoc correction; we should fix this more thoroughly + double a = NR::atan2 (dir) + 0.01; + this->set_infinite_direction (axis, NR::Point (cos (a), sin (a))); // we call this function again in case there is another conflict (which is unlikely, but possible) + return; + } + + get_vanishing_point (axis)->set_infinite_direction (dir); + for (GSList *i = this->boxes; i != NULL; i = i->next) { + sp_3dbox_reshape_after_VP_rotation (SP_3DBOX (i->data), axis); + sp_3dbox_set_z_orders_later_on (SP_3DBOX (i->data)); + } + update_box_reprs(); +} + +void +Perspective3D::rotate (Box3D::Axis const axis, double const angle, bool const alt_pressed) +{ + Box3D::VanishingPoint *vp = get_vanishing_point (axis); + if (!vp->is_finite()) { + //double add_value = angle; + double a = NR::atan2 (vp->v_dir) * 180/M_PI; + a += alt_pressed ? 0.5 * ((angle > 0 ) - (angle < 0)) : angle; // the r.h.s. yields +/-0.5 or angle + a *= M_PI/180; + this->set_infinite_direction (axis, NR::Point (cos (a), sin (a))); + } +} + Axis Perspective3D::get_axis_of_VP (VanishingPoint *vp) { @@ -205,7 +241,7 @@ Perspective3D::set_vanishing_point (Box3D::Axis const dir, gdouble pt_x, gdouble case Z: vp = vp_z; break; - case NONE: + default: // no vanishing point to set return; } @@ -296,7 +332,7 @@ Perspective3D::reshape_boxes (Box3D::Axis axes) new_pt = vp->get_pos() + box->ratio_z * (box->corners[0] - vp->get_pos()); sp_3dbox_move_corner_in_Z_direction (box, 4, new_pt); } - } + } sp_3dbox_set_shape (box, true); } @@ -310,6 +346,9 @@ Perspective3D::toggle_boxes (Box3D::Axis axis) sp_3dbox_reshape_after_VP_toggling (SP_3DBOX (i->data), axis); } update_box_reprs(); + + SP3DBoxContext *bc = SP_3DBOX_CONTEXT (inkscape_active_event_context()); + bc->_vpdrag->updateDraggers (); } void @@ -324,10 +363,21 @@ void Perspective3D::update_z_orders () { for (GSList *i = this->boxes; i != NULL; i = i->next) { - sp_3dbox_set_z_orders (SP_3DBOX (i->data)); + sp_3dbox_set_z_orders_later_on (SP_3DBOX (i->data)); } } +/* the direction from a point pt towards the specified vanishing point of the perspective */ +NR::Point +Perspective3D::direction (NR::Point pt, Box3D::Axis axis) +{ + Box3D::VanishingPoint *vp = this->get_vanishing_point (axis); + if (!vp->is_finite()) { + return vp->v_dir; + } + return (vp->get_pos() - pt); +} + // swallow the list of boxes from the other perspective and delete it void Perspective3D::absorb (Perspective3D *other) @@ -382,13 +432,15 @@ Perspective3D::print_debugging_info () if (j != NULL) { g_print ("%d", SP_3DBOX (j->data)->my_counter); } + g_print ("\n"); } + g_print ("\n"); } - g_print ("\n====================================================\n"); + g_print ("====================================================\n"); } -} // namespace Box3D - +} // namespace Box3D + /* Local Variables: mode:c++