home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / GRAPHICS / rayshade.lzh / setup.c < prev    next >
Text File  |  1990-05-08  |  5KB  |  190 lines

  1. /*
  2.  * setup.c
  3.  *
  4.  * Copyright (C) 1989, Craig E. Kolb
  5.  *
  6.  * This software may be freely copied, modified, and redistributed,
  7.  * provided that this copyright notice is preserved on all copies.
  8.  *
  9.  * There is no warranty or other guarantee of fitness for this software,
  10.  * it is provided solely .  Bug reports or fixes may be sent
  11.  * to the author, who may or may not act on them as he desires.
  12.  *
  13.  * You may not include this software in a program or other software product
  14.  * without supplying the source, or without informing the end-user that the
  15.  * source is available for no extra charge.
  16.  *
  17.  * If you modify this software, you should include a notice giving the
  18.  * name of the person performing the modification, the date of modification,
  19.  * and the reason for such modification.
  20.  *
  21.  * $Id: setup.c,v 3.0.1.3 90/04/04 19:00:19 craig Exp $
  22.  *
  23.  * $Log:    setup.c,v $
  24.  * Revision 3.0.1.3  90/04/04  19:00:19  craig
  25.  * patch5: Lint removal.
  26.  * 
  27.  * Revision 3.0.1.2  90/02/12  13:26:49  craig
  28.  * patch4: Added calls to new error/warning routines.
  29.  * patch4: Attempting to render empty scene now results in an error message.
  30.  * 
  31.  * Revision 3.0.1.1  89/12/02  16:52:33  craig
  32.  * patch2: Added code to set default value for ReportFreq.
  33.  * 
  34.  * Revision 3.0  89/10/27  02:06:03  craig
  35.  * Baseline for first official release.
  36.  * 
  37.  */
  38. #include <stdio.h>
  39. #include "constants.h"
  40. #include "defaults.h"
  41. #include "typedefs.h"
  42. #include "funcdefs.h"
  43.  
  44. #ifdef MULTIMAX
  45. #include <parallel.h>
  46. #define SHARED_BYTES    23    /* 2^23 bytes of shared memory */
  47. #endif
  48. /*
  49.  * Set default parameters
  50.  */
  51. setup()
  52. {
  53.     extern int maxlevel, ReportFreq;
  54.     extern double hfov, vfov;
  55.     extern Vector eyep, lookp, up;
  56.     extern Object *World;
  57.     extern ObjList *CurObj;
  58. #ifdef MULTIMAX
  59.     unsigned int bytes;
  60.  
  61.     /*
  62.      * Initialize shared memory stuff.
  63.      */
  64.     bytes = 1 << SHARED_BYTES;
  65.     if (share_malloc_init(bytes) == -1) {
  66.         RSerror("Cannot share_malloc %d bytes.\n",bytes);
  67.     } else
  68.         fprintf(stderr,"Malloced %d bytes of shared memory.\n",
  69.                 bytes);
  70. #endif
  71.     /*
  72.      * Like every other object, the objects that make up
  73.      * "World" are stored in a simple linked list until it
  74.      * has been completely defined.  Once the definition is
  75.      * complete we convert the linked list into a Grid or List
  76.      * as per the user's wishes.
  77.      */
  78.     World = new_object("world", LIST, (char *)NULL, (Trans *)NULL);
  79.  
  80.     maxlevel = MAXLEVEL;
  81.     hfov = HFOV;
  82.     vfov = UNSET;
  83.     eyep.x = EYEX;
  84.     eyep.y = EYEY;
  85.     eyep.z = EYEZ;
  86.     lookp.x = LOOKX;
  87.     lookp.y = LOOKY;
  88.     lookp.z = LOOKZ;
  89.     up.x = UPX;
  90.     up.y = UPY;
  91.     up.z = UPZ;
  92.     ReportFreq = REPORTFREQ;
  93.  
  94.     /*
  95.      * Kinda yicky, but compatible.
  96.      */
  97.     CurObj = (ObjList *)Malloc(sizeof(ObjList));
  98.     CurObj->next = (ObjList *)0;
  99.     CurObj->data = (Object *)0;
  100.     InitRTable();            /* Initialize values for Noise() */
  101. }
  102.  
  103. /*
  104.  * cleanup()
  105.  *
  106.  * Initialize variables not set on command line or in input file.
  107.  */
  108. cleanup()
  109. {
  110.     int i;
  111.     extern Object *World;
  112.     extern int nlight, maxlevel;
  113.     extern int Xres, Yres, StartLine, Jittered, JitSamples, pixel_div;
  114.     extern double RedContrast, GreenContrast, BlueContrast, TreeCutoff;
  115.     extern double vfov, hfov;
  116.     extern Light light[];
  117.     extern FILE *fstats;
  118.  
  119.     /*
  120.      * Complain if there are no primitives to be rendered.
  121.      */
  122.     if (World->prims == 0) {
  123.         RSerror("Nothing to be rendered.\n");
  124.     }
  125.     /*
  126.      * Because we want the user to be able to override the input file
  127.      * through the command line, we have to initialize some variables to
  128.      * bogus values so that when the file is being parsed, it is
  129.      * possible to tell if a given variable has been set on the
  130.      * command line.
  131.      *
  132.      * If such variables are not set to legal values on the command
  133.      * line or in the input file, we must do it here.
  134.      */
  135.     if (Xres == UNSET)
  136.         Xres = XRESOLUTION;
  137.     if (Yres == UNSET)
  138.         Yres = YRESOLUTION;
  139.  
  140.     if (StartLine == UNSET)
  141.         StartLine = Yres -1;
  142.     else
  143.         fprintf(fstats,"Starting on line %d\n",StartLine);
  144.  
  145.     /*
  146.      * If not defined in the input file, calculate VFOV
  147.      * by hand.  This assumes that pixels are square, which is
  148.      * probably a bad idea.  ("aspect" option?)
  149.      */
  150.     if (vfov == UNSET)
  151.         vfov = hfov * Yres / Xres;
  152.  
  153.     if (!Jittered && pixel_div == UNSET)
  154.         pixel_div = PIXEL_DIV;
  155.  
  156.     if (JitSamples == UNSET)
  157.         JitSamples = DEFLIGHTSAMPLES;
  158.  
  159.     if (Jittered && JitSamples > 5) {
  160.         RSerror("Sorry, %d rays/pixel not supported.\n",
  161.                         JitSamples*JitSamples);
  162.     }
  163.     if (!Jittered && JitSamples < 3) {
  164.         RSerror("Samples (-S) value must be at least 3.\n");
  165.     }
  166.  
  167.     if (TreeCutoff == UNSET)
  168.         TreeCutoff = DEFCUTOFF;
  169.  
  170.     if (RedContrast == UNSET)
  171.         RedContrast = DEFREDCONT;
  172.     if (GreenContrast == UNSET)
  173.         GreenContrast = DEFGREENCONT;
  174.     if (BlueContrast == UNSET)
  175.         BlueContrast = DEFBLUECONT;
  176.  
  177.     /*
  178.      * Now that we've parsed the input file, we know what
  179.      * maxlevel is, so we can allocate the right amount of
  180.      * space for each light source's cache and related
  181.      * transformation.
  182.      */
  183.     for (i = 0; i < nlight; i++) {
  184.         light[i].cache = (Primitive **)Calloc((unsigned)maxlevel+1,
  185.                     sizeof(Primitive *));
  186.         light[i].trans = (TransInfo *)Malloc((maxlevel+1)*
  187.                     sizeof(TransInfo));
  188.     }
  189. }
  190.