home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / graphic / qrt / qrt.c < prev    next >
Text File  |  1990-01-21  |  7KB  |  292 lines

  1. #include "header.h"
  2.  
  3. int GetObject();
  4. int RayTrace();
  5.  
  6.  
  7. /**********************************************************
  8.  
  9.                Test routine - unused
  10.  
  11.  **********************************************************/
  12.  
  13. #ifdef TESTS
  14.  
  15. Tree_Walker(obj,num)
  16.   OBJ_PTR obj;
  17.   int num;
  18. {
  19.   int x;
  20.  
  21.   for (x=0; x<num; x++) printf(" ");
  22.   printf("%d\n",obj->type);
  23.  
  24.   if (obj->child!=NULL)
  25.     Tree_Walker(obj->child,num+2);
  26.  
  27.   if (obj->nextobj!=NULL)
  28.     Tree_Walker(obj->nextobj,num);
  29. }
  30.  
  31. #endif
  32.  
  33.  
  34. /**********************************************************
  35.  
  36.     Initialize some observer data, like up and right
  37.     vectors, focal length, etc.
  38.  
  39.  **********************************************************/
  40.  
  41. Setup_Observer() {
  42.  
  43.   if (THEWORLD.observer==NULL) Error(NO_OBSERVER,1);
  44.  
  45.   Normalize(&((THEWORLD.observer)->vect1));
  46.   VectEQ(&(THEWORLD.obsup),&((THEWORLD.observer)->vect2));
  47.  
  48.   CrossProd(&(THEWORLD.obsright),             /* right = up x dir */
  49.             &(THEWORLD.obsup),
  50.             &((THEWORLD.observer)->vect1));
  51.  
  52.   CrossProd(&(THEWORLD.obsup),                /* up = dir x right */
  53.             &((THEWORLD.observer)->vect1),
  54.             &(THEWORLD.obsright));
  55.  
  56.   Normalize(&(THEWORLD.obsup));
  57.   Normalize(&(THEWORLD.obsright));
  58.  
  59. }
  60.  
  61.  
  62. /**********************************************************
  63.  
  64.          Initialize the world and assign defaults
  65.  
  66.  **********************************************************/
  67.  
  68. init_world() {                     /* make a universe */
  69.   THEWORLD.stack      =
  70.   THEWORLD.observer   =
  71.   THEWORLD.instances  =
  72.   THEWORLD.sky        =
  73.   THEWORLD.lamps      = NULL;
  74.   THEWORLD.patlist    = NULL;
  75.   THEWORLD.outfile    = NULL;
  76.   THEWORLD.objcount   = 0;
  77.   THEWORLD.lampcount  = 0;
  78.   THEWORLD.flength    = 50;
  79.  
  80.   THEWORLD.skycolor_zenith.r =
  81.   THEWORLD.skycolor_zenith.b =
  82.   THEWORLD.skycolor_zenith.g =
  83.   THEWORLD.skycolor_horiz.r  =
  84.   THEWORLD.skycolor_horiz.g  =
  85.   THEWORLD.skycolor_horiz.b  = 0;
  86.  
  87.   THEWORLD.ray_intersects  =
  88.   THEWORLD.pixels_hit      =
  89.   THEWORLD.primary_traced  =
  90.   THEWORLD.to_lamp         =
  91.   THEWORLD.refl_trans      =
  92.   THEWORLD.bbox_intersects =
  93.   THEWORLD.pattern_matches =
  94.   THEWORLD.intersect_tests = 0;
  95.  
  96.   THEWORLD.globindex = 1.00;   /* global index of refraction */
  97.  
  98.   def.cinfo.trans.r  =         /* default transmittion */
  99.   def.cinfo.trans.g  =
  100.   def.cinfo.trans.b  = 0;
  101.  
  102.   def.cinfo.mirror.r =         /* default reflection */
  103.   def.cinfo.mirror.g =
  104.   def.cinfo.mirror.b = 0;
  105.  
  106.   def.cinfo.amb.r    =         /* default ambiant light */
  107.   def.cinfo.amb.g    =
  108.   def.cinfo.amb.b    = 25;
  109.  
  110.   def.cinfo.diff.r   =         /* default diffuse light */
  111.   def.cinfo.diff.g   =
  112.   def.cinfo.diff.b   = CNUM;
  113.  
  114.   def.cinfo.density.x=
  115.   def.cinfo.density.y=
  116.   def.cinfo.density.z= .01;    /* default glass density */
  117.  
  118.   def.cinfo.fuzz     = 0;
  119.   def.cinfo.index    = CNUM;
  120.   def.cinfo.dither   = 3;
  121.   def.cinfo.reflect  = 0;
  122.   def.cinfo.sreflect = 10;
  123.  
  124.   def.shadow        = TRUE;    /* shadows */
  125.   def.vlamp         = FALSE;   /* no visible lamps */
  126.   def.int_x         =          /* no interpolation */
  127.   def.int_y         = 1;
  128.   def.threshold     = .1;      /* threshold at 10 percent */
  129.   def.ithreshold    = def.threshold * CNUM;
  130.  
  131. # ifdef AMIGA
  132.     def.x_res       = 320;     /* AMIGA 4096 color mode */
  133.     def.y_res       = 400;
  134.     def.aspect      = .56;
  135. # endif
  136.  
  137. # ifdef UNIX
  138.     def.x_res       = 768;     /* UNIX medium sized window */
  139.     def.y_res       = 640;
  140.     def.aspect      = .89;
  141. # endif
  142.  
  143. # ifdef UNIX_HIRES
  144.     def.x_res       = 1280;    /* HP hi-res workstation */
  145.     def.y_res       = 1024;
  146.     def.aspect      = .89;
  147. # endif
  148.  
  149. # ifdef MAC_II
  150.     def.x_res       = 640;     /* MAC II full screen */
  151.     def.y_res       = 480;
  152.     def.aspect      = 1.0;     /* is this right? */
  153. # endif
  154.  
  155. # ifdef ATARI_ST
  156.     def.x_res       = 640;     /* ATARI ST full screen */
  157.     def.y_res       = 200;     /* don't know aspect */
  158. # endif
  159.  
  160. # ifdef MSDOS
  161.     def.x_res       = 320;    /* VGA mode 13h */
  162.     def.y_res       = 200;
  163.     def.aspect      = 0.565;
  164. # endif
  165.  
  166. # ifdef MSDOS
  167.     def.x_res       = 800;    /* SVGA mode */
  168.     def.y_res       = 600;
  169.     def.aspect      = 1.0667;
  170. # endif
  171.  
  172. # ifdef MSDOS
  173.     def.x_res       = 640;    /* SVGA mode */
  174.     def.y_res       = 480;
  175.     def.aspect      = 1.0667;
  176. # endif
  177.  
  178. }
  179.  
  180.  
  181. /**********************************************************
  182.  
  183.      Call other stuff to load world and generate image
  184.  
  185.      Changed 12 Mar 88 to add command line arguments.
  186.  
  187.  **********************************************************/
  188.  
  189. main(argc,argv)
  190.   int argc; char *argv[];
  191. {
  192.  
  193.   printf("\nQuick Ray Trace: Copyright 1988, 1989 Steve Koren\nVersion 1.5\n");
  194.  
  195.   init_world();
  196.  
  197.   if (!LoadWorld()) Error(SYNTAX_ERROR,2);
  198.  
  199.   Parse_CL_Args(argc,argv);
  200.  
  201.   Make_Bbox(THEWORLD.stack);     /* make bboxes */
  202.   Do_Precomp(THEWORLD.stack);    /* precompute stuff */
  203.  
  204.   fclose(stdin);
  205.  
  206.   Setup_Observer();
  207.  
  208.   Open_File();
  209.     Screen_Trace();
  210.   Close_File();
  211.  
  212.   World_Stats();
  213.   fclose(stdout);
  214.   return(NULL);
  215. }
  216.  
  217.  
  218. /**********************************************************
  219.  
  220.   Added 12 Mar 88 to parse command line arguments.
  221.  
  222.   Command line arguments are optional as follows:
  223.  
  224.    -xres int -yres int -aspect float -foclen float
  225.  
  226.   The command line arguments take precidence over the
  227.   DEFAULT() command values.
  228.  
  229.  **********************************************************/
  230.  
  231. Parse_CL_Args(argc,argv)
  232.   int argc;
  233.   char *argv[];
  234. {
  235.   int x, atoi(), found;
  236.  
  237.   for (x=1; x<argc; x++) {       /* parse command line args */
  238.     found = FALSE;
  239.  
  240.     if (strcmp(argv[x],"-xres")==0) {
  241.  
  242.       if (++x >= argc)
  243.         Error(TOO_FEW_PARMS,3);
  244.  
  245.       if ((def.x_res = atoi(argv[x])) <= 0)
  246.         Error(LESS_THAN_ZERO,4);
  247.  
  248.       found        = TRUE;
  249.     }
  250.  
  251.     if (strcmp(argv[x],"-yres")==0) {
  252.  
  253.       if (++x >= argc)
  254.         Error(TOO_FEW_PARMS,5);
  255.  
  256.       if ((def.y_res = atoi(argv[x])) <= 0)
  257.         Error(LESS_THAN_ZERO,6);
  258.  
  259.       found        = TRUE;
  260.     }
  261.  
  262.     if (strcmp(argv[x],"-aspect")==0) {
  263.  
  264.       if (++x >= argc)
  265.         Error(TOO_FEW_PARMS,7);
  266.  
  267.       if ((def.aspect = atof(argv[x])) <= 0)
  268.         Error(LESS_THAN_ZERO,8);
  269.  
  270.       found        = TRUE;
  271.     }
  272.  
  273.     if (strcmp(argv[x],"-foclen")==0) {
  274.  
  275.       if (++x >= argc)
  276.         Error(TOO_FEW_PARMS,9);
  277.  
  278.       if ((THEWORLD.flength = atoi(argv[x])) <=0)
  279.         Error(LESS_THAN_ZERO,010);
  280.  
  281.       found        = TRUE;
  282.     }
  283.  
  284.     if (!found) {
  285.       printf("Usage: %s [-xres n] [-yres n] [-aspect n] [-foclen n]\n\n",
  286.              argv[0]);
  287.       Error(ILLEGAL_OPTION,011);
  288.     }
  289.  
  290.   }
  291. }
  292.