428bb49adce311bc6eeeabdba866eccd67261d21
1 /*
2 * Vanishing point for 3D perspectives
3 *
4 * Authors:
5 * Maximilian Albert <Anhalter42@gmx.de>
6 *
7 * Copyright (C) 2007 authors
8 *
9 * Released under GNU GPL, read the file 'COPYING' for more information
10 */
12 #ifndef SEEN_VANISHING_POINT_H
13 #define SEEN_VANISHING_POINT_H
15 #include "libnr/nr-point.h"
16 #include "knot.h"
17 #include "selection.h"
18 #include "axis-manip.h"
20 #include "line-geometry.h" // TODO: Remove this include as soon as we don't need create_canvas_(point|line) any more.
22 class SP3DBox;
24 namespace Box3D {
26 enum VPState {
27 VP_FINITE = 0, // perspective lines meet in the VP
28 VP_INFINITE // perspective lines are parallel
29 };
31 // FIXME: Store the Axis of the VP inside the class
32 class VanishingPoint : public NR::Point {
33 public:
34 inline VanishingPoint() : NR::Point() {};
35 /***
36 inline VanishingPoint(NR::Point const &pt, NR::Point const &ref = NR::Point(0,0))
37 : NR::Point (pt),
38 ref_pt (ref),
39 v_dir (pt[NR::X] - ref[NR::X], pt[NR::Y] - ref[NR::Y]) {}
40 inline VanishingPoint(NR::Coord x, NR::Coord y, NR::Point const &ref = NR::Point(0,0))
41 : NR::Point (x, y),
42 ref_pt (ref),
43 v_dir (x - ref[NR::X], y - ref[NR::Y]) {}
44 ***/
45 VanishingPoint(NR::Point const &pt, NR::Point const &inf_dir, VPState st);
46 VanishingPoint(NR::Point const &pt);
47 VanishingPoint(NR::Point const &dir, VPState const state);
48 VanishingPoint(NR::Point const &pt, NR::Point const &direction);
49 VanishingPoint(NR::Coord x, NR::Coord y);
50 VanishingPoint(NR::Coord x, NR::Coord y, VPState const state);
51 VanishingPoint(NR::Coord x, NR::Coord y, NR::Coord dir_x, NR::Coord dir_y);
52 VanishingPoint(VanishingPoint const &rhs);
53 ~VanishingPoint();
55 bool operator== (VanishingPoint const &other);
57 inline NR::Point get_pos() const { return NR::Point ((*this)[NR::X], (*this)[NR::Y]); }
58 inline void set_pos(NR::Point const &pt) { (*this)[NR::X] = pt[NR::X];
59 (*this)[NR::Y] = pt[NR::Y]; }
60 inline void set_pos(const double pt_x, const double pt_y) { (*this)[NR::X] = pt_x;
61 (*this)[NR::Y] = pt_y; }
62 inline void set_infinite_direction (const NR::Point dir) { v_dir = dir; }
63 inline void set_infinite_direction (const double dir_x, const double dir_y) { v_dir = NR::Point (dir_x, dir_y); }
65 bool is_finite() const;
66 VPState toggle_parallel();
67 void draw(Box3D::Axis const axis); // Draws a point on the canvas if state == VP_FINITE
68 //inline VPState state() { return state; }
70 VPState state;
71 //NR::Point ref_pt; // point of reference to compute the direction of parallel lines
72 NR::Point v_dir; // direction of perslective lines if the VP has state == VP_INFINITE
74 private:
75 };
77 class Perspective3D;
78 class VPDrag;
80 struct VPDragger {
81 public:
82 VPDragger(VPDrag *parent, NR::Point p, VanishingPoint *vp);
83 ~VPDragger();
85 VPDrag *parent;
86 SPKnot *knot;
88 // position of the knot, desktop coords
89 NR::Point point;
90 // position of the knot before it began to drag; updated when released
91 NR::Point point_original;
93 GSList *vps; // the list of vanishing points
95 void addVP(VanishingPoint *vp);
96 void removeVP(VanishingPoint *vp);
97 /* returns the VP of the dragger that belongs to the given perspective */
98 VanishingPoint *getVPofPerspective (Perspective3D *persp);
100 void updateTip();
102 bool hasBox (const SP3DBox *box);
103 guint numberOfBoxes(); // the number of boxes linked to all VPs of the dragger
105 bool hasPerspective (const Perspective3D *perps);
106 void mergePerspectives (); // remove duplicate perspectives
108 void reshapeBoxes(NR::Point const &p, Box3D::Axis axes);
109 void updateBoxReprs();
110 void updateZOrders();
111 };
113 struct VPDrag {
114 public:
115 VPDrag(SPDocument *document);
116 ~VPDrag();
118 VPDragger *getDraggerFor (VanishingPoint const &vp);
120 //void grabKnot (VanishingPoint const &vp, gint x, gint y, guint32 etime);
122 bool local_change;
124 SPDocument *document;
125 GList *draggers;
126 GSList *lines;
128 void updateDraggers ();
129 void updateLines ();
130 void updateBoxHandles ();
131 void drawLinesForFace (const SP3DBox *box, Box3D::Axis axis); //, guint corner1, guint corner2, guint corner3, guint corner4);
132 bool show_lines; /* whether perspective lines are drawn at all */
133 guint front_or_rear_lines; /* whether we draw perspective lines from all corners or only the
134 front/rear corners (indicated by the first/second bit, respectively */
137 inline bool hasEmptySelection() { return this->selection->isEmpty(); }
138 bool allBoxesAreSelected (VPDragger *dragger);
139 GSList * selectedBoxesWithVPinDragger (VPDragger *dragger);
141 // FIXME: Should this be private? (It's the case with the corresponding function in gradient-drag.h)
142 // But vp_knot_grabbed_handler
143 void addDragger (VanishingPoint *vp);
145 private:
146 //void deselect_all();
148 void addLine (NR::Point p1, NR::Point p2, guint32 rgba);
150 Inkscape::Selection *selection;
151 sigc::connection sel_changed_connection;
152 sigc::connection sel_modified_connection;
153 };
155 } // namespace Box3D
158 /** A function to print out the VanishingPoint (prints the coordinates) **/
159 /***
160 inline std::ostream &operator<< (std::ostream &out_file, const VanishingPoint &vp) {
161 out_file << vp;
162 return out_file;
163 }
164 ***/
167 #endif /* !SEEN_VANISHING_POINT_H */
169 /*
170 Local Variables:
171 mode:c++
172 c-file-style:"stroustrup"
173 c-file-offsets:((innamespace . 0)(inline-open . 0))
174 indent-tabs-mode:nil
175 fill-column:99
176 End:
177 */
178 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :