home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / grafik / tc_3d / tc-16.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-13  |  19.6 KB  |  469 lines

  1. /* TC-16.C */
  2. /* Demonstrates package design and using a computer-shaped
  3.     3d solid parallelepiped (box) using the plain equation
  4.     method of hidden surface removal and the sirfaces normal
  5.     method of halftone shading */
  6.  
  7. /* ----------------------------------------------------------------------- */
  8. /* INCLUDE FILES */
  9. #include <process.h>
  10. #include <bios.h>
  11. #include <stdio.h>
  12. #include <graphics.h>
  13. #include <math.h>
  14.  
  15. /* ----------------------------------------------------------------------- */
  16. /* DECLARATIONS */
  17.  
  18. float        x=0.0,y=0.0,z=0.0;                                              /* world coordinates */
  19. float        x1=0.0,x2=0.0,x3=0.0;                                        /* polygon vertices */
  20. float        y01=0.0,y2=0.0,y3=0.0;                                        /* polygon vertices */
  21. float        z1=0.0,z2=0.0,z3=0.0;                                        /* polygon vertices */
  22. float        sx1=0.0,sx2=0.0,sx3=0.0,sx4=0.0,sx5=0.0;                /* display coordinaes */
  23. float        sy1=0.0,sy2=0.0,sy3=0.0,sy4=0.0,sy5=0.0;                /* display coordinates */
  24. float        sx=0.0,sy=0.0;                                                    /* output of 3d perspective formulas */
  25. float        xa=0.0,ya=0.0,za=0.0;                                        /* temporary values in 3d formulas */
  26. float        d=1200.0;                                                        /* angular perspective value */
  27. double    r1=5.98319;                                                        /* yaw angle in radians */
  28. double    r2=6.48319;                                                        /* roll angle in radians */
  29. double    r3=5.90008;                                                        /* pitch angle in radians */
  30. double    sr1=0.0,sr2=0.0,sr3=0.0;                                    /* sine rotation factors */
  31. double    cr1=0.0,cr2=0.0,cr3=0.0;                                    /* cosine rotation factors */
  32. float        mx=-8.0,my=5.0,mz=-350.0;                                    /* viewpoint position */
  33. int        maxx=639,minx=0,maxy=199,miny=0;                            /* scaling viewport */
  34. float        screen_x=639,screen_y=199;                                    /* dimensions of screen mode */
  35. int        C0=0,C1=1,C2=2,C3=3,C4=4,C5=5,C6=6,C7=7,C8=8,        /* color varariables */
  36.             C9=9,C10=10,C11=11,C12=12,C13=13,C14=14,C15=15,
  37.             mode_flag=0;
  38. float        rx=0.0,ry=0.0;                                                    /* scaling values used in mapping routine */
  39. int        t=0,t1=0,t2=0;                                                    /* loop counters */
  40. int        p1=0;                                                                /* array indexer */
  41. int        key_matte_clr=6;                                                /* exclusive key matte color */
  42. int        edge_clr=7;                                                        /* used to draw edges on models */
  43. int        solid_clr=0;                                                    /* used to fill surfaces on solid models */
  44. float        x_res,y_res;                                                    /* used for 2d mappinf from 640*480 template */
  45. float        sp=0.0;                                                            /* visibility factor in hidden surface routine */
  46. float        sp1=0.0,sp2=0.0,sp3=0.0;                                    /* temporary values of sp */
  47.  
  48. int        NORM_HUE=0;                                                        /* halftoning color */
  49. int        BASE_CLR=0;                                                        /* prep cooor for dithering */
  50. int        CC4=0;                                                            /* underlay color for dithering */
  51. int        CC5=0;                                                            /* overlay color for dithering */
  52. unsigned short CC6=0xffff;                                                /* pattern for dithering */
  53. float        xx1=.4,yy1=.70771,zz1=.70771;                                /* location of light source - elevation 45 degrees, compas 135 degrees {{REDIFINED !!}}*/
  54. float        v4=0.0;                                                            /* illumination factor 0 to 1 range */
  55. int        v5=0;                                                                /* illumination factor base 1 range */
  56. int        v6=11;                                                            /* VGA and EGA illumination range */
  57. int        v7=0;                                                                /* temporary varaible used for illumination range */
  58. float        xu=0.0,yu=0.0,zu=0.0;                                        /* vector from vertex one to vertex two */
  59. float        xv=0.0,yv=0.0,zv=0.0;                                        /* vector from vertex 1 to vertex 3 */
  60. float        xn=0.0,y0n=0.0,zn=0.0;                                        /* surface perpendicular factor */
  61. float        v1=0.0,v2=0.0;                                                    /* length of surface perpendicular vector */
  62. float        v3=0.0;                                                            /* ratio of length to unit vector magnitude */
  63. float        xw=0.0,yw=0.0,zw=0.0;                                        /* surface perpendicual unit vector */
  64. int        polary[4][2];  /* used in my 3d solid polygon draw routine */
  65.  
  66. /* define halftone codes */
  67. char fill_0[]={0,0,0,0,0,0,0,0};                                        /* 0% fill */
  68. char fill_3[]={0,32,0,0,0,2,0,0};                                    /* 3% fill */
  69. char fill_6[]={32,0,2,0,128,0,8,0};                                    /* 6% fill */
  70. char fill_12[]={32,2,128,8,32,2,128,8};                            /* 12% fill */
  71. char fill_25[]={68,17,68,17,68,17,68,17};                            /* 25% fill */
  72. char fill_37[]={170,68,170,17,170,68,170,17};                    /* 37% fill */
  73. char fill_50[]={85,170,85,170,85,170,85,170};                    /* 50% fill */
  74. char fill_62[]={85,187,85,238,85,187,85,238};                    /* 62% fill */
  75. char fill_75[]={187,238,187,238,187,238,187,238};                /* 75% fill */
  76. char fill_87[]={223,253,127,247,223,253,127,247};                /* 87% fill */
  77. char fill_93[]={255,223,255,223,255,223,255,223};                /* 93% fill */
  78. char fill_100[]={255,255,255,255,255,255,255,255};                /* 100% fill */
  79.  
  80. /* database of vertices for 3d models */
  81. int        array1[][3]={
  82.             30,-30,45,    30,30,45,    -30,30,45,    -30,-30,45, 30,30,-45,
  83.             -30,30,-45,    -30,-30,-45,    30,-30,-45};
  84.  
  85. /* database of fill origins for 3d model */
  86. int        array2[][3]={
  87.             0,-30,0,    0,0,-45,    -30,0,0,    0,0,45,    30,0,0,    0,30,0};
  88.  
  89. float        B1[8][3];                                                        /* array of 8 sets of xyz view coordinates */
  90. float        B2[8][2];                                                        /* array of 8 sets of sx,sy display coordinates */
  91. float        B3[6][2];                                                        /* array of 6 sets of sx,sy display coordinates */
  92.  
  93. /* declare global subroutines */
  94. void keyboard(void);void quit_pgm(void);void calc_3d(void);
  95. void rotation(void);void window(void);void graphics_setup(void);
  96. void coords(void);void draw_poly(void);void notice (int x,int y);
  97. void visibility_test(void);void store_coords(void);
  98. void illumination(void);void dither(void);void shade(void);
  99. void values(void);
  100.  
  101. /* ----------------------------------------------------------------------- */
  102. /* MAIN ROUTINE */
  103.  
  104. main(){
  105. graphics_setup();
  106. setviewport(0,0,maxx,maxy,1);
  107. key_matte_clr=C6;
  108. edge_clr=C7;solid_clr=C0;
  109. NORM_HUE=C8;
  110.  
  111. /* aurbrushed backgroung */
  112.  
  113. sx=170;sy=72 ;coords();sx1=sx;sy1=sy;sx=470;sy=98 ;coords();
  114. sx2=sx;sy2=sy;setfillpattern(fill_6 ,C4);bar(sx1,sy1,sx2,sy2);
  115. sx=170;sy=98 ;coords();sx1=sx;sy1=sy;sx=470;sy=132;coords();
  116. sx2=sx;sy2=sy;setfillpattern(fill_12,C4);bar(sx1,sy1,sx2,sy2);
  117. sx=170;sy=132;coords();sx1=sx;sy1=sy;sx=470;sy=168;coords();
  118. sx2=sx;sy2=sy;setfillpattern(fill_25,C4);bar(sx1,sy1,sx2,sy2);
  119. sx=170;sy=168;coords();sx1=sx;sy1=sy;sx=470;sy=204;coords();
  120. sx2=sx;sy2=sy;setfillpattern(fill_37,C4);bar(sx1,sy1,sx2,sy2);
  121. sx=170;sy=204;coords();sx1=sx;sy1=sy;sx=470;sy=240;coords();
  122. sx2=sx;sy2=sy;setfillpattern(fill_50,C4);bar(sx1,sy1,sx2,sy2);
  123. sx=170;sy=240;coords();sx1=sx;sy1=sy;sx=470;sy=276;coords();
  124. sx2=sx;sy2=sy;setfillpattern(fill_62,C4);bar(sx1,sy1,sx2,sy2);
  125. sx=170;sy=276;coords();sx1=sx;sy1=sy;sx=470;sy=312;coords();
  126. sx2=sx;sy2=sy;setfillpattern(fill_75,C4);bar(sx1,sy1,sx2,sy2);
  127. sx=170;sy=312;coords();sx1=sx;sy1=sy;sx=470;sy=348;coords();
  128. sx2=sx;sy2=sy;setfillpattern(fill_87,C4);bar(sx1,sy1,sx2,sy2);
  129. sx=170;sy=348;coords();sx1=sx;sy1=sy;sx=470;sy=384;coords();
  130. sx2=sx;sy2=sy;setfillpattern(fill_100,C4);bar(sx1,sy1,sx2,sy2);
  131.  
  132. store_coords();
  133.  
  134. surface0:
  135. x1=B1[7][0];y01=B1[7][1];z1=B1[7][2];x2=B1[0][0];y2=B1[0][1];
  136. z2=B1[0][2];x3=B1[3][0];y3=B1[3][1];z3=B1[3][2];visibility_test();
  137. if (sp>0) goto surface1;
  138. sx1=B2[7][0];sy1=B2[7][1];sx2=B2[0][0];sy2=B2[0][1];sx3=B2[3][0];
  139. sy3=B2[3][1];sx4=B2[6][0];sy4=B2[6][1];sx5=B3[0][0];sy5=B3[0][1];
  140. draw_poly();illumination();shade();dither();
  141.  
  142. surface1:
  143. x1=B1[6][0];y01=B1[6][1];z1=B1[6][2];x2=B1[5][0];y2=B1[5][1];
  144. z2=B1[5][2];x3=B1[4][0];y3=B1[4][1];z3=B1[4][2];visibility_test();
  145. if (sp>0) goto surface2;
  146. sx1=B2[6][0];sy1=B2[6][1];sx2=B2[5][0];sy2=B2[5][1];sx3=B2[4][0];
  147. sy3=B2[4][1];sx4=B2[7][0];sy4=B2[7][1];sx5=B3[1][0];sy5=B3[1][1];
  148. draw_poly();illumination();shade();dither();
  149.  
  150. surface2:
  151. x1=B1[3][0];y01=B1[3][1];z1=B1[3][2];x2=B1[2][0];y2=B1[2][1];
  152. z2=B1[2][2];x3=B1[5][0];y3=B1[5][1];z3=B1[5][2];visibility_test();
  153. if (sp>0) goto surface3;
  154. sx1=B2[3][0];sy1=B2[3][1];sx2=B2[2][0];sy2=B2[2][1];sx3=B2[5][0];
  155. sy3=B2[5][1];sx4=B2[6][0];sy4=B2[6][1];sx5=B3[2][0];sy5=B3[2][1];
  156. draw_poly();illumination();shade();dither();
  157.  
  158. surface3:
  159. x1=B1[0][0];y01=B1[0][1];z1=B1[0][2];x2=B1[1][0];y2=B1[1][1];
  160. z2=B1[1][2];x3=B1[2][0];y3=B1[2][1];z3=B1[2][2];visibility_test();
  161. if (sp>0) goto surface4;
  162. sx1=B2[0][0];sy1=B2[0][1];sx2=B2[1][0];sy2=B2[1][1];sx3=B2[2][0];
  163. sy3=B2[2][1];sx4=B2[3][0];sy4=B2[3][1];sx5=B3[3][0];sy5=B3[3][1];
  164. draw_poly();illumination();shade();dither();
  165.  
  166. surface4:
  167. x1=B1[7][0];y01=B1[7][1];z1=B1[7][2];x2=B1[4][0];y2=B1[4][1];
  168. z2=B1[4][2];x3=B1[1][0];y3=B1[1][1];z3=B1[1][2];visibility_test();
  169. if (sp>0) goto surface5;
  170. sx1=B2[7][0];sy1=B2[7][1];sx2=B2[4][0];sy2=B2[4][1];sx3=B2[1][0];
  171. sy3=B2[1][1];sx4=B2[0][0];sy4=B2[0][1];sx5=B3[4][0];sy5=B3[4][1];
  172. draw_poly();illumination();shade();dither();
  173.  
  174. surface5:
  175. x1=B1[1][0];y01=B1[1][1];z1=B1[1][2];x2=B1[4][0];y2=B1[4][1];
  176. z2=B1[4][2];x3=B1[5][0];y3=B1[5][1];z3=B1[5][2];visibility_test();
  177. if (sp>0) goto surfaces_done;
  178. sx1=B2[1][0];sy1=B2[1][1];sx2=B2[4][0];sy2=B2[4][1];sx3=B2[5][0];
  179. sy3=B2[5][1];sx4=B2[2][0];sy4=B2[2][1];sx5=B3[5][0];sy5=B3[5][1];
  180. draw_poly();illumination();shade();dither();
  181.  
  182. /* draw the designs */
  183. NORM_HUE=C1;
  184. x=-30;y= 20;z=45;calc_3d();window();x1=x;y01=y;z1=z;sx1=sx;sy1=sy;
  185. x=-30;y=-20;z=45;calc_3d();window();x2=x;y2=y;z2=z;sx2=sx;sy2=sy;
  186. x= 30;y=-20;z=45;calc_3d();window();x3=x;y3=y;z3=z;sx3=sx;sy3=sy;
  187. x= 30;y= 20;z=45;calc_3d();window();sx4=sx;sy4=sy;
  188. x=  0;y=  0;z=45;calc_3d();window();sx5=sx;sy5=sy;
  189. draw_poly();illumination();shade();dither();                        /* end of blue design */
  190.  
  191. x= 30;y= 20;z= 45;calc_3d();window();x1=x;y01=y;z1=z;sx1=sx;sy1=sy;
  192. x= 30;y=-20;z= 45;calc_3d();window();x2=x;y2=y;z2=z;sx2=sx;sy2=sy;
  193. x= 30;y=-20;z=-45;calc_3d();window();x3=x;y3=y;z3=z;sx3=sx;sy3=sy;
  194. x= 30;y= 20;z=-45;calc_3d();window();sx4=sx;sy4=sy;
  195. x= 30;y=  0;z=  0;calc_3d();window();sx5=sx;sy5=sy;
  196. draw_poly();illumination();shade();dither();                        /* side blue design */
  197.  
  198. x=-20;y= 30;z=-25;calc_3d();window();x1=x;y01=y;z1=z;sx1=sx;sy1=sy;
  199. x=-20;y= 30;z= 25;calc_3d();window();x2=x;y2=y;z2=z;sx2=sx;sy2=sy;
  200. x= 20;y= 30;z= 25;calc_3d();window();x3=x;y3=y;z3=z;sx3=sx;sy3=sy;
  201. x= 20;y= 30;z=-25;calc_3d();window();sx4=sx;sy4=sy;
  202. x= 0;y= 30;z=  0;calc_3d();window();sx5=sx;sy5=sy;
  203. draw_poly();illumination();shade();dither();                        /* top blue design */
  204.  
  205. NORM_HUE=C4;                                                                /* define shading color */
  206. x=-30;y= 10;z= 45;calc_3d();window();x1=x;y01=y;z1=z;sx1=sx;sy1=sy;
  207. x=-30;y=-10;z= 45;calc_3d();window();x2=x;y2=y;z2=z;sx2=sx;sy2=sy;
  208. x= 30;y=-10;z= 45;calc_3d();window();x3=x;y3=y;z3=z;sx3=sx;sy3=sy;
  209. x= 30;y= 10;z= 45;calc_3d();window();sx4=sx;sy4=sy;
  210. x=  0;y= -5;z= 45;calc_3d();window();sx5=sx;sy5=sy;
  211. draw_poly();illumination();shade();dither();                        /* end red design */
  212.  
  213. x= 30;y= 10;z= 45;calc_3d();window();x1=x;y01=y;z1=z;sx1=sx;sy1=sy;
  214. x= 30;y=-10;z= 45;calc_3d();window();x2=x;y2=y;z2=z;sx2=sx;sy2=sy;
  215. x= 30;y=-10;z=-45;calc_3d();window();x3=x;y3=y;z3=z;sx3=sx;sy3=sy;
  216. x= 30;y= 10;z=-45;calc_3d();window();sx4=sx;sy4=sy;
  217. x= 30;y= -5;z=  0;calc_3d();window();sx5=sx;sy5=sy;
  218. draw_poly();illumination();shade();dither();                        /* side red design */
  219.  
  220. x=-10;y= 30;z=-15;calc_3d();window();x1=x;y01=y;z1=z;sx1=sx;sy1=sy;
  221. x=-10;y= 30;z= 15;calc_3d();window();x2=x;y2=y;z2=z;sx2=sx;sy2=sy;
  222. x= 10;y= 30;z= 15;calc_3d();window();x3=x;y3=y;z3=z;sx3=sx;sy3=sy;
  223. x= 10;y= 30;z=-15;calc_3d();window();sx4=sx;sy4=sy;
  224. x=  0;y= 30;z=  0;calc_3d();window();sx5=sx;sy5=sy;
  225. draw_poly();illumination();shade();dither();                        /* top red design */
  226.  
  227. surfaces_done:setcolor(C7);notice(0,0);
  228. for (t1=1;t1!=2;) keyboard();
  229. quit_pgm();
  230. }
  231.  
  232. /* ----------------------------------------------------------------------- */
  233. /* SUBROUTINE: CALCULATE SIN,COS FACTORS */
  234.  
  235. void rotation(void){
  236. sr1=sin(r1);sr2=sin(r2);sr3=sin(r3);cr1=cos(r1);cr2=cos(r2);
  237. cr3=cos(r3);return;}
  238.  
  239. /* ----------------------------------------------------------------------- */
  240. /* SUBROUTINE: STANDARD 3D FORMULAS */
  241. /* Pass: x,y,z cartesian world coordinates.
  242.    Returns: sx,sy cartesian display coordinates.
  243.           x,y,z catesian view coordinates */
  244.  
  245. void calc_3d(void){
  246. x=(-1)*x;xa=cr1*x-sr1*z;za=sr1*x+cr1*z;x=cr2*xa+sr2*y;
  247. ya=cr2*y-sr2*xa;z=cr3*za-sr3*ya;y=sr3*za+cr3*ya;x=x+mx;y=y+my;
  248. z=z+mz;sx=d*x/z;sy=d*y/z;return;}
  249.  
  250. /* ----------------------------------------------------------------------- */
  251. /* SUBROUTINE: CALCULATE & DISPLAY VIEW COORDINATES & DISPLAY COORDS */
  252.  
  253. void store_coords(void){
  254. rotation();
  255.  
  256. for (t=0;t<=7;t++){
  257.     x=array1[t][0];y=array1[t][1];z=array1[t][2];
  258.     calc_3d();window();
  259.     B1[t][0]=x;B1[t][1]=y;B1[t][2]=z;
  260.     B2[t][0]=sx;B2[t][1]=sy;
  261.     };
  262.  
  263. for (t=0;t<=5;t++){
  264.     x=array2[t][0];y=array2[t][1];z=array2[t][2];
  265.     calc_3d();window();
  266.     B3[t][0]=sx;B3[t][1]=sy;
  267.     };
  268.     return;
  269.     }
  270.  
  271. /* ----------------------------------------------------------------------- */
  272. /* HIDDEN SURFACE VISIBILTY TEST */
  273. void visibility_test(void){
  274. sp1=x1*(y2*z3-y3*z2);sp1=(-1)*sp1;sp2=x2*(y3*z1-y01*z3);
  275. sp3=x3*(y01*z2-y2*z1);sp=sp1-sp2-sp3;return;}
  276.  
  277. /* ----------------------------------------------------------------------- */
  278. /* SUBROUTINE: DRAW 4-SIDED SOLID POLYGON IN 3D SPACE */
  279.  
  280. void draw_poly(void){
  281. setlinestyle(USERBIT_LINE,0xffff,NORM_WIDTH);
  282. setfillstyle(SOLID_FILL,solid_clr);
  283. setcolor(edge_clr);
  284.  
  285. polary[0][0]=sx1;polary[0][1]=sy1;polary[1][0]=sx2;polary[1][1]=sy2;
  286. polary[2][0]=sx3;polary[2][1]=sy3;polary[3][0]=sx4;polary[3][1]=sy4;
  287.  
  288. fillpoly (4,(int far*) polary);
  289. return;
  290. }
  291.  
  292. /* ----------------------------------------------------------------------- */
  293. /* SUBROUTINES: CALCULATE ILLUMINATION LEVEL */
  294.  
  295. void illumination(void){
  296. xu=x2-x1;yu=y2-y01;zu=z2-z1;                                        /* vector from vertex 1 to vertex 2 */
  297. xv=x3-x1;yv=y3-y01;zv=z3-z1;                                        /* vector from vertex 1 to vertex 3 */
  298. xn=(yu*zv)-(zu*yv);y0n=(zu*xv)-(xu*zv);
  299.     zn=(xu*yv)-(yu*xv);                                                /* surface perpendicular vector */
  300. y0n=y0n*(-1);zn=zn*(-1);                                            /* convert to cartesian system */
  301. v1=(xn*xn)+(y0n*y0n)+(zn*zn);
  302. v2=sqrt(v1);                                                            /* magnitude of surface perpendicular vector */
  303. v3=1/v2;                                                                    /* ratio of magnitude to length of unit vector */
  304. xw=v3*xn;yw=v3*y0n;zw=v3*zn;                                        /* surface perpendicular to unit vector */
  305. v4=(xw*xx1)+(yw*yy1)+(zw*zz1);                                    /* illumination factor 0 to 1 */
  306. v4=v4*v6;                                                                /* expand illumination range from base 0 */
  307. v7=v4;                                                                    /* convert illumination range to integer */
  308. v5=v7+1;                                                                    /* illumination range from base 1 */
  309. return;
  310. }
  311.  
  312. /* ----------------------------------------------------------------------- */
  313. /* SUBROUTINE: ILLUMINATION MATRIX */
  314.  
  315. void shade(void){
  316. switch (v5){
  317.     case 1:setfillpattern(fill_6,NORM_HUE);CC6=0x1010;values();return;
  318.     case 2:setfillpattern(fill_6,NORM_HUE);CC6=0x1010;values();return;
  319.     case 3:setfillpattern(fill_6,NORM_HUE);CC6=0x1010;values();return;
  320.     case 4:setfillpattern(fill_12,NORM_HUE);CC6=0x2020;values();return;
  321.     case 5:setfillpattern(fill_25,NORM_HUE);CC6=0x2222;values();return;
  322.     case 6:setfillpattern(fill_37,NORM_HUE);CC6=0xaaaa;values();return;
  323.     case 7:setfillpattern(fill_50,NORM_HUE);CC6=0xaaaa;values();return;
  324.     case 8:setfillpattern(fill_62,NORM_HUE);CC6=0xaaaa;values();return;
  325.     case 9:setfillpattern(fill_75,NORM_HUE);CC6=0xbbbb;values();return;
  326.     case 10:setfillpattern(fill_87,NORM_HUE);CC6=0xdddd;values();return;
  327.     case 11:setfillpattern(fill_93,NORM_HUE);CC6=0xefef;values();return;
  328.     case 12:setfillpattern(fill_100,NORM_HUE);CC6=0xffff;values();return;
  329.     defualt:setfillpattern(fill_6,NORM_HUE);CC6=0x1010;values();}
  330. return;}
  331.  
  332. /* ----------------------------------------------------------------------- */
  333. /* LOCAL SUBROUTINE: prep fill and set dithering variables */
  334. void values(void){
  335. floodfill(sx5,sy5,edge_clr);CC4=BASE_CLR;CC5=NORM_HUE;return;}
  336.  
  337. /* ----------------------------------------------------------------------- */
  338. /* SUBROUTINE: APPLY DITHERING */
  339.  
  340. void dither(void){
  341. setlinestyle(USERBIT_LINE,0xffff,NORM_WIDTH);setcolor(CC4);
  342. moveto (sx1,sy1);lineto(sx2,sy2);lineto(sx3,sy3);
  343. lineto(sx4,sy4);lineto(sx1,sy1);
  344. setlinestyle(USERBIT_LINE,CC6,NORM_WIDTH);setcolor(CC5);
  345. moveto(sx1,sy1);lineto(sx2,sy2);lineto(sx3,sy3);
  346. lineto(sx4,sy4);lineto(sx1,sy1);
  347. return;
  348. }
  349.  
  350. /* ----------------------------------------------------------------------- */
  351. /* SUBROUTINE: MAP CARTESIAN COORDS TO PHYSICAL SCREEN COORDS */
  352.  
  353. void window(void){
  354. sx=sx+399;sy=sy+299;rx=screen_x/799;ry=screen_y/599;sx=sx*rx;
  355. sy=sy*ry;return;}
  356.  
  357. /* ----------------------------------------------------------------------- */
  358. /* SUBROUTINE: CHACK THE KEYBOARD BUFFER */
  359. void keyboard(void){
  360. if (bioskey(1)==0) return; else quit_pgm();}
  361.  
  362. /* ----------------------------------------------------------------------- */
  363. /* SUBROUTINE: GRACEFUL EXIT FROM PROGRAM */
  364.  
  365. void quit_pgm(void){
  366. cleardevice();restorecrtmode();exit(0);}
  367.  
  368. /* ----------------------------------------------------------------------- */
  369. /* SUBROUTINE: VGA/EGA/MCGA/CGA COMPATIBILITY MODULE */
  370.  
  371. void graphics_setup(void){
  372. int graphics_adapter,graphics_mode;
  373. detectgraph(&graphics_adapter,&graphics_mode);
  374. if (graphics_adapter==VGA) goto VGA_mode;
  375. if (graphics_mode==EGAHI) goto EGA_ECD_mode;
  376. if (graphics_mode==EGALO) goto EGA_SCD_mode;
  377. if (graphics_adapter==CGA) goto CGA_mode;
  378. if (graphics_adapter==MCGA) goto CGA_mode;
  379. goto abort_message;
  380.  
  381. VGA_mode:
  382. graphics_adapter=VGA;graphics_mode=VGAHI;
  383. initgraph(&graphics_adapter,&graphics_mode,"");
  384. x_res=640;y_res=480;mode_flag=1;
  385.         maxx=639;minx=0;maxy=479;miny=0;screen_x=639;screen_y=479;
  386.         setcolor(7);moveto(0,472);
  387.           outtext("Revisions by A. Helder");
  388.         moveto(472,472);
  389.         outtext("Press any key to quit");
  390.         moveto(160,0);
  391.           outtext("USING C TO GENERATE PACKAGING DESIGN");
  392.         return;
  393.  
  394. EGA_ECD_mode:
  395. graphics_adapter=EGA;graphics_mode=EGAHI;
  396. initgraph(&graphics_adapter,&graphics_mode,"");
  397. x_res=640;y_res=350;mode_flag=2;
  398.         maxx=639;minx=0;maxy=349;miny=0;screen_x=639;screen_y=349;
  399.         setcolor(7);moveto(0,342);
  400.           outtext("Revisions by A. Helder");
  401.         moveto(472,342);
  402.         outtext ("Press any key to quit");
  403.         moveto(160,0);
  404.           outtext("USING C TO GENERATE PACKAGING DESIGN");
  405.         return;
  406.  
  407. EGA_SCD_mode:
  408. graphics_adapter=EGA;graphics_mode=EGALO;
  409. initgraph(&graphics_adapter,&graphics_mode,"");
  410. x_res=640;y_res=200;mode_flag=3;
  411.         maxx=639;minx=0;maxy=199;miny=0;screen_x=639;screen_y=199;
  412.         setcolor(7);moveto(0,192);
  413.           outtext("Revisions by A. Helder");
  414.         moveto(472,192);
  415.         outtext("PRESS ANY KEY TO QUIT");
  416.         moveto(160,0);
  417.           outtext("USING C TO GENERATE PACKAGING DESIGN");
  418.         return;
  419.  
  420. CGA_mode:
  421. graphics_adapter=CGA;graphics_mode=CGAC3;
  422. initgraph(&graphics_adapter,&graphics_mode,"");
  423. x_res=320;y_res=200;mode_flag=1;C7=3;
  424.         maxx=319;minx=0;maxy=199;miny=0;screen_x=319;screen_y=199;
  425.         setcolor(3);moveto(48,192);
  426.           outtext("Revisions by A. Helder");
  427.         moveto(88,0);
  428.           outtext ("PACKAGING DESIGN");
  429.         return;
  430.  
  431. abort_message:
  432. printf("\n\nUnable to proceed - Requires VGA,EGA,CGA or MCGA adapter");
  433. printf("\nWith appropriate monitor");
  434. exit(0);
  435. }
  436.  
  437. /* ----------------------------------------------------------------------- */
  438. /* SUBROUTINE: MAP 640*480 TEMPLATE TO 2D SCREEN */
  439. void coords(void)
  440. {
  441. sx=sx*(x_res/640);sy=sy*(y_res/480);return;
  442. }
  443.  
  444. /* ----------------------------------------------------------------------- */
  445. /* SUBROUTINE: COPYRIGHT NOTICE */
  446.  
  447. int copyright[][3]={0x7c00,0x0000,0x0000,0x8231,
  448. 0x819c,0x645e,0xba4a,0x4252,0x96d0,0xa231,0x8252,0x955e,0xba4a,
  449. 0x43d2,0xf442,0x8231,0x825c,0x945e,0x7c00,0x0000,0x0000};
  450.  
  451. void notice(int x, int y){
  452. int a,b,c; int t1=0;
  453.  
  454. for (t1=0;t1<=6;t1++)
  455.     {
  456.     a=copyright[t1][0];b=copyright[t1][1];
  457.     c=copyright[t1][2];
  458.     setlinestyle(USERBIT_LINE,a,NORM_WIDTH);
  459.     moveto(x,y);lineto(x+15,y);
  460.     setlinestyle(USERBIT_LINE,b,NORM_WIDTH);
  461.     moveto(x+16,y);lineto(x+31,y);
  462.     setlinestyle(USERBIT_LINE,c,NORM_WIDTH);
  463.     moveto(x+32,y);lineto(x+47,y);y++;
  464.     };
  465. setlinestyle(USERBIT_LINE,0xFFFF,NORM_WIDTH);
  466. return;}
  467.  
  468. /* end of source code */
  469.