/* * (c) SPDsoft 1994 + ATIC */ #include #include #include #include "menu.h" #include "version.h" static char __ident[] = IDENT; #define VERS_STR ((char*)&__ident[4]) #define X 0 #define Y 1 #define DDELTA 0.07 #define Boolean int #define MIN(a,b) ((a)>(b)?(b):(a)); #ifndef M_PI # define M_PI 3.14159265358979323846 #endif 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 draw_geom( Angle alfa, Angle beta, Angle gamma, double i_d, int Reset ); typedef struct { Boolean doublebuffer; Boolean zbuffer; Boolean smooth; Boolean AutoSpin; 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=10; pref G_Prefs; mouse G_Mouse; long zval; double i_d, i_a; int cheat_flag=1; Boolean Reset=FALSE; 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; long menuval; short val; Boolean quitting=0; Boolean NeedRedraw=TRUE; short click=0; short first[2]; char tmpStr[64]; i_a = i_d = 0.0; get_options(argc,argv); init_graphics(); prefsize(300L,300L); gwid=winopen("SPDsoft: isoaxis"); 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(); keepaspect(300L,300L); winconstraints(); if(G_Prefs.zbuffer) { lsetdepth(getgdesc(GD_ZMIN),getgdesc(GD_ZMAX)); zbuffer(TRUE); zval=getgdesc(GD_ZMAX); } if ( G_Prefs.smooth ) { subpixel( TRUE ); blendfunction(BF_SA, BF_MSA); /* blendfunction(BF_MIN_SA_MDA, BF_ONE);*/ linesmooth( SML_SMOOTHER ); /* polysmooth(PYSM_ON);*/ } mmode(MVIEWING); /* ortho(-2.5,2.5,-2.5,2.5,-2.5,2.5);*/ for (quitting=0;!quitting;) { while (qtest() || (!NeedRedraw ) ) { /* Event Loop */ switch(MyEvent=qread(&val)) { case ESCKEY: quitting=!val; break; case ZKEY: i_d += DDELTA; if(i_d > M_PI) i_d = -M_PI+DDELTA; NeedRedraw=TRUE; break; case XKEY: i_d -= DDELTA; if(i_d < -M_PI) i_d = M_PI - DDELTA; NeedRedraw=TRUE; break; case AKEY: alfa=-dalfa; NeedRedraw=TRUE; break; case SKEY: alfa=+dalfa; NeedRedraw=TRUE; break; case QKEY: dalfa-=2; alfa=+dalfa; NeedRedraw=TRUE; break; case WKEY: dalfa+=2; alfa=+dalfa; NeedRedraw=TRUE; break; case RKEY: polymode(PYM_FILL); i_d=0.0; alfa=beta=gamma=0; Reset=TRUE; NeedRedraw=TRUE; break; case REDRAW: NeedRedraw=TRUE; 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 RIGHTMOUSE: if (val) { switch(menuval = dopup(menu[MainMenu])) { case SpinMode: G_Prefs.AutoSpin = !G_Prefs.AutoSpin ; break; case Points: polymode(PYM_POINT); break; case Lines: polymode(PYM_LINE); break; case Polygons: polymode(PYM_FILL); break; case Hollow: polymode(PYM_HOLLOW); break; case Restart: polymode(PYM_FILL); i_d = 0.0; alfa=beta=gamma=0; Reset = TRUE; break; case Quit: quitting = TRUE; break; default: break; } NeedRedraw=TRUE; } break; case MIDDLEMOUSE: G_Mouse.middle=val; click=val; if(click) { first[X]=getvaluator(MOUSEX); first[Y]=getvaluator(MOUSEY); } NeedRedraw=TRUE; break; default: break; } /* switch */ if (quitting) break; } /* while */ if(G_Mouse.middle) { beta=(Angle)( (G_Mouse.loc[X]-first[X])*1800/(short)G_Prefs.window_size[X]); gamma=-(Angle)( (G_Mouse.loc[Y]-first[Y])*1800/(short)G_Prefs.window_size[Y]); first[X] = G_Mouse.loc[X]; first[Y] = G_Mouse.loc[Y]; redraw(); } else { redraw(); if(!G_Prefs.AutoSpin) NeedRedraw=FALSE; } } /* for */ 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 available\n"); G_Prefs.zbuffer=0; } qdevice(ZKEY); qdevice(XKEY); qdevice(AKEY); qdevice(SKEY); qdevice(QKEY); qdevice(WKEY); qdevice(RKEY); qdevice(ESCKEY); qdevice(REDRAW); qdevice(WINSHUT); 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(RIGHTMOUSE); qdevice(MOUSEX); qdevice(MOUSEY); menu[DrawMenu]=defpup(TheMenu[DrawMenu]); menu[MainMenu]=defpup(TheMenu[MainMenu],menu[DrawMenu]); } void redraw(void) { 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(); } draw_geom(alfa, beta, gamma, i_d, Reset); if(!G_Prefs.AutoSpin) alfa=beta=gamma=0; Reset=0; 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.smooth = 0; G_Prefs.AutoSpin = 1; while ( (opcion=getopt(argc,argv,"cashdzV")) != EOF ) { switch(opcion) { case 'c': cheat_flag = !cheat_flag; break; case 'a': G_Prefs.AutoSpin = 0; break; case 'd': G_Prefs.doublebuffer = 0; break; case 'V': fprintf(stdout,"%s\n", VERS_STR); exit(0); break; case 'z': G_Prefs.zbuffer = 0; break; case 's': G_Prefs.smooth = 1; /* polysmooth PYSM_ON*/ if(1!=getgdesc(GD_POLYSMOOTH)) { fprintf(stderr,"Warning: Antialiasing not available\n"); /* G_Prefs.smooth = 0;*/ } break; default: usage(argv[0]); } if ( theError!=0) usage(argv[0]); } } void usage(char *name) { fprintf(stderr, "usage: %s [-adzVh]\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",name, "-d: disable double buffer", "-z: disable z buffer", "-s: smooth (still working on it!)", "-V: Print version", "-a: AutoSpin initially off", "-h: This text", "Note: z and x flips isoaxis(tm) in and out" ); exit(-1); }