98788f51247a0f6aa6c969d9e7530f2d00b69ffa
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 bool hasBox (const SP3DBox *box);
99 guint numberOfBoxes(); // the number of boxes linked to all VPs of the dragger
101 bool hasPerspective (const Perspective3D *perps);
102 void mergePerspectives (); // remove duplicate perspectives
104 void reshapeBoxes(NR::Point const &p, Box3D::Axis axes);
105 void updateBoxReprs();
106 };
108 struct VPDrag {
109 public:
110 VPDrag(SPDesktop *desktop);
111 ~VPDrag();
113 VPDragger *getDraggerFor (VanishingPoint const &vp);
115 //void grabKnot (VanishingPoint const &vp, gint x, gint y, guint32 etime);
117 bool local_change;
119 SPDesktop *desktop;
120 GList *draggers;
121 GSList *lines;
123 void updateDraggers ();
124 void updateLines ();
125 void updateBoxHandles ();
126 void drawLinesForFace (const SP3DBox *box, Box3D::Axis axis); //, guint corner1, guint corner2, guint corner3, guint corner4);
127 bool show_lines; /* whether perspective lines are drawn at all */
128 guint front_or_rear_lines; /* whether we draw perspective lines from all corners or only the
129 front/rear corners (indicated by the first/second bit, respectively */
132 inline bool hasEmptySelection() { return this->selection->isEmpty(); }
133 bool allBoxesAreSelected (VPDragger *dragger);
134 GSList * selectedBoxesWithVPinDragger (VPDragger *dragger);
136 // FIXME: Should this be private? (It's the case with the corresponding function in gradient-drag.h)
137 // But vp_knot_grabbed_handler
138 void addDragger (VanishingPoint *vp);
140 private:
141 //void deselect_all();
143 void addLine (NR::Point p1, NR::Point p2, guint32 rgba);
145 Inkscape::Selection *selection;
146 sigc::connection sel_changed_connection;
147 sigc::connection sel_modified_connection;
148 };
150 } // namespace Box3D
153 /** A function to print out the VanishingPoint (prints the coordinates) **/
154 /***
155 inline std::ostream &operator<< (std::ostream &out_file, const VanishingPoint &vp) {
156 out_file << vp;
157 return out_file;
158 }
159 ***/
162 #endif /* !SEEN_VANISHING_POINT_H */
164 /*
165 Local Variables:
166 mode:c++
167 c-file-style:"stroustrup"
168 c-file-offsets:((innamespace . 0)(inline-open . 0))
169 indent-tabs-mode:nil
170 fill-column:99
171 End:
172 */
173 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :