box3d-face.cpp revision 492de225e9b11f35d98b6b75efa58e115ee688fa
#define __SP_3DBOX_FACE_C__
/*
* Face of a 3D box ('perspectivic rectangle')
*
* Authors:
* Maximilian Albert <Anhalter42@gmx.de>
*
* Copyright (C) 2007 authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "box3d-face.h"
#include "prefs-utils.h"
// FIXME: It's quite redundant to pass the box plus the corners plus the axes. At least the corners can
// theoretically be reconstructed from the box and the axes, but in order to do this we need
// access to box->corners, which is not possible if we only have a forward declaration of SP3DBox
// in box3d-face.h. (But we can't include box3d.h itself because the latter already includes
// box3d-face.h).
{
/*
Box3D::Axis axis = (rel_pos == Box3D::FRONT ? Box3D::NONE : Box3D::third_axis_direction (plane));
set_corners (box->corners[axis],
box->corners[axis ^ dir1],
box->corners[axis ^ dir1 ^ dir2],
box->corners[axis ^ dir2]);
*/
set_corners (A, B, C, D);
}
{
for (int i = 0; i < 4; ++i) {
if (this->corners[i]) {
//delete this->corners[i];
}
}
}
{
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] = ul;
if (!pt_align) {
corners[2] = lr;
} else {
if (align_along_PL) {
Box3D::Axis dir3 = Box3D::third_axis_direction (dir1, dir2);
Box3D::Line line1(*Box3D::Perspective3D::current_perspective->get_vanishing_point(dir1), lr);
Box3D::Line line2(*pt_align, *Box3D::Perspective3D::current_perspective->get_vanishing_point(dir3));
corners[2] = *line1.intersect(line2);
} else {
corners[2] = Box3D::Line(*pt_align, *Box3D::Perspective3D::current_perspective->get_vanishing_point(dir1)).closest_to(lr);
}
}
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 (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?
// Maybe set them equal to the corresponding VPs?
if (!ur) ur = NR::Point(0.0, 0.0);
if (!ll) ll = NR::Point(0.0, 0.0);
corners[1] = *ll;
corners[3] = *ur;
this->dir1 = dir1;
this->dir2 = dir2;
// FIXME: Can be made more concise
NR::Point tmp_pt;
for (unsigned int i=0; i < shift_count; i++) {
tmp_pt = corners[3];
corners[1] = corners[0];
corners[2] = corners[1];
corners[3] = corners[2];
corners[0] = tmp_pt;
}
}
***/
{
for (int i = 0; i < 4; ++i) {
}
}
/**
* Construct a 3D box face with opposite corners A and C whose sides are directed
* along axis1 and axis2. The corners have the following order:
*
* A = corners[0] --> along axis1 --> B = corners[1] --> along axis2 --> C = corners[2]
* --> along axis1 --> D = corners[3] --> along axis2 --> D = corners[0].
*
* Note that several other functions rely on this precise order.
*/
/***
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;
if (!SP_IS_3DBOX_CONTEXT(inkscape_active_event_context()))
return;
SP3DBoxContext *bc = SP_3DBOX_CONTEXT(inkscape_active_event_context());
Box3D::PerspectiveLine line1 (A, axis1, Box3D::Perspective3D::current_perspective);
Box3D::PerspectiveLine line2 (C, axis2, Box3D::Perspective3D::current_perspective);
NR::Maybe<NR::Point> B = line1.intersect(line2);
Box3D::PerspectiveLine line3 (*corners[0], axis2, Box3D::Perspective3D::current_perspective);
Box3D::PerspectiveLine line4 (*corners[2], axis1, Box3D::Perspective3D::current_perspective);
NR::Maybe<NR::Point> D = line3.intersect(line4);
// FIXME: How to handle the case if one of the intersections doesn't exist?
// Maybe set them equal to the corresponding VPs?
if (!D) D = NR::Point(0.0, 0.0);
if (!B) B = NR::Point(0.0, 0.0);
*corners[1] = *B;
*corners[3] = *D;
this->dir1 = axis1;
this->dir2 = axis2;
}
***/
{
return *corners[i % 4];
}
/**
* Append the curve's path as a child to the given 3D box (since SP3DBox
* is derived from SPGroup, so we can append children to its svg representation)
*/
{
if (this->path) {
//g_print ("Path already exists. Returning ...\n");
return;
}
if (existing_path != NULL) {
// no need to create a new path
this->path = existing_path;
return;
}
/* create new path for face */
Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(SP_OBJECT(parent_box3d)));
/* set the correct style */
}
{
}
// to avoid "flashing" during the initial dragging process, we make the rear face invisible in this case
return;
}
/* use last used style */
} else {
/* use default style */
}
}
/**
* Write the path's "d" attribute to the SVG representation.
*/
void Box3DFace::set_path_repr()
{
}
{
return;
}
}
{
break;
break;
break;
default:
break;
}
}
{
g_warning ("Invalid description of 3D box face.\n");
return -1;
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :