Code

More 3D auxiliary/convenience functions
[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 Axis axes[3]   = { X,  Y,  Z };
20 Axis planes[3] = { XY, XZ, YZ };
21 FrontOrRear face_positions [2] = { FRONT, REAR };
23 // FIXME: We should always require to have both the point (for finite VPs)
24 //        and the direction (for infinite VPs) set. Otherwise toggling 
25 //        shows very unexpected behaviour.
26 //        Later on we can maybe infer the infinite direction from the finite point
27 //        and a suitable center of the scene. How to go in the other direction?
28 VanishingPoint::VanishingPoint(NR::Point const &pt, NR::Point const &inf_dir, VPState st)
29                              : NR::Point (pt), state (st), v_dir (inf_dir) {}
31 VanishingPoint::VanishingPoint(NR::Point const &pt)
32                              : NR::Point (pt), state (VP_FINITE), v_dir (0.0, 0.0) {}
34 VanishingPoint::VanishingPoint(NR::Point const &pt, NR::Point const &direction)
35                              : NR::Point (pt), state (VP_INFINITE), v_dir (direction) {}
37 VanishingPoint::VanishingPoint(NR::Coord x, NR::Coord y)
38                              : NR::Point(x, y), state(VP_FINITE), v_dir(0.0, 0.0) {}
40 VanishingPoint::VanishingPoint(NR::Coord dir_x, NR::Coord dir_y, VPState st)
41                              : NR::Point(0.0, 0.0), state(st), v_dir(dir_x, dir_y) {}
43 VanishingPoint::VanishingPoint(NR::Coord x, NR::Coord y, NR::Coord dir_x, NR::Coord dir_y)
44                              : NR::Point(x, y), state(VP_INFINITE), v_dir(dir_x, dir_y) {}
46 VanishingPoint::VanishingPoint(VanishingPoint const &rhs) : NR::Point (rhs)
47 {
48     this->state = rhs.state;
49     //this->ref_pt = rhs.ref_pt;
50     this->v_dir = rhs.v_dir;
51 }
54 bool VanishingPoint::is_finite()
55 {
56     return this->state == VP_FINITE;
57 }
59 VPState VanishingPoint::toggle_parallel()
60 {
61     if (this->state == VP_FINITE) {
62         this->state = VP_INFINITE;
63     } else {
64         this->state = VP_FINITE;
65     }
67     return this->state;
68 }
70 void VanishingPoint::draw(Box3D::Axis const axis)
71 {
72     switch (axis) {
73         case X:
74             if (state == VP_FINITE)
75                 create_canvas_point(*this, 6.0, 0xff000000);
76             else
77                 create_canvas_point(*this, 6.0, 0xffffff00);
78             break;
79         case Y:
80             if (state == VP_FINITE)
81                 create_canvas_point(*this, 6.0, 0x0000ff00);
82             else
83                 create_canvas_point(*this, 6.0, 0xffffff00);
84             break;
85         case Z:
86             if (state == VP_FINITE)
87                 create_canvas_point(*this, 6.0, 0x00770000);
88             else
89                 create_canvas_point(*this, 6.0, 0xffffff00);
90             break;
91         default:
92             g_assert_not_reached();
93             break;
94     }
95 }
97 } // namespace Box3D 
98  
99 /*
100   Local Variables:
101   mode:c++
102   c-file-style:"stroustrup"
103   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
104   indent-tabs-mode:nil
105   fill-column:99
106   End:
107 */
108 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :