1 #ifndef __NR_3DUTILS_H__
2 #define __NR_3DUTILS_H__
4 /*
5 * 3D utils. Definition of gdouble vectors of dimension 3 and of some basic
6 * functions.
7 *
8 * Authors:
9 * Jean-Rene Reinhard <jr@komite.net>
10 *
11 * Copyright (C) 2007 authors
12 *
13 * Released under GNU GPL, read the file 'COPYING' for more information
14 */
16 #include <gdk/gdktypes.h>
18 struct NRPixBlock;
20 namespace NR {
22 struct Matrix;
24 #define X_3D 0
25 #define Y_3D 1
26 #define Z_3D 2
28 /**
29 * a type of 3 gdouble components vectors
30 */
31 typedef gdouble Fvector[3];
33 /**
34 * The eye vector
35 */
36 const static Fvector EYE_VECTOR = {0, 0, 1};
38 /**
39 * returns the euclidian norm of the vector v
40 *
41 * \param v a reference to a vector with double components
42 * \return the euclidian norm of v
43 */
44 gdouble norm(const Fvector &v);
46 /**
47 * Normalizes a vector
48 *
49 * \param v a reference to a vector to normalize
50 */
51 void normalize_vector(Fvector &v);
53 /**
54 * Computes the scalar product between two Fvectors
55 *
56 * \param a a Fvector reference
57 * \param b a Fvector reference
58 * \return the scalar product of a and b
59 */
60 gdouble scalar_product(const Fvector &a, const Fvector &b);
62 /**
63 * Computes the normalized sum of two Fvectors
64 *
65 * \param r a Fvector reference where we store the result
66 * \param a a Fvector reference
67 * \param b a Fvector reference
68 */
69 void normalized_sum(Fvector &r, const Fvector &a, const Fvector &b);
71 /**
72 * Computes the unit suface normal vector of surface given by "in" at (i, j)
73 * and store it into N. "in" is a (NRPixBlock *) in mode RGBA but only the alpha
74 * channel is considered as a bump map. ss is the altitude when for the alpha
75 * value 255. dx and dy are the deltas used to compute in our discrete setting
76 *
77 * \param N a reference to a Fvector in which we store the unit surface normal
78 * \param ss the surface scale
79 * \param in a NRPixBlock * whose alpha channel codes the surface
80 * \param i the x coordinate of the point at which we compute the normal
81 * \param j the y coordinate of the point at which we compute the normal
82 * \param dx the delta used in the x coordinate
83 * \param dy the delta used in the y coordinate
84 */
85 void compute_surface_normal(Fvector &N, gdouble ss, NRPixBlock *in, int i, int j, int dx, int dy);
87 /**
88 * Applies the transformation matrix to (x, y, z). This function assumes that
89 * trans[0] = trans[3]. x and y are transformed according to trans, z is
90 * multiplied by trans[0].
91 *
92 * \param x a reference to a x coordinate
93 * \param y a reference to a y coordinate
94 * \param z a reference to a z coordinate
95 * \param z a reference to a transformation matrix
96 */
97 void convert_coord(gdouble &x, gdouble &y, gdouble &z, Matrix const &trans);
99 } /* namespace NR */
101 #endif /* __NR_3DUTILS_H__ */
102 /*
103 Local Variables:
104 mode:c++
105 c-file-style:"stroustrup"
106 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
107 indent-tabs-mode:nil
108 fill-column:99
109 End:
110 */
111 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :