58b3b142727c8fd93b8f1b8b28d8547e5879e818
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 namespace Box3D {
24 enum VPState {
25 VP_FINITE = 0, // perspective lines meet in the VP
26 VP_INFINITE // perspective lines are parallel
27 };
29 // FIXME: Store the Axis of the VP inside the class
30 class VanishingPoint : public NR::Point {
31 public:
32 inline VanishingPoint() : NR::Point() {};
33 /***
34 inline VanishingPoint(NR::Point const &pt, NR::Point const &ref = NR::Point(0,0))
35 : NR::Point (pt),
36 ref_pt (ref),
37 v_dir (pt[NR::X] - ref[NR::X], pt[NR::Y] - ref[NR::Y]) {}
38 inline VanishingPoint(NR::Coord x, NR::Coord y, NR::Point const &ref = NR::Point(0,0))
39 : NR::Point (x, y),
40 ref_pt (ref),
41 v_dir (x - ref[NR::X], y - ref[NR::Y]) {}
42 ***/
43 VanishingPoint(NR::Point const &pt, NR::Point const &inf_dir, VPState st);
44 VanishingPoint(NR::Point const &pt);
45 VanishingPoint(NR::Point const &dir, VPState const state);
46 VanishingPoint(NR::Point const &pt, NR::Point const &direction);
47 VanishingPoint(NR::Coord x, NR::Coord y);
48 VanishingPoint(NR::Coord x, NR::Coord y, VPState const state);
49 VanishingPoint(NR::Coord x, NR::Coord y, NR::Coord dir_x, NR::Coord dir_y);
50 VanishingPoint(VanishingPoint const &rhs);
51 ~VanishingPoint();
53 bool operator== (VanishingPoint const &other);
55 inline NR::Point get_pos() const { return NR::Point ((*this)[NR::X], (*this)[NR::Y]); }
56 inline void set_pos(NR::Point const &pt) { (*this)[NR::X] = pt[NR::X];
57 (*this)[NR::Y] = pt[NR::Y]; }
58 inline void set_pos(const double pt_x, const double pt_y) { (*this)[NR::X] = pt_x;
59 (*this)[NR::Y] = pt_y; }
61 bool is_finite() const;
62 VPState toggle_parallel();
63 void draw(Box3D::Axis const axis); // Draws a point on the canvas if state == VP_FINITE
64 //inline VPState state() { return state; }
66 VPState state;
67 //NR::Point ref_pt; // point of reference to compute the direction of parallel lines
68 NR::Point v_dir; // direction of perslective lines if the VP has state == VP_INFINITE
70 private:
71 };
73 class VPDrag;
75 struct VPDragger {
76 public:
77 VPDragger(VPDrag *parent, NR::Point p, VanishingPoint *vp);
78 ~VPDragger();
80 VPDrag *parent;
81 SPKnot *knot;
83 // position of the knot, desktop coords
84 NR::Point point;
85 // position of the knot before it began to drag; updated when released
86 NR::Point point_original;
88 GSList *vps; // the list of vanishing points
90 void addVP(VanishingPoint *vp);
91 void removeVP(VanishingPoint *vp);
93 void reshapeBoxes(NR::Point const &p, Box3D::Axis axes);
94 void updateBoxReprs();
95 };
97 struct VPDrag {
98 public:
99 VPDrag(SPDesktop *desktop);
100 ~VPDrag();
102 VPDragger *getDraggerFor (VanishingPoint const &vp);
104 //void grabKnot (VanishingPoint const &vp, gint x, gint y, guint32 etime);
106 bool local_change;
108 SPDesktop *desktop;
109 GList *draggers;
110 //GSList *lines;
112 void updateDraggers ();
113 //void updateLines ();
115 private:
116 //void deselect_all();
118 //void addLine (NR::Point p1, NR::Point p2, guint32 rgba);
119 void addDragger (VanishingPoint *vp);
121 Inkscape::Selection *selection;
122 sigc::connection sel_changed_connection;
123 sigc::connection sel_modified_connection;
124 };
126 } // namespace Box3D
129 /** A function to print out the VanishingPoint (prints the coordinates) **/
130 /***
131 inline std::ostream &operator<< (std::ostream &out_file, const VanishingPoint &vp) {
132 out_file << vp;
133 return out_file;
134 }
135 ***/
138 #endif /* !SEEN_VANISHING_POINT_H */
140 /*
141 Local Variables:
142 mode:c++
143 c-file-style:"stroustrup"
144 c-file-offsets:((innamespace . 0)(inline-open . 0))
145 indent-tabs-mode:nil
146 fill-column:99
147 End:
148 */
149 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :