home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / macraysh.sit / Code / Source / setup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-11  |  6.2 KB  |  276 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 91/07/17 14:47:24 kolb Exp Locker: kolb $
  17.  *
  18.  * $Log:    setup.c,v $
  19.  * Revision 4.0  91/07/17  14:47:24  kolb
  20.  * Initial version.
  21.  * 
  22.  */
  23. #include "rayshade.h"
  24. #include "defaults.h"
  25. #include "surface.h"
  26. #include "atmosphere.h"
  27. #include "light.h"
  28. #include "infinite.h"
  29. #include "list.h"
  30. #include "options.h"
  31. #include "stats.h"
  32. #include "viewing.h"
  33. #include "picture.h"
  34.  
  35. extern GeomList *Defstack;
  36.  
  37. void RSResetValues() ;
  38.  
  39. /*
  40.  * Set default parameters
  41.  */
  42. void
  43. RSSetup()
  44. {
  45.     extern SurfList *CurSurf;
  46.     extern Medium TopMedium;
  47.     extern void NoiseInit();
  48.  
  49.     Camera.hfov = HFOV;
  50.     Camera.vfov = UNSET;
  51.     Camera.pos.x = EYEX;
  52.     Camera.pos.y = EYEY;
  53.     Camera.pos.z = EYEZ;
  54.     Camera.lookp.x = LOOKX;
  55.     Camera.lookp.y = LOOKY;
  56.     Camera.lookp.z = LOOKZ;
  57.     Camera.up.x = UPX;
  58.     Camera.up.y = UPY;
  59.     Camera.up.z = UPZ;
  60.     Camera.focaldist = UNSET;
  61.     Camera.aperture = 0.;
  62.  
  63.     Screen.xres = Screen.yres = 50;
  64.  
  65.     Options.contrast.r = DEFREDCONT;
  66.     Options.contrast.g = DEFGREENCONT;
  67.     Options.contrast.b = DEFBLUECONT;
  68.         
  69.     Options.maxdepth = MAXDEPTH;
  70.     Options.report_freq = REPORTFREQ;
  71.     Options.jitter = TRUE;
  72.     Options.samples = UNSET;
  73.     Options.gaussian = GAUSSIAN;
  74.     Options.filterwidth = UNSET;
  75.     Options.contrast.r = UNSET;
  76.     Options.ambient.r = Options.ambient.g =
  77.         Options.ambient.b = 1.0;
  78.     Options.cutoff.r = UNSET;
  79.     Options.cache = TRUE;
  80.     Options.shadowtransp = TRUE;
  81. /*    Options.xmin = Options.ymin = 0.;
  82.     Options.xmax = Options.ymax = 1.; */
  83.  
  84.     Options.crop[LOW][X] = Options.crop[LOW][Y] = 0.;
  85.     Options.crop[HIGH][X] = Options.crop[HIGH][Y] = 1.;
  86.     
  87.     Options.pictfile = stdout;
  88.     Options.gamma = GAMMA;
  89.     Options.eyesep = UNSET;
  90.  
  91.     Options.totalframes = 1;
  92.     Options.startframe = 0;
  93.     Options.starttime = 0.;
  94.     Options.framelength = 1.;
  95.     Options.shutterspeed = 0.;
  96.  
  97.     
  98.  
  99.     TopMedium.index = DEFAULT_INDEX;
  100.     TopMedium.statten = 1.0;
  101.     NoiseInit();            /* Initialize values for Noise() */
  102.  
  103.     /*
  104.      * Top of object definition stack points to the World object.
  105.      * The World object is always a list.
  106.      */
  107.     Defstack = GeomStackPush(GeomListCreate(), (GeomList *)NULL);
  108.     Defstack->obj->name = strsave("World");
  109.     /* Initialize surface stack */
  110.     CurSurf = SurfPush((Surface *)NULL, (SurfList *)NULL);
  111. }
  112.  
  113. /*
  114.  * cleanup()
  115.  *
  116.  * Initialize options/variables not set on command line or in input file.
  117.  * Perform sanity checks on widow dimension, maxdepth, etc.
  118.  */
  119. void
  120. RSCleanup()
  121. {
  122.     extern Light *Lights;
  123.     extern void OpenStatsFile();
  124.     extern FILE *yyin;
  125.  
  126.     yyin = (FILE *)NULL;    /* mark that we're done reading input */
  127.  
  128.     if (Options.samples == UNSET)
  129.         Options.samples = DEFSAMPLES;
  130.  
  131.     if (Options.filterwidth == UNSET) {
  132.         if (Options.gaussian)
  133.             Options.filterwidth = FILTERWIDTH;
  134.         else
  135.             /* Default box filter width of 1.0 */
  136.             Options.filterwidth = 1.0;
  137.     }
  138.  
  139.     Options.endframe = Options.startframe + Options.totalframes -1;
  140.  
  141.     ViewingSetup();
  142.  
  143.     if (Options.cutoff.r == UNSET)
  144.         Options.cutoff.r = Options.cutoff.g =
  145.             Options.cutoff.b = DEFCUTOFF;
  146.  
  147.     /*
  148.      * Set contrast.
  149.      */
  150.     if (Options.contrast.r == UNSET) {
  151.         Options.contrast.r = DEFREDCONT;
  152.         Options.contrast.g = DEFGREENCONT;
  153.         Options.contrast.b = DEFBLUECONT;
  154.     }
  155.  
  156.     /*
  157.      * Image gamma is inverse of display gamma.
  158.      */
  159.     if (fabs(Options.gamma) > EPSILON)
  160.         Options.gamma = 1. / Options.gamma;
  161.     else
  162.         Options.gamma = FAR_AWAY;
  163.  
  164.     if (Options.maxdepth < 0)
  165.         Options.maxdepth = 0;
  166.  
  167.  
  168.     LightSetup();
  169. }
  170.  
  171. void
  172. RSStartFrame(frame)
  173. int frame;
  174. {
  175.     /*
  176.      * Set the frame start time
  177.      */
  178.     Options.framenum = frame;
  179.     Options.framestart = Options.starttime +
  180.             Options.framenum*Options.framelength;
  181.     SamplingSetTime(Options.framestart, Options.shutterspeed,
  182.             Options.framenum);
  183.     /*
  184.      * Set up viewing parameters.
  185.      */
  186.     RSViewing();
  187.     /*
  188.      * Initialize world
  189.      */
  190.     WorldSetup() ;
  191. }
  192.  
  193.  
  194.  
  195. /*
  196.  * Initialize non-time-varying goodies.
  197.  */
  198. void
  199. RSInitialize()
  200. {
  201.     /*
  202.      * Set variables that weren't set on command line
  203.      * or in input file.
  204.      */
  205.     RSCleanup();
  206.     /*
  207.      * Set sampling options.
  208.      */
  209.     SamplingSetOptions(Options.samples, Options.gaussian,Options.filterwidth);
  210. }
  211.  
  212. /*
  213.  * To make RayShade reentrant on the Macintosh, we need to reset all values, for
  214.  * every trace. Every structure will then be reinitialised before the trace begins
  215.  */
  216.  
  217. void
  218. RSResetValues()
  219. {
  220.     extern Surface *Surfaces ;
  221.     extern Light *Lights ;
  222.     extern Geom *GeomRep, *World, *Objects ;
  223.     extern Atmosphere *AtmosEffects;        /* atmospheric effects */
  224.     extern Methods     *iBlobMethods, *iBoxMethods, *iConeMethods, *iCsgMethods,
  225.                     *iCylinderMethods, *iDiscMethods, *iGridMethods , *iHfMethods,
  226.                     *iListMethods,*iInstanceMethods, *iPlaneMethods, *iPolygonMethods,
  227.                     *iSphereMethods, *iTorusMethods, *iTriangleMethods ;
  228.     extern LightMethods
  229.                     *iExtendedMethods, *iInfMethods, *iJitteredMethods, *iPointMethods,
  230.                     *iSpotMethods ;
  231.     extern TransMethods
  232.                     *iRotateMethods, *iScaleMethods, *iTranslateMethods, *iXformMethods ;
  233.     extern Medium TopMedium;
  234.  
  235.     /* Now reset our lists of objects/lights/textures etc */
  236.  
  237.     Surfaces = NULL ;
  238.     Lights = NULL ;
  239.     GeomRep = NULL ;
  240.     World = NULL ;
  241.     Objects = NULL ;
  242.     AtmosEffects = NULL;
  243.  
  244.     /* Really these methods shouldnt have to be reinitialised, but since they are allocated with 
  245.      * the general memory management routines they are deallocated and so have to be reset
  246.      */
  247.  
  248.     iBlobMethods = NULL ;
  249.     iBoxMethods = NULL ;
  250.     iConeMethods = NULL ;
  251.     iCsgMethods = NULL ;
  252.     iCylinderMethods = NULL ;
  253.     iDiscMethods = NULL ;
  254.     iGridMethods = NULL ;
  255.     iHfMethods = NULL ;
  256.     iListMethods = NULL ;
  257.     iInstanceMethods = NULL ;
  258.     iPlaneMethods = NULL ;
  259.     iPolygonMethods = NULL ;
  260.     iSphereMethods = NULL ;
  261.     iTorusMethods = NULL ;
  262.     iTriangleMethods = NULL ;
  263.  
  264.     iExtendedMethods = NULL ;
  265.     iInfMethods = NULL ;
  266.     iJitteredMethods = NULL ;
  267.     iPointMethods = NULL ;
  268.     iSpotMethods = NULL ;
  269.  
  270.     iRotateMethods = NULL ;
  271.     iScaleMethods = NULL ;
  272.     iTranslateMethods = NULL ;
  273.     iXformMethods = NULL;
  274.  
  275.     RSSetup();
  276. }