summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 725274d)
raw | patch | inline | side by side (parent: 725274d)
author | cilix42 <cilix42@users.sourceforge.net> | |
Tue, 3 Jul 2007 19:20:05 +0000 (19:20 +0000) | ||
committer | cilix42 <cilix42@users.sourceforge.net> | |
Tue, 3 Jul 2007 19:20:05 +0000 (19:20 +0000) |
Handle the corners in the box itself and only link to them from the separate faces. This way we can make the code *much* cleaner and more generic.
Provide generic auxiliary functions for the movement of corners in XY-plane and Z-direction.
Provide generic auxiliary functions for the movement of corners in XY-plane and Z-direction.
src/box3d-face.cpp | patch | blob | history | |
src/box3d-face.h | patch | blob | history | |
src/box3d.cpp | patch | blob | history | |
src/box3d.h | patch | blob | history | |
src/vanishing-point.h | patch | blob | history |
diff --git a/src/box3d-face.cpp b/src/box3d-face.cpp
index e499fe4d02c4e2b0ffe3cca5cb54e03ea7203b01..5eefcb812b4fbc52b7b4892fd8de8d12ca99ea19 100644 (file)
--- a/src/box3d-face.cpp
+++ b/src/box3d-face.cpp
Box3DFace::Box3DFace(SP3DBox *box3d) : dir1 (Box3D::NONE), dir2 (Box3D::NONE), path (NULL), parent_box3d (box3d)
{
for (int i = 0; i < 4; ++i) {
- this->corners[i] = NR::Point(0, 0);
+ this->corners[i] = new NR::Point(0, 0);
}
}
+Box3DFace::Box3DFace(SP3DBox *box3d, NR::Point &A, NR::Point &B, NR::Point &C, NR::Point &D)
+{
+ set_corners (A, B, C, D);
+}
+
+Box3DFace::~Box3DFace()
+{
+ for (int i = 0; i < 4; ++i) {
+ if (this->corners[i]) {
+ delete this->corners[i];
+ this->corners[i] = NULL;
+ }
+ }
+}
+
+void Box3DFace::set_corners(NR::Point &A, NR::Point &B, NR::Point &C, NR::Point &D)
+{
+ corners[0] = &A;
+ corners[1] = &B;
+ corners[2] = &C;
+ corners[3] = &D;
+}
+
+/***
void Box3DFace::set_shape(NR::Point const ul, NR::Point const lr,
Box3D::Axis const dir1, Box3D::Axis const dir2,
unsigned int shift_count, NR::Maybe<NR::Point> pt_align, bool align_along_PL)
corners[0] = tmp_pt;
}
}
+***/
Box3DFace::Box3DFace(Box3DFace const &box3dface)
{
void
Box3DFace::set_face (NR::Point const A, NR::Point const C, Box3D::Axis const axis1, Box3D::Axis const axis2)
{
- corners[0] = A;
- corners[2] = C;
+ *corners[0] = A;
+ *corners[2] = C;
if (!SP_IS_3DBOX_CONTEXT(inkscape_active_event_context()))
return;
SP3DBoxContext *bc = SP_3DBOX_CONTEXT(inkscape_active_event_context());
@@ -100,8 +125,8 @@ Box3DFace::set_face (NR::Point const A, NR::Point const C, Box3D::Axis const axi
Box3D::PerspectiveLine line2 (C, axis2);
NR::Maybe<NR::Point> B = line1.intersect(line2);
- Box3D::PerspectiveLine line3 (corners[0], axis2);
- Box3D::PerspectiveLine line4 (corners[2], axis1);
+ Box3D::PerspectiveLine line3 (*corners[0], axis2);
+ Box3D::PerspectiveLine line4 (*corners[2], axis1);
NR::Maybe<NR::Point> D = line3.intersect(line4);
// FIXME: How to handle the case if one of the intersections doesn't exist?
@@ -109,8 +134,8 @@ Box3DFace::set_face (NR::Point const A, NR::Point const C, Box3D::Axis const axi
if (!D) D = NR::Point(0.0, 0.0);
if (!B) B = NR::Point(0.0, 0.0);
- corners[1] = *B;
- corners[3] = *D;
+ *corners[1] = *B;
+ *corners[3] = *D;
this->dir1 = axis1;
this->dir2 = axis2;
@@ -119,7 +144,7 @@ Box3DFace::set_face (NR::Point const A, NR::Point const C, Box3D::Axis const axi
NR::Point Box3DFace::operator[](unsigned int i)
{
- return corners[i % 4];
+ return *corners[i % 4];
}
/**
return;
}
SPCurve *curve = sp_curve_new();
- sp_curve_moveto(curve, corners[0][NR::X], height - corners[0][NR::Y]);
- sp_curve_lineto(curve, corners[1][NR::X], height - corners[1][NR::Y]);
- sp_curve_lineto(curve, corners[2][NR::X], height - corners[2][NR::Y]);
- sp_curve_lineto(curve, corners[3][NR::X], height - corners[3][NR::Y]);
+ sp_curve_moveto(curve, (*corners[0])[NR::X], height - (*corners[0])[NR::Y]);
+ sp_curve_lineto(curve, (*corners[1])[NR::X], height - (*corners[1])[NR::Y]);
+ sp_curve_lineto(curve, (*corners[2])[NR::X], height - (*corners[2])[NR::Y]);
+ sp_curve_lineto(curve, (*corners[3])[NR::X], height - (*corners[3])[NR::Y]);
sp_curve_closepath(curve);
sp_shape_set_curve(SP_SHAPE(this->path), curve, true);
sp_curve_unref(curve);
GString *pstring = g_string_new("");
g_string_sprintf (pstring, "M %f,%f L %f,%f L %f,%f L %f,%f z",
- corners[0][NR::X], height - corners[0][NR::Y],
- corners[1][NR::X], height - corners[1][NR::Y],
- corners[2][NR::X], height - corners[2][NR::Y],
- corners[3][NR::X], height - corners[3][NR::Y]);
+ (*corners[0])[NR::X], height - (*corners[0])[NR::Y],
+ (*corners[1])[NR::X], height - (*corners[1])[NR::Y],
+ (*corners[2])[NR::X], height - (*corners[2])[NR::Y],
+ (*corners[3])[NR::X], height - (*corners[3])[NR::Y]);
return pstring->str;
}
diff --git a/src/box3d-face.h b/src/box3d-face.h
index e557aebf29d1b6935d0b1d12a22410a99e999448..3b96937b657cd26f31ce610dabcb8e04083f2fbb 100644 (file)
--- a/src/box3d-face.h
+++ b/src/box3d-face.h
class Box3DFace {
public:
Box3DFace(SP3DBox *box3d);
+ Box3DFace(SP3DBox *box3d, NR::Point &A, NR::Point &B, NR::Point &C, NR::Point &D);
//Box3DFace(SP3DBox *box3d, NR::Point const ul, NR::Point const lr,
// Box3D::Axis const dir1, Box3D::Axis const dir2,
// unsigned int shift_count = 0, NR::Maybe<NR::Point> pt_align = NR::Nothing(), bool align_along_PL = false);
Box3DFace(Box3DFace const &box3dface);
+ ~Box3DFace();
+
NR::Point operator[](unsigned int i);
void draw(SP3DBox *box3d, SPCurve *c);
+ /***
void set_shape(NR::Point const ul, NR::Point const lr,
Box3D::Axis const dir1, Box3D::Axis const dir2,
unsigned int shift_count = 0, NR::Maybe<NR::Point> pt_align = NR::Nothing(),
bool align_along_PL = false);
+ ***/
+ void set_corners (NR::Point &A, NR::Point &B, NR::Point &C, NR::Point &D);
void set_face (NR::Point const A, NR::Point const C, Box3D::Axis const dir1, Box3D::Axis const dir2);
void hook_path_to_3dbox();
gchar * svg_repr_string();
private:
- NR::Point corners[4];
+ NR::Point *corners[4];
Box3D::Axis dir1;
Box3D::Axis dir2;
diff --git a/src/box3d.cpp b/src/box3d.cpp
index 290b5111ec5baba205e0e69cd71fbf7df000d198..258c658791084c66f11b9d2ecec287a9cc5edc0b 100644 (file)
--- a/src/box3d.cpp
+++ b/src/box3d.cpp
sp_3dbox_class_init(SP3DBoxClass *klass)
{
SPObjectClass *sp_object_class = (SPObjectClass *) klass;
- SPItemClass *item_class = (SPItemClass *) klass;
+ // SPItemClass *item_class = (SPItemClass *) klass;
parent_class = (SPGroupClass *) g_type_class_ref(SP_TYPE_GROUP);
static void
sp_3dbox_init(SP3DBox *box3d)
{
- if (box3d == NULL) { g_warning ("box3d is NULL!\n"); }
box3d->faces[4] = new Box3DFace (box3d);
//box3d->faces[4]->hook_path_to_3dbox();
for (int i = 0; i < 6; ++i) {
@@ -163,8 +162,6 @@ static Inkscape::XML::Node *sp_3dbox_write(SPObject *object, Inkscape::XML::Node
box3d->faces[4]->set_path_repr();
if (bc->extruded) {
- NR::Point corner1, corner2, corner3, corner4;
- sp_3dbox_compute_specific_corners (bc, corner1, corner2, corner3, corner4);
for (int i = 0; i < 6; ++i) {
if (i == 4) continue;
box3d->faces[i]->set_path_repr();
return;
SP3DBoxContext *bc = SP_3DBOX_CONTEXT(inkscape_active_event_context());
- // FIXME: Why must the coordinates be flipped vertically???
- //SPDocument *doc = SP_OBJECT_DOCUMENT(box3d);
- //gdouble height = sp_document_height(doc);
-
- /* Curve-adaption variant: */
- NR::Point corner1, corner2, corner3, corner4;
- corner1 = bc->drag_origin;
-
+ /* Only update the curves during dragging; setting the svg representations
+ is expensive and only done once at the end */
+ sp_3dbox_recompute_corners (box3d, bc->drag_origin, bc->drag_ptB, bc->drag_ptC);
if (bc->extruded) {
- sp_3dbox_compute_specific_corners (bc, corner1, corner2, corner3, corner4);
- for (int i=0; i < 6; ++i) {
- if (!box3d->faces[i]) {
- g_warning ("Face no. %d does not exist!\n", i);
- return;
- }
- }
- box3d->faces[0]->set_face (bc->drag_origin, corner4, Box3D::Z, Box3D::Y);
- box3d->faces[0]->set_curve();
- box3d->faces[5]->set_face (corner3, bc->drag_ptC, Box3D::Y, Box3D::X);
- box3d->faces[5]->set_curve();
- box3d->faces[3]->set_face (bc->drag_origin, corner2, Box3D::X, Box3D::Z);
- box3d->faces[3]->set_curve();
- box3d->faces[2]->set_face (bc->drag_ptB, corner4, Box3D::X, Box3D::Z);
- box3d->faces[2]->set_curve();
-
- box3d->faces[1]->set_face (corner1, bc->drag_ptC, Box3D::Z, Box3D::Y);
- box3d->faces[1]->set_curve();
+ box3d->faces[0]->set_corners (box3d->corners[0], box3d->corners[4], box3d->corners[6], box3d->corners[2]);
+ box3d->faces[1]->set_corners (box3d->corners[1], box3d->corners[5], box3d->corners[7], box3d->corners[3]);
+ box3d->faces[2]->set_corners (box3d->corners[0], box3d->corners[1], box3d->corners[5], box3d->corners[4]);
+ box3d->faces[3]->set_corners (box3d->corners[2], box3d->corners[3], box3d->corners[7], box3d->corners[6]);
+ box3d->faces[5]->set_corners (box3d->corners[4], box3d->corners[5], box3d->corners[7], box3d->corners[6]);
}
- box3d->faces[4]->set_face(bc->drag_origin, bc->drag_ptB, Box3D::Y, Box3D::X);
- box3d->faces[4]->set_curve();
+ box3d->faces[4]->set_corners (box3d->corners[0], box3d->corners[1], box3d->corners[3], box3d->corners[2]);
+
+ sp_3dbox_update_curves (box3d);
+}
+
+
+void sp_3dbox_recompute_corners (SP3DBox *box, NR::Point const A, NR::Point const B, NR::Point const C)
+{
+ sp_3dbox_move_corner_in_XY_plane (box, 2, A);
+ sp_3dbox_move_corner_in_XY_plane (box, 1, B);
+ sp_3dbox_move_corner_in_constrained_Z_direction (box, 5, C);
}
+void
+sp_3dbox_update_curves (SP3DBox *box) {
+ for (int i = 0; i < 6; ++i) {
+ if (box->faces[i]) box->faces[i]->set_curve();
+ }
+}
void
-sp_3dbox_compute_specific_corners (SP3DBoxContext *box3d_context, NR::Point &corner1, NR::Point &corner2, NR::Point &corner3, NR::Point &corner4)
+sp_3dbox_move_corner_in_XY_plane (SP3DBox *box, guint id, NR::Point pt)
{
- // TODO: Check for numerical stability and handle "wrong" cases more gracefully.
- // (This now mostly applies to the intersection code in the PerspectiveLine class)
- Box3D::PerspectiveLine pl1 (box3d_context->drag_origin, Box3D::X);
- Box3D::PerspectiveLine pl2 (box3d_context->drag_ptB, Box3D::Y);
- corner1 = pl1.meet(pl2);
-
- Box3D::PerspectiveLine pl3 (corner1, Box3D::Z);
- Box3D::PerspectiveLine pl4 (box3d_context->drag_ptC, Box3D::Y);
- corner2 = pl3.meet(pl4);
-
- Box3D::PerspectiveLine pl5 (corner2, Box3D::X);
- Box3D::PerspectiveLine pl6 (box3d_context->drag_origin, Box3D::Z);
- corner3 = pl5.meet(pl6);
-
- Box3D::PerspectiveLine pl7 (box3d_context->drag_ptC, Box3D::X);
- Box3D::PerspectiveLine pl8 (corner3, Box3D::Y);
- corner4 = pl7.meet(pl8);
+ NR::Point A (box->corners[id ^ Box3D::XY]);
+
+ /* set the 'front' corners */
+ box->corners[id] = pt;
+
+ Box3D::PerspectiveLine pl_one (A, Box3D::Y);
+ Box3D::PerspectiveLine pl_two (pt, Box3D::X);
+ box->corners[id ^ Box3D::X] = pl_one.meet(pl_two);
+
+ pl_one = Box3D::PerspectiveLine (A, Box3D::X);
+ pl_two = Box3D::PerspectiveLine (pt, Box3D::Y);
+ box->corners[id ^ Box3D::Y] = pl_one.meet(pl_two);
+
+ /* set the 'rear' corners */
+ NR::Point B (box->corners[id ^ Box3D::XYZ]);
+
+ pl_one = Box3D::PerspectiveLine (box->corners[id ^ Box3D::X], Box3D::Z);
+ pl_two = Box3D::PerspectiveLine (B, Box3D::Y);
+ box->corners[id ^ Box3D::XZ] = pl_one.meet(pl_two);
+
+ pl_one = Box3D::PerspectiveLine (box->corners[id ^ Box3D::XZ], Box3D::X);
+ pl_two = Box3D::PerspectiveLine (pt, Box3D::Z);
+ box->corners[id ^ Box3D::Z] = pl_one.meet(pl_two);
+
+ pl_one = Box3D::PerspectiveLine (box->corners[id ^ Box3D::Z], Box3D::Y);
+ pl_two = Box3D::PerspectiveLine (B, Box3D::X);
+ box->corners[id ^ Box3D::YZ] = pl_one.meet(pl_two);
+
}
+void
+sp_3dbox_move_corner_in_constrained_Z_direction (SP3DBox *box, guint id, NR::Point pt)
+{
+ /* set the four corners of the face containing corners[id] */
+ box->corners[id] = Box3D::PerspectiveLine (box->corners[id], Box3D::Z).closest_to(pt);
+
+ Box3D::PerspectiveLine pl_one (box->corners[id], Box3D::X);
+ Box3D::PerspectiveLine pl_two (box->corners[id ^ Box3D::XZ], Box3D::Z);
+ box->corners[id ^ Box3D::X] = pl_one.meet(pl_two);
+
+ pl_one = Box3D::PerspectiveLine (box->corners[id ^ Box3D::X], Box3D::Y);
+ pl_two = Box3D::PerspectiveLine (box->corners[id ^ Box3D::XYZ], Box3D::Z);
+ box->corners[id ^ Box3D::XY] = pl_one.meet(pl_two);
+
+ pl_one = Box3D::PerspectiveLine (box->corners[id], Box3D::Y);
+ pl_two = Box3D::PerspectiveLine (box->corners[id ^ Box3D::YZ], Box3D::Z);
+ box->corners[id ^ Box3D::Y] = pl_one.meet(pl_two);
+}
/*
diff --git a/src/box3d.h b/src/box3d.h
index 982596d8f20b43771f895208f5a0a3da76d93a3b..1fb8280eed9ae4acfbc94974cb0ccfb833137897 100644 (file)
--- a/src/box3d.h
+++ b/src/box3d.h
struct SP3DBox : public SPGroup {
+ NR::Point corners[8];
Box3DFace *faces[6];
};
GType sp_3dbox_get_type (void);
void sp_3dbox_position_set (SP3DBoxContext &bc);
-void sp_3dbox_compute_specific_corners (SP3DBoxContext *box3d_context, NR::Point &corner1, NR::Point &corner2, NR::Point &corner3, NR::Point &corner4);
+void sp_3dbox_recompute_corners (SP3DBox *box, NR::Point const pt1, NR::Point const pt2, NR::Point const pt3);
+void sp_3dbox_update_curves (SP3DBox *box);
+void sp_3dbox_move_corner_in_XY_plane (SP3DBox *box, guint id, NR::Point pt);
+void sp_3dbox_move_corner_in_constrained_Z_direction (SP3DBox *box, guint id, NR::Point pt);
+
+inline NR::Point sp_3dbox_get_corner (SP3DBox *box, guint id) { return box->corners[id]; }
#endif
diff --git a/src/vanishing-point.h b/src/vanishing-point.h
index 3be5d085ee35ce3733bf3d74e7272b2ea06eef2c..b94193adcba70b56af1841cc6c202320dee459e7 100644 (file)
--- a/src/vanishing-point.h
+++ b/src/vanishing-point.h
X = 1,
Y = 2,
Z = 4,
+ XY = 3,
+ XZ = 5,
+ YZ = 6,
+ XYZ = 7,
NONE = 0
};