summaryrefslogtreecommitdiffstats
path: root/src/display/nr-3dutils.cpp
diff options
context:
space:
mode:
authorKrzysztof Kosi??ski <tweenk.pl@gmail.com>2010-08-04 03:45:58 +0000
committerKrzysztof KosiƄski <tweenk.pl@gmail.com>2010-08-04 03:45:58 +0000
commit30884b9e814d7baaa2299803e8cb76cf203ca084 (patch)
tree579df4681a79a963913cea8d4891405d74280615 /src/display/nr-3dutils.cpp
parentFix pattern viewBox (diff)
downloadinkscape-30884b9e814d7baaa2299803e8cb76cf203ca084.tar.gz
inkscape-30884b9e814d7baaa2299803e8cb76cf203ca084.zip
Wholesale cruft removal part 1
(bzr r9508.1.44)
Diffstat (limited to 'src/display/nr-3dutils.cpp')
-rw-r--r--src/display/nr-3dutils.cpp125
1 files changed, 3 insertions, 122 deletions
diff --git a/src/display/nr-3dutils.cpp b/src/display/nr-3dutils.cpp
index 89c21940a..1d92d3ec9 100644
--- a/src/display/nr-3dutils.cpp
+++ b/src/display/nr-3dutils.cpp
@@ -11,134 +11,15 @@
#include <glib/gmessages.h>
-#include "libnr/nr-pixblock.h"
#include "display/nr-3dutils.h"
#include <cmath>
+#include <2geom/point.h>
+#include <2geom/matrix.h>
namespace NR {
-#define BEGIN 0 // TOP or LEFT
-#define MIDDLE 1
-#define END 2 // BOTTOM or RIGHT
-
-#define START(v) ((v)==BEGIN? 1 : 0)
-#define FINISH(v) ((v)==END? 1 : 2)
-
-signed char K_X[3][3][3][3] = {
- //K_X[TOP]
- {
- //K_X[TOP][LEFT]
- {
- { 0, 0, 0},
- { 0, -2, 2},
- { 0, -1, 1}
- },
- {
- { 0, 0, 0},
- {-2, 0, 2},
- {-1, 0, 1}
- },
- {
- { 0, 0, 0},
- {-2, 2, 0},
- {-1, 1, 0}
- }
- },
- //K_X[MIDDLE]
- {
- //K_X[MIDDLE][LEFT]
- {
- { 0, -1, 1},
- { 0, -2, 2},
- { 0, -1, 1}
- },
- {
- {-1, 0, 1},
- {-2, 0, 2},
- {-1, 0, 1}
- },
- {
- {-1, 1, 0},
- {-2, 2, 0},
- {-1, 1, 0}
- }
- },
- //K_X[BOTTOM]
- {
- //K_X[BOTTOM][LEFT]
- {
- { 0, -1, 1},
- { 0, -2, 2},
- { 0, 0, 0}
- },
- {
- {-1, 0, 1},
- {-2, 0, 2},
- { 0, 0, 0}
- },
- {
- {-1, 1, 0},
- {-2, 2, 0},
- { 0, 0, 0}
- }
- }
-};
-
-//K_Y is obtained by transposing K_X globally and each of its components
-
-gdouble FACTOR_X[3][3] = {
- {2./3, 1./3, 2./3},
- {1./2, 1./4, 1./2},
- {2./3, 1./3, 2./3}
-};
-
-//FACTOR_Y is obtained by transposing FACTOR_X
-
-inline
-int get_carac(int i, int len, int delta) {
- if (i < delta)
- return BEGIN;
- else if (i > len - 1 - delta)
- return END;
- else
- return MIDDLE;
-}
-
-//assumes in is RGBA
-//should be made more resistant
-void compute_surface_normal(Fvector &N, gdouble ss, NRPixBlock *in, int i, int j, int dx, int dy) {
- int w = in->area.x1 - in->area.x0;
- int h = in->area.y1 - in->area.y0;
- int k, l, alpha_idx, alpha_idx_y;
- int x_carac, y_carac;
- gdouble alpha;
- gdouble accu_x;
- gdouble accu_y;
- unsigned char *data = NR_PIXBLOCK_PX (in);
- g_assert(NR_PIXBLOCK_BPP(in) == 4);
- x_carac = get_carac(j, w, dx); //LEFT, MIDDLE or RIGHT
- y_carac = get_carac(i, h, dy); //TOP, MIDDLE or BOTTOM
- alpha_idx = 4*(i*w + j);
- accu_x = 0;
- accu_y = 0;
- for (k = START(y_carac); k <= FINISH(y_carac); k++) {
- alpha_idx_y = alpha_idx + 4*(k-1)*dy*w;
- for (l = START(x_carac); l <= FINISH(x_carac); l++) {
- alpha = (data + alpha_idx_y + 4*dx*(l-1))[3];
- accu_x += K_X[y_carac][x_carac][k][l] * alpha;
- accu_y += K_X[x_carac][y_carac][l][k] * alpha;
- }
- }
- ss /= 255.0; // Correction for scale of pixel values
- N[X_3D] = -ss * FACTOR_X[y_carac][x_carac] * accu_x / dx;
- N[Y_3D] = -ss * FACTOR_X[x_carac][y_carac] * accu_y / dy;
- N[Z_3D] = 1.0;
- normalize_vector(N);
- //std::cout << "(" << N[X_3D] << ", " << N[Y_3D] << ", " << N[Z_3D] << ")" << std::endl;
-}
-
void convert_coord(gdouble &x, gdouble &y, gdouble &z, Geom::Matrix const &trans) {
- Point p = Point(x, y);
+ Geom::Point p = Geom::Point(x, y);
p *= trans;
x = p[Geom::X];
y = p[Geom::Y];