RAY.C 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /****************************************************************************
  2. * ray.c
  3. *
  4. * This module implements the code pertaining to rays.
  5. *
  6. * from Persistence of Vision(tm) Ray Tracer
  7. * Copyright 1996,1999 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.
  14. * If POVLEGAL.DOC is not available or for more info please contact the POV-Ray
  15. * Team Coordinator by email to team-coord@povray.org or visit us on the web at
  16. * http://www.povray.org. The latest version of POV-Ray may be found at this site.
  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. #include "frame.h"
  24. #include "vector.h"
  25. #include "povproto.h"
  26. #include "povray.h"
  27. #include "interior.h"
  28. #include "ray.h"
  29. #include "texture.h"
  30. /*****************************************************************************
  31. * Local preprocessor defines
  32. ******************************************************************************/
  33. /*****************************************************************************
  34. * Local typedefs
  35. ******************************************************************************/
  36. /*****************************************************************************
  37. * Local variables
  38. ******************************************************************************/
  39. /*****************************************************************************
  40. * Static functions
  41. ******************************************************************************/
  42. /*****************************************************************************
  43. *
  44. * FUNCTION
  45. *
  46. * Initialize_Ray_Containers
  47. *
  48. * INPUT
  49. *
  50. * OUTPUT
  51. *
  52. * RETURNS
  53. *
  54. * AUTHOR
  55. *
  56. * POV-Ray Team
  57. *
  58. * DESCRIPTION
  59. *
  60. * -
  61. *
  62. * CHANGES
  63. *
  64. * -
  65. *
  66. ******************************************************************************/
  67. void Initialize_Ray_Containers(RAY *Ray)
  68. {
  69. Ray->Index = - 1;
  70. }
  71. /*****************************************************************************
  72. *
  73. * FUNCTION
  74. *
  75. * Copy_Ray_Containers
  76. *
  77. * INPUT
  78. *
  79. * OUTPUT
  80. *
  81. * RETURNS
  82. *
  83. * AUTHOR
  84. *
  85. * POV-Ray Team
  86. *
  87. * DESCRIPTION
  88. *
  89. * -
  90. *
  91. * CHANGES
  92. *
  93. * -
  94. *
  95. ******************************************************************************/
  96. void Copy_Ray_Containers(RAY *Dest_Ray, RAY *Source_Ray)
  97. {
  98. register int i;
  99. if ((Dest_Ray->Index = Source_Ray->Index) >= MAX_CONTAINING_OBJECTS)
  100. {
  101. Error("ERROR - Containing Index too high.\n");
  102. }
  103. for (i = 0 ; i <= Source_Ray->Index; i++)
  104. {
  105. Dest_Ray->Interiors[i] = Source_Ray->Interiors[i];
  106. }
  107. }
  108. /*****************************************************************************
  109. *
  110. * FUNCTION
  111. *
  112. * Ray_Enter
  113. *
  114. * INPUT
  115. *
  116. * OUTPUT
  117. *
  118. * RETURNS
  119. *
  120. * AUTHOR
  121. *
  122. * POV-Ray Team
  123. *
  124. * DESCRIPTION
  125. *
  126. * -
  127. *
  128. * CHANGES
  129. *
  130. * Oct 1995 : Fixed bug with IOR assignment (only valid for plain textures) [DB]
  131. *
  132. ******************************************************************************/
  133. void Ray_Enter(RAY *Ray, INTERIOR *interior)
  134. {
  135. int index;
  136. if ((index = ++(Ray->Index)) >= MAX_CONTAINING_OBJECTS)
  137. {
  138. Error("Too many nested refracting objects.");
  139. }
  140. Ray->Interiors[index] = interior;
  141. }
  142. /*****************************************************************************
  143. *
  144. * FUNCTION
  145. *
  146. * Ray_Exit
  147. *
  148. * INPUT
  149. *
  150. * OUTPUT
  151. *
  152. * RETURNS
  153. *
  154. * AUTHOR
  155. *
  156. * POV-Ray Team
  157. *
  158. * DESCRIPTION
  159. *
  160. * Remove given entry from given ray's container.
  161. *
  162. * CHANGES
  163. *
  164. * -
  165. *
  166. ******************************************************************************/
  167. void Ray_Exit(RAY *Ray, int nr)
  168. {
  169. int i;
  170. for (i = nr; i < Ray->Index; i++)
  171. {
  172. Ray->Interiors[i] = Ray->Interiors[i+1];
  173. }
  174. if (--(Ray->Index) < - 1)
  175. {
  176. Error("Too many exits from refractions.");
  177. }
  178. }
  179. /*****************************************************************************
  180. *
  181. * FUNCTION
  182. *
  183. * Interior_In_Ray_Container
  184. *
  185. * INPUT
  186. *
  187. * OUTPUT
  188. *
  189. * RETURNS
  190. *
  191. * AUTHOR
  192. *
  193. * Dieter Bayer
  194. *
  195. * DESCRIPTION
  196. *
  197. * Test if a given interior is in the container of a given ray.
  198. *
  199. * CHANGES
  200. *
  201. * Mar 1996 : Creation.
  202. *
  203. ******************************************************************************/
  204. int Interior_In_Ray_Container(RAY *ray, INTERIOR *interior)
  205. {
  206. int i, found = -1;
  207. if (ray->Index > -1)
  208. {
  209. for (i = 0; i <= ray->Index; i++)
  210. {
  211. if (interior == ray->Interiors[i])
  212. {
  213. found = i;
  214. break;
  215. }
  216. }
  217. }
  218. return(found);
  219. }