Code

First (very limited) version of the 3D box tool; allows for drawing of new boxes...
[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"
15 #include <iostream>
17 namespace Box3D {
19 // FIXME: We should always require to have both the point (for finite VPs)
20 //        and the direction (for infinite VPs) set. Otherwise toggling 
21 //        shows very unexpected behaviour.
22 //        Later on we can maybe infer the infinite direction from the finite point
23 //        and a suitable center of the scene. How to go in the other direction?
24 VanishingPoint::VanishingPoint(NR::Point const &pt, NR::Point const &inf_dir, VPState st)
25                              : NR::Point (pt), state (st), v_dir (inf_dir) {}
27 VanishingPoint::VanishingPoint(NR::Point const &pt)
28                              : NR::Point (pt), state (VP_FINITE), v_dir (0.0, 0.0) {}
30 VanishingPoint::VanishingPoint(NR::Point const &pt, NR::Point const &direction)
31                              : NR::Point (pt), state (VP_INFINITE), v_dir (direction) {}
33 VanishingPoint::VanishingPoint(NR::Coord x, NR::Coord y)
34                              : NR::Point(x, y), state(VP_FINITE), v_dir(0.0, 0.0) {}
36 VanishingPoint::VanishingPoint(NR::Coord dir_x, NR::Coord dir_y, VPState st)
37                              : NR::Point(0.0, 0.0), state(st), v_dir(dir_x, dir_y) {}
39 VanishingPoint::VanishingPoint(NR::Coord x, NR::Coord y, NR::Coord dir_x, NR::Coord dir_y)
40                              : NR::Point(x, y), state(VP_INFINITE), v_dir(dir_x, dir_y) {}
42 VanishingPoint::VanishingPoint(VanishingPoint const &rhs) : NR::Point (rhs)
43 {
44     this->state = rhs.state;
45     //this->ref_pt = rhs.ref_pt;
46     this->v_dir = rhs.v_dir;
47 }
50 bool VanishingPoint::is_finite()
51 {
52     return this->state == VP_FINITE;
53 }
55 VPState VanishingPoint::toggle_parallel()
56 {
57     if (this->state == VP_FINITE) {
58         this->state = VP_INFINITE;
59     } else {
60         this->state = VP_FINITE;
61     }
63     return this->state;
64 }
66 void VanishingPoint::draw(PerspDir const axis)
67 {
68     switch (axis) {
69         case X:
70             if (state == VP_FINITE)
71                 create_canvas_point(*this, 6.0, 0xff000000);
72             else
73                 create_canvas_point(*this, 6.0, 0xffffff00);
74             break;
75         case Y:
76             if (state == VP_FINITE)
77                 create_canvas_point(*this, 6.0, 0x0000ff00);
78             else
79                 create_canvas_point(*this, 6.0, 0xffffff00);
80             break;
81         case Z:
82             if (state == VP_FINITE)
83                 create_canvas_point(*this, 6.0, 0x00770000);
84             else
85                 create_canvas_point(*this, 6.0, 0xffffff00);
86             break;
87     }
88 }
90 } // namespace Box3D 
91  
92 /*
93   Local Variables:
94   mode:c++
95   c-file-style:"stroustrup"
96   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
97   indent-tabs-mode:nil
98   fill-column:99
99   End:
100 */
101 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :