home *** CD-ROM | disk | FTP | other *** search
- /*
- * initialize.c -- just to initialize all sorts of stuff
- *
- * (c) 1993, 1994 Han-Wen Nienhuys <hanwen@stack.urc.tue.nl>
- *
- * Based on work by George Kyriazis, 1988.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 675 Mass Ave, Cambridge, MA 02139, USA.
- */
- #include <stdlib.h>
- #include <ctype.h>
- #include "ray.h"
- #include "proto.h"
- #include "extern.h"
-
- /* error message */
- PUBLIC void
- alloc_err(char *s)
- {
- errormsg("could not allocate %s\n", s);
- }
-
- PUBLIC void
- start_stats(void)
- {
- printf("%d objects at toplevel, %ld bounds\n", noo, global_stats.bounds);
- printf("%ld primitives in scene, %ld non primitives\n", global_stats.prims, global_stats.nonprims);
-
-
- /* should init'ed after parsing, because of maxtracelevel */
- global_ior = malloc((max_trace_level + 2) * sizeof(double));
-
- global_ior[0] = global_ior[1] = atmosphere_ior;
- ior_depth = 1;
-
- timer_start();
- }
-
-
- PUBLIC void
- initialize(void)
- {
- /* do some global constants */
-
- setcolor(background_color, 0, 0, 0);
- setvector(bggradient, 0, 0, 0);
- max_trace_level = DEFAULTMAXLEVEL;
- first_light = NULL;
- error_out = stdout;
- Aalias_width = -1.0;
-
- setcolor(ambient_light, 1, 1, 1);
-
- shading_model = 0;
- global_ior = NULL;
- ior_depth = 0;
- atmosphere_ior = 1;
-
- setvector(fudge, BOUNDFUDGE, BOUNDFUDGE, BOUNDFUDGE);
-
- thescene = get_new_composite_object();
- thescene->text = get_new_texture();
- thecamera = get_new_camera();
- tolerance = DEFAULT_TOLERANCE;
- }
-
- PUBLIC void
- set_defaults(void)
- {
- /* some defaults */
- xres = yres = 50;
-
- debug_options = 0x00;
- keyboard_exit = TRUE;
- continue_flag = FALSE;
- silent_mode = FALSE;
-
- time1 = time2 = 0.0;
- Aalias_width = 0.0;
- tries = 1;
- }
-
- /* print stats of all shapes. Called after interrupt */
- PUBLIC void
- print_all_shape_stats(char *format, object *p)
- {
- double rel;
- long hit,
- howmuch,
- test;
- char s[100];
-
- if (p == NULL)
- return;
-
- if (p->bound != NULL) {
- print_all_shape_stats(format, p->bound);
- }
- if (p->clip != NULL) {
- print_all_shape_stats(format, p->bound);
- }
- for (; p != NULL; p = p->next) {
- howmuch = p->methods->howmuch;
-
- /* make sure we don't print it again. */
- if (howmuch) {
- p->methods->howmuch = 0;
- hit = p->methods->hit;
- test = p->methods->test;
-
- if (test > 0)
- rel = 100.0 * (double) hit / (double) test;
- else
- rel = 0.0;
-
- /* do the actual printing */
- if (p->type != LIGHTSOURCE)
- sprintf(s, "%s: ", p->methods->name);
- else
- sprintf(s, "Light: ");
- s[0] = toupper(s[0]);
- printf(format, s, howmuch, test, hit, rel);
- }
- switch (p->type) {
- case EXTRUSION:
- print_all_shape_stats(format, p->data.extrusion->shape);
- break;
- case CSGUNION:
- case CSGINTER:
- print_all_shape_stats(format, p->data.CSG);
- break;
- case COMPOSITE:
- print_all_shape_stats(format, p->data.composite->contents);
- break;
- }
- }
-
- }
-
- /***************************************************************************
- * set aside storage for global identifiers *
- ***************************************************************************/
-
- #undef EXTERN
- #define EXTERN
-
- #include "extern.h"
-