Code

Write/read perspectives to/from SVG; store ratios of the distances from corners to...
[inkscape.git] / src / vanishing-point.cpp
1 #define __VANISHING_POINT_C__
3 /*
4  * Vanishing point for 3D perspectives
5  *
6  * Authors:
7  *   Maximilian Albert <Anhalter42@gmx.de>
8  *
9  * Copyright (C) 2007 authors
10  *
11  * Released under GNU GPL, read the file 'COPYING' for more information
12  */
14 #include "vanishing-point.h"
16 namespace Box3D {
18 // FIXME: We should always require to have both the point (for finite VPs)
19 //        and the direction (for infinite VPs) set. Otherwise toggling 
20 //        shows very unexpected behaviour.
21 //        Later on we can maybe infer the infinite direction from the finite point
22 //        and a suitable center of the scene. How to go in the other direction?
23 VanishingPoint::VanishingPoint(NR::Point const &pt, NR::Point const &inf_dir, VPState st)
24                              : NR::Point (pt), state (st), v_dir (inf_dir) {}
26 VanishingPoint::VanishingPoint(NR::Point const &pt)
27                              : NR::Point (pt), state (VP_FINITE), v_dir (0.0, 0.0) {}
29 VanishingPoint::VanishingPoint(NR::Point const &pt, NR::Point const &direction)
30                              : NR::Point (pt), state (VP_INFINITE), v_dir (direction) {}
32 VanishingPoint::VanishingPoint(NR::Coord x, NR::Coord y)
33                              : NR::Point(x, y), state(VP_FINITE), v_dir(0.0, 0.0) {}
35 VanishingPoint::VanishingPoint(NR::Coord dir_x, NR::Coord dir_y, VPState st)
36                              : NR::Point(0.0, 0.0), state(st), v_dir(dir_x, dir_y) {}
38 VanishingPoint::VanishingPoint(NR::Coord x, NR::Coord y, NR::Coord dir_x, NR::Coord dir_y)
39                              : NR::Point(x, y), state(VP_INFINITE), v_dir(dir_x, dir_y) {}
41 VanishingPoint::VanishingPoint(VanishingPoint const &rhs) : NR::Point (rhs)
42 {
43     this->state = rhs.state;
44     //this->ref_pt = rhs.ref_pt;
45     this->v_dir = rhs.v_dir;
46 }
48 bool VanishingPoint::operator== (VanishingPoint const &other)
49 {
50     // Should we compare the parent perspectives, too? Probably not.
51     if ((*this)[NR::X] == other[NR::X] && (*this)[NR::Y] == other[NR::Y]
52         && this->state == other.state && this->v_dir == other.v_dir) {
53         return true;
54     }
55     return false;
56 }
58 bool VanishingPoint::is_finite() const
59 {
60     return this->state == VP_FINITE;
61 }
63 VPState VanishingPoint::toggle_parallel()
64 {
65     if (this->state == VP_FINITE) {
66         this->state = VP_INFINITE;
67     } else {
68         this->state = VP_FINITE;
69     }
71     return this->state;
72 }
74 void VanishingPoint::draw(Box3D::Axis const axis)
75 {
76     switch (axis) {
77         case X:
78             if (state == VP_FINITE)
79                 create_canvas_point(*this, 6.0, 0xff000000);
80             else
81                 create_canvas_point(*this, 6.0, 0xffffff00);
82             break;
83         case Y:
84             if (state == VP_FINITE)
85                 create_canvas_point(*this, 6.0, 0x0000ff00);
86             else
87                 create_canvas_point(*this, 6.0, 0xffffff00);
88             break;
89         case Z:
90             if (state == VP_FINITE)
91                 create_canvas_point(*this, 6.0, 0x00770000);
92             else
93                 create_canvas_point(*this, 6.0, 0xffffff00);
94             break;
95         default:
96             g_assert_not_reached();
97             break;
98     }
99 }
101 } // namespace Box3D 
102  
103 /*
104   Local Variables:
105   mode:c++
106   c-file-style:"stroustrup"
107   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
108   indent-tabs-mode:nil
109   fill-column:99
110   End:
111 */
112 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :