home *** CD-ROM | disk | FTP | other *** search
/ Altsys Virtuoso 2.0K / virtuoso_20k.iso / DemoApps / Graphics / Viewers / raytracers / ohta / Source / dindex.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-08  |  663 b   |  40 lines

  1. #include "ray.h"
  2.  
  3. dindex(v)
  4. struct vector v;
  5. {double x,y,z,ax,ay,az;
  6.     x=v.x;
  7.     y=v.y;
  8.     z=v.z;
  9.     ax=(x>0)?x:-x;
  10.     ay=(y>0)?y:-y;
  11.     az=(z>0)?z:-z;
  12.     if(ax>=ay&&ax>=az)
  13.         if(x>0)
  14.             return index2(y,z,ax);
  15.         else
  16.             return index2(y,z,ax)+(NRECTS*NRECTS);
  17.     else if(ay>=ax&&ay>=az)
  18.         if(y>0)
  19.             return index2(z,x,ay)+(2*NRECTS*NRECTS);
  20.         else
  21.             return index2(z,x,ay)+(3*NRECTS*NRECTS);
  22.     else
  23.         if(z>0)
  24.             return index2(x,y,az)+(4*NRECTS*NRECTS);
  25.         else
  26.             return index2(x,y,az)+(5*NRECTS*NRECTS);
  27. }
  28.  
  29. index2(x,y,r)
  30. double r,x,y;
  31. {register int m,n;
  32.     m=(r+x)/(r*2)*NRECTS;
  33.     if(m==NRECTS)
  34.         m=NRECTS-1;
  35.     n=(r+y)/(r*2)*NRECTS;
  36.     if(n==NRECTS)
  37.         n=NRECTS-1;
  38.     return n*NRECTS+m;
  39. }
  40.