1 /*
2 
3 Copyright (C) 2015-2018 Night Dive Studios, LLC.
4 
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 
18 */
19 /*
20  * $Source: n:/project/lib/src/2d/RCS/genvcply.c $
21  * $Revision: 1.4 $
22  * $Author: baf $
23  * $Date: 1994/02/14 20:38:31 $
24  *
25  * This file is part of the 2d library.
26  *
27  * $Log: genvcply.c $
28  * Revision 1.4  1994/02/14  20:38:31  baf
29  * Added dummy parameter to cpoly and spoly routines, for uniformity needed by 3D.
30  *
31  * Revision 1.3  1993/10/19  10:14:04  kaboom
32  * Updated calls to polygon routines for new arguments.
33  *
34  * Revision 1.2  1993/10/08  01:15:52  kaboom
35  * Changed quotes in #include lines to angle brackets for Watcom.
36  *
37  * Revision 1.1  1993/08/19  21:52:29  jaemz
38  * Initial revision
39  */
40 
41 #include "grcply.h"
42 #include "plytyp.h"
43 #include "scrdat.h"
44 
gen_vox_cpoly(fix x[4],fix y[4],fix dz[3],int near_ver,grs_bitmap * col,grs_bitmap * ht)45 void gen_vox_cpoly(fix x[4],fix y[4],fix dz[3],int near_ver,grs_bitmap *col,grs_bitmap *ht)
46 {
47    int du,dv,initu,endu,initv,endv;
48    int i,j;
49    int c;
50    long z;
51    int far_ver;
52 
53    /* Test of broadcasting system */
54    fix fdxdu,fdydu,fdxdv,fdydv;
55    fix fcurx,fcury;
56    fix fdxdz,fdydz;
57    fix oldcurx;
58    fix oldcury;
59    fix vlist[20];
60    grs_vertex *vpl[4];
61 //   fix vlist[8];
62 //   grs_rgb clist[4];
63    int xp[2][80];
64    int yp[2][80];
65    ulong pp[2][80];
66    int currow = 0;
67 
68    vpl[0]=(grs_vertex *)vlist; vpl[1]=(grs_vertex *)(vlist+5);
69    vpl[2]=(grs_vertex *)(vlist+10); vpl[3]=(grs_vertex *)(vlist+15);
70    far_ver = (near_ver+2)%4;
71 
72    /* How to scan given near_ver */
73    if (near_ver == 0 || near_ver == 3) { initu = col->w -1; du = -1; endu = -1; }
74    else { initu = 0; du = 1; endu = col->w ; }
75    if (near_ver < 2) { initv = col->h-1; dv = -1; endv = -1; }
76    else { initv = 0; dv = 1; endv = col->h; }
77 
78    fdxdu = (x[1]-x[0])/(col->w - 1);
79    fdydu = (y[1]-y[0])/(col->w - 1);
80    fdxdv = (x[2]-x[1])/(col->w - 1);
81    fdydv = (y[2]-y[1])/(col->w - 1);
82 
83    fdxdz = dz[0];
84    fdydz = dz[1];
85 
86    oldcurx = fcurx = x[0] + fdxdu*initu + fdxdv*initv;
87    oldcury = fcury = y[0] + fdydu*initu + fdydv*initv;
88 
89    fdxdu *= du;
90    fdydu *= du;
91    fdxdv *= dv;
92    fdydv *= dv;
93 
94    for(j=initv;j!=endv;j+=dv) {
95       for(i=initu;i!=endu;i+=du) {
96          c = *( col->bits +i +j*col->row);
97          //c = get_pal(col,i,j);
98          if (c != 0) {
99             z = *(ht->bits + i + j*col->row);
100             //z = get_pal(ht,i,j);
101             /* Put in array */
102             xp[currow][i] = (fcurx + fdxdz*z);
103             yp[currow][i] = (fcury + fdydz*z);
104             pp[currow][i] = c;
105          }
106          else {
107             pp[currow][i] = 0;
108          }
109          fcurx += fdxdu;
110          fcury += fdydu;
111       }
112       if (currow==1) {
113          /* plot the triangles */
114          for(i=initu;i!=endu;i+=du) {
115             /* check for any transparents */
116             if (pp[0][i]*pp[1][i]*pp[1][i+du]*pp[0][i+du] != 0) {
117 //               vlist[0] = xp[0][i];
118 //               vlist[1] = yp[0][i];
119 //               clist[0] = grd_bpal[pp[0][i]];
120                vpl[0]->x = xp[0][i];
121                vpl[0]->y = yp[0][i];
122                vpl[0]->u = fix_make(grd_pal[pp[0][i]+0],0x8000);
123                vpl[0]->v = fix_make(grd_pal[pp[0][i]+1],0x8000);
124                vpl[0]->w = fix_make(grd_pal[pp[0][i]+2],0x8000);
125 
126 //               vlist[4] = xp[1][i+du];
127 //               vlist[5] = yp[1][i+du];
128 //               clist[2] = grd_bpal[pp[1][i+du]];
129                vpl[2]->x = xp[1][i+du];
130                vpl[2]->y = yp[1][i+du];
131                vpl[2]->u = fix_make(grd_pal[pp[1][i+du]+0],0x8000);
132                vpl[2]->v = fix_make(grd_pal[pp[1][i+du]+1],0x8000);
133                vpl[2]->w = fix_make(grd_pal[pp[1][i+du]+2],0x8000);
134 
135                if (du*dv > 0) {
136 //                  vlist[2] = xp[0][i+du];
137 //                  vlist[3] = yp[0][i+du];
138 //                  clist[1] = grd_bpal[pp[0][i+du]];
139                   vpl[1]->x = xp[0][i+du];
140                   vpl[1]->y = yp[0][i+du];
141                   vpl[1]->u = fix_make(grd_pal[pp[0][i+du]+0],0x8000);
142                   vpl[1]->v = fix_make(grd_pal[pp[0][i+du]+1],0x8000);
143                   vpl[1]->w = fix_make(grd_pal[pp[0][i+du]+2],0x8000);
144 
145 //                  vlist[6] = xp[1][i];
146 //                  vlist[7] = yp[1][i];
147 //                  clist[3] = grd_bpal[pp[1][i]];
148                   vpl[3]->x = xp[1][i+du];
149                   vpl[3]->y = yp[1][i+du];
150                   vpl[3]->u = fix_make(grd_pal[pp[1][i+du]+0],0x8000);
151                   vpl[3]->v = fix_make(grd_pal[pp[1][i+du]+1],0x8000);
152                   vpl[3]->w = fix_make(grd_pal[pp[1][i+du]+2],0x8000);
153                }
154                else {
155 //                  vlist[6] = xp[0][i+du];
156 //                  vlist[7] = yp[0][i+du];
157 //                  clist[3] = grd_bpal[pp[0][i+du]];
158                   vpl[3]->x = xp[0][i+du];
159                   vpl[3]->y = yp[0][i+du];
160                   vpl[3]->u = fix_make(grd_pal[pp[0][i+du]+0],0x8000);
161                   vpl[3]->v = fix_make(grd_pal[pp[0][i+du]+1],0x8000);
162                   vpl[3]->w = fix_make(grd_pal[pp[0][i+du]+2],0x8000);
163 
164 //                  vlist[2] = xp[1][i];
165 //                  vlist[3] = yp[1][i];
166 //                  clist[1] = grd_bpal[pp[1][i]];
167                   vpl[1]->x = xp[1][i];
168                   vpl[1]->y = yp[1][i];
169                   vpl[1]->u = fix_make(grd_pal[pp[1][i]+0],0x8000);
170                   vpl[1]->v = fix_make(grd_pal[pp[1][i]+1],0x8000);
171                   vpl[1]->w = fix_make(grd_pal[pp[1][i]+2],0x8000);
172                 }
173 
174                gr_ucpoly(0,4,vpl);
175             }
176          }
177          /* copy from 1 to 0 */
178          for(i=initu;i!=endu;i+=du) {
179             xp[0][i] = xp[1][i];
180             yp[0][i] = yp[1][i];
181             pp[0][i] = pp[1][i];
182          }
183       }
184       else ++currow;
185       fcurx = (oldcurx += fdxdv);
186       fcury = (oldcury += fdydv);
187    }
188 }
189 
190 
191