home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume18 / mtvraytrace / part01 / trace.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-26  |  1.0 KB  |  48 lines

  1. /***********************************************************************
  2.  * $Author: markv $
  3.  * $Revision: 1.2 $
  4.  * $Date: 88/09/12 13:01:15 $
  5.  * $Log:    trace.c,v $
  6.  * Revision 1.2  88/09/12  13:01:15  markv
  7.  * Fixed Trace to call Intersect with the max dist argument of HUGE.
  8.  * 
  9.  * Revision 1.1  88/09/11  11:00:45  markv
  10.  * Initial revision
  11.  * 
  12.  ***********************************************************************/
  13.  
  14. #include <stdio.h>
  15. #include <math.h>
  16. #include "defs.h"
  17. #include "extern.h"
  18.  
  19. Trace(level, weight, ray, color) 
  20.  int level;
  21.  Flt weight;
  22.  Ray *ray ;
  23.  Color color ;
  24. {
  25.     Object *prim ;
  26.     Vec P, N ;
  27.     Isect hit ;
  28.  
  29.     if (level >= maxlevel) {
  30.         color[0] = color[1] = color[2] = 0.0 ;
  31.         return ;
  32.     }
  33.         
  34.     nRays ++ ;
  35.  
  36.     if (Intersect(ray, &hit, HUGE)) {
  37.         prim = hit.isect_prim ;
  38.         RayPoint(ray, hit.isect_t, P);
  39.         (*prim -> o_procs -> normal) (prim, &hit, P, N);
  40.         if ((VecDot(ray->D, N)) >= 0.0) {
  41.             VecNegate(N);
  42.         }
  43.         Shade(level, weight, P, N, ray -> D, &hit, color);
  44.     } else {
  45.         VecCopy(BackgroundColor, color) ;
  46.     }
  47. }
  48.