summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 54c7f91)
raw | patch | inline | side by side (parent: 54c7f91)
author | cilix42 <cilix42@users.sourceforge.net> | |
Sat, 1 Sep 2007 13:29:40 +0000 (13:29 +0000) | ||
committer | cilix42 <cilix42@users.sourceforge.net> | |
Sat, 1 Sep 2007 13:29:40 +0000 (13:29 +0000) |
diff --git a/src/box3d-context.cpp b/src/box3d-context.cpp
index 8b8b1ca9932b010d7900383459baaafba97cbe46..2abf0112f8bdbb8d63ae76d00b0b86d99813510c 100644 (file)
--- a/src/box3d-context.cpp
+++ b/src/box3d-context.cpp
@@ -451,6 +451,36 @@ static gint sp_3dbox_context_root_handler(SPEventContext *event_context, GdkEven
ret = TRUE;
break;
+ case GDK_bracketright:
+ inkscape_active_document()->current_perspective->rotate (Box3D::X, -10);
+ ret = true;
+ break;
+
+ case GDK_bracketleft:
+ inkscape_active_document()->current_perspective->rotate (Box3D::X, 10);
+ ret = true;
+ break;
+
+ case GDK_parenright:
+ inkscape_active_document()->current_perspective->rotate (Box3D::Y, -10);
+ ret = true;
+ break;
+
+ case GDK_parenleft:
+ inkscape_active_document()->current_perspective->rotate (Box3D::Y, 10);
+ ret = true;
+ break;
+
+ case GDK_braceright:
+ inkscape_active_document()->current_perspective->rotate (Box3D::Z, -10);
+ ret = true;
+ break;
+
+ case GDK_braceleft:
+ inkscape_active_document()->current_perspective->rotate (Box3D::Z, 10);
+ ret = true;
+ break;
+
case GDK_I:
Box3D::Perspective3D::print_debugging_info();
ret = true;
diff --git a/src/box3d.cpp b/src/box3d.cpp
index 5e67f46ab33b148e2a14833968c50fd8c2fc9369..1942ea3d66494438522e0eebb575b3f4cf37282e 100644 (file)
--- a/src/box3d.cpp
+++ b/src/box3d.cpp
}
}
+void
+sp_3dbox_reshape_after_VP_rotation (SP3DBox *box, Box3D::Axis axis)
+{
+ Box3D::Perspective3D *persp = inkscape_active_document()->get_persp_of_box (box);
+ Box3D::VanishingPoint *vp = persp->get_vanishing_point (axis);
+
+ guint c1 = (axis == Box3D::Z) ? 1 : sp_3dbox_get_front_corner_id (box); // hack
+ guint c2 = c1 ^ axis;
+ NR::Point v = box->corners[c1] - box->corners[c2];
+ double dist = NR::L2 (v) * ((NR::dot (v, vp->v_dir) < 0) ? 1 : -1); // "directed" distance
+
+ Box3D::PerspectiveLine pline (box->corners[c1], axis, persp);
+ NR::Point pt = pline.point_from_lambda (dist);
+
+ sp_3dbox_move_corner_in_Z_direction (box, c2, pt, axis == Box3D::Z);
+}
+
void
sp_3dbox_move_corner_in_XY_plane (SP3DBox *box, guint id, NR::Point pt, Box3D::Axis axes)
{
diff --git a/src/box3d.h b/src/box3d.h
index 3d52c96d147845c5646ced8873840dae3fea1771..1e567ded95d2e1751d73cda2e8fb7bff9d9691f1 100644 (file)
--- a/src/box3d.h
+++ b/src/box3d.h
void sp_3dbox_link_to_existing_paths (SP3DBox *box, Inkscape::XML::Node *repr);
void sp_3dbox_set_ratios (SP3DBox *box, Box3D::Axis axes = Box3D::XYZ);
void sp_3dbox_switch_front_face (SP3DBox *box, Box3D::Axis axis);
+void sp_3dbox_reshape_after_VP_rotation (SP3DBox *box, Box3D::Axis axis);
void sp_3dbox_move_corner_in_XY_plane (SP3DBox *box, guint id, NR::Point pt, Box3D::Axis axes = Box3D::XY);
void sp_3dbox_move_corner_in_Z_direction (SP3DBox *box, guint id, NR::Point pt, bool constrained = true);
void sp_3dbox_reshape_after_VP_toggling (SP3DBox *box, Box3D::Axis axis);
diff --git a/src/line-geometry.cpp b/src/line-geometry.cpp
index 7b6ba04490498992ca02c7b2199031c093c27f9d..872e9ed6b7f58ba47d9f6160ac168d299c09a064 100644 (file)
--- a/src/line-geometry.cpp
+++ b/src/line-geometry.cpp
return lambda;
}
-inline static double determinant (NR::Point const &a, NR::Point const &b)
-{
- return (a[NR::X] * b[NR::Y] - a[NR::Y] * b[NR::X]);
-}
-
/* The coordinates of w with respect to the basis {v1, v2} */
std::pair<double, double> coordinates (NR::Point const &v1, NR::Point const &v2, NR::Point const &w)
{
diff --git a/src/line-geometry.h b/src/line-geometry.h
index fc8f157e99b42225c372711ed9ed8850c94aba66..e678c40312a958dfc6e97c16c910578720b84719 100644 (file)
--- a/src/line-geometry.h
+++ b/src/line-geometry.h
NR::Coord d0;
};
+inline double determinant (NR::Point const &a, NR::Point const &b)
+{
+ return (a[NR::X] * b[NR::Y] - a[NR::Y] * b[NR::X]);
+}
std::pair<double, double> coordinates (NR::Point const &v1, NR::Point const &v2, NR::Point const &w);
bool lies_in_sector (NR::Point const &v1, NR::Point const &v2, NR::Point const &w);
bool lies_in_quadrangle (NR::Point const &A, NR::Point const &B, NR::Point const &C, NR::Point const &D, NR::Point const &pt);
diff --git a/src/perspective3d.cpp b/src/perspective3d.cpp
index 8b1b3863de97d9c8c6a0416fcd6548cc5e37e3c4..9321af35630ca2d8ac9fbfd096de09ba7d80f5e6 100644 (file)
--- a/src/perspective3d.cpp
+++ b/src/perspective3d.cpp
@@ -180,6 +180,41 @@ Perspective3D::set_vanishing_point (Box3D::Axis const dir, VanishingPoint const
}
}
+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);
+}
+
+void
+Perspective3D::rotate (Box3D::Axis const axis, double const angle)
+{
+ Box3D::VanishingPoint *vp = get_vanishing_point (axis);
+ if (!vp->is_finite()) {
+ double a = NR::atan2 (vp->v_dir) * 180/M_PI;
+ a += angle;
+ a *= M_PI/180;
+ this->set_infinite_direction (axis, NR::Point (cos (a), sin (a)));
+ 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();
+ }
+}
+
Axis
Perspective3D::get_axis_of_VP (VanishingPoint *vp)
{
diff --git a/src/perspective3d.h b/src/perspective3d.h
index 8c63cf42e12d7c27eefd3a4c09dd4735d19942a1..a431e1f99846344588cd0afd1e7022a8f26c03ba 100644 (file)
--- a/src/perspective3d.h
+++ b/src/perspective3d.h
Axis get_axis_of_VP (VanishingPoint *vp);
void set_vanishing_point (Box3D::Axis const dir, VanishingPoint const &pt);
void set_vanishing_point (Box3D::Axis const dir, gdouble pt_x, gdouble pt_y, gdouble dir_x, gdouble dir_y, VPState st);
+ void set_infinite_direction (Box3D::Axis axis, NR::Point const dir);
+ void rotate (Box3D::Axis const dir, double const angle);
void add_box (SP3DBox *box);
void remove_box (const SP3DBox *box);
bool has_box (const SP3DBox *box) const;
diff --git a/src/vanishing-point.h b/src/vanishing-point.h
index 7d53fa89d431a7cb06d581f276531eadd089e72a..428bb49adce311bc6eeeabdba866eccd67261d21 100644 (file)
--- a/src/vanishing-point.h
+++ b/src/vanishing-point.h
(*this)[NR::Y] = pt[NR::Y]; }
inline void set_pos(const double pt_x, const double pt_y) { (*this)[NR::X] = pt_x;
(*this)[NR::Y] = pt_y; }
+ inline void set_infinite_direction (const NR::Point dir) { v_dir = dir; }
+ inline void set_infinite_direction (const double dir_x, const double dir_y) { v_dir = NR::Point (dir_x, dir_y); }
bool is_finite() const;
VPState toggle_parallel();