home *** CD-ROM | disk | FTP | other *** search
/ Chestnut's Multimedia Mania / MM_MANIA.ISO / graphics / povsrc20 / ray.c < prev    next >
C/C++ Source or Header  |  1993-07-29  |  3KB  |  102 lines

  1. /****************************************************************************
  2. *                ray.c
  3. *
  4. *  This module implements the code pertaining to rays.
  5. *
  6. *  from Persistence of Vision Raytracer
  7. *  Copyright 1993 Persistence of Vision Team
  8. *---------------------------------------------------------------------------
  9. *  NOTICE: This source code file is provided so that users may experiment
  10. *  with enhancements to POV-Ray and to port the software to platforms other 
  11. *  than those supported by the POV-Ray Team.  There are strict rules under
  12. *  which you are permitted to use this file.  The rules are in the file
  13. *  named POVLEGAL.DOC which should be distributed with this file. If 
  14. *  POVLEGAL.DOC is not available or for more info please contact the POV-Ray
  15. *  Team Coordinator by leaving a message in CompuServe's Graphics Developer's
  16. *  Forum.  The latest version of POV-Ray may be found there as well.
  17. *
  18. * This program is based on the popular DKB raytracer version 2.12.
  19. * DKBTrace was originally written by David K. Buck.
  20. * DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
  21. *
  22. *****************************************************************************/
  23.  
  24. #include "frame.h"
  25. #include "vector.h"
  26. #include "povproto.h"
  27.  
  28. #define Mix(a,b,c)   {   \
  29.    (a).x = (b).x * (c).y; \
  30.    (a).y = (b).x * (c).z; \
  31.    (a).z = (b).y * (c).z; }
  32.  
  33. void Make_Ray(r)
  34. RAY *r;
  35.   {
  36.   VECTOR Temp_Init_Dir;
  37.  
  38.   VSquareTerms (r -> Initial_2, r -> Initial);
  39.   VSquareTerms (r -> Direction_2, r -> Direction);
  40.   VEvaluate (r -> Initial_Direction, r -> Initial, r -> Direction);
  41.   Mix (r -> Mixed_Initial_Initial, r -> Initial, r -> Initial);
  42.   Mix (r -> Mixed_Dir_Dir, r -> Direction, r -> Direction);
  43.   Mix (Temp_Init_Dir, r -> Initial, r -> Direction);
  44.   Mix (r -> Mixed_Init_Dir, r -> Direction, r -> Initial);
  45.   VAdd (r -> Mixed_Init_Dir, r -> Mixed_Init_Dir, Temp_Init_Dir);
  46.   r -> Quadric_Constants_Cached = TRUE;
  47.   }
  48.  
  49. void Initialize_Ray_Containers (Ray)
  50. RAY *Ray;
  51.   {
  52.   Ray -> Containing_Index = -1;
  53.   }
  54.  
  55. void Copy_Ray_Containers (Dest_Ray, Source_Ray)
  56. RAY *Dest_Ray, *Source_Ray;
  57.   {
  58.   register int i;
  59.  
  60.   if ((Dest_Ray -> Containing_Index = Source_Ray -> Containing_Index)
  61.     >= MAX_CONTAINING_OBJECTS) 
  62.     {
  63.     fprintf (stderr, "ERROR - Containing Index too high\n");
  64.     close_all();
  65.     exit (1);
  66.     }
  67.  
  68.   for (i = 0 ; i < MAX_CONTAINING_OBJECTS ; i++) 
  69.     {
  70.     Dest_Ray -> Containing_Textures[i] = Source_Ray -> Containing_Textures[i];
  71.     Dest_Ray -> Containing_IORs[i] = Source_Ray -> Containing_IORs[i];
  72.     }
  73.   }
  74.  
  75. void Ray_Enter (ray, texture)
  76. RAY *ray;
  77. TEXTURE *texture;
  78.   {
  79.   register int index;
  80.  
  81.   if ((index = ++(ray -> Containing_Index)) >= MAX_CONTAINING_OBJECTS) 
  82.     {
  83.     fprintf (stderr, "Too many nested refracting objects\n");
  84.     close_all();
  85.     exit(1);
  86.     }
  87.  
  88.   ray -> Containing_Textures [index] = texture;
  89.   ray -> Containing_IORs [index] = texture->Finish->Index_Of_Refraction;
  90.   }
  91.  
  92. void Ray_Exit (ray)
  93. RAY *ray;
  94.   {
  95.   if (--(ray -> Containing_Index) < -1) 
  96.     {
  97.     fprintf (stderr, "Too many exits from refractions\n");
  98.     close_all();
  99.     exit(1);
  100.     }
  101.   }
  102.