home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / raytrace / dbw_render / source / c / EXT < prev    next >
Encoding:
Text File  |  1992-10-23  |  5.2 KB  |  220 lines

  1. /************************************************************************
  2.  *                                                                      *
  3.  *                  Copyright (c) 1987, David B. Wecker                 *
  4.  *                         All Rights Reserved                          *
  5.  *                                                                      *
  6.  * This file is part of DBW_Render                                      *
  7.  *                                                                      *
  8.  * DBW_Render is distributed in the hope that it will be useful, but    *
  9.  * WITHOUT ANY WARRANTY. No author or distributor accepts               *
  10.  * responsibility to anyone for the consequences of using it or for     *
  11.  * whether it serves any particular purpose or works at all, unless     *
  12.  * he says so in writing. Refer to the DBW_Render General Public        *
  13.  * License for full details.                                            *
  14.  *                                                                      *
  15.  * Everyone is granted permission to copy, modify and redistribute      *
  16.  * DBW_Render, but only under the conditions described in the           *
  17.  * DBW_Render General Public License. A copy of this license is         *
  18.  * supposed to have been given to you along with DBW_Render so you      *
  19.  * can know your rights and responsibilities. It should be in a file    *
  20.  * named COPYING. Among other things, the copyright notice and this     *
  21.  * notice must be preserved on all copies.                              *
  22.  ************************************************************************
  23.  
  24. #define MODULE_EXTENT
  25. #include "ray.h"
  26.  
  27. node *masternp = NULL;
  28. node **nppstack[100] = 
  29. {
  30.      &masternp,
  31. }
  32. ;
  33. int  nppsp = 0;
  34.  
  35. /* V1.01  */
  36. #ifdef MCH_AMIGA
  37. #define   LARGEST     ((float)1.7e+38)
  38. #else
  39.  
  40. /* V1.01  */
  41. #     ifdef IBM_PC
  42. #define   LARGEST     ((float)1.7e+38)
  43. #     else
  44. #define   LARGEST     HUGE
  45. #     endif
  46.  
  47. /* V1.01  */
  48. #endif
  49.  
  50. #define   curnpp         (nppstack[nppsp])
  51. #define   pushnpp(npp)   (nppstack[++nppsp] = npp)
  52. #define   popnpp         (nppstack[nppsp--])
  53.  
  54. void sphere_rextent();
  55. void triangle_rextent();
  56. void quad_rextent();
  57. void ring_rextent();
  58. void cyl_rextent();
  59. void cone_rextent();
  60.  
  61.  
  62.  
  63. void setextent(ep,re)
  64. extent *ep;
  65. rextent *re;
  66. {
  67.      int i;
  68.      float t;
  69.  
  70.      for (ep->radius = 0.,i = 0; i < 3; i++) 
  71.      {
  72.           ep->center[i] = (re->min[i] + re->max[i]) / 2.0;
  73.           t = re->max[i] - ep->center[i];
  74.           ep->radius += t * t;
  75.      }
  76.      ep->radius = (float)sqrt(ep->radius);
  77. }
  78.  
  79. /*
  80.  *   find the bounding extent (sphere) for the current object
  81.  */
  82.  
  83. void getextent(np,re)
  84. node *np;
  85. rextent *re;
  86. {
  87.      rextent newre;
  88.  
  89.      cv(LARGEST,LARGEST,LARGEST,re->min);     /* V1.01  */
  90.      cv(-LARGEST,-LARGEST,-LARGEST,re->max);  /* V1.01  */
  91.  
  92.      while (np) 
  93.      {
  94.           switch (np->kind) 
  95.           {
  96.                /* user-defined extent */
  97.           case EXTENT :
  98.  
  99.                getextent(eptr(np)->sub,&newre);
  100.                setextent(np,&newre);
  101.                break;
  102.  
  103.                /* planar objects */
  104.           case TRIANGLE:
  105.  
  106.                triangle_rextent(np,&newre); 
  107.                break;
  108.           case QUAD:
  109.  
  110.                quad_rextent(np,&newre); 
  111.                break;
  112.           case RING:
  113.  
  114.                ring_rextent(np,&newre); 
  115.                break;
  116.  
  117.                /* volume objects */
  118.           case SPHERE:
  119.  
  120.                sphere_rextent(np,&newre); 
  121.                break;
  122.           case CYLINDER:
  123.                /* in work */
  124.                cyl_rextent(np,&newre);
  125.                break;
  126.  
  127.           }
  128.           unionrextent(re,&newre,re);
  129.           np = np->next;
  130.      }
  131. }
  132.  
  133. /*
  134.  *   The bounding extent for a sphere is the sphere itself.
  135.  */
  136.  
  137. void sphere_rextent(sp,re)
  138. sphere *sp;
  139. rextent *re;
  140. {
  141.      int i;
  142.  
  143.      for (i = 0; i < 3; i++) 
  144.      {
  145.           re->min[i] = sp->center[i] - sp->radius;
  146.           re->max[i] = sp->center[i] + sp->radius;
  147.      }
  148. }
  149.  
  150. /*
  151.  *   The bounding extent for a triangle is
  152.  */
  153.  
  154. void triangle_rextent(tp,re)
  155. triangle *tp;
  156. rextent *re;
  157. {
  158.      vector v1,v2;
  159.  
  160.      cv(LARGEST,LARGEST,LARGEST,re->min);     /* V1.01  */
  161.      cv(-LARGEST,-LARGEST,-LARGEST,re->max);  /* V1.01  */
  162.  
  163.      vecsum(tp->position,tp->ve,v1);
  164.      vecsum(tp->position,tp->vp,v2);
  165.  
  166.      unionvector(re,tp->position,re);
  167.      unionvector(re,v1,re);
  168.      unionvector(re,v2,re);
  169. }
  170.  
  171. void quad_rextent(qp,re)
  172. quad *qp;
  173. rextent *re;
  174. {
  175.      vector v;
  176.  
  177.      cv(LARGEST,LARGEST,LARGEST,re->min);     /* V1.01  */
  178.      cv(-LARGEST,-LARGEST,-LARGEST,re->max);  /* V1.01  */
  179.  
  180.      unionvector(re,qp->position,re);
  181.  
  182.      vecsum(qp->position,qp->ve,v);
  183.      unionvector(re,v,re);
  184.  
  185.      vecsum(qp->position,qp->vp,v);
  186.      unionvector(re,v,re);
  187.  
  188.      vecsum(v,qp->ve,v);
  189.      unionvector(re,v,re);
  190. }
  191.  
  192. /*
  193.  *   The bounding extent for a ring is a sphere with
  194.  *   the same radius as the outside radius of the ring.
  195.  */
  196.  
  197. void ring_rextent(rp,re)
  198. ring *rp;
  199. rextent *re;
  200. {
  201.      int i;
  202.  
  203.      for (i = 0; i < 3; i++) 
  204.      {
  205.           re->min[i] = rp->position[i] - rp->maxrad;
  206.           re->max[i] = rp->position[i] + rp->maxrad;
  207.      }
  208. }
  209.  
  210. /* 
  211.  *   The bounding extent for a cylinder is a sphere
  212.  *   in which the cylinder will fit
  213.  */
  214.  
  215. void cyl_rextent(rp,re)
  216. cylinder *rp;
  217. rextent *re;
  218. {
  219. }
  220.