home *** CD-ROM | disk | FTP | other *** search
- /*
- * setup.c
- *
- * Copyright (C) 1989, 1991, Craig E. Kolb
- * All rights reserved.
- *
- * This software may be freely copied, modified, and redistributed
- * provided that this copyright notice is preserved on all copies.
- *
- * You may not distribute this software, in whole or in part, as part of
- * any commercial product without the express consent of the authors.
- *
- * There is no warranty or other guarantee of fitness of this software
- * for any purpose. It is provided solely "as is".
- *
- * $Id: setup.c,v 4.0 91/07/17 14:47:24 kolb Exp Locker: kolb $
- *
- * $Log: setup.c,v $
- * Revision 4.0 91/07/17 14:47:24 kolb
- * Initial version.
- *
- */
- #include "rayshade.h"
- #include "defaults.h"
- #include "surface.h"
- #include "atmosphere.h"
- #include "light.h"
- #include "infinite.h"
- #include "list.h"
- #include "options.h"
- #include "stats.h"
- #include "viewing.h"
- #include "picture.h"
-
- extern GeomList *Defstack;
-
- void RSResetValues() ;
-
- /*
- * Set default parameters
- */
- void
- RSSetup()
- {
- extern SurfList *CurSurf;
- extern Medium TopMedium;
- extern void NoiseInit();
-
- Camera.hfov = HFOV;
- Camera.vfov = UNSET;
- Camera.pos.x = EYEX;
- Camera.pos.y = EYEY;
- Camera.pos.z = EYEZ;
- Camera.lookp.x = LOOKX;
- Camera.lookp.y = LOOKY;
- Camera.lookp.z = LOOKZ;
- Camera.up.x = UPX;
- Camera.up.y = UPY;
- Camera.up.z = UPZ;
- Camera.focaldist = UNSET;
- Camera.aperture = 0.;
-
- Screen.xres = Screen.yres = 50;
-
- Options.contrast.r = DEFREDCONT;
- Options.contrast.g = DEFGREENCONT;
- Options.contrast.b = DEFBLUECONT;
-
- Options.maxdepth = MAXDEPTH;
- Options.report_freq = REPORTFREQ;
- Options.jitter = TRUE;
- Options.samples = UNSET;
- Options.gaussian = GAUSSIAN;
- Options.filterwidth = UNSET;
- Options.contrast.r = UNSET;
- Options.ambient.r = Options.ambient.g =
- Options.ambient.b = 1.0;
- Options.cutoff.r = UNSET;
- Options.cache = TRUE;
- Options.shadowtransp = TRUE;
- /* Options.xmin = Options.ymin = 0.;
- Options.xmax = Options.ymax = 1.; */
-
- Options.crop[LOW][X] = Options.crop[LOW][Y] = 0.;
- Options.crop[HIGH][X] = Options.crop[HIGH][Y] = 1.;
-
- Options.pictfile = stdout;
- Options.gamma = GAMMA;
- Options.eyesep = UNSET;
-
- Options.totalframes = 1;
- Options.startframe = 0;
- Options.starttime = 0.;
- Options.framelength = 1.;
- Options.shutterspeed = 0.;
-
-
-
- TopMedium.index = DEFAULT_INDEX;
- TopMedium.statten = 1.0;
- NoiseInit(); /* Initialize values for Noise() */
-
- /*
- * Top of object definition stack points to the World object.
- * The World object is always a list.
- */
- Defstack = GeomStackPush(GeomListCreate(), (GeomList *)NULL);
- Defstack->obj->name = strsave("World");
- /* Initialize surface stack */
- CurSurf = SurfPush((Surface *)NULL, (SurfList *)NULL);
- }
-
- /*
- * cleanup()
- *
- * Initialize options/variables not set on command line or in input file.
- * Perform sanity checks on widow dimension, maxdepth, etc.
- */
- void
- RSCleanup()
- {
- extern Light *Lights;
- extern void OpenStatsFile();
- extern FILE *yyin;
-
- yyin = (FILE *)NULL; /* mark that we're done reading input */
-
- if (Options.samples == UNSET)
- Options.samples = DEFSAMPLES;
-
- if (Options.filterwidth == UNSET) {
- if (Options.gaussian)
- Options.filterwidth = FILTERWIDTH;
- else
- /* Default box filter width of 1.0 */
- Options.filterwidth = 1.0;
- }
-
- Options.endframe = Options.startframe + Options.totalframes -1;
-
- ViewingSetup();
-
- if (Options.cutoff.r == UNSET)
- Options.cutoff.r = Options.cutoff.g =
- Options.cutoff.b = DEFCUTOFF;
-
- /*
- * Set contrast.
- */
- if (Options.contrast.r == UNSET) {
- Options.contrast.r = DEFREDCONT;
- Options.contrast.g = DEFGREENCONT;
- Options.contrast.b = DEFBLUECONT;
- }
-
- /*
- * Image gamma is inverse of display gamma.
- */
- if (fabs(Options.gamma) > EPSILON)
- Options.gamma = 1. / Options.gamma;
- else
- Options.gamma = FAR_AWAY;
-
- if (Options.maxdepth < 0)
- Options.maxdepth = 0;
-
-
- LightSetup();
- }
-
- void
- RSStartFrame(frame)
- int frame;
- {
- /*
- * Set the frame start time
- */
- Options.framenum = frame;
- Options.framestart = Options.starttime +
- Options.framenum*Options.framelength;
- SamplingSetTime(Options.framestart, Options.shutterspeed,
- Options.framenum);
- /*
- * Set up viewing parameters.
- */
- RSViewing();
- /*
- * Initialize world
- */
- WorldSetup() ;
- }
-
-
-
- /*
- * Initialize non-time-varying goodies.
- */
- void
- RSInitialize()
- {
- /*
- * Set variables that weren't set on command line
- * or in input file.
- */
- RSCleanup();
- /*
- * Set sampling options.
- */
- SamplingSetOptions(Options.samples, Options.gaussian,Options.filterwidth);
- }
-
- /*
- * To make RayShade reentrant on the Macintosh, we need to reset all values, for
- * every trace. Every structure will then be reinitialised before the trace begins
- */
-
- void
- RSResetValues()
- {
- extern Surface *Surfaces ;
- extern Light *Lights ;
- extern Geom *GeomRep, *World, *Objects ;
- extern Atmosphere *AtmosEffects; /* atmospheric effects */
- extern Methods *iBlobMethods, *iBoxMethods, *iConeMethods, *iCsgMethods,
- *iCylinderMethods, *iDiscMethods, *iGridMethods , *iHfMethods,
- *iListMethods,*iInstanceMethods, *iPlaneMethods, *iPolygonMethods,
- *iSphereMethods, *iTorusMethods, *iTriangleMethods ;
- extern LightMethods
- *iExtendedMethods, *iInfMethods, *iJitteredMethods, *iPointMethods,
- *iSpotMethods ;
- extern TransMethods
- *iRotateMethods, *iScaleMethods, *iTranslateMethods, *iXformMethods ;
- extern Medium TopMedium;
-
- /* Now reset our lists of objects/lights/textures etc */
-
- Surfaces = NULL ;
- Lights = NULL ;
- GeomRep = NULL ;
- World = NULL ;
- Objects = NULL ;
- AtmosEffects = NULL;
-
- /* Really these methods shouldnt have to be reinitialised, but since they are allocated with
- * the general memory management routines they are deallocated and so have to be reset
- */
-
- iBlobMethods = NULL ;
- iBoxMethods = NULL ;
- iConeMethods = NULL ;
- iCsgMethods = NULL ;
- iCylinderMethods = NULL ;
- iDiscMethods = NULL ;
- iGridMethods = NULL ;
- iHfMethods = NULL ;
- iListMethods = NULL ;
- iInstanceMethods = NULL ;
- iPlaneMethods = NULL ;
- iPolygonMethods = NULL ;
- iSphereMethods = NULL ;
- iTorusMethods = NULL ;
- iTriangleMethods = NULL ;
-
- iExtendedMethods = NULL ;
- iInfMethods = NULL ;
- iJitteredMethods = NULL ;
- iPointMethods = NULL ;
- iSpotMethods = NULL ;
-
- iRotateMethods = NULL ;
- iScaleMethods = NULL ;
- iTranslateMethods = NULL ;
- iXformMethods = NULL;
-
- RSSetup();
- }