nr-3dutils.cpp revision af0732a2bf24fbea12a085b855224577e7101851
/*
* 3D utils.
*
* Authors:
* Jean-Rene Reinhard <jr@komite.net>
*
* Copyright (C) 2007 authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include <glib/gmessages.h>
#include "libnr/nr-pixblock.h"
#include "libnr/nr-matrix.h"
#include "display/nr-3dutils.h"
#include <cmath>
namespace NR {
#define BEGIN 0 // TOP or LEFT
#define MIDDLE 1
//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
{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
if (i < delta)
return BEGIN;
return END;
else
return MIDDLE;
}
//assumes in is RGBA
//should be made more resistant
int k, l, alpha_idx, alpha_idx_y;
alpha_idx = 4*(i*w + j);
accu_x = 0;
accu_y = 0;
}
}
N[Z_3D] = 1;
normalize_vector(N);
//std::cout << "(" << N[X_3D] << ", " << N[Y_3D] << ", " << N[Z_3D] << ")" << std::endl;
}
p *= trans;
x = p[X];
y = p[Y];
z *= trans[0];
}
}
void normalize_vector(Fvector &v) {
int i, j;
//TODO test nv == 0
for (j = 0; j < 3; j++) {
v[j] /= nv;
}
}
}
normalize_vector(r);
}
}/* namespace NR */
/*
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:encoding=utf-8:textwidth=99 :