home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff397.lzh / DKBTrace / DKBSource.LZH / ray.c < prev    next >
C/C++ Source or Header  |  1990-08-26  |  4KB  |  127 lines

  1. /*****************************************************************************
  2. *
  3. *                                      ray.c
  4. *
  5. *   from DKBTrace (c) 1990  David Buck
  6. *
  7. *  This module implements functions pertaining to rays.
  8. *
  9. * This software is freely distributable. The source and/or object code may be
  10. * copied or uploaded to communications services so long as this notice remains
  11. * at the top of each file.  If any changes are made to the program, you must
  12. * clearly indicate in the documentation and in the programs startup message
  13. * who it was who made the changes. The documentation should also describe what
  14. * those changes were. This software may not be included in whole or in
  15. * part into any commercial package without the express written consent of the
  16. * author.  It may, however, be included in other public domain or freely
  17. * distributed software so long as the proper credit for the software is given.
  18. *
  19. * This software is provided as is without any guarantees or warranty. Although
  20. * the author has attempted to find and correct any bugs in the software, he
  21. * is not responsible for any damage caused by the use of the software.  The
  22. * author is under no obligation to provide service, corrections, or upgrades
  23. * to this package.
  24. *
  25. * Despite all the legal stuff above, if you do find bugs, I would like to hear
  26. * about them.  Also, if you have any comments or questions, you may contact me
  27. * at the following address:
  28. *
  29. *     David Buck
  30. *     22C Sonnet Cres.
  31. *     Nepean Ontario
  32. *     Canada, K2H 8W7
  33. *
  34. *  I can also be reached on the following bulleton boards:
  35. *
  36. *     ATX              (613) 526-4141
  37. *     OMX              (613) 731-3419
  38. *     Mystic           (613) 731-0088 or (613) 731-6698
  39. *
  40. *  Fidonet:   1:163/109.9
  41. *  Internet:  David_Buck@Carleton.CA
  42. *
  43. *  IBM Port by Aaron A. Collins. Aaron may be reached on the following BBS'es:
  44. *
  45. *     Lattice BBS                      (708) 916-1200
  46. *     The Information Exchange BBS     (708) 945-5575
  47. *     Stillwaters BBS                  (708) 403-2826
  48. *
  49. *****************************************************************************/
  50.  
  51.  
  52.  
  53. #include "frame.h"
  54. #include "vector.h"
  55. #include "dkbproto.h"
  56.  
  57. #define Mix(a,b,c) { \
  58.    (a).x = (b).x * (c).y; \
  59.    (a).y = (b).x * (c).z; \
  60.    (a).z = (b).y * (c).z; }
  61.  
  62. void Make_Ray(r)
  63.    RAY *r;
  64.    {
  65.    VECTOR Temp_Init_Dir;
  66.  
  67.    VSquareTerms (r -> Initial_2, r -> Initial);
  68.    VSquareTerms (r -> Direction_2, r -> Direction);
  69.    VEvaluate (r -> Initial_Direction, r -> Initial, r -> Direction);
  70.    Mix (r -> Mixed_Initial_Initial, r -> Initial, r -> Initial);
  71.    Mix (r -> Mixed_Dir_Dir, r -> Direction, r -> Direction);
  72.    Mix (Temp_Init_Dir, r -> Initial, r -> Direction);
  73.    Mix (r -> Mixed_Init_Dir, r -> Direction, r -> Initial);
  74.    VAdd (r -> Mixed_Init_Dir, r -> Mixed_Init_Dir, Temp_Init_Dir);
  75.    r -> Quadric_Constants_Cached = TRUE;
  76.    }
  77.  
  78. void Initialize_Ray_Containers (Ray)
  79.    RAY *Ray;
  80.    {
  81.    Ray -> Containing_Index = -1;
  82.    }
  83.  
  84. void Copy_Ray_Containers (Dest_Ray, Source_Ray)
  85.    RAY *Dest_Ray, *Source_Ray;
  86.    {
  87.    register int i;
  88.    
  89.    if ((Dest_Ray -> Containing_Index = Source_Ray -> Containing_Index)
  90.          >= MAX_CONTAINING_OBJECTS) {
  91.       printf ("ERROR - Containing Index too high\n");
  92.       close_all();
  93.       exit (0);
  94.       }
  95.  
  96.    for (i = 0 ; i < MAX_CONTAINING_OBJECTS ; i++) {
  97.       Dest_Ray -> Containing_Objects[i] = Source_Ray -> Containing_Objects[i];
  98.       Dest_Ray -> Containing_IORs[i] = Source_Ray -> Containing_IORs[i];
  99.       }
  100.    }
  101.  
  102. void Ray_Enter (ray, object)
  103.    RAY *ray;
  104.    OBJECT *object;
  105.    {
  106.    register int index;
  107.  
  108.    if ((index = ++(ray -> Containing_Index)) >= MAX_CONTAINING_OBJECTS) {
  109.       printf ("Too many nested refracting objects\n");
  110.       close_all();
  111.       exit(0);
  112.       }
  113.  
  114.    ray -> Containing_Objects [index] = object;
  115.    ray -> Containing_IORs [index] = object->Object_Texture->Object_Index_Of_Refraction;
  116.    }
  117.  
  118. void Ray_Exit (ray)
  119.    RAY *ray;
  120.    {
  121.    if (--(ray -> Containing_Index) < -1) {
  122.       printf ("Too many exits from refractions\n");
  123.       close_all();
  124.       exit(0);
  125.       }
  126.    }
  127.