Code

New/updated 3D box auxiliary/convenience functions (e.g., allow (un)constrained movem...
[inkscape.git] / src / vanishing-point.h
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 "line-geometry.h"
18 namespace Box3D {
20 enum VPState {
21     VP_FINITE = 0, // perspective lines meet in the VP
22     VP_INFINITE    // perspective lines are parallel
23 };
25 // The X-/Y-/Z-axis corresponds to the first/second/third digit
26 // in binary representation, respectively.
27 enum Axis {
28     X = 1,
29     Y = 2,
30     Z = 4,
31     XY = 3,
32     XZ = 5,
33     YZ = 6,
34     XYZ = 7,
35     NONE = 0
36 };
39 inline bool is_single_axis_direction (Box3D::Axis dir) {
40     // tests whether dir is nonzero and a power of 2
41     return (!(dir & (dir - 1)) && dir);
42 }
44 /** Given two axis directions out of {X, Y, Z}, returns the remaining one */
45 inline Box3D::Axis third_axis_direction (Box3D::Axis dir1, Box3D::Axis dir2) {
46     return (Box3D::Axis) ((dir1 + dir2) ^ 0x7);
47 }
49 /* returns the first axis direction occuring in the (possibly compound) expression 'dirs' */
50 inline Box3D::Axis extract_single_axis_direction (Box3D::Axis dirs) {
51     if (dirs & Box3D::X) return Box3D::X;
52     if (dirs & Box3D::Y) return Box3D::Y;
53     if (dirs & Box3D::Z) return Box3D::Z;
54     return Box3D::NONE;
55 }
57 /* returns an axis direction perpendicular to the ones occuring in the (possibly compound) expression 'dirs' */
58 inline Box3D::Axis get_perpendicular_axis_direction (Box3D::Axis dirs) {
59     if (!(dirs & Box3D::X)) return Box3D::X;
60     if (!(dirs & Box3D::Y)) return Box3D::Y;
61     if (!(dirs & Box3D::Z)) return Box3D::Z;
62     return Box3D::NONE;
63 }
66 // FIXME: Store the Axis of the VP inside the class
67 class VanishingPoint : public NR::Point {
68 public:
69     inline VanishingPoint() : NR::Point() {};
70     /***
71     inline VanishingPoint(NR::Point const &pt, NR::Point const &ref = NR::Point(0,0))
72                          : NR::Point (pt),
73                            ref_pt (ref),
74                            v_dir (pt[NR::X] - ref[NR::X], pt[NR::Y] - ref[NR::Y]) {}
75     inline VanishingPoint(NR::Coord x, NR::Coord y, NR::Point const &ref = NR::Point(0,0))
76                          : NR::Point (x, y),
77                            ref_pt (ref),
78                            v_dir (x - ref[NR::X], y - ref[NR::Y]) {}
79     ***/
80     VanishingPoint(NR::Point const &pt, NR::Point const &inf_dir, VPState st);
81     VanishingPoint(NR::Point const &pt);
82     VanishingPoint(NR::Point const &dir, VPState const state);
83     VanishingPoint(NR::Point const &pt, NR::Point const &direction);
84     VanishingPoint(NR::Coord x, NR::Coord y);
85     VanishingPoint(NR::Coord x, NR::Coord y, VPState const state);
86     VanishingPoint(NR::Coord x, NR::Coord y, NR::Coord dir_x, NR::Coord dir_y);
87     VanishingPoint(VanishingPoint const &rhs);
89     bool is_finite();
90     VPState toggle_parallel();
91     void draw(Box3D::Axis const axis); // Draws a point on the canvas if state == VP_FINITE
92     //inline VPState state() { return state; }
93         
94     VPState state;
95     //NR::Point ref_pt; // point of reference to compute the direction of parallel lines
96     NR::Point v_dir; // direction of perslective lines if the VP has state == VP_INFINITE
98 private:
99 };
102 } // namespace Box3D
105 /** A function to print out the VanishingPoint (prints the coordinates) **/
106 /***
107 inline std::ostream &operator<< (std::ostream &out_file, const VanishingPoint &vp) {
108     out_file << vp;
109     return out_file;
111 ***/
114 #endif /* !SEEN_VANISHING_POINT_H */
116 /*
117   Local Variables:
118   mode:c++
119   c-file-style:"stroustrup"
120   c-file-offsets:((innamespace . 0)(inline-open . 0))
121   indent-tabs-mode:nil
122   fill-column:99
123   End:
124 */
125 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :