home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Shareware - Software Farm 2
/
wosw_2.zip
/
wosw_2
/
CPROG
/
TC_3D.ZIP
/
TC-18.C
< prev
Wrap
Text File
|
1991-02-13
|
22KB
|
529 lines
/* tc-18.c */
/* Draws a container design (soft drink can) */
/* ----------------------------------------------------------------------- */
/* INCLUDE FILES */
#include <process.h>
#include <bios.h>
#include <stdio.h>
#include <graphics.h>
#include <math.h>
/* ----------------------------------------------------------------------- */
/* DECLARATIONS */
float x=0.0,y=0.0,z=0.0; /* world coordinates */
float x1=0.0,x2=0.0,x3=0.0; /* polygon vertices */
float y01=0.0,y2=0.0,y3=0.0; /* polygon vertices */
float z1=0.0,z2=0.0,z3=0.0; /* polygon vertices */
float sx1=0.0,sx2=0.0,sx3=0.0,sx4=0.0,sx5=0.0; /* display coordinaes */
float sy1=0.0,sy2=0.0,sy3=0.0,sy4=0.0,sy5=0.0; /* display coordinates */
float sx=0.0,sy=0.0; /* output of 3d perspective formulas */
float xa=0.0,ya=0.0,za=0.0; /* temporary values in 3d formulas */
float d=1200.0; /* angular perspective value */
double r1=5.09448; /* yaw angle in radians */
double r2=5.09448; /* roll angle in radians */
double r3=6.28319; /* pitch angle in radians */
double sr1=0.0,sr2=0.0,sr3=0.0; /* sine rotation factors */
double cr1=0.0,cr2=0.0,cr3=0.0; /* cosine rotation factors */
float mx=0.0,my=-10.0,mz=-350.0; /* viewpoint position */
int maxx=639,minx=0,maxy=199,miny=0; /* scaling viewport */
float screen_x=639,screen_y=199; /* dimensions of screen mode */
int C0=0,C1=1,C2=2,C3=3,C4=4,C5=5,C6=6,C7=7,C8=8, /* color varariables */
C9=9,C10=10,C11=11,C12=12,C13=13,C14=14,C15=15,
mode_flag=0;
float rx=0.0,ry=0.0; /* scaling values used in mapping routine */
int t=0,t1=0,t2=0; /* loop counters */
int p1=0; /* array indexer */
int key_matte_clr=6; /* exclusive key matte color */
int edge_clr=7; /* used to draw edges on models */
int solid_clr=0; /* used to fill surfaces on solid models */
float x_res,y_res; /* used for 2d mappinf from 640*480 template */
float sp=0.0; /* visibility factor in hidden surface routine */
float sp1=0.0,sp2=0.0,sp3=0.0; /* temporary values of sp */
int NORM_HUE=0; /* halftoning color */
int BASE_CLR=0; /* prep cooor for dithering */
int CC4=0; /* underlay color for dithering */
int CC5=0; /* overlay color for dithering */
unsigned short CC6=0xffff; /* pattern for dithering */
float xx1=0,yy1=.0,zz1=1; /* location of light source - elevation 45 degrees, compas 135 degrees {{REDIFINED !!}}*/
float v4=0.0; /* illumination factor 0 to 1 range */
int v5=0; /* illumination factor base 1 range */
int v6=11; /* VGA and EGA illumination range */
int v7=0; /* temporary varaible used for illumination range */
float xu=0.0,yu=0.0,zu=0.0; /* vector from vertex one to vertex two */
float xv=0.0,yv=0.0,zv=0.0; /* vector from vertex 1 to vertex 3 */
float xn=0.0,y0n=0.0,zn=0.0; /* surface perpendicular factor */
float v1=0.0,v2=0.0; /* length of surface perpendicular vector */
float v3=0.0; /* ratio of length to unit vector magnitude */
float xw=0.0,yw=0.0,zw=0.0; /* surface perpendicual unit vector */
int polary[4][2]; /* used in my 3d solid polygon draw routine */
/* define halftone codes */
char fill_0[]={0,0,0,0,0,0,0,0}; /* 0% fill */
char fill_3[]={0,32,0,0,0,2,0,0}; /* 3% fill */
char fill_6[]={32,0,2,0,128,0,8,0}; /* 6% fill */
char fill_12[]={32,2,128,8,32,2,128,8}; /* 12% fill */
char fill_25[]={68,17,68,17,68,17,68,17}; /* 25% fill */
char fill_37[]={170,68,170,17,170,68,170,17}; /* 37% fill */
char fill_50[]={85,170,85,170,85,170,85,170}; /* 50% fill */
char fill_62[]={85,187,85,238,85,187,85,238}; /* 62% fill */
char fill_75[]={187,238,187,238,187,238,187,238}; /* 75% fill */
char fill_87[]={223,253,127,247,223,253,127,247}; /* 87% fill */
char fill_93[]={255,223,255,223,255,223,255,223}; /* 93% fill */
char fill_100[]={255,255,255,255,255,255,255,255}; /* 100% fill */
/* database of z coordinates on surface of container */
float database_1[]={2,2,1,-1,-2.5,-3.8,-4.8,-6,-6.7,-7.5,-8,-8.5,
-8.8,-9.2,-10,-10.2,-10.9,-11,-11.2,-11.5,-11.7,
-11.9,-12,-12,-11.9,-11.7,-11.5,-11.2,-11,-10.9,
-10.2,-10,-9.2,-8.8,-8.5,-8,-7.5,-6.7,-6,-4.8,
-3.8,-2.5,-1,1,2};
float database_2[]={26,26,28,29.2,31,32,33,34,35,35.8,36.5,37,37.2,
37.5,37.8,38,38.2,38.3,38.5,38.6,38.6,38.6,38.5,
38.3,38.2,38,37.8,37.5,37.2,37,36.5,35.8,35,
34,33,32,31,29.2,27.5,25.2,23};
float database_3[]={26,26,25.5,25,24.5,24.2,24,23.8,23.7,23.7,23.7,
23.7,23.7,23.7,23.8,23.9,23.9,24,24.1,24.2,24.5,
24.8,25.1,25.3,25.3,25.5,25.8,26,26,25.8,25.7,
25.6,25.5,25.2,25.1,25,24.5,24.3,23.8,23.7,23};
float database_4[]={8.2,7.9,7.5,7.1,7,6.9,6.8,6.7,6.6,6.6,6.6,
6.7,6.7,6.7,6.8,6.9,7,7.1,7.3,7.5,8,8.2,8.6,
8.9,9,9.1,9.4,9.6,9.9,10,10,10,10,9.9,9.8,9.5,
9.4,9.1,8.9,8.4,8};
float database_5[]={8.2,7,5.5,3.7,2,0,-1,-2,-2.8,-3.8,-4.5,-5.1,
-5.7,-5.9,-6.3,-6.7,-7,-7.2,-7.3,-7.4,-7.5,-7.5,
-7.4,-7.3,-7.1,-7,-6.7,-6.5,-6,-5.5,-4.8,-4,-3.2,
-2.5,-1.5,-.5,.5,2.1,3.5,6,8};
int q=0,q1=0,q2=0; /* cylinder surface and vertex counters */
double r4=6.28319,r5=6.28319; /* spherical coordinate angles */
float B11[36][3]; /* 36 sets of xyz coordinates, near end */
float B12[36][3]; /* 36 sets of xyz view coordinates, far end */
float B21[36][2]; /* 36 sets of sx,sy display coordinates, near end */
float B22[36][2]; /* 36 sets of sx,sy display coordinates, far end */
double sr4=0.0,cr4=0.0,sr5=0.0,cr5=0.0; /* rotation factors */
/* declare global subroutines */
void keyboard(void);void quit_pgm(void);void calc_3d(void);
void rotation(void);void window(void);void graphics_setup(void);
void coords(void);void draw_poly(void);void notice(int x,int y);
void illumination(void);void dither(void);void shade(void);
void values(void);
void visibility_test(void);void cyl_coords(void);
void draw_surface(void);
/* ----------------------------------------------------------------------- */
/* MAIN ROUTINE */
main(){
graphics_setup();
setviewport(0,0,maxx,maxy,1);
key_matte_clr=C6;
edge_clr=C7;solid_clr=C0;
NORM_HUE=C7;
rotation();
if (mode_flag==4) my=0.0; /* if cga */
/* airbrushed backgroung */
sx=170;sy=72 ;coords();sx1=sx;sy1=sy;sx=470;sy=98 ;coords();
sx2=sx;sy2=sy;setfillpattern(fill_6 ,C4);bar(sx1,sy1,sx2,sy2);
sx=170;sy=98 ;coords();sx1=sx;sy1=sy;sx=470;sy=132;coords();
sx2=sx;sy2=sy;setfillpattern(fill_12,C4);bar(sx1,sy1,sx2,sy2);
sx=170;sy=132;coords();sx1=sx;sy1=sy;sx=470;sy=168;coords();
sx2=sx;sy2=sy;setfillpattern(fill_25,C4);bar(sx1,sy1,sx2,sy2);
sx=170;sy=168;coords();sx1=sx;sy1=sy;sx=470;sy=204;coords();
sx2=sx;sy2=sy;setfillpattern(fill_37,C4);bar(sx1,sy1,sx2,sy2);
sx=170;sy=204;coords();sx1=sx;sy1=sy;sx=470;sy=240;coords();
sx2=sx;sy2=sy;setfillpattern(fill_50,C4);bar(sx1,sy1,sx2,sy2);
sx=170;sy=240;coords();sx1=sx;sy1=sy;sx=470;sy=276;coords();
sx2=sx;sy2=sy;setfillpattern(fill_62,C4);bar(sx1,sy1,sx2,sy2);
sx=170;sy=276;coords();sx1=sx;sy1=sy;sx=470;sy=312;coords();
sx2=sx;sy2=sy;setfillpattern(fill_75,C4);bar(sx1,sy1,sx2,sy2);
sx=170;sy=312;coords();sx1=sx;sy1=sy;sx=470;sy=348;coords();
sx2=sx;sy2=sy;setfillpattern(fill_87,C4);bar(sx1,sy1,sx2,sy2);
sx=170;sy=348;coords();sx1=sx;sy1=sy;sx=470;sy=384;coords();
sx2=sx;sy2=sy;setfillpattern(fill_100,C4);bar(sx1,sy1,sx2,sy2);
/* calculate coordinates for near end of cylinder */
r4=0;r5=0;
for (t=0;t<=35;t++){
x=30;cyl_coords();z=z+50;calc_3d();window();
B11[t][0]=x;B11[t][1]=y;B11[t][2]=z;
B21[t][0]=sx;B21[t][1]=sy;
/* keyboard();*/
r5=r5+.17453;}
/* calculate coordinates for far end of cylinder */
r4=0;r5=0;
for (t=0;t<=35;t++){
x=30;cyl_coords();z=z-50;calc_3d();window();
B12[t][0]=x;B12[t][1]=y;B12[t][2]=z;
B22[t][0]=sx;B22[t][1]=sy;
/* keyboard(); */
r5=r5+.17453;}
/* draw surfaces of 3d cylinder */
for (q1=0;q1<=35;q1++){
q2=q1+1;if (q2>35) q2=0;
draw_surface();
/* keyboard();*/
}
/* draw near end of 3d cylinder */
x1=B11[0][0];y01=B11[0][1];z1=B11[0][2];
x2=B11[25][0];y2=B11[25][1];z2=B11[25][2];
x3=B11[11][0];y3=B11[11][1];z3=B11[11][2];
visibility_test();if (sp>0) goto all_done;
setcolor(key_matte_clr);setfillstyle(SOLID_FILL,key_matte_clr);
setlinestyle(USERBIT_LINE,0xffff,NORM_WIDTH);
for (q1=0;q1<=35;q1++){
q2=q1+1;if (q2>35) q2=0;
sx1=B21[q1][0];sy1=B21[q1][1];sx2=B21[q2][0];sy2=B21[q2][1];
moveto(sx1,sy1);lineto(sx2,sy2);}
x=0.0;y=0.0;z=50.0;calc_3d();window();floodfill(sx,sy,key_matte_clr);
setcolor(edge_clr);
for (q1=0;q1<=35;q1++){
q2=q1+1;if (q2>35) q2=0;
sx1=B21[q1][0];sy1=B21[q1][1];sx2=B21[q2][0];sy2=B21[q2][1];
moveto(sx1,sy1);lineto(sx2,sy2);}
x=0.0;y=0.0;z=50.0;calc_3d();window();
setfillstyle(SOLID_FILL,solid_clr);floodfill(sx,sy,edge_clr);
x=0.0;y=0.0;z=50.0;calc_3d();window();sx5=sx;sy5=sy;
illumination();shade();keyboard();
for (q1=0;q1<=35;q1++){
q2=q1+1;if (q2>35) q2=0;
sx1=B21[q1][0];sy1=B21[q1][1];sx2=B21[q2][0];sy2=B21[q2][1];
setlinestyle(USERBIT_LINE,0xffff,NORM_WIDTH);setcolor(CC4);
moveto(sx1,sy1);lineto(sx2,sy2);
setlinestyle(USERBIT_LINE,CC6,NORM_WIDTH);setcolor(CC5);
moveto(sx1,sy1);lineto(sx2,sy2);}
setlinestyle(USERBIT_LINE,0xffff,NORM_WIDTH);
/* create lower red design */
edge_clr=C4;
if (mode_flag==4) edge_clr=C6;
setcolor(edge_clr);
x=30;r5=2.601631;cyl_coords();z=-40;calc_3d();window();
moveto(sx,sy);putpixel(sx,sy,edge_clr); /* set point */
x=30;r5=2.601631;cyl_coords();z=2.5;calc_3d();window();
lineto(sx,sy); /* vertical line */
x=30;r5=.490874;cyl_coords();z=-40;calc_3d();window();
moveto(sx,sy);putpixel(sx,sy,edge_clr); /* set point */
x=30;r5=.490874;cyl_coords();z=2.5;calc_3d();window();
lineto(sx,sy); /* vertical line */
keyboard();
x=30;r5=.490874;cyl_coords();z=-40;calc_3d();window();
moveto(sx,sy);putpixel(sx,sy,edge_clr);
for (r5=.490874;r5<=2.601631;r5+=.0490873){
keyboard();x=30;cyl_coords();z=-40;calc_3d();window();
lineto(sx,sy);} /* bottom line */
p1=0;
r5=.490874;x=30;cyl_coords();z=database_1[p1];p1++;
calc_3d();window();moveto(sx,sy);putpixel(sx,sy,edge_clr);
for (r5=.490874;r5<=2.601631;r5+=.0490873){
keyboard();x=30;cyl_coords();
z=database_1[p1];p1++;calc_3d();window();lineto(sx,sy);}
x=30;r5=1.570796;cyl_coords();z=-25;calc_3d();window();
setfillstyle(SOLID_FILL,edge_clr);
floodfill(sx,sy,edge_clr); /* area fill */
/*----- create upper semi-circle design -----*/
edge_clr=C4;
if (mode_flag==4) edge_clr=C6;
setcolor(edge_clr);
p1=0;
r5=.638136;x=30;cyl_coords();z=database_2[p1];p1++;
calc_3d();window();moveto(sx,sy);putpixel(sx,sy,edge_clr);
for (r5=.638136;r5<=2.552544;r5+=.0490873){
keyboard();x=30;cyl_coords();
z=database_2[p1];p1++;calc_3d();window();lineto(sx,sy);}
p1=0;
r5=.638136;x=30;cyl_coords();z=database_3[p1];p1++;
calc_3d();window();moveto(sx,sy);putpixel(sx,sy,edge_clr);
for (r5=.638136;r5<=2.552544;r5+=.0490873){
keyboard();x=30;cyl_coords();
z=database_3[p1];p1++;calc_3d();window();lineto(sx,sy);}
x=30;r5=1.570796;cyl_coords();z=32;calc_3d();window();
setfillstyle(SOLID_FILL,edge_clr);floodfill(sx,sy,edge_clr);
/*----- create central semi-circle design -----*/
edge_clr=C1;
if (mode_flag==4) edge_clr=C6;
setcolor(edge_clr);
p1=0;
r5=.638136;x=30;cyl_coords();z=database_4[p1];p1++;
calc_3d();window();moveto(sx,sy);putpixel(sx,sy,edge_clr);
for (r5=.638136;r5<=2.552544;r5+=.0490873){
keyboard();x=30;cyl_coords();
z=database_4[p1];p1++;calc_3d();window();lineto(sx,sy);}
p1=0;
r5=.638136;x=30;cyl_coords();z=database_5[p1];p1++;
calc_3d();window();moveto(sx,sy);putpixel(sx,sy,edge_clr);
for (r5=.638136;r5<=2.552544;r5+=.0490873){
keyboard();x=30;cyl_coords();
z=database_5[p1];p1++;calc_3d();window();lineto(sx,sy);}
x=30;r5=1.570796;cyl_coords();z=0;calc_3d();window();
setfillstyle(SOLID_FILL,edge_clr);floodfill(sx,sy,edge_clr);
all_done:
setcolor(C7);notice (0,0);
for (t1=1;t1!=2;) keyboard();
quit_pgm;
}
/* ----------------------------------------------------------------------- */
/* SUBROUTINE: CALCULATE WORLD COORDINATES FOR cylinder */
void cyl_coords(void){
sr4=sin(r4);cr4=cos(r4);sr5=sin(r5);
cr5=cos(r5);x1=sr5*x;y=cr5*x;x=cr4*x1;z=sr4*x1;return;}
/* ----------------------------------------------------------------------- */
/* SUBROUTINE: DRAW 4 SIDED POLYGON SURFACE ON SPHERE */
void draw_surface(void){
x1=B11[q1][0];y01=B11[q1][1];z1=B11[q1][2];
x2=B11[q2][0];y2=B11[q2][1];z2=B11[q2][2];
x3=B12[q2][0];y3=B12[q2][1];z3=B12[q2][2];
visibility_test();if (sp>0) return;
sx1=B21[q1][0];sy1=B21[q1][1];
sx2=B21[q2][0];sy2=B21[q2][1];
sx3=B22[q2][0];sy3=B22[q2][1];
sx4=B22[q1][0];sy4=B22[q1][1];
x=x1+.5*(x3-x1);y=y01+.5*(y3-y01);z=z1+.5*(z3-z1);
sx=d*x/z;sy=d*y/z;window();sx5=sx;sy5=sy;
draw_poly();illumination();shade();dither();
return;}
/* ----------------------------------------------------------------------- */
/* SUBROUTINE: CALCULATE SIN,COS FACTORS */
void rotation(void){
sr1=sin(r1);sr2=sin(r2);sr3=sin(r3);cr1=cos(r1);cr2=cos(r2);
cr3=cos(r3);return;}
/* ----------------------------------------------------------------------- */
/* SUBROUTINE: STANDARD 3D FORMULAS */
/* Pass: x,y,z cartesian world coordinates.
Returns: sx,sy cartesian display coordinates.
x,y,z catesian view coordinates */
void calc_3d(void){
x=(-1)*x;xa=cr1*x-sr1*z;za=sr1*x+cr1*z;x=cr2*xa+sr2*y;
ya=cr2*y-sr2*xa;z=cr3*za-sr3*ya;y=sr3*za+cr3*ya;x=x+mx;y=y+my;
z=z+mz;sx=d*x/z;sy=d*y/z;return;}
/* ----------------------------------------------------------------------- */
/* HIDDEN SURFACE VISIBILTY TEST */
void visibility_test(void){
sp1=x1*(y2*z3-y3*z2);sp1=(-1)*sp1;sp2=x2*(y3*z1-y01*z3);
sp3=x3*(y01*z2-y2*z1);sp=sp1-sp2-sp3;return;}
/* ----------------------------------------------------------------------- */
/* SUBROUTINE: DRAW 4-SIDED SOLID POLYGON IN 3D SPACE */
void draw_poly(void){
setlinestyle(USERBIT_LINE,0xffff,NORM_WIDTH);
setfillstyle(SOLID_FILL,solid_clr);
setcolor(edge_clr);
polary[0][0]=sx1;polary[0][1]=sy1;polary[1][0]=sx2;polary[1][1]=sy2;
polary[2][0]=sx3;polary[2][1]=sy3;polary[3][0]=sx4;polary[3][1]=sy4;
fillpoly (4,(int far*) polary);
return;
}
/* ----------------------------------------------------------------------- */
/* SUBROUTINES: CALCULATE ILLUMINATION LEVEL */
void illumination(void){
xu=x2-x1;yu=y2-y01;zu=z2-z1; /* vector from vertex 1 to vertex 2 */
xv=x3-x1;yv=y3-y01;zv=z3-z1; /* vector from vertex 1 to vertex 3 */
xn=(yu*zv)-(zu*yv);y0n=(zu*xv)-(xu*zv);
zn=(xu*yv)-(yu*xv); /* surface perpendicular vector */
y0n=y0n*(-1);zn=zn*(-1); /* convert to cartesian system */
v1=(xn*xn)+(y0n*y0n)+(zn*zn);
v2=sqrt(v1); /* magnitude of surface perpendicular vector */
v3=1/v2; /* ratio of magnitude to length of unit vector */
xw=v3*xn;yw=v3*y0n;zw=v3*zn; /* surface perpendicular to unit vector */
v4=(xw*xx1)+(yw*yy1)+(zw*zz1); /* illumination factor 0 to 1 */
v4=v4*v6; /* expand illumination range from base 0 */
v7=v4; /* convert illumination range to integer */
v5=v7+1; /* illumination range from base 1 */
return;
}
/* ----------------------------------------------------------------------- */
/* SUBROUTINE: ILLUMINATION MATRIX */
void shade(void){
switch (v5){
case 1:setfillpattern(fill_6,NORM_HUE);CC6=0x1010;values();return;
case 2:setfillpattern(fill_6,NORM_HUE);CC6=0x1010;values();return;
case 3:setfillpattern(fill_6,NORM_HUE);CC6=0x1010;values();return;
case 4:setfillpattern(fill_12,NORM_HUE);CC6=0x2020;values();return;
case 5:setfillpattern(fill_25,NORM_HUE);CC6=0x2222;values();return;
case 6:setfillpattern(fill_37,NORM_HUE);CC6=0xaaaa;values();return;
case 7:setfillpattern(fill_50,NORM_HUE);CC6=0xaaaa;values();return;
case 8:setfillpattern(fill_62,NORM_HUE);CC6=0xaaaa;values();return;
case 9:setfillpattern(fill_75,NORM_HUE);CC6=0xbbbb;values();return;
case 10:setfillpattern(fill_87,NORM_HUE);CC6=0xdddd;values();return;
case 11:setfillpattern(fill_93,NORM_HUE);CC6=0xefef;values();return;
case 12:setfillpattern(fill_100,NORM_HUE);CC6=0xffff;values();return;
defualt:setfillpattern(fill_6,NORM_HUE);CC6=0x1010;values();}
return;}
/* ----------------------------------------------------------------------- */
/* LOCAL SUBROUTINE: prep fill and set dithering variables */
void values(void){
floodfill(sx5,sy5,edge_clr);CC4=BASE_CLR;CC5=NORM_HUE;return;}
/* ----------------------------------------------------------------------- */
/* SUBROUTINE: APPLY DITHERING */
void dither(void){
setlinestyle(USERBIT_LINE,0xffff,NORM_WIDTH);setcolor(CC4);
moveto (sx1,sy1);lineto(sx2,sy2);lineto(sx3,sy3);
lineto(sx4,sy4);lineto(sx1,sy1);
setlinestyle(USERBIT_LINE,CC6,NORM_WIDTH);setcolor(CC5);
moveto(sx1,sy1);lineto(sx2,sy2);lineto(sx3,sy3);
lineto(sx4,sy4);lineto(sx1,sy1);
return;
}
/* ----------------------------------------------------------------------- */
/* SUBROUTINE: MAP CARTESIAN COORDS TO PHYSICAL SCREEN COORDS */
void window(void){
sx=sx+399;sy=sy+299;rx=screen_x/799;ry=screen_y/599;sx=sx*rx;
sy=sy*ry;return;}
/* ----------------------------------------------------------------------- */
/* SUBROUTINE: CHACK THE KEYBOARD BUFFER */
void keyboard(void){
if (bioskey(1)==0) return; else quit_pgm();}
/* ----------------------------------------------------------------------- */
/* SUBROUTINE: GRACEFUL EXIT FROM PROGRAM */
void quit_pgm(void){
cleardevice();restorecrtmode();exit(0);}
/* ----------------------------------------------------------------------- */
/* SUBROUTINE: VGA/EGA/MCGA/CGA COMPATIBILITY MODULE */
void graphics_setup(void){
int graphics_adapter,graphics_mode;
detectgraph(&graphics_adapter,&graphics_mode);
if (graphics_adapter==VGA) goto VGA_mode;
if (graphics_mode==EGAHI) goto EGA_ECD_mode;
if (graphics_mode==EGALO) goto EGA_SCD_mode;
if (graphics_adapter==CGA) goto CGA_mode;
if (graphics_adapter==MCGA) goto CGA_mode;
goto abort_message;
VGA_mode:
graphics_adapter=VGA;graphics_mode=VGAHI;
initgraph(&graphics_adapter,&graphics_mode,"");
x_res=640;y_res=480;mode_flag=1;
maxx=639;minx=0;maxy=479;miny=0;screen_x=639;screen_y=479;
setcolor(7);moveto(0,472);
outtext("Revisions by A. Helder");
moveto(472,472);
outtext("Press any key to quit");
moveto(160,0);
outtext("USING C TO GENERATE PACKAGING DESIGN");
return;
EGA_ECD_mode:
graphics_adapter=EGA;graphics_mode=EGAHI;
initgraph(&graphics_adapter,&graphics_mode,"");
x_res=640;y_res=350;mode_flag=2;
maxx=639;minx=0;maxy=349;miny=0;screen_x=639;screen_y=349;
setcolor(7);moveto(0,342);
outtext("Revisions by A. Helder");
moveto(472,342);
outtext ("Press any key to quit");
moveto(160,0);
outtext("USING C TO GENERATE PACKAGING DESIGN");
return;
EGA_SCD_mode:
graphics_adapter=EGA;graphics_mode=EGALO;
initgraph(&graphics_adapter,&graphics_mode,"");
x_res=640;y_res=200;mode_flag=3;
maxx=639;minx=0;maxy=199;miny=0;screen_x=639;screen_y=199;
setcolor(7);moveto(0,192);
outtext("Revisions by A. Helder");
moveto(472,192);
outtext("PRESS ANY KEY TO QUIT");
moveto(160,0);
outtext("USING C TO GENERATE PACKAGING DESIGN");
return;
CGA_mode:
graphics_adapter=CGA;graphics_mode=CGAC3;
initgraph(&graphics_adapter,&graphics_mode,"");
x_res=320;y_res=200;mode_flag=1;C7=3;
maxx=319;minx=0;maxy=199;miny=0;screen_x=319;screen_y=199;
setcolor(3);moveto(48,192);
outtext("Revisions by A. Helder");
moveto(88,0);
outtext ("PACKAGING DESIGN");
return;
abort_message:
printf("\n\nUnable to proceed - Requires VGA,EGA,CGA or MCGA adapter");
printf("\nWith appropriate monitor");
exit(0);
}
/* ----------------------------------------------------------------------- */
/* SUBROUTINE: MAP 640*480 TEMPLATE TO 2D SCREEN */
void coords(void)
{
sx=sx*(x_res/640);sy=sy*(y_res/480);return;
}
/* ----------------------------------------------------------------------- */
/* SUBROUTINE: COPYRIGHT NOTICE */
int copyright[][3]={0x7c00,0x0000,0x0000,0x8231,
0x819c,0x645e,0xba4a,0x4252,0x96d0,0xa231,0x8252,0x955e,0xba4a,
0x43d2,0xf442,0x8231,0x825c,0x945e,0x7c00,0x0000,0x0000};
void notice(int x, int y){
int a,b,c; int t1=0;
for (t1=0;t1<=6;t1++)
{
a=copyright[t1][0];b=copyright[t1][1];
c=copyright[t1][2];
setlinestyle(USERBIT_LINE,a,NORM_WIDTH);
moveto(x,y);lineto(x+15,y);
setlinestyle(USERBIT_LINE,b,NORM_WIDTH);
moveto(x+16,y);lineto(x+31,y);
setlinestyle(USERBIT_LINE,c,NORM_WIDTH);
moveto(x+32,y);lineto(x+47,y);y++;
};
setlinestyle(USERBIT_LINE,0xFFFF,NORM_WIDTH);
return;}
/* end of source code */