Code

4dd309b1f6513a6fc64d41b44e4041b256330002
[inkscape.git] / src / perspective3d.h
1 /*
2  * Class modelling a 3D perspective
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_PERSPECTIVE3D_H
13 #define SEEN_PERSPECTIVE3D_H
15 #include "vanishing-point.h"
16 #include "svg/stringstream.h"
17 #include <glib.h>
19 class SP3DBox;
21 namespace Box3D {
23 class PerspectiveLine;
25 class Perspective3D {
26 public:
27     Perspective3D(VanishingPoint const &pt_x, VanishingPoint const &pt_y, VanishingPoint const &pt_z);
28     Perspective3D(Perspective3D &other);
29     ~Perspective3D();
31     bool operator== (Perspective3D const &other) const;
33     bool has_vanishing_point (VanishingPoint *vp);
34     VanishingPoint *get_vanishing_point (Box3D::Axis const dir);
35     Axis get_axis_of_VP (VanishingPoint *vp);
36     void set_vanishing_point (Box3D::Axis const dir, VanishingPoint const &pt);
37     void set_vanishing_point (Box3D::Axis const dir, gdouble pt_x, gdouble pt_y, gdouble dir_x, gdouble dir_y, VPState st);
38     void add_box (SP3DBox *box);
39     void remove_box (const SP3DBox *box);
40     bool has_box (const SP3DBox *box) const;
41     inline guint number_of_boxes () { return g_slist_length (boxes); }
42     void reshape_boxes (Box3D::Axis axes);
43     void toggle_boxes (Box3D::Axis axes); // update the shape of boxes after a VP's state was toggled
44     void update_box_reprs ();
45     void update_z_orders ();
47     /* convenience functions for interaction with dragging machinery: */
48     bool all_boxes_occur_in_list (GSList *boxes_to_do);
49     GSList * boxes_occurring_in_list (GSList * list_of_boxes);
51     void absorb (Perspective3D *other); // swallow the other perspective if both coincide
53     static gint counter; // for testing only
54     gint my_counter; // for testing only
56     static GSList * perspectives; // All existing 3D perspectives
57     // FIXME: Perspectives should be linked to the list of existing ones automatically in the constructor
58     //        and removed in the destructor!
59     static void add_perspective (Box3D::Perspective3D * const persp);
60     static void remove_perspective (Box3D::Perspective3D * const persp);
62     /* find an existing perspective whose VPs are equal to those of persp */
63     static Box3D::Perspective3D * find_perspective (Box3D::Perspective3D * const persp);
65     static void print_debugging_info();
66     static Perspective3D * current_perspective;
68 private:
69     VanishingPoint *vp_x;
70     VanishingPoint *vp_y;
71     VanishingPoint *vp_z;
72     GSList * boxes; // holds a list of boxes sharing this specific perspective
73 };
75 Perspective3D * get_persp_of_box (const SP3DBox *box);
76 Perspective3D * get_persp_of_VP (const VanishingPoint *vp);
78 NR::Point perspective_intersection (NR::Point pt1, Box3D::Axis dir1, NR::Point pt2, Box3D::Axis dir2, Perspective3D *persp);
79 NR::Point perspective_line_snap (NR::Point pt, Box3D::Axis dir, NR::Point ext_pt, Perspective3D *persp);
81 } // namespace Box3D
84 /** A function to print out the VanishingPoint (prints the coordinates) **/
85 /***
86 inline std::ostream &operator<< (std::ostream &out_file, const VanishingPoint &vp) {
87     out_file << vp;
88     return out_file;
89 }
90 ***/
93 #endif /* !SEEN_PERSPECTIVE3D_H */
95 /*
96   Local Variables:
97   mode:c++
98   c-file-style:"stroustrup"
99   c-file-offsets:((innamespace . 0)(inline-open . 0))
100   indent-tabs-mode:nil
101   fill-column:99
102   End:
103 */
104 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :