index c8171ccd2c519a505d5d90c55d4c97090fcfc9b4..ffeaebe8e57fa823fb223d40b9e8b8c9ecc2a764 100644 (file)
/*
* 3D utils.
- *
+ *
* Authors:
* Jean-Rene Reinhard <jr@komite.net>
*
#include <glib/gmessages.h>
#include "libnr/nr-pixblock.h"
-#include "libnr/nr-matrix.h"
#include "display/nr-3dutils.h"
#include <cmath>
#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]
{
{ 0, -2, 2},
{ 0, -1, 1}
},
- {
+ {
{ 0, 0, 0},
{-2, 0, 2},
{-1, 0, 1}
- },
- {
+ },
+ {
{ 0, 0, 0},
{-2, 2, 0},
{-1, 1, 0}
{ 0, -2, 2},
{ 0, -1, 1}
},
- {
+ {
{-1, 0, 1},
{-2, 0, 2},
{-1, 0, 1}
- },
- {
+ },
+ {
{-1, 1, 0},
{-2, 2, 0},
{-1, 1, 0}
{ 0, -2, 2},
{ 0, 0, 0}
},
- {
+ {
{-1, 0, 1},
{-2, 0, 2},
{ 0, 0, 0}
- },
- {
+ },
+ {
{-1, 1, 0},
{-2, 2, 0},
{ 0, 0, 0}
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) {
@@ -116,7 +115,7 @@ void compute_surface_normal(Fvector &N, gdouble ss, NRPixBlock *in, int i, int j
gdouble accu_x;
gdouble accu_y;
unsigned char *data = NR_PIXBLOCK_PX (in);
- g_assert(in->mode == NR_PIXBLOCK_MODE_R8G8B8A8P);
+ 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);
@@ -132,7 +131,7 @@ void compute_surface_normal(Fvector &N, gdouble ss, NRPixBlock *in, int i, int j
}
N[X_3D] = -1 * ss * FACTOR_X[y_carac][x_carac] * accu_x / dx;
N[Y_3D] = -1 * ss * FACTOR_X[x_carac][y_carac] * accu_y / dy;
- N[Z_3D] = 1;
+ N[Z_3D] = 1;
normalize_vector(N);
//std::cout << "(" << N[X_3D] << ", " << N[Y_3D] << ", " << N[Z_3D] << ")" << std::endl;
}
}
gdouble norm(const Fvector &v) {
- return sqrt(v[X_3D]*v[X_3D] + v[Y_3D]*v[Y_3D] + v[Z_3D]*v[Z_3D]);
+ return sqrt(v[X_3D]*v[X_3D] + v[Y_3D]*v[Y_3D] + v[Z_3D]*v[Z_3D]);
}
void normalize_vector(Fvector &v) {
- int i, j;
gdouble nv = norm(v);
//TODO test nv == 0
- for (j = 0; j < 3; j++) {
+ for (int j = 0; j < 3; j++) {
v[j] /= nv;
}
-}
+}
gdouble scalar_product(const Fvector &a, const Fvector &b) {
return a[X_3D] * b[X_3D] +