home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Graphics / graphics-16000.iso / msdos / raytrace / rayshade / src / setup.c < prev    next >
C/C++ Source or Header  |  1992-05-04  |  6KB  |  266 lines

  1. /*
  2.  * setup.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: setup.c,v 4.0.1.2 92/01/14 18:29:35 cek Exp Locker: cek $
  17.  *
  18.  * $Log:    setup.c,v $
  19.  * Revision 4.0.1.2  92/01/14  18:29:35  cek
  20.  * patch3: Added initialization of cpp option.
  21.  * 
  22.  * Revision 4.0.1.1  91/09/29  15:52:20  cek
  23.  * patch1: Added crop window initialization.
  24.  * patch1: Moved RSViewing call to appropriate location.
  25.  * 
  26.  * Revision 4.0  91/07/17  14:47:24  kolb
  27.  * Initial version.
  28.  * 
  29.  */
  30. #include "rayshade.h"
  31. #include "defaults.h"
  32. #include "surface.h"
  33. #include "atmosphere.h"
  34. #include "light.h"
  35. #include "infinite.h"
  36. #include "list.h"
  37. #include "options.h"
  38. #include "stats.h"
  39. #include "viewing.h"
  40. #include "picture.h"
  41.  
  42. #ifdef MULTIMAX
  43. #include <parallel.h>
  44. #define SHARED_BYTES    23    /* 2^23 bytes of shared memory */
  45. #endif
  46.  
  47. extern GeomList *Defstack;
  48.  
  49. static void SetupWorld();
  50.  
  51. /*
  52.  * Set default parameters
  53.  */
  54. void
  55. RSSetup()
  56. {
  57.     extern SurfList *CurSurf;
  58.     extern Medium TopMedium;
  59.     extern void NoiseInit();
  60. #ifdef MULTIMAX
  61.     unsigned int bytes;
  62.  
  63.     /*
  64.      * Initialize shared memory stuff.
  65.      */
  66.     bytes = 1 << SHARED_BYTES;
  67.     if (share_malloc_init(bytes) == -1) {
  68.         RLerror(RL_PANIC, "Cannot share_malloc %d bytes.\n",bytes);
  69.     } else
  70.         fprintf(fstats,"Malloced %d bytes of shared memory.\n",
  71.                 bytes);
  72. #endif
  73.  
  74.     Camera.hfov = HFOV;
  75.     Camera.vfov = UNSET;
  76.     Camera.pos.x = EYEX;
  77.     Camera.pos.y = EYEY;
  78.     Camera.pos.z = EYEZ;
  79.     Camera.lookp.x = LOOKX;
  80.     Camera.lookp.y = LOOKY;
  81.     Camera.lookp.z = LOOKZ;
  82.     Camera.up.x = UPX;
  83.     Camera.up.y = UPY;
  84.     Camera.up.z = UPZ;
  85.     Camera.focaldist = UNSET;
  86.     Camera.aperture = 0.;
  87.  
  88.     Screen.xres = Screen.yres = UNSET;
  89.  
  90. #ifdef __WATCOMC__
  91.     Options.cpp = FALSE;
  92. #else
  93.     Options.cpp = TRUE;
  94. #endif
  95.     Options.maxdepth = MAXDEPTH;
  96.     Options.report_freq = REPORTFREQ;
  97.     Options.jitter = TRUE;
  98.     Options.samples = UNSET;
  99.     Options.gaussian = GAUSSIAN;
  100.     Options.filterwidth = UNSET;
  101.     Options.contrast.r = UNSET;
  102.     Options.ambient.r = Options.ambient.g =
  103.         Options.ambient.b = 1.0;
  104.     Options.cutoff.r = UNSET;
  105.     Options.cache = TRUE;
  106.     Options.shadowtransp = TRUE;
  107.     Options.crop[LOW][X] = Options.crop[LOW][Y] = 0.;
  108.     Options.crop[HIGH][X] = Options.crop[HIGH][Y] = 1.;
  109.     Stats.fstats = stderr;
  110.     Options.pictfile = stdout;
  111. #ifdef URT
  112.     Options.alpha = TRUE;
  113.     Options.exp_output = FALSE;
  114. #endif
  115.     Options.gamma = GAMMA;
  116.     Options.eyesep = UNSET;
  117. #ifdef LINDA
  118.     Options.workers = WORKERS;
  119. #endif
  120.  
  121.     Options.totalframes = 1;
  122.     Options.startframe = 0;
  123.     Options.starttime = 0.;
  124.     Options.framelength = 1.;
  125.     Options.shutterspeed = 0.;
  126.  
  127.     TopMedium.index = DEFAULT_INDEX;
  128.     TopMedium.statten = 1.0;
  129.     NoiseInit();            /* Initialize values for Noise() */
  130.  
  131.     /*
  132.      * Top of object definition stack points to the World object.
  133.      * The World object is always a list.
  134.      */
  135.     Defstack = GeomStackPush(GeomListCreate(), (GeomList *)NULL);
  136.     Defstack->obj->name = strsave("World");
  137.     /* Initialize surface stack */
  138.     CurSurf = SurfPush((Surface *)NULL, (SurfList *)NULL);
  139. }
  140.  
  141. /*
  142.  * cleanup()
  143.  *
  144.  * Initialize options/variables not set on command line or in input file.
  145.  * Perform sanity checks on widow dimension, maxdepth, etc.
  146.  */
  147. void
  148. RSCleanup()
  149. {
  150.     extern Light *Lights;
  151.     extern void OpenStatsFile();
  152.     extern FILE *yyin;
  153.  
  154.     yyin = (FILE *)NULL;    /* mark that we're done reading input */
  155.  
  156.     if (Options.samples == UNSET)
  157.         Options.samples = DEFSAMPLES;
  158.  
  159.     if (Options.filterwidth == UNSET) {
  160.         if (Options.gaussian)
  161.             Options.filterwidth = FILTERWIDTH;
  162.         else
  163.             /* Default box filter width of 1.0 */
  164.             Options.filterwidth = 1.0;
  165.     }
  166.  
  167.     Options.endframe = Options.startframe + Options.totalframes -1;
  168.  
  169.     OpenStatsFile();
  170.  
  171.     ViewingSetup();
  172.  
  173.     if (Options.cutoff.r == UNSET)
  174.         Options.cutoff.r = Options.cutoff.g =
  175.             Options.cutoff.b = DEFCUTOFF;
  176.  
  177.     /*
  178.      * Set contrast.
  179.      */
  180.     if (Options.contrast.r == UNSET) {
  181.         Options.contrast.r = DEFREDCONT;
  182.         Options.contrast.g = DEFGREENCONT;
  183.         Options.contrast.b = DEFBLUECONT;
  184.     }
  185.  
  186.     /*
  187.      * Image gamma is inverse of display gamma.
  188.      */
  189.     if (fabs(Options.gamma) > EPSILON)
  190.         Options.gamma = 1. / Options.gamma;
  191.     else
  192.         Options.gamma = FAR_AWAY;
  193.  
  194.     if (Options.maxdepth < 0)
  195.         Options.maxdepth = 0;
  196.  
  197.  
  198.     LightSetup();
  199. }
  200.  
  201. void
  202. RSStartFrame(frame)
  203. int frame;
  204. {
  205.     /*
  206.      * Set the frame start time
  207.      */
  208.     Options.framenum = frame;
  209.     Options.framestart = Options.starttime +
  210.             Options.framenum*Options.framelength;
  211.     SamplingSetTime(Options.framestart, Options.shutterspeed,
  212.             Options.framenum);
  213.     /*
  214.      * Set up viewing parameters.
  215.      * Can't animate camera yet; when possible, this will
  216.      * need to be much smarter.
  217.      * RSViewing();
  218.      */
  219.  
  220.     /*
  221.      * Initialize world
  222.      */
  223.     WorldSetup();
  224. }
  225.  
  226. /*
  227.  * Initialize non-time-varying goodies.
  228.  */
  229. void
  230. RSInitialize(argc, argv)
  231. int argc;
  232. char **argv;
  233. {
  234.     /*
  235.       * Initialize variables, etc.
  236.      */
  237.     RSSetup();
  238.     /*
  239.      * Parse options from command line.
  240.      */
  241.     RSOptionsSet(argc, argv);
  242.     /*
  243.      * Process input file.
  244.      */
  245.     if (Options.verbose) {
  246.         VersionPrint();
  247.         fprintf(Stats.fstats,"Reading input file...\n");
  248.         (void)fflush(Stats.fstats);
  249.     }
  250.     RSReadInputFile();
  251.     /*
  252.      * Set variables that weren't set on command line
  253.      * or in input file.
  254.      */
  255.     RSCleanup();
  256.     /*
  257.      * Set sampling options.
  258.      */
  259.     SamplingSetOptions(Options.samples, Options.gaussian,
  260.                Options.filterwidth);
  261.     /*
  262.      * Camera is currently static; initialize it here.
  263.      */
  264.     RSViewing();
  265. }
  266.