~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/draw/paint/draw_shade.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**@(#)
  2 **/
  3 #include <math.h>
  4 #include <tina/sys.h>
  5 #include <tina/sysfuncs.h>
  6 #include <tina/math.h>
  7 #include <tina/mathfuncs.h>
  8 #include <tina/vision.h>
  9 #include <tina/visionfuncs.h>
 10 #include <tina/tv.h>
 11 #include <tina/draw.h>
 12 #include <tina/drawfuncs.h>
 13 #include <tina/tvfuncs.h>
 14 
 15 void    zbuff_image_terrain3_old(Tv * tv, Vec3 ** p, char **mask, int m, int n, Imrect * image)
 16 
 17 
 18 
 19 /* m rows and n cols */
 20 
 21 {
 22     int     i, j;
 23     int   **g;                  /* shadding model */
 24 
 25     if (tv == NULL || p == NULL)
 26         return;
 27 
 28     g = iarray_alloc(0, 0, m, n);
 29 
 30     for (i = 0; i < m; ++i)
 31         for (j = 0; j < n; ++j)
 32             if (mask == NULL || mask[i][j])
 33             {
 34                 g[i][j] = im_sub_pix(image, vec3_y(p[i][j]), vec3_x(p[i][j]));
 35                 if (g[i][j] > 255)
 36                     g[i][j] = 255;
 37                 if (g[i][j] < 0)
 38                     g[i][j] = 0;
 39             }
 40     m--;
 41     n--;
 42     for (i = 0; i < m; ++i)
 43         for (j = 0; j < n; ++j)
 44         {
 45             if (mask != NULL && (!mask[i][j] || !mask[i + 1][j + 1] ||
 46                                  !mask[i][j + 1] || !mask[i + 1][j]))
 47                 continue;
 48 
 49             tv_zbuff_interp_quad3(tv,
 50                    p[i][j], p[i + 1][j], p[i][j + 1], p[i + 1][j + 1],
 51                   g[i][j], g[i + 1][j], g[i][j + 1], g[i + 1][j + 1]);
 52         }
 53 }
 54 
 55 void    zbuff_image_terrain3(Tv * tv, Vec3 ** p, char **mask, int m, int n, Imrect * image)
 56 
 57 
 58 
 59 /* m rows and n cols */
 60 
 61 {
 62     int     i, j;
 63 
 64     if (tv == NULL || p == NULL)
 65         return;
 66 
 67     m--;
 68     n--;
 69     for (i = 0; i < m; ++i)
 70         for (j = 0; j < n; ++j)
 71         {
 72             if (mask != NULL && (!mask[i][j] || !mask[i + 1][j + 1] ||
 73                                  !mask[i][j + 1] || !mask[i + 1][j]))
 74                 continue;
 75 
 76             tv_zbuff_image_quad3(tv,
 77                    p[i][j], p[i + 1][j], p[i][j + 1], p[i + 1][j + 1],
 78                                  vec3_y(p[i][j]), vec3_y(p[i + 1][j]),
 79                          vec3_y(p[i][j + 1]), vec3_y(p[i + 1][j + 1]),
 80                                  vec3_x(p[i][j]), vec3_x(p[i + 1][j]),
 81                          vec3_x(p[i][j + 1]), vec3_x(p[i + 1][j + 1]),
 82                                  image);
 83         }
 84 }
 85 
 86 void    zbuff_shade_terrain3(Tv * tv, Vec3 ** p, char **mask, int m, int n)
 87 
 88 
 89 
 90 /* m rows and n cols */
 91 {
 92     int     i, j;
 93     int   **g;                  /* shadding model */
 94 
 95     if (tv == NULL || p == NULL)
 96         return;
 97 
 98     g = iarray_alloc(0, 0, m, n);
 99 
100     for (i = 0; i < m; ++i)
101         for (j = 0; j < n; ++j)
102         {
103             Vec3    vx = {Vec3_id};
104             Vec3    vy = {Vec3_id};
105             Vec3    normal = {Vec3_id};
106 
107             if (mask != NULL && !mask[i][j])
108                 continue;
109 
110             if (i == m - 1 || (mask != NULL && !mask[i + 1][j]))
111                 vy = vec3_diff(p[i][j], p[i - 1][j]);
112             else
113                 vy = vec3_diff(p[i + 1][j], p[i][j]);
114 
115             if (j == n - 1 || (mask != NULL && !mask[i][j + 1]))
116                 vx = vec3_diff(p[i][j], p[i][j - 1]);
117             else
118                 vx = vec3_diff(p[i][j + 1], p[i][j]);
119 
120             normal = vec3_unit(vec3_cross(vx, vy));     /* surface normal at i,j */
121 
122             g[i][j] = (int)(64.0 + 191.0 * fabs(vec3_dot(normal, tv->ez3)));
123             if (g[i][j] > 255)
124                 g[i][j] = 255;
125         }
126 
127     m--;
128     n--;
129     for (i = 0; i < m; ++i)
130         for (j = 0; j < n; ++j)
131         {
132             if (mask != NULL && (!mask[i][j] || !mask[i + 1][j + 1] ||
133                                  !mask[i][j + 1] || !mask[i + 1][j]))
134                 continue;
135 
136             tv_zbuff_interp_quad3(tv,
137                    p[i][j], p[i + 1][j], p[i][j + 1], p[i + 1][j + 1],
138                   g[i][j], g[i + 1][j], g[i][j + 1], g[i + 1][j + 1]);
139         }
140 }
141 
142 
143 /* A 3 vector of VEC3 */
144 void    zbuff_shade_tri3(Tv * tv, Vec3 * tri)
145 {
146     Ipos    p[3] = {{Ipos_id}, {Ipos_id}, {Ipos_id}};
147     Vec3    normal = {Vec3_id};
148     int     i, z[3];
149     double  gl, g[3];
150 
151     if (tv == NULL)
152         return;
153 
154     normal = vec3_unitcross(vec3_diff(tri[0], tri[1]), vec3_diff(tri[1], tri[2]));
155 
156     gl = 0.4 + 0.6 * fabs(vec3_dot(normal, tv->ez3));
157 
158     for (i = 0; i < 3; ++i)
159     {
160         p[i] = tv_zbuff_proj3(tv, tri[i], &z[i]);
161         g[i] = gl;
162     }
163 
164     tv_zbuff_interp_convex_poly(tv, 3, p, z, g);
165 }
166 
167 void    zbuff_shade_cone(Tv * tv, Cone * cone)
168 {
169     double  t1, t2;
170     Vec3    cone_point();
171 
172     if (cone == NULL)
173         return;
174 
175     t1 = cone->c1->conic->t1;
176     t2 = cone->c1->conic->t2;
177     tv_zbuff_surf3(tv, cone_point, (Vec3(*) ()) NULL, (void *) cone, 0.0, t1, 1.0, t2, 1, 4, 10);
178 }
179 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.