home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / macraysh.sit / Code / Source / objdef.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-06  |  2.4 KB  |  114 lines

  1. /*
  2.  * objdef.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: objdef.c,v 4.0 91/07/17 14:46:38 kolb Exp Locker: kolb $
  17.  *
  18.  * $Log:    objdef.c,v $
  19.  * Revision 4.0  91/07/17  14:46:38  kolb
  20.  * Initial version.
  21.  * 
  22.  */
  23.  
  24. #include "rayshade.h"
  25. #include "options.h"
  26. #include "stats.h"
  27.  
  28. Geom *Objects = NULL;        /* named objects */
  29. Geom *World;                /* top-level object */
  30.  
  31.  
  32. /*
  33.  * Return pointer to named object, NULL if no such object has been defined.
  34.  */
  35. Geom *
  36. GeomGetNamed(name)
  37. char *name;
  38. {
  39.     Geom *otmp;
  40.     for (otmp = Objects; otmp; otmp = otmp->next)
  41.         if (strcmp(name, otmp->name) == 0)
  42.             return otmp;
  43.     return (Geom *)NULL;
  44. }
  45.  
  46. /*
  47.  * Add object to list of defined objects.  At this point, the object has
  48.  * been converted to the correct type, and obj->next is either NULL or
  49.  * garbage.
  50.  */
  51. void
  52. GeomAddToDefined(obj)
  53. Geom *obj;
  54. {
  55.     obj->next = Objects;
  56.     Objects = obj;
  57.     if (Options.verbose)
  58.         AggregatePrintInfo(obj);
  59. }
  60.  
  61. /*
  62.  * Return a copy of the named object.
  63.  */
  64. Geom *
  65. GeomCopyNamed(name)
  66. char *name;
  67. {
  68.     Geom *child;
  69.  
  70.     child = GeomGetNamed(name);
  71.     if (child == (Geom *)NULL)
  72.         RLerror(RL_PANIC, "There is no object named \"%s\".", name,0,0);
  73.     child = GeomCopy(child);
  74.     return child;
  75. }
  76.  
  77. void
  78. WorldSetup()
  79. {
  80.     extern GeomList *Defstack;
  81.  
  82.     /*
  83.      * Define World object, if not done previously.
  84.      */
  85.     if (World == (Geom *)NULL) {
  86.         World = Defstack->obj;    /* World is topmost object on stack */
  87.         if (Defstack->next)
  88.             RLerror(RL_ABORT, "Geom def stack is screwey.\n",0,0,0);
  89.         World->prims = AggregateConvert(World, World->next);
  90.     }
  91.  
  92.     GeomComputeBounds(World);
  93.  
  94.     /*
  95.      * Complain if there are no primitives to be rendered.
  96.      */
  97.     /* Not needed for macintosh version */
  98. /*    if (World->prims == 0) {
  99.         RLerror(RL_WARN, "Nothing to be rendered.\n", 0,0,0);
  100.     } */
  101. }
  102.  
  103. /*
  104.  * Main ray-spawning routine required by libray
  105.  */
  106. int
  107. TraceRay(ray, hitlist, mindist, maxdist)
  108. Ray *ray;
  109. HitList *hitlist;
  110. Float mindist, *maxdist;
  111. {
  112.     return intersect(World, ray, hitlist, mindist, maxdist);
  113. }
  114.