home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume5 / tracer / tracer.c < prev   
C/C++ Source or Header  |  1989-02-03  |  3KB  |  121 lines

  1.  
  2.  
  3. /* tracer version 2.1 */
  4. #include <stdio.h>
  5. #include <math.h>
  6. #include "rtd.h"
  7. #include "macros.h"
  8.  
  9.  
  10. FILE * fp;
  11. double  suzie[300][300],
  12.         sam = 1.0;
  13. int     xsue,
  14.         ysue;
  15. struct ball *bl[150];
  16. int     level,
  17.         nob;
  18. struct sphere   ls;
  19.  
  20. main (argc, argv)
  21. int     argc;
  22. char  **argv;
  23. {
  24.     FILE * df, *texfile;
  25.     static double   xco,
  26.                     yco;
  27.     struct ray  rr;
  28.     struct vector   vp;
  29.     double  x,
  30.             y,
  31.             z;
  32.     int     i,
  33.             in = 0,
  34.             out = 0,
  35.             tex = 0;
  36.     int     c;
  37.  
  38. /* command interp */
  39.  
  40.     for (i = 1; i < argc; i++) {
  41.     if (argv[i][0] != '-')
  42.         booboo ("Options strt with a '-' bozo");
  43.     c = argv[i][1];
  44.  
  45.     switch (c) {
  46.         case ('i'): 
  47.         if (in)
  48.             booboo ("Sorry, but you may only have one input file");
  49.         in = 1;
  50.         if ((i + 1) >= argc || argv[i + 1][0] == '-')/* no arg */
  51.             df = stdin;
  52.         else
  53.             if ((df = fopen (argv[++i], "r")) == NULL)
  54.             booboo ("input file not found");
  55.         break;
  56.         case ('o'): 
  57.         if (out)
  58.             booboo ("Sorry, but you may have only one output file");
  59.         out = 1;
  60.         if ((i + 1) >= argc || argv[i + 1][0] == '-')/* no arg */
  61.             fp = stdout;
  62.         else
  63.             fp = fopen (argv[++i], "w");
  64.         break;
  65.         case ('s'): 
  66.         if (tex)
  67.             booboo ("Sorry, but you may have only one image file");
  68.         if ((i + 1) >= argc || argv[i + 1][0] == '-')/* no arg */
  69.             booboo ("-s requires an argument");
  70.         tex = 1;
  71.         if ((texfile = fopen (argv[++i], "r")) == NULL)
  72.             booboo ("image file not found");
  73.         break;
  74.         booboo ("this line shouldn't do anything");
  75.         case ('S'): 
  76.         if (argv[i][2] < '0' || argv[i][2] > '9'){
  77. printf("%c\n",argv[i][2]);
  78.             booboo ("-S needs a numerical argument");}
  79.         sam = atof (&(argv[i][2]));
  80.         break;
  81.         default: 
  82.         booboo ("Unrecognized option. Better try again");
  83.     }
  84.     }
  85.  
  86.  
  87.     if (!in)
  88.     if ((df = fopen ("bdata.i", "r")) == NULL)
  89.         booboo ("bdata.i not found");
  90.     if (!out)
  91.     fp = fopen ("data.dis", "w");
  92.     if (!tex)
  93.     if ((texfile = fopen ("pat.def", "r")) == NULL)
  94.         booboo ("pat.def not found");
  95.  
  96.  
  97.  
  98.     nob = g_bal (df);
  99.     g_bod (texfile);
  100.  
  101.  
  102.  
  103.     MV (95.0, 140.0, -200.0, vp);
  104.     MV (0.0, 900.0, 0.0, ls.cent);
  105.     ls.rad = 40;
  106.     fprintf (fp, "%d %d\n", (int) ((XMAX - XMIN) * SCALE +0.9999999), (int) ((YMAX - YMIN) * SCALE +0.9999999));
  107.  
  108.     for (yco = YMAX * SCALE; yco > YMIN * SCALE; yco--)
  109.     for (xco = XMIN * SCALE; xco < XMAX * SCALE; xco++) {
  110.         MV (xco / SCALE, yco / SCALE, 0.0, rr.org);
  111.         SV (rr.dir, rr.org, vp);
  112.         fprintf (fp, "%c", shade (&rr));
  113.     }
  114. }
  115.  
  116. booboo (str)
  117. char   *str; {
  118.     printf ("%s\n", str);
  119.     exit (-1);
  120. }
  121.