home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 3 / Amiga Tools 3.iso / grafik / raytracing / rayshade-4.0.6.3 / libray / libobj / instance.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-09  |  2.6 KB  |  112 lines

  1. /*
  2.  * instance.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.  * instance.c,v 4.1 1994/08/09 07:59:24 explorer Exp
  17.  *
  18.  * instance.c,v
  19.  * Revision 4.1  1994/08/09  07:59:24  explorer
  20.  * Bump version to 4.1
  21.  *
  22.  * Revision 1.1.1.1  1994/08/08  04:52:09  explorer
  23.  * Initial import.  This is a prerelease of 4.0.6enh3, or 4.1 possibly.
  24.  *
  25.  * Revision 4.0  91/07/17  14:38:26  kolb
  26.  * Initial version.
  27.  * 
  28.  */
  29. #include "geom.h"
  30. #include "instance.h"
  31.  
  32. static Methods *iInstanceMethods = NULL;
  33. static char instanceName[] = "instance";
  34.  
  35. Instance *
  36. InstanceCreate(obj)
  37. Geom *obj;
  38. {
  39.     Instance *inst;
  40.  
  41.     if (obj == (Geom *)NULL) {
  42.         RLerror(RL_WARN, "Instance of NULL?\n");
  43.         return (Instance *)NULL;
  44.     }
  45.     inst = (Instance *)share_malloc(sizeof(Instance));
  46.     inst->obj = obj;
  47.     BoundsCopy(obj->bounds, inst->bounds);
  48.     return inst;
  49. }
  50.  
  51. char *
  52. InstanceName()
  53. {
  54.     return instanceName;
  55. }
  56.  
  57.  
  58. /*
  59.  * Intersect ray & an instance by calling intersect.
  60.  */
  61. int
  62. InstanceIntersect(inst, ray, hitlist, mindist, maxdist)
  63. Instance *inst;
  64. Ray *ray;
  65. HitList *hitlist;
  66. Float mindist, *maxdist;
  67. {
  68.     return intersect(inst->obj, ray, hitlist, mindist, maxdist);
  69. }
  70.  
  71. Methods *
  72. InstanceMethods()
  73. {
  74.     /*
  75.      * Instances are special in that there is no
  76.      * "convert" method -- when created, they are passed
  77.      * a pointer to the object being instantiated.
  78.      * This means that you will need to set an instance's
  79.      * 'prims' field by hand (e.g., inst->prims = object->prims).
  80.      */
  81.     if (iInstanceMethods == (Methods *)NULL) {
  82.         iInstanceMethods = MethodsCreate();
  83.         iInstanceMethods->methods = InstanceMethods;
  84.         iInstanceMethods->create = (GeomCreateFunc *)InstanceCreate;
  85.         iInstanceMethods->name = InstanceName;
  86.         iInstanceMethods->intersect = InstanceIntersect;
  87.         iInstanceMethods->bounds = InstanceBounds;
  88.         iInstanceMethods->convert = (voidstar)NULL;
  89.         iInstanceMethods->checkbounds = FALSE;
  90.         iInstanceMethods->closed = TRUE;
  91.     }
  92.     return iInstanceMethods;
  93. }
  94.  
  95. void
  96. InstanceBounds(inst, bounds)
  97. Instance *inst;
  98. Float bounds[2][3];
  99. {
  100.     GeomComputeBounds(inst->obj);
  101.     BoundsCopy(inst->obj->bounds, inst->bounds);
  102.     BoundsCopy(inst->bounds, bounds);
  103. }
  104.  
  105. void
  106. InstanceMethodRegister(meth)
  107. UserMethodType meth;
  108. {
  109.     if (iInstanceMethods)
  110.         iInstanceMethods->user = meth;
  111. }
  112.