home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / macraysh.sit / Code / Source / options.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-28  |  6.6 KB  |  262 lines

  1. /*
  2.  * options.c
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * $Id: options.c,v 4.0 91/07/17 14:46:47 kolb Exp Locker: kolb $
  17.  *
  18.  * $Log:    options.c,v $
  19.  * Revision 4.0  91/07/17  14:46:47  kolb
  20.  * Initial version.
  21.  * 
  22.  */
  23. #include "rayshade.h"
  24. #include "options.h"
  25. #include "stats.h"
  26. #include "viewing.h"
  27.  
  28. RSOptions    Options;
  29.  
  30. static void usage();
  31.  
  32. void
  33. RSOptionsSet(argc, argv)
  34. int argc;
  35. char **argv;
  36. {
  37.     Options.progname = strsave(argv[0]);
  38.     Options.inputname = (char *)NULL;
  39.  
  40.     while (--argc) {
  41.         argv++;
  42.         if (argv[0][0] != '-') {
  43.             /*
  44.              * Must be the input file name.
  45.              * If already given, complain and then exit.
  46.              */
  47.             if (Options.inputname != (char *)NULL) {
  48.                 usage();    
  49.                 exit(1);
  50.             }
  51.             Options.inputname = strsave(argv[0]);
  52.             continue;
  53.         }
  54.         /* else */
  55.         switch(argv[0][1]) {
  56.             case 'A':
  57.                 /*
  58.                  * First frame number
  59.                  */
  60.                 Options.startframe = atoi(argv[1]);
  61.                 argv++; argc--;
  62.                 break;
  63.             case 'C':
  64.                 Options.cutoff.r = atof(argv[1]);
  65.                 Options.cutoff.g = atof(argv[2]);
  66.                 Options.cutoff.b = atof(argv[3]);
  67.                 Options.cutoff_set = TRUE;
  68.                 argv += 3; argc -= 3;
  69.                 break;
  70.             case 'D':
  71.                 Options.maxdepth = atoi(argv[1]);
  72.                 Options.maxdepth_set = TRUE;
  73.                 argv++; argc--;
  74.                 break;
  75.             case 'E':
  76.                 Options.eyesep = atof(argv[1]);
  77.                 Options.eyesep_set = TRUE;
  78.                 argc--; argv++;
  79.                 break;
  80.             case 'F':
  81.                 Options.report_freq = atoi(argv[1]);
  82.                 if (Options.report_freq < 1)
  83.                     Options.report_freq = 1;
  84.                 Options.freq_set = TRUE;
  85.                 argv++; argc--;
  86.                 break;
  87.             case 'f':
  88.                 Options.flipnorm = !Options.flipnorm;
  89.                 break;
  90.             case 'G':
  91.                 Options.gamma = atof(argv[1]);
  92.                 argv++; argc--;
  93.                 break;
  94.             case 'g':
  95.                 Options.gaussian = !Options.gaussian;
  96.                 break;
  97.             case 'h':
  98.             case '?':
  99.                 usage();
  100.                 exit(0);
  101.                 break;
  102.             case 'j':
  103.                 Options.jitter = !Options.jitter;
  104.                 Options.jitter_set = TRUE;
  105.                 break;
  106.             case 'l':
  107.                 Options.stereo = LEFT;
  108.                 break;
  109.             case 'N':
  110.                 Options.totalframes = atof(argv[1]);
  111.                 Options.totalframes_set = TRUE;
  112.                 argv++; argc--;
  113.                 break;
  114.             case 'n':
  115.                 Options.no_shadows = !Options.no_shadows;
  116.                 break;
  117.             case 'O':
  118.                 Options.imgname = strsave(argv[1]);
  119.                 argv++;
  120.                 argc--;
  121.                 break;
  122.             case 'o':
  123.                 Options.shadowtransp = !Options.shadowtransp;
  124.                 break;
  125.             case 'p':
  126.                 /*
  127.                  * Preview-quality rendering
  128.                  * no shadows
  129.                  * max depth of 0
  130.                  * 1 jittered sample/pixel
  131.                  */
  132.                 Options.no_shadows = TRUE;
  133.                 Options.maxdepth = 0;
  134.                 Options.maxdepth_set = TRUE;
  135.                 Options.jitter = TRUE;
  136.                 Options.jitter_set = TRUE;
  137.                 Options.samples = 1;
  138.                 Options.samples_set = TRUE;
  139.                 break;
  140.             case 'q':
  141.                 Options.quiet = TRUE;
  142.                 break;
  143.             case 'R':
  144.                 Screen.xres = atoi(argv[1]);
  145.                 Screen.yres = atoi(argv[2]);
  146.                 Options.resolution_set = TRUE;
  147.                 argv += 2;
  148.                 argc -= 2;
  149.                 break;
  150.             case 'r':
  151.                 Options.stereo = RIGHT;
  152.                 break;
  153.             case 'S':
  154.                 Options.samples = atoi(argv[1]);
  155.                 if (Options.samples < 1)
  156.                     Options.samples = 1;
  157.                 Options.samples_set = TRUE;
  158.                 argv++; argc--;
  159.                 break;
  160.             case 's':
  161.                 Options.cache = !Options.cache;
  162.                 break;
  163.             case 'T':
  164.                 Options.contrast.r = atof(argv[1]);
  165.                 Options.contrast.g = atof(argv[2]);
  166.                 Options.contrast.b = atof(argv[3]);
  167.                 Options.contrast_set = TRUE;
  168.                 argv += 3;
  169.                 argc -= 3;
  170.                 break;
  171.             case 'v':
  172.                 Options.verbose = TRUE;
  173.                 break;
  174.             case 'V':
  175.                 Options.verbose = TRUE;
  176.                 if (argv[1][0] == '-') {
  177.                     /* User probably blew it, and
  178.                      * it's difficult to remove a file
  179.                      * that begins with '-'...
  180.                      */
  181.                     usage();
  182.                     exit(2);
  183.                 }
  184.                 argv++; argc--;
  185.                 break;
  186.  
  187.             default:
  188.                 RLerror(RL_PANIC,"Bad argument: %s\n",argv[0],0,0);
  189.         }
  190.     }
  191. }
  192.  
  193. void
  194. RSOptionsList()
  195. {
  196.     if (Options.totalframes > 1) {
  197.         printf("Rendering frames %d through %d.\n",Options.startframe, Options.endframe);
  198.     } else {
  199.         printf("Rendering frame %d.\n", Options.startframe);
  200.     }
  201.  
  202.     printf("Screen resolution: %d x %d\n",Screen.xres,Screen.yres);
  203.     printf("Image window: (%d - %d), (%d - %d).\n",Screen.minx, Screen.maxx, Screen.miny, Screen.maxy);
  204.  
  205.     if (Options.jitter)
  206.         printf("Using jittered sampling, ");
  207.     printf("Max sampling rate %d %s/pixel.\n",
  208.         Options.samples*Options.samples,
  209.         Options.samples == 1 ? "sample" : "samples");
  210.  
  211.     printf("Maximum contrast: %g red, %g green, %g blue.\n",
  212.         Options.contrast.r, Options.contrast.g,
  213.         Options.contrast.b);
  214.     printf("Maximum ray depth: %d.  Cutoff thresh: %g %g %g.\n",
  215.             Options.maxdepth,
  216.             Options.cutoff.r, Options.cutoff.g, Options.cutoff.b);
  217.     if (Options.stereo == LEFT)
  218.         printf("Rendering image for left eye.\n");
  219.     else if (Options.stereo == RIGHT)
  220.         printf("Rendering image for right eye.\n");
  221.     if (Options.no_shadows) {
  222.         printf("No shadows are rendered.\n");
  223.     } else if (Options.shadowtransp) {
  224.         printf("Object opacity affects depth of shadowing.\n");
  225.     }
  226.     if (!Options.cache)
  227.         printf("Shadow caching is disabled.\n");
  228.     if (Options.totalframes != 1)
  229.         printf("Rendering %d frames.\n",Options.totalframes);
  230. }
  231.  
  232. static void
  233. usage()
  234. {
  235.     printf("usage: %s [options] [filename]\n", Options.progname);
  236.     printf("Where options include:\n");
  237.     printf("\t-A frame\t(Begin with given frame #.)\n");
  238.  
  239.     printf("\t-C thresh\t(Set adaptive ray tree cutoff value.)\n");
  240.  
  241.     printf("\t-D depth\t(Set maximum ray tree depth.)\n");
  242.     printf("\t-E eye_sep\t(Set eye separation in stereo pairs.)\n");
  243.  
  244.     printf("\t-F freq\t\t(Set frequency of status report.)\n");
  245.     printf("\t-G gamma\t(Use given gamma correction exponent.)\n");
  246.     printf("\t-h \t\t(Print this message.)\n");
  247.     printf("\t-l \t\t(Render image for left eye view.)\n");
  248.     printf("\t-N number\t(Render given number of frames.)\n");
  249.     printf("\t-n \t\t(Do not render shadows.)\n");
  250.     printf("\t-O outfile \t(Set output file name.)\n");
  251.     printf("\t-o \t\t(Toggle opacity effect on shadowing.)\n");
  252.     printf("\t-p \t\t(Preview-quality rendering.)\n");
  253.     printf("\t-q \t\t(Run quietly.)\n");
  254.     printf("\t-R xres yres\t(Render at given resolution.)\n");
  255.     printf("\t-r \t\t(Render image for right eye view.)\n");
  256.     printf("\t-S samples\t(Max density of samples^2 samples.)\n");
  257.     printf("\t-s \t\t(Don't cache shadowing information.)\n");
  258.     printf("\t-T r g b\t(Set contrast threshold (0. - 1.).)\n");
  259.     printf("\t-V filename \t(Write verbose output to filename.)\n");
  260.     printf("\t-v \t\t(Verbose output.)\n");
  261. }
  262.