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; }
63 bool is_finite() const;
64 VPState toggle_parallel();
65 void draw(Box3D::Axis const axis); // Draws a point on the canvas if state == VP_FINITE
66 //inline VPState state() { return state; }
68 VPState state;
69 //NR::Point ref_pt; // point of reference to compute the direction of parallel lines
70 NR::Point v_dir; // direction of perslective lines if the VP has state == VP_INFINITE
72 private:
73 };
75 class Perspective3D;
76 class VPDrag;
78 struct VPDragger {
79 public:
80 VPDragger(VPDrag *parent, NR::Point p, VanishingPoint *vp);
81 ~VPDragger();
83 VPDrag *parent;
84 SPKnot *knot;
86 // position of the knot, desktop coords
87 NR::Point point;
88 // position of the knot before it began to drag; updated when released
89 NR::Point point_original;
91 GSList *vps; // the list of vanishing points
93 void addVP(VanishingPoint *vp);
94 void removeVP(VanishingPoint *vp);
95 /* returns the VP of the dragger that belongs to the given perspective */
96 VanishingPoint *getVPofPerspective (Perspective3D *persp);
98 void updateTip();
100 bool hasBox (const SP3DBox *box);
101 guint numberOfBoxes(); // the number of boxes linked to all VPs of the dragger
103 bool hasPerspective (const Perspective3D *perps);
104 void mergePerspectives (); // remove duplicate perspectives
106 void reshapeBoxes(NR::Point const &p, Box3D::Axis axes);
107 void updateBoxReprs();
108 void updateZOrders();
109 };
111 struct VPDrag {
112 public:
113 VPDrag(SPDocument *document);
114 ~VPDrag();
116 VPDragger *getDraggerFor (VanishingPoint const &vp);
118 //void grabKnot (VanishingPoint const &vp, gint x, gint y, guint32 etime);
120 bool local_change;
122 SPDocument *document;
123 GList *draggers;
124 GSList *lines;
126 void updateDraggers ();
127 void updateLines ();
128 void updateBoxHandles ();
129 void drawLinesForFace (const SP3DBox *box, Box3D::Axis axis); //, guint corner1, guint corner2, guint corner3, guint corner4);
130 bool show_lines; /* whether perspective lines are drawn at all */
131 guint front_or_rear_lines; /* whether we draw perspective lines from all corners or only the
132 front/rear corners (indicated by the first/second bit, respectively */
135 inline bool hasEmptySelection() { return this->selection->isEmpty(); }
136 bool allBoxesAreSelected (VPDragger *dragger);
137 GSList * selectedBoxesWithVPinDragger (VPDragger *dragger);
139 // FIXME: Should this be private? (It's the case with the corresponding function in gradient-drag.h)
140 // But vp_knot_grabbed_handler
141 void addDragger (VanishingPoint *vp);
143 private:
144 //void deselect_all();
146 void addLine (NR::Point p1, NR::Point p2, guint32 rgba);
148 Inkscape::Selection *selection;
149 sigc::connection sel_changed_connection;
150 sigc::connection sel_modified_connection;
151 };
153 } // namespace Box3D
156 /** A function to print out the VanishingPoint (prints the coordinates) **/
157 /***
158 inline std::ostream &operator<< (std::ostream &out_file, const VanishingPoint &vp) {
159 out_file << vp;
160 return out_file;
161 }
162 ***/
165 #endif /* !SEEN_VANISHING_POINT_H */
167 /*
168 Local Variables:
169 mode:c++
170 c-file-style:"stroustrup"
171 c-file-offsets:((innamespace . 0)(inline-open . 0))
172 indent-tabs-mode:nil
173 fill-column:99
174 End:
175 */
176 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :