home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Raytrace & Morphing / SOS-RAYTRACE.ISO / programm / source / rayce27s / initiali.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-02  |  3.7 KB  |  159 lines

  1. /*
  2.  * initialize.c -- just to initialize all sorts of stuff
  3.  * 
  4.  * (c) 1993, 1994 Han-Wen Nienhuys <hanwen@stack.urc.tue.nl>
  5.  * 
  6.  * Based on work by George Kyriazis, 1988.
  7.  * 
  8.  * This program is free software; you can redistribute it and/or modify it
  9.  * under the terms of the GNU General Public License as published by the
  10.  * Free Software Foundation;
  11.  * 
  12.  * This program is distributed in the hope that it will be useful, but
  13.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * General Public License for more details.
  16.  * 
  17.  * You should have received a copy of the GNU General Public License along
  18.  * with this program; if not, write to the Free Software Foundation, Inc.,
  19.  * 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  */
  21. #include    <stdlib.h>
  22. #include     <ctype.h>
  23. #include    "ray.h"
  24. #include    "proto.h"
  25. #include     "extern.h"
  26.  
  27. /* error message */
  28. PUBLIC void
  29. alloc_err(char *s)
  30. {
  31.     errormsg("could not allocate %s\n", s);
  32. }
  33.  
  34. PUBLIC void
  35. start_stats(void)
  36. {
  37.     printf("%d objects at toplevel, %ld bounds\n", noo, global_stats.bounds);
  38.     printf("%ld primitives in scene, %ld non primitives\n", global_stats.prims, global_stats.nonprims);
  39.  
  40.  
  41.     /* should init'ed after parsing, because of maxtracelevel */
  42.     global_ior = malloc((max_trace_level + 2) * sizeof(double));
  43.  
  44.     global_ior[0] = global_ior[1] = atmosphere_ior;
  45.     ior_depth = 1;
  46.  
  47.     timer_start();
  48. }
  49.  
  50.  
  51. PUBLIC void
  52. initialize(void)
  53. {
  54.     /* do some global constants */
  55.  
  56.     setcolor(background_color, 0, 0, 0);
  57.     setvector(bggradient, 0, 0, 0);
  58.     max_trace_level = DEFAULTMAXLEVEL;
  59.     first_light = NULL;
  60.     error_out = stdout;
  61.     Aalias_width = -1.0;
  62.  
  63.     setcolor(ambient_light, 1, 1, 1);
  64.  
  65.     shading_model = 0;
  66.     global_ior = NULL;
  67.     ior_depth = 0;
  68.     atmosphere_ior = 1;
  69.  
  70.     setvector(fudge, BOUNDFUDGE, BOUNDFUDGE, BOUNDFUDGE);
  71.  
  72.     thescene = get_new_composite_object();
  73.     thescene->text = get_new_texture();
  74.     thecamera = get_new_camera();
  75.     tolerance = DEFAULT_TOLERANCE;
  76. }
  77.  
  78. PUBLIC void
  79. set_defaults(void)
  80. {
  81.     /* some defaults */
  82.     xres = yres = 50;
  83.  
  84.     debug_options = 0x00;
  85.     keyboard_exit = TRUE;
  86.     continue_flag = FALSE;
  87.     silent_mode = FALSE;
  88.  
  89.     time1 = time2 = 0.0;
  90.     Aalias_width = 0.0;
  91.     tries = 1;
  92. }
  93.  
  94. /* print stats of all shapes. Called after interrupt */
  95. PUBLIC void
  96. print_all_shape_stats(char *format, object *p)
  97. {
  98.     double          rel;
  99.     long            hit,
  100.                     howmuch,
  101.                     test;
  102.     char            s[100];
  103.  
  104.     if (p == NULL)
  105.     return;
  106.  
  107.     if (p->bound != NULL) {
  108.     print_all_shape_stats(format, p->bound);
  109.     }
  110.     if (p->clip != NULL) {
  111.     print_all_shape_stats(format, p->bound);
  112.     }
  113.     for (; p != NULL; p = p->next) {
  114.     howmuch = p->methods->howmuch;
  115.  
  116.     /* make sure we don't print it again. */
  117.     if (howmuch) {
  118.         p->methods->howmuch = 0;
  119.         hit = p->methods->hit;
  120.         test = p->methods->test;
  121.  
  122.         if (test > 0)
  123.         rel = 100.0 * (double) hit / (double) test;
  124.         else
  125.         rel = 0.0;
  126.  
  127.         /* do the actual printing */
  128.         if (p->type != LIGHTSOURCE)
  129.         sprintf(s, "%s: ", p->methods->name);
  130.         else
  131.         sprintf(s, "Light: ");
  132.         s[0] = toupper(s[0]);
  133.         printf(format, s, howmuch, test, hit, rel);
  134.     }
  135.     switch (p->type) {
  136.     case EXTRUSION:
  137.         print_all_shape_stats(format, p->data.extrusion->shape);
  138.         break;
  139.     case CSGUNION:
  140.     case CSGINTER:
  141.         print_all_shape_stats(format, p->data.CSG);
  142.         break;
  143.     case COMPOSITE:
  144.         print_all_shape_stats(format, p->data.composite->contents);
  145.         break;
  146.     }
  147.     }
  148.  
  149. }
  150.  
  151. /***************************************************************************
  152.  * set aside storage for global identifiers                   *
  153.  ***************************************************************************/
  154.  
  155. #undef  EXTERN
  156. #define EXTERN
  157.  
  158. #include "extern.h"
  159.