home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Graphics / Graphics.zip / povsrc31.zip / interior.c < prev    next >
C/C++ Source or Header  |  1999-12-11  |  7KB  |  377 lines

  1. /****************************************************************************
  2. *                   interior.c
  3. *
  4. *  This module contains all functions for interior stuff.
  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.  
  24. #include "frame.h"
  25. #include "vector.h"
  26. #include "povproto.h"
  27. #include "chi2.h"
  28. #include "colour.h"
  29. #include "povray.h"
  30. #include "texture.h"
  31. #include "pigment.h"
  32. #include "objects.h"
  33. #include "lighting.h"
  34. #include "matrices.h"
  35. #include "interior.h"
  36. #include "povray.h"
  37. #include "point.h"
  38. #include "texture.h"
  39. #include "ray.h"
  40.  
  41.  
  42.  
  43. /*****************************************************************************
  44. * Local preprocessor defines
  45. ******************************************************************************/
  46.  
  47. /*****************************************************************************
  48. * Local typedefs
  49. ******************************************************************************/
  50.  
  51.  
  52.  
  53. /*****************************************************************************
  54. * Local variables
  55. ******************************************************************************/
  56.  
  57.  
  58.  
  59. /*****************************************************************************
  60. * Static functions
  61. ******************************************************************************/
  62.  
  63.  
  64.  
  65. /*****************************************************************************
  66. *
  67. * FUNCTION
  68. *
  69. *   Init_Interior
  70. *
  71. * INPUT
  72. *
  73. * OUTPUT
  74. *
  75. * RETURNS
  76. *
  77. * AUTHOR
  78. *
  79. *   Dieter Bayer
  80. *
  81. * DESCRIPTION
  82. *
  83. *   Initialize interior.
  84. *
  85. * CHANGES
  86. *
  87. *   Jan 1997 : Creation.
  88. *
  89. ******************************************************************************/
  90.  
  91. void Init_Interior(INTERIOR *Interior)
  92. {
  93. }
  94.  
  95.  
  96.  
  97. /*****************************************************************************
  98. *
  99. * FUNCTION
  100. *
  101. *   Create_Interior
  102. *
  103. * INPUT
  104. *
  105. * OUTPUT
  106. *
  107. * RETURNS
  108. *
  109. *   INTERIOR * - created interior
  110. *
  111. * AUTHOR
  112. *
  113. *   Dieter Bayer
  114. *
  115. * DESCRIPTION
  116. *
  117. *   Create a interior.
  118. *
  119. * CHANGES
  120. *
  121. *   Dec 1994 : Creation.
  122. *   Sep 1999 : Fade_Colour added - Edward Coffey
  123. *
  124. ******************************************************************************/
  125.  
  126. INTERIOR *Create_Interior()
  127. {
  128.   INTERIOR *New;
  129.  
  130.   New = (INTERIOR *)POV_MALLOC(sizeof(INTERIOR), "interior");
  131.   
  132.   New->References = 1;
  133.  
  134.   New->IOR = 0.0;
  135.   New->Dispersion = 1.0;
  136.   New->Disp_NElems = 1; /* DEFAULT_DISP_NELEMS */
  137.           
  138.   New->Old_Refract = 1.0;
  139.  
  140.   New->Caustics = 0.0;
  141.  
  142.   New->Fade_Distance = 0.0;
  143.   New->Fade_Power    = 0.0;
  144.   Make_Colour(New->Fade_Colour, 0.0, 0.0, 0.0);
  145.  
  146.   New->IMedia = NULL;
  147.  
  148.   return(New);
  149. }
  150.  
  151.  
  152.  
  153. /*****************************************************************************
  154. *
  155. * FUNCTION
  156. *
  157. *   Copy_Interior
  158. *
  159. * INPUT
  160. *
  161. *   Old - interior to copy
  162. *
  163. * OUTPUT
  164. *
  165. * RETURNS
  166. *
  167. *   INTERIOR * - new interior
  168. *
  169. * AUTHOR
  170. *
  171. *   Dieter Bayer
  172. *
  173. * DESCRIPTION
  174. *
  175. *   Copy an interior.
  176. *
  177. * CHANGES
  178. *
  179. *   Dec 1994 : Creation.
  180. *
  181. ******************************************************************************/
  182.  
  183. INTERIOR *Copy_Interior(INTERIOR *Old)
  184. {
  185.   INTERIOR *New;
  186.  
  187.   if (Old != NULL)
  188.   {
  189.     New = Create_Interior();
  190.  
  191.     *New = *Old;
  192.  
  193.     New->IMedia = Copy_Media(Old->IMedia);
  194.  
  195.     return(New);
  196.   }
  197.   else
  198.   {
  199.     return(NULL);
  200.   }
  201. }
  202.  
  203. /*****************************************************************************
  204. *
  205. * FUNCTION
  206. *
  207. *   Copy_Interior_Pointer
  208. *
  209. * INPUT
  210. *
  211. *   Old - interior to copy
  212. *
  213. * OUTPUT
  214. *
  215. * RETURNS
  216. *
  217. *   INTERIOR * - new interior
  218. *
  219. * AUTHOR
  220. *
  221. *   Dieter Bayer
  222. *
  223. * DESCRIPTION
  224. *
  225. *   Copy an interior by increasing number of references.
  226. *
  227. * CHANGES
  228. *
  229. *   Dec 1994 : Creation.
  230. *
  231. ******************************************************************************/
  232.  
  233. INTERIOR *Copy_Interior_Pointer(INTERIOR *Old)
  234. {
  235.   if (Old != NULL)
  236.   {
  237.     Old->References++;
  238.   }
  239.  
  240.   return(Old);
  241. }
  242.  
  243.  
  244.  
  245. /*****************************************************************************
  246. *
  247. * FUNCTION
  248. *
  249. *   Destroy_Interior
  250. *
  251. * INPUT
  252. *
  253. *   Interior - interior to destroy
  254. *
  255. * OUTPUT
  256. *
  257. * RETURNS
  258. *
  259. * AUTHOR
  260. *
  261. *   Dieter Bayer
  262. *
  263. * DESCRIPTION
  264. *
  265. *   Destroy an interior.
  266. *
  267. * CHANGES
  268. *
  269. *   Dec 1994 : Creation.
  270. *
  271. ******************************************************************************/
  272.  
  273. void Destroy_Interior(INTERIOR *Interior)
  274. {
  275.   if ((Interior != NULL) && (--(Interior->References) == 0))
  276.   {
  277.     Destroy_Media(Interior->IMedia);
  278.  
  279.     POV_FREE(Interior);
  280.   }
  281. }
  282.  
  283.  
  284.  
  285. /*****************************************************************************
  286. *
  287. * FUNCTION
  288. *
  289. *   Transform_Interior
  290. *
  291. * INPUT
  292. *
  293. * OUTPUT
  294. *
  295. * RETURNS
  296. *
  297. * AUTHOR
  298. *
  299. *   Dieter Bayer
  300. *
  301. * DESCRIPTION
  302. *
  303. *   Transform interior.
  304. *
  305. * CHANGES
  306. *
  307. *   Jan 1997 : Creation.
  308. *
  309. ******************************************************************************/
  310.  
  311. void Transform_Interior(INTERIOR *Interior, TRANSFORM *Trans)
  312. {
  313.   if (Interior != NULL)
  314.   {
  315.     if (Interior->IMedia != NULL)
  316.     {
  317.       Transform_Media(Interior->IMedia, Trans);
  318.     }
  319.   }
  320. }
  321.  
  322.  
  323. MATERIAL *Create_Material()
  324. {
  325.   MATERIAL *New;
  326.  
  327.   New = (MATERIAL *)POV_MALLOC(sizeof(MATERIAL), "material");
  328.   
  329.   New->Texture  = NULL;
  330. #ifdef InteriorTexturePatch
  331.   New->Interior_Texture  = NULL;/*Chris Huff: Interior Texture patch*/
  332. #endif
  333.   New->Interior = NULL;
  334.  
  335.   return(New);
  336. }
  337.  
  338.  
  339. MATERIAL *Copy_Material(MATERIAL *Old)
  340. {
  341.   MATERIAL *New;
  342.  
  343.   if (Old != NULL)
  344.   {
  345.     New = Create_Material();
  346.  
  347.     *New = *Old;
  348.  
  349.     New->Texture  = Copy_Textures(Old->Texture);
  350. #ifdef InteriorTexturePatch
  351.     New->Interior_Texture  = Copy_Textures(Old->Interior_Texture);/*Chris Huff: Interior Texture patch*/
  352.  #endif
  353.     New->Interior = Copy_Interior(Old->Interior);
  354.  
  355.     return(New);
  356.   }
  357.   else
  358.   {
  359.     return(NULL);
  360.   }
  361. }
  362.  
  363. void Destroy_Material(MATERIAL *Material)
  364. {
  365.   if (Material != NULL) 
  366.   {
  367.     Destroy_Textures(Material->Texture);
  368. #ifdef InteriorTexturePatch
  369.     Destroy_Textures(Material->Interior_Texture);/*Chris Huff: Interior Texture patch*/
  370. #endif
  371.     Destroy_Interior(Material->Interior);
  372.  
  373.     POV_FREE(Material);
  374.   }
  375. }
  376.  
  377.