summaryrefslogtreecommitdiffstats
path: root/src/perspective3d.cpp
diff options
context:
space:
mode:
authorMaximilian Albert <maximilian.albert@gmail.com>2007-06-21 13:01:57 +0000
committercilix42 <cilix42@users.sourceforge.net>2007-06-21 13:01:57 +0000
commitcf233ff5bbc68bd598ef4b81c7b4063548f2eff9 (patch)
tree56d48726d21ad368509a945bf7df91966115cc9c /src/perspective3d.cpp
parentFix function plotter for the most common case where there are no transforms a... (diff)
downloadinkscape-cf233ff5bbc68bd598ef4b81c7b4063548f2eff9.tar.gz
inkscape-cf233ff5bbc68bd598ef4b81c7b4063548f2eff9.zip
First (very limited) version of the 3D box tool; allows for drawing of new boxes in a fixed perspective without any live interaction.
(bzr r3084)
Diffstat (limited to 'src/perspective3d.cpp')
-rw-r--r--src/perspective3d.cpp98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/perspective3d.cpp b/src/perspective3d.cpp
new file mode 100644
index 000000000..678b695d0
--- /dev/null
+++ b/src/perspective3d.cpp
@@ -0,0 +1,98 @@
+#define __PERSPECTIVE3D_C__
+
+/*
+ * Class modelling a 3D perspective
+ *
+ * Authors:
+ * Maximilian Albert <Anhalter42@gmx.de>
+ *
+ * Copyright (C) 2007 authors
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "box3d-context.h"
+#include "perspective-line.h"
+#include <iostream>
+
+namespace Box3D {
+
+/**
+ * Computes the intersection of the two perspective lines from pt1 and pt2 to the respective
+ * vanishing points in the given directions.
+ */
+// FIXME: This has been moved to a virtual method inside PerspectiveLine; can probably be purged
+NR::Point perspective_intersection (NR::Point pt1, Box3D::PerspDir dir1, NR::Point pt2, Box3D::PerspDir dir2)
+{
+ VanishingPoint const *vp1 = SP3DBoxContext::current_perspective->get_vanishing_point(dir1);
+ VanishingPoint const *vp2 = SP3DBoxContext::current_perspective->get_vanishing_point(dir2);
+ NR::Maybe<NR::Point> meet = Line(pt1, *vp1).intersect(Line(pt2, *vp2));
+ // FIXME: How to handle parallel lines (also depends on the type of the VPs)?
+ if (!meet) { meet = NR::Point (0.0, 0.0); }
+ return *meet;
+}
+
+/**
+ * Find the point on the perspective line from line_pt to the
+ * vanishing point in direction dir that is closest to ext_pt.
+ */
+NR::Point perspective_line_snap (NR::Point line_pt, PerspDir dir, NR::Point ext_pt)
+{
+ return PerspectiveLine(line_pt, dir).closest_to(ext_pt);
+}
+
+Perspective3D::Perspective3D (VanishingPoint const &pt_x, VanishingPoint const &pt_y, VanishingPoint const &pt_z)
+ : vp_x (pt_x),
+ vp_y (pt_y),
+ vp_z (pt_z)
+{
+ // Draw the three vanishing points
+ vp_x.draw(X);
+ vp_y.draw(Y);
+ vp_z.draw(Z);
+}
+
+VanishingPoint *Perspective3D::get_vanishing_point (PerspDir const dir)
+{
+ // FIXME: Also handle value 'NONE' in switch
+ switch (dir) {
+ case X:
+ return &vp_x;
+ break;
+ case Y:
+ return &vp_y;
+ break;
+ case Z:
+ return &vp_z;
+ break;
+ }
+}
+
+void Perspective3D::set_vanishing_point (PerspDir const dir, VanishingPoint const &pt)
+{
+ // FIXME: Also handle value 'NONE' in switch
+ switch (dir) {
+ case X:
+ vp_x = pt;
+ break;
+ case Y:
+ vp_y = pt;
+ break;
+ case Z:
+ vp_z = pt;
+ break;
+ }
+}
+
+} // namespace Box3D
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :