/* * (c) SPDsoft 1993 + ATIC */ #include #include #include #define X 0 #define Y 1 #define Boolean char #define MIN(a,b) ((a)>(b)?(b):(a)); void init_graphics(void); void redraw(void); void fatalError(char *name,char *str); Boolean get_options(int argc,char *argv[]); void usage(char *name); extern char *optarg; extern int optind,opterr; extern void init_geom(char* name); extern void draw_geom(void); typedef struct { Boolean doublebuffer; Boolean zbuffer; char* fname; long window_size[2]; long window_orig[2]; } pref; typedef struct { int left; int middle; int right; Device mdev[2]; short loc[2]; } mouse; Angle alfa=0; Angle beta=0; Angle gamma=0; Angle dalfa=0; pref G_Prefs; mouse G_Mouse; long zval; char* def_name="tr.dat"; void fatalError(char *name,char *str) { fprintf(stderr, "%s: Fatal Error: %s. bye...\n",name,str); exit(-2); } main(int argc,char *argv[]) { long gwid; long gw_x, gw_y; long MyEvent; short val; int quitting=0; short click=0; short first[2]; Angle sb, sg; char tmpStr[64]; get_options(argc,argv); init_graphics(); init_geom(G_Prefs.fname); gwid=winopen("Hola!"); getsize(&G_Prefs.window_size[X],&G_Prefs.window_size[Y]); getorigin(&G_Prefs.window_orig[X],&G_Prefs.window_orig[Y]); clear(); RGBmode(); if(G_Prefs.doublebuffer) doublebuffer(); gconfig(); ortho(-2,2,-2,2,-2,2); /* perspective(600,1.3333,10.0,10000.0);*/ if(G_Prefs.zbuffer) { zbuffer(TRUE); zval=getgdesc(GD_ZMAX); } for (quitting=0;!quitting;) { while (!qtest()) { if(G_Mouse.middle) { beta=sb+(Angle)( (G_Mouse.loc[X]-first[X])*1800/(short)G_Prefs.window_size[X]); gamma=sg-(Angle)( (G_Mouse.loc[Y]-first[Y])*1800/(short)G_Prefs.window_size[Y]); redraw(); } } /* Event Loop */ switch(MyEvent=qread(&val)) { case ESCKEY: quitting=!val; break; case AKEY: alfa-=dalfa; redraw(); break; case SKEY: alfa+=dalfa; redraw(); break; case QKEY: dalfa-=2; alfa+=dalfa; redraw(); break; case WKEY: dalfa+=2; alfa+=dalfa; redraw(); break; case RKEY: init_geom(G_Prefs.fname); redraw(); break; case REDRAW: redraw(); break; case WINQUIT: quitting=1; break; case INPUTCHANGE: break; case MOUSEX: /* mouses' sex ? */ G_Mouse.loc[X]=val; break; case MOUSEY: G_Mouse.loc[Y]=val; break; case LEFTMOUSE: G_Mouse.left=val; click=val; break; case MIDDLEMOUSE: G_Mouse.middle=val; click=val; if(click) { first[X]=getvaluator(MOUSEX); first[Y]=getvaluator(MOUSEY); sb=beta; sg=gamma; } break; default: break; } } winclose(gwid); return(0); } void init_graphics(void) { if(getgdesc(GD_BITS_NORM_DBL_RED)==0) { fprintf(stderr,"Warning, switching to single buffer mode\n"); G_Prefs.doublebuffer=0; } if(getgdesc(GD_BITS_NORM_ZBUFFER)==0) { fprintf(stderr,"Warning, no Z-buffer\n"); G_Prefs.zbuffer=0; } qdevice(AKEY); qdevice(SKEY); qdevice(QKEY); qdevice(WKEY); qdevice(RKEY); qdevice(ESCKEY); qdevice(REDRAW); qdevice(WINQUIT); G_Mouse.mdev[X]=MOUSEX; G_Mouse.mdev[Y]=MOUSEY; getdev(2,G_Mouse.mdev,G_Mouse.loc); qdevice(LEFTMOUSE); qdevice(MIDDLEMOUSE); qdevice(MOUSEX); qdevice(MOUSEY); } void redraw(void) { short sr,sg,sb; long gw_x, gw_y; getsize(&gw_x, &gw_y); if((G_Prefs.window_size[X]!=gw_x)||(G_Prefs.window_size[Y]!=gw_y)) { viewport(0,gw_x-1,0,gw_y-1); G_Prefs.window_size[X]=gw_x; G_Prefs.window_size[Y]=gw_y; } getorigin(&gw_x, &gw_y); if((G_Prefs.window_orig[X]!=gw_x)||(G_Prefs.window_orig[Y]!=gw_y)) { G_Prefs.window_orig[X]=gw_x; G_Prefs.window_orig[Y]=gw_y; } if(G_Prefs.zbuffer) czclear(0x000000, zval); else { cpack(0x00000000); clear(); } pushmatrix(); /* translate(0,0,-5000);*/ rotate(beta,'y'); rotate(gamma,'x'); rotate(alfa,'z'); draw_geom(); popmatrix(); gflush(); if(G_Prefs.doublebuffer) swapbuffers(); } /* ---------------------------------------------------------------*/ Boolean get_options(int argc,char *argv[]) { int opcion; int theError=0; G_Prefs.doublebuffer=1; G_Prefs.zbuffer=1; G_Prefs.fname=def_name; while ( (opcion=getopt(argc,argv,"hdzf:")) != EOF ) { switch(opcion) { case 'd': G_Prefs.doublebuffer = 0; break; case 'z': G_Prefs.zbuffer = 0; break; case 'f': G_Prefs.fname = optarg; break; default: usage(argv[0]); } if ( theError!=0) usage(argv[0]); } } void usage(char *name) { fprintf(stderr, "usage: %s [-d][-z][-h] [-f file]\n%s\n%s\n%s%s\n%s\n%s\n%s\n",name, "-d: disable double buffer", "-z: disable z buffer", "-f: data file, default ",def_name, "-h: This text", "", "SPDsoft 1994, gl demo" ); exit(-1); }