Code

Move 3D axis manipulation functions to separate file
[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 }
49 bool VanishingPoint::is_finite()
50 {
51     return this->state == VP_FINITE;
52 }
54 VPState VanishingPoint::toggle_parallel()
55 {
56     if (this->state == VP_FINITE) {
57         this->state = VP_INFINITE;
58     } else {
59         this->state = VP_FINITE;
60     }
62     return this->state;
63 }
65 void VanishingPoint::draw(Box3D::Axis const axis)
66 {
67     switch (axis) {
68         case X:
69             if (state == VP_FINITE)
70                 create_canvas_point(*this, 6.0, 0xff000000);
71             else
72                 create_canvas_point(*this, 6.0, 0xffffff00);
73             break;
74         case Y:
75             if (state == VP_FINITE)
76                 create_canvas_point(*this, 6.0, 0x0000ff00);
77             else
78                 create_canvas_point(*this, 6.0, 0xffffff00);
79             break;
80         case Z:
81             if (state == VP_FINITE)
82                 create_canvas_point(*this, 6.0, 0x00770000);
83             else
84                 create_canvas_point(*this, 6.0, 0xffffff00);
85             break;
86         default:
87             g_assert_not_reached();
88             break;
89     }
90 }
92 } // namespace Box3D 
93  
94 /*
95   Local Variables:
96   mode:c++
97   c-file-style:"stroustrup"
98   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
99   indent-tabs-mode:nil
100   fill-column:99
101   End:
102 */
103 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :