summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f51078c)
raw | patch | inline | side by side (parent: f51078c)
author | cilix42 <cilix42@users.sourceforge.net> | |
Tue, 3 Jul 2007 18:09:45 +0000 (18:09 +0000) | ||
committer | cilix42 <cilix42@users.sourceforge.net> | |
Tue, 3 Jul 2007 18:09:45 +0000 (18:09 +0000) |
src/box3d-context.cpp | patch | blob | history | |
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 |
diff --git a/src/box3d-context.cpp b/src/box3d-context.cpp
index ead6486e50fdc89f8549f174d4f3f8247de8fc4e..a46783f4cec67789a60e9e636e85d6674444aee8 100644 (file)
--- a/src/box3d-context.cpp
+++ b/src/box3d-context.cpp
/* The separate faces (created from rear to front) */
SP3DBox *box3d = SP_3DBOX(rc.item);
- box3d->face3.hook_path_to_3dbox();
- box3d->face4.hook_path_to_3dbox();
- box3d->face5.hook_path_to_3dbox();
- box3d->face6.hook_path_to_3dbox();
- box3d->face1.hook_path_to_3dbox();
- box3d->face2.hook_path_to_3dbox();
+ box3d->faces[2].hook_path_to_3dbox();
+ box3d->faces[3].hook_path_to_3dbox();
+ box3d->faces[4].hook_path_to_3dbox();
+ box3d->faces[5].hook_path_to_3dbox();
+ box3d->faces[0].hook_path_to_3dbox();
+ box3d->faces[1].hook_path_to_3dbox();
rc.item->updateRepr();
diff --git a/src/box3d-face.cpp b/src/box3d-face.cpp
index eb05b2c040de1e3c8c34909633df9432243e4cf4..b3a26b9caec04aa091acea92e40aca57efdf002f 100644 (file)
--- a/src/box3d-face.cpp
+++ b/src/box3d-face.cpp
#include "box3d-face.h"
#include <iostream>
-Box3DFace::Box3DFace(SP3DBox *box3d) : corner1 (0, 0), corner2 (0, 0), corner3 (0, 0), corner4 (0, 0),
- dir1 (Box3D::NONE), dir2 (Box3D::NONE), path (NULL), parent_box3d (box3d)
+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);
+ }
}
void Box3DFace::set_shape(NR::Point const ul, NR::Point const lr,
Box3D::PerspDir const dir1, Box3D::PerspDir const dir2,
unsigned int shift_count, NR::Maybe<NR::Point> pt_align, bool align_along_PL)
{
- corner1 = ul;
+ corners[0] = ul;
if (!pt_align) {
- corner3 = lr;
+ corners[2] = lr;
} else {
if (align_along_PL) {
Box3D::PerspDir dir3;
if (dir1 == Box3D::Z && dir2 == Box3D::Y) dir3 = Box3D::X;
Box3D::Line line1(*SP3DBoxContext::current_perspective->get_vanishing_point(dir1), lr);
Box3D::Line line2(*pt_align, *SP3DBoxContext::current_perspective->get_vanishing_point(dir3));
- corner3 = *line1.intersect(line2);
+ corners[2] = *line1.intersect(line2);
} else {
- corner3 = Box3D::Line(*pt_align, *SP3DBoxContext::current_perspective->get_vanishing_point(dir1)).closest_to(lr);
+ corners[2] = Box3D::Line(*pt_align, *SP3DBoxContext::current_perspective->get_vanishing_point(dir1)).closest_to(lr);
}
}
- Box3D::PerspectiveLine first_line (corner1, dir1);
- Box3D::PerspectiveLine second_line (corner3, dir2);
+ Box3D::PerspectiveLine first_line (corners[0], dir1);
+ Box3D::PerspectiveLine second_line (corners[2], dir2);
NR::Maybe<NR::Point> ur = first_line.intersect(second_line);
- Box3D::PerspectiveLine third_line (corner1, dir2);
- Box3D::PerspectiveLine fourth_line (corner3, dir1);
+ Box3D::PerspectiveLine third_line (corners[0], dir2);
+ Box3D::PerspectiveLine fourth_line (corners[2], dir1);
NR::Maybe<NR::Point> ll = third_line.intersect(fourth_line);
// FIXME: How to handle the case if one of the intersections doesn't exist?
if (!ur) ur = NR::Point(0.0, 0.0);
if (!ll) ll = NR::Point(0.0, 0.0);
- corner2 = *ll;
- corner4 = *ur;
+ corners[1] = *ll;
+ corners[3] = *ur;
this->dir1 = dir1;
this->dir2 = dir2;
- // FIXME: More effective with array of corners
+ // FIXME: Can be made more concise
NR::Point tmp_pt;
for (unsigned int i=0; i < shift_count; i++) {
- tmp_pt = corner4;
- corner2 = corner1;
- corner3 = corner2;
- corner4 = corner3;
- corner1 = tmp_pt;
+ tmp_pt = corners[3];
+ corners[1] = corners[0];
+ corners[2] = corners[1];
+ corners[3] = corners[2];
+ corners[0] = tmp_pt;
}
}
Box3DFace::Box3DFace(Box3DFace const &box3dface)
{
- this->corner1 = box3dface.corner1;
- this->corner2 = box3dface.corner2;
- this->corner3 = box3dface.corner3;
- this->corner4 = box3dface.corner4;
- this->dir1 = box3dface.dir1;
- this->dir2 = box3dface.dir2;
+ for (int i = 0; i < 4; ++i) {
+ this->corners[i] = box3dface.corners[i];
+ }
+ this->dir1 = box3dface.dir1;
+ this->dir2 = box3dface.dir2;
}
NR::Point Box3DFace::operator[](unsigned int i)
{
- unsigned int index = i % 4;
- switch (index) {
- case 0: return corner1; break;
- case 1: return corner2; break;
- case 2: return corner3; break;
- case 3: return corner4; break;
- }
- // The following two lines are just to prevent a compiler warning ("control reaches
- // end of non-void function); they can be removed if desired
- g_message ("Error: This code line hould not be reached\n");
- return NR::Point (0, 0);
+ return corners[i % 4];
}
/**
gdouble height = sp_document_height(doc);
SPCurve *curve = sp_curve_new();
- sp_curve_moveto(curve, corner1[NR::X], height - corner1[NR::Y]);
- sp_curve_lineto(curve, corner2[NR::X], height - corner2[NR::Y]);
- sp_curve_lineto(curve, corner3[NR::X], height - corner3[NR::Y]);
- sp_curve_lineto(curve, corner4[NR::X], height - corner4[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",
- corner1[NR::X], height - corner1[NR::Y],
- corner2[NR::X], height - corner2[NR::Y],
- corner3[NR::X], height - corner3[NR::Y],
- corner4[NR::X], height - corner4[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 123d4cbbc9025d7253e4ba45af653fa910b94e22..124d51776ae756e32db780fd0c686f913ae6a62d 100644 (file)
--- a/src/box3d-face.h
+++ b/src/box3d-face.h
gchar * svg_repr_string();
private:
- NR::Point corner1;
- NR::Point corner2;
- NR::Point corner3;
- NR::Point corner4;
+ NR::Point corners[4];
Box3D::PerspDir dir1;
Box3D::PerspDir dir2;
diff --git a/src/box3d.cpp b/src/box3d.cpp
index 127ffa8483bb1056ee55f883e0ce665d91266395..af31ff1a1fb00f4c414af55f297e723303083eb8 100644 (file)
--- a/src/box3d.cpp
+++ b/src/box3d.cpp
static void
sp_3dbox_init(SP3DBox *box3d)
{
- box3d->face1 = Box3DFace (box3d);
- box3d->face2 = Box3DFace (box3d);
- box3d->face3 = Box3DFace (box3d);
- box3d->face4 = Box3DFace (box3d);
- box3d->face5 = Box3DFace (box3d);
- box3d->face6 = Box3DFace (box3d);
+ for (int i = 0; i < 6; ++i) {
+ box3d->faces[i] = Box3DFace (box3d);
+ }
}
static void
@@ -143,15 +140,13 @@ static Inkscape::XML::Node *sp_3dbox_write(SPObject *object, Inkscape::XML::Node
}
- box3d->face1.set_path_repr();
+ box3d->faces[0].set_path_repr();
if (bc->extruded) {
NR::Point corner1, corner2, corner3, corner4;
sp_3dbox_compute_specific_corners (bc, corner1, corner2, corner3, corner4);
- box3d->face2.set_path_repr();
- box3d->face3.set_path_repr();
- box3d->face4.set_path_repr();
- box3d->face5.set_path_repr();
- box3d->face6.set_path_repr();
+ for (int i = 0; i < 6; ++i) {
+ box3d->faces[i].set_path_repr();
+ }
}
if (((SPObjectClass *) (parent_class))->write) {
((SPObjectClass *) (parent_class))->write(object, repr, flags);
if (bc->extruded) {
sp_3dbox_compute_specific_corners (bc, corner1, corner2, corner3, corner4);
- box3d->face3.set_shape(bc->drag_origin, corner4, Box3D::Y, Box3D::Z);
- box3d->face3.set_curve();
- box3d->face4.set_shape(corner2, corner4, Box3D::X, Box3D::Z);
- box3d->face4.set_curve();
- box3d->face5.set_shape(bc->drag_origin, corner2, Box3D::X, Box3D::Y);
- box3d->face5.set_curve();
- box3d->face6.set_shape(bc->drag_ptB, corner4, Box3D::X, Box3D::Y);
- box3d->face6.set_curve();
-
- box3d->face2.set_shape(corner1, bc->drag_ptC, Box3D::Y, Box3D::Z);
- box3d->face2.set_curve();
+ box3d->faces[2].set_shape(bc->drag_origin, corner4, Box3D::Y, Box3D::Z);
+ box3d->faces[2].set_curve();
+ box3d->faces[3].set_shape(corner2, corner4, Box3D::X, Box3D::Z);
+ box3d->faces[3].set_curve();
+ box3d->faces[4].set_shape(bc->drag_origin, corner2, Box3D::X, Box3D::Y);
+ box3d->faces[4].set_curve();
+ box3d->faces[5].set_shape(bc->drag_ptB, corner4, Box3D::X, Box3D::Y);
+ box3d->faces[5].set_curve();
+
+ box3d->faces[1].set_shape(corner1, bc->drag_ptC, Box3D::Y, Box3D::Z);
+ box3d->faces[1].set_curve();
}
- box3d->face1.set_shape(bc->drag_origin, bc->drag_ptB, Box3D::X, Box3D::Z);
- box3d->face1.set_curve();
+ box3d->faces[0].set_shape(bc->drag_origin, bc->drag_ptB, Box3D::X, Box3D::Z);
+ box3d->faces[0].set_curve();
}
diff --git a/src/box3d.h b/src/box3d.h
index c83194fa0b259856afe35e447ed3d217e93fb854..33284810392fcf0d525746d4e40bdd1fbcab30dd 100644 (file)
--- a/src/box3d.h
+++ b/src/box3d.h
#include "inkscape.h"
#include "perspective-line.h"
-//#include "display/curve.h"
#include "sp-item-group.h"
#include "sp-path.h"
struct SP3DBox : public SPGroup {
- Box3DFace face1;
- Box3DFace face2;
- Box3DFace face3;
- Box3DFace face4;
- Box3DFace face5;
- Box3DFace face6;
+ Box3DFace faces[6];
};
struct SP3DBoxClass {