summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/perspective3d.cpp41
-rw-r--r--src/perspective3d.h7
-rw-r--r--src/vanishing-point.cpp2
-rw-r--r--src/vanishing-point.h2
4 files changed, 37 insertions, 15 deletions
diff --git a/src/perspective3d.cpp b/src/perspective3d.cpp
index 1ad910bfa..27366e564 100644
--- a/src/perspective3d.cpp
+++ b/src/perspective3d.cpp
@@ -61,18 +61,32 @@ perspective_line_snap (NR::Point line_pt, Box3D::Axis dir, NR::Point ext_pt, Per
Perspective3D::Perspective3D (VanishingPoint const &pt_x, VanishingPoint const &pt_y, VanishingPoint const &pt_z)
: desktop (NULL),
- vp_x (pt_x),
- vp_y (pt_y),
- vp_z (pt_z),
boxes (NULL)
{
+ vp_x = new VanishingPoint (pt_x);
+ vp_y = new VanishingPoint (pt_y);
+ vp_z = new VanishingPoint (pt_z);
}
+Perspective3D::Perspective3D (Perspective3D &other)
+ : desktop (other.desktop),
+ boxes (NULL) // FIXME: Should we add an option to copy the list of boxes?
+{
+ vp_x = new VanishingPoint (*other.vp_x);
+ vp_y = new VanishingPoint (*other.vp_y);
+ vp_z = new VanishingPoint (*other.vp_z);
+}
+
+
Perspective3D::~Perspective3D ()
{
g_assert (desktop != NULL);
desktop->remove_perspective (this);
+ delete vp_x;
+ delete vp_y;
+ delete vp_z;
+
g_slist_free (boxes);
}
@@ -80,16 +94,23 @@ Perspective3D::~Perspective3D ()
VanishingPoint *
Perspective3D::get_vanishing_point (Box3D::Axis const dir)
{
- // FIXME: Also handle value 'NONE' in switch
switch (dir) {
case X:
- return &vp_x;
+ return vp_x;
break;
case Y:
- return &vp_y;
+ return vp_y;
break;
case Z:
- return &vp_z;
+ return vp_z;
+ break;
+ case NONE:
+ g_warning ("Axis direction must be specified. As a workaround we return the VP in X direction.\n");
+ return vp_x;
+ break;
+ default:
+ g_warning ("Single axis direction needed to determine corresponding vanishing point.\n");
+ return get_vanishing_point (extract_first_axis_direction(dir));
break;
}
}
@@ -99,13 +120,13 @@ Perspective3D::set_vanishing_point (Box3D::Axis const dir, VanishingPoint const
{
switch (dir) {
case X:
- vp_x = pt;
+ (*vp_x) = pt;
break;
case Y:
- vp_y = pt;
+ (*vp_y) = pt;
break;
case Z:
- vp_z = pt;
+ (*vp_z) = pt;
break;
case NONE:
// no vanishing point to set
diff --git a/src/perspective3d.h b/src/perspective3d.h
index fa9eda65f..afecb2e48 100644
--- a/src/perspective3d.h
+++ b/src/perspective3d.h
@@ -23,6 +23,7 @@ class PerspectiveLine;
class Perspective3D {
public:
Perspective3D(VanishingPoint const &pt_x, VanishingPoint const &pt_y, VanishingPoint const &pt_z);
+ Perspective3D(Perspective3D &other);
~Perspective3D();
VanishingPoint *get_vanishing_point (Box3D::Axis const dir);
@@ -36,9 +37,9 @@ public:
SPDesktop * desktop; // we need to store the perspective's desktop to be able to access it in the destructor
private:
- VanishingPoint vp_x;
- VanishingPoint vp_y;
- VanishingPoint vp_z;
+ VanishingPoint *vp_x;
+ VanishingPoint *vp_y;
+ VanishingPoint *vp_z;
GSList * boxes; // holds a list of boxes sharing this specific perspective
};
diff --git a/src/vanishing-point.cpp b/src/vanishing-point.cpp
index 7d5b24a86..20c67cb28 100644
--- a/src/vanishing-point.cpp
+++ b/src/vanishing-point.cpp
@@ -46,7 +46,7 @@ VanishingPoint::VanishingPoint(VanishingPoint const &rhs) : NR::Point (rhs)
}
-bool VanishingPoint::is_finite()
+bool VanishingPoint::is_finite() const
{
return this->state == VP_FINITE;
}
diff --git a/src/vanishing-point.h b/src/vanishing-point.h
index e6c106481..85b7434e2 100644
--- a/src/vanishing-point.h
+++ b/src/vanishing-point.h
@@ -47,7 +47,7 @@ public:
VanishingPoint(NR::Coord x, NR::Coord y, NR::Coord dir_x, NR::Coord dir_y);
VanishingPoint(VanishingPoint const &rhs);
- bool is_finite();
+ bool is_finite() const;
VPState toggle_parallel();
void draw(Box3D::Axis const axis); // Draws a point on the canvas if state == VP_FINITE
//inline VPState state() { return state; }