home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Graphics / Graphics.zip / povsrc31.zip / objects.c < prev    next >
C/C++ Source or Header  |  2001-01-23  |  19KB  |  1,110 lines

  1. /****************************************************************************
  2. *                objects.c
  3. *
  4. *  This module implements the methods for objects and composite objects.
  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 "povray.h"
  26. #include "vector.h"
  27. #include "povproto.h"
  28. #include "interior.h"
  29. #include "objects.h"
  30. #include "texture.h"
  31. /* NK 1998 */
  32. #include "matrices.h"
  33. /* NK ---- */
  34. #ifdef GlowPatch
  35. #include "glow.h"
  36. #endif
  37.  
  38.  
  39. /*****************************************************************************
  40. * Local preprocessor defines
  41. ******************************************************************************/
  42.  
  43.  
  44.  
  45. /*****************************************************************************
  46. * Local typedefs
  47. ******************************************************************************/
  48.  
  49.  
  50.  
  51. /*****************************************************************************
  52. * Local variables
  53. ******************************************************************************/
  54.  
  55. unsigned int Number_of_istacks;
  56. unsigned int Max_Intersections;
  57. ISTACK *free_istack;
  58.  
  59.  
  60.  
  61. /*****************************************************************************
  62. * Static functions
  63. ******************************************************************************/
  64.  
  65. static OBJECT *Copy_Bound_Clip (OBJECT *Old);
  66. static void create_istack (void);
  67.  
  68.  
  69.  
  70. /*****************************************************************************
  71. *
  72. * FUNCTION
  73. *
  74. *   Intersection
  75. *
  76. * INPUT
  77. *   
  78. * OUTPUT
  79. *   
  80. * RETURNS
  81. *   
  82. * AUTHOR
  83. *
  84. *   POV-Ray Team
  85. *   
  86. * DESCRIPTION
  87. *
  88. *   -
  89. *
  90. * CHANGES
  91. *
  92. *   -
  93. *
  94. ******************************************************************************/
  95.  
  96. int Intersection (INTERSECTION *Ray_Intersection, OBJECT *Object, RAY *Ray)
  97. {
  98.   ISTACK *Depth_Stack;
  99.   INTERSECTION *Local;
  100.   DBL Closest = HUGE_VAL;
  101.  
  102.   if (Object == NULL)
  103.   {
  104.     return (FALSE);
  105.   }
  106.  
  107.   if (!Ray_In_Bound (Ray,Object->Bound))
  108.   {
  109.     return (FALSE);
  110.   }
  111.  
  112.   Depth_Stack = open_istack ();
  113.  
  114.   if (All_Intersections (Object, Ray, Depth_Stack))
  115.   {
  116.     while ((Local = pop_entry(Depth_Stack)) != NULL)
  117.     {
  118.       if (Local->Depth < Closest)
  119.       {
  120.         *Ray_Intersection = *Local;
  121.  
  122.         Closest = Local->Depth;
  123.       }
  124.     }
  125.  
  126.     close_istack (Depth_Stack);
  127.  
  128.     return (TRUE);
  129.   }
  130.   else
  131.   {
  132.     close_istack (Depth_Stack);
  133.  
  134.     return (FALSE);
  135.   }
  136. }
  137.  
  138.  
  139.  
  140. /*****************************************************************************
  141. *
  142. * FUNCTION
  143. *
  144. *   Inside_Object
  145. *
  146. * INPUT
  147. *   
  148. * OUTPUT
  149. *   
  150. * RETURNS
  151. *   
  152. * AUTHOR
  153. *
  154. *   POV-Ray Team
  155. *   
  156. * DESCRIPTION
  157. *
  158. *   -
  159. *
  160. * CHANGES
  161. *
  162. *   -
  163. *
  164. ******************************************************************************/
  165.  
  166. int Inside_Object (VECTOR IPoint, OBJECT *Object)
  167. {
  168.   OBJECT *Sib;
  169.  
  170.   for (Sib = Object->Clip; Sib != NULL; Sib = Sib->Sibling)
  171.   {
  172.     if (!Inside_Object(IPoint, Sib))
  173.     {
  174.       return(FALSE);
  175.     }
  176.   }
  177.  
  178.   return (Inside(IPoint,Object));
  179. }
  180.  
  181.  
  182.  
  183. /*****************************************************************************
  184. *
  185. * FUNCTION
  186. *
  187. *   Ray_In_Bound
  188. *
  189. * INPUT
  190. *   
  191. * OUTPUT
  192. *   
  193. * RETURNS
  194. *   
  195. * AUTHOR
  196. *
  197. *   POV-Ray Team
  198. *   
  199. * DESCRIPTION
  200. *
  201. *   -
  202. *
  203. * CHANGES
  204. *
  205. *   -
  206. *
  207. ******************************************************************************/
  208.  
  209. int Ray_In_Bound (RAY *Ray, OBJECT *Bounding_Object)
  210. {
  211.   OBJECT *Bound;
  212.   INTERSECTION Local;
  213.  
  214.   for (Bound = Bounding_Object; Bound != NULL; Bound = Bound->Sibling)
  215.   {
  216.     Increase_Counter(stats[Bounding_Region_Tests]);
  217.  
  218.     if (!Intersection (&Local, Bound, Ray))
  219.     {
  220.       if (!Inside_Object(Ray->Initial, Bound))
  221.       {
  222.         return (FALSE);
  223.       }
  224.     }
  225.  
  226.     Increase_Counter(stats[Bounding_Region_Tests_Succeeded]);
  227.   }
  228.  
  229.   return (TRUE);
  230. }
  231.  
  232.  
  233.  
  234. /*****************************************************************************
  235. *
  236. * FUNCTION
  237. *
  238. *   Point_In_Clip
  239. *
  240. * INPUT
  241. *   
  242. * OUTPUT
  243. *   
  244. * RETURNS
  245. *   
  246. * AUTHOR
  247. *
  248. *   POV-Ray Team
  249. *   
  250. * DESCRIPTION
  251. *
  252. *   -
  253. *
  254. * CHANGES
  255. *
  256. *   -
  257. *
  258. ******************************************************************************/
  259.  
  260. int Point_In_Clip (VECTOR IPoint, OBJECT *Clip)
  261. {
  262.   OBJECT *Local_Clip;
  263.  
  264.   for (Local_Clip = Clip; Local_Clip != NULL; Local_Clip = Local_Clip->Sibling)
  265.   {
  266.     Increase_Counter(stats[Clipping_Region_Tests]);
  267.  
  268.     if (!Inside_Object(IPoint, Local_Clip))
  269.     {
  270.       return (FALSE);
  271.     }
  272.  
  273.     Increase_Counter(stats[Clipping_Region_Tests_Succeeded]);
  274.   }
  275.  
  276.   return (TRUE);
  277. }
  278.  
  279.  
  280.  
  281. /*****************************************************************************
  282. *
  283. * FUNCTION
  284. *
  285. *   Translate_Object
  286. *
  287. * INPUT
  288. *   
  289. * OUTPUT
  290. *   
  291. * RETURNS
  292. *   
  293. * AUTHOR
  294. *
  295. *   POV-Ray Team
  296. *   
  297. * DESCRIPTION
  298. *
  299. *   -
  300. *
  301. * CHANGES
  302. *
  303. *   -
  304. *
  305. ******************************************************************************/
  306.  
  307. void Translate_Object (OBJECT *Object, VECTOR Vector, TRANSFORM *Trans)
  308. {
  309.   OBJECT *Sib;
  310. #ifdef GlowPatch
  311.     int j=0;
  312.     for(j=0; j<Object->numOfGlows; j++)
  313.         Transform_Glow(Object->glowList[j], Trans);
  314. #endif
  315.  
  316.   if (Object == NULL)
  317.   {
  318.     return;
  319.   }
  320.  
  321.   for (Sib = Object->Bound; Sib != NULL; Sib = Sib->Sibling)
  322.   {
  323.     Translate_Object(Sib, Vector, Trans);
  324.   }
  325.  
  326.   if (Object->Clip != Object->Bound)
  327.   {
  328.     for (Sib = Object->Clip; Sib != NULL; Sib = Sib->Sibling)
  329.     {
  330.       Translate_Object(Sib, Vector, Trans);
  331.     }
  332.   }
  333.  
  334.   /* NK 1998 added if */
  335.   if (!Test_Flag(Object, UV_FLAG))
  336.   {
  337.     Transform_Textures(Object->Texture, Trans);
  338.     #ifdef InteriorTexturePatch
  339.   Transform_Textures(Object->Interior_Texture, Trans);/*Chris Huff: Interior Texture patch*/
  340.   #endif
  341.   }
  342.  
  343.   if (Object->UV_Trans == NULL)
  344.    Object->UV_Trans = Create_Transform();
  345.   Compose_Transforms(Object->UV_Trans, Trans);
  346.  
  347.   Transform_Interior(Object->Interior, Trans);
  348.  
  349.   Translate(Object, Vector, Trans);
  350. }
  351.  
  352.  
  353.  
  354. /*****************************************************************************
  355. *
  356. * FUNCTION
  357. *
  358. *   Rotate_Object
  359. *
  360. * INPUT
  361. *
  362. * OUTPUT
  363. *   
  364. * RETURNS
  365. *   
  366. * AUTHOR
  367. *
  368. *   POV-Ray Team
  369. *
  370. * DESCRIPTION
  371. *
  372. *   -
  373. *
  374. * CHANGES
  375. *
  376. *   -
  377. *
  378. ******************************************************************************/
  379.  
  380. void Rotate_Object (OBJECT *Object, VECTOR Vector, TRANSFORM *Trans)
  381. {
  382.   OBJECT *Sib;
  383. #ifdef GlowPatch
  384.     int j=0;
  385.     for(j=0; j<Object->numOfGlows; j++)
  386.         Transform_Glow(Object->glowList[j], Trans);
  387. #endif
  388.  
  389.   if (Object == NULL)
  390.   {
  391.     return;
  392.   }
  393.  
  394.   for (Sib = Object->Bound; Sib != NULL; Sib = Sib->Sibling)
  395.   {
  396.     Rotate_Object(Sib, Vector, Trans);
  397.   }
  398.  
  399.   if (Object->Clip != Object->Bound)
  400.   {
  401.     for (Sib = Object->Clip; Sib != NULL; Sib = Sib->Sibling)
  402.     {
  403.       Rotate_Object(Sib, Vector, Trans);
  404.     }
  405.   }
  406.  
  407.   /* NK 1998 added if */
  408.   if (!Test_Flag(Object, UV_FLAG))
  409.   {
  410.     Transform_Textures(Object->Texture, Trans);
  411. #ifdef InteriorTexturePatch
  412.   Transform_Textures(Object->Interior_Texture, Trans);/*Chris Huff: Interior Texture patch*/
  413. #endif
  414.   }
  415.  
  416.   if (Object->UV_Trans == NULL)
  417.    Object->UV_Trans = Create_Transform();
  418.   Compose_Transforms(Object->UV_Trans, Trans);
  419.  
  420.   Transform_Interior(Object->Interior, Trans);
  421.  
  422.   Rotate(Object, Vector, Trans);
  423. }
  424.  
  425.  
  426.  
  427. /*****************************************************************************
  428. *
  429. * FUNCTION
  430. *
  431. *   Scale_Object
  432. *
  433. * INPUT
  434. *
  435. * OUTPUT
  436. *   
  437. * RETURNS
  438. *   
  439. * AUTHOR
  440. *
  441. *   POV-Ray Team
  442. *   
  443. * DESCRIPTION
  444. *
  445. *   -
  446. *
  447. * CHANGES
  448. *
  449. *   -
  450. *
  451. ******************************************************************************/
  452.  
  453. void Scale_Object (OBJECT *Object, VECTOR Vector, TRANSFORM *Trans)
  454. {
  455.   OBJECT *Sib;
  456. #ifdef GlowPatch
  457.     int j=0;
  458.     for(j=0; j<Object->numOfGlows; j++)
  459.         Transform_Glow(Object->glowList[j], Trans);
  460. #endif
  461.  
  462.   if (Object == NULL)
  463.   {
  464.     return;
  465.   }
  466.  
  467.   for (Sib = Object->Bound; Sib != NULL; Sib = Sib->Sibling)
  468.   {
  469.     Scale_Object(Sib, Vector, Trans);
  470.   }
  471.  
  472.   if (Object->Clip != Object->Bound)
  473.   {
  474.     for (Sib = Object->Clip; Sib != NULL; Sib = Sib->Sibling)
  475.     {
  476.       Scale_Object(Sib, Vector, Trans);
  477.     }
  478.   }
  479.  
  480.   /* NK 1998 added if */
  481.   if (!Test_Flag(Object, UV_FLAG))
  482.   {
  483.     Transform_Textures(Object->Texture, Trans);
  484. #ifdef InteriorTexturePatch
  485.   Transform_Textures(Object->Interior_Texture, Trans);/*Chris Huff: Interior Texture patch*/
  486. #endif
  487.   }
  488.  
  489.   if (Object->UV_Trans == NULL)
  490.    Object->UV_Trans = Create_Transform();
  491.   Compose_Transforms(Object->UV_Trans, Trans);
  492.  
  493.   Transform_Interior(Object->Interior, Trans);
  494.  
  495.   Scale(Object, Vector, Trans);
  496. }
  497.  
  498.  
  499.  
  500. /*****************************************************************************
  501. *
  502. * FUNCTION
  503. *
  504. *   Transform_Object
  505. *
  506. * INPUT
  507. *   
  508. * OUTPUT
  509. *   
  510. * RETURNS
  511. *   
  512. * AUTHOR
  513. *
  514. *   POV-Ray Team
  515. *   
  516. * DESCRIPTION
  517. *
  518. *   -
  519. *
  520. * CHANGES
  521. *
  522. *   -
  523. *
  524. ******************************************************************************/
  525.  
  526. void Transform_Object (OBJECT *Object, TRANSFORM *Trans)
  527. {
  528.   OBJECT *Sib;
  529. #ifdef GlowPatch
  530.     int j=0;
  531.     for(j=0; j<Object->numOfGlows; j++)
  532.         Transform_Glow(Object->glowList[j], Trans);
  533. #endif
  534.  
  535.   if (Object == NULL)
  536.   {
  537.     return;
  538.   }
  539.  
  540.   for (Sib = Object->Bound; Sib != NULL; Sib = Sib->Sibling)
  541.   {
  542.     Transform_Object(Sib, Trans);
  543.   }
  544.  
  545.   if (Object->Clip != Object->Bound)
  546.   {
  547.     for (Sib = Object->Clip; Sib != NULL; Sib = Sib->Sibling)
  548.     {
  549.       Transform_Object(Sib, Trans);
  550.     }
  551.   }
  552.  
  553.   /* NK 1998 added if */
  554.   if (!Test_Flag(Object, UV_FLAG))
  555.   {
  556.     Transform_Textures(Object->Texture, Trans);
  557. #ifdef InteriorTexturePatch
  558.   Transform_Textures(Object->Interior_Texture, Trans);/*Chris Huff: Interior Texture patch*/
  559. #endif
  560.   }
  561.  
  562.   if (Object->UV_Trans == NULL)
  563.    Object->UV_Trans = Create_Transform();
  564.   Compose_Transforms(Object->UV_Trans, Trans);
  565.  
  566.   Transform_Interior(Object->Interior, Trans);
  567.  
  568.   Transform(Object,Trans);
  569. }
  570.  
  571.  
  572.  
  573. /*****************************************************************************
  574. *
  575. * FUNCTION
  576. *
  577. *   Invert_Object
  578. *
  579. * INPUT
  580. *   
  581. * OUTPUT
  582. *   
  583. * RETURNS
  584. *   
  585. * AUTHOR
  586. *
  587. *   POV-Ray Team
  588. *   
  589. * DESCRIPTION
  590. *
  591. *   -
  592. *
  593. * CHANGES
  594. *
  595. *   -
  596. *
  597. ******************************************************************************/
  598.  
  599. void Invert_Object (OBJECT *Object)
  600. {
  601.   if (Object == NULL)
  602.   {
  603.     return;
  604.   }
  605.  
  606.   Invert (Object);
  607. }
  608.  
  609.  
  610.  
  611. /*****************************************************************************
  612. *
  613. * FUNCTION
  614. *
  615. *   Copy_Bound_Clip
  616. *
  617. * INPUT
  618. *   
  619. * OUTPUT
  620. *   
  621. * RETURNS
  622. *   
  623. * AUTHOR
  624. *
  625. *   POV-Ray Team
  626. *   
  627. * DESCRIPTION
  628. *
  629. *   -
  630. *
  631. * CHANGES
  632. *
  633. *   -
  634. *
  635. ******************************************************************************/
  636.  
  637. static OBJECT *Copy_Bound_Clip (OBJECT *Old)
  638. {
  639.   OBJECT *Current, *New, *Prev, *First;
  640.  
  641.   First = Prev = NULL;
  642.  
  643.   for (Current = Old; Current != NULL; Current = Current->Sibling)
  644.   {
  645.     New = Copy_Object (Current);
  646.  
  647.     if (First == NULL)
  648.     {
  649.       First = New;
  650.     }
  651.  
  652.     if (Prev != NULL)
  653.     {
  654.       Prev->Sibling = New;
  655.     }
  656.  
  657.     Prev = New;
  658.   }
  659.  
  660.   return (First);
  661. }
  662.  
  663.  
  664.  
  665. /*****************************************************************************
  666. *
  667. * FUNCTION
  668. *
  669. *   Copy_Object
  670. *
  671. * INPUT
  672. *   
  673. * OUTPUT
  674. *   
  675. * RETURNS
  676. *   
  677. * AUTHOR
  678. *
  679. *   POV-Ray Team
  680. *   
  681. * DESCRIPTION
  682. *
  683. *   -
  684. *
  685. * CHANGES
  686. *
  687. *   -
  688. *
  689. ******************************************************************************/
  690.  
  691. OBJECT *Copy_Object (OBJECT *Old)
  692. {
  693.   OBJECT *New;
  694.  
  695.   if (Old == NULL)
  696.   {
  697.     return (NULL);
  698.   }
  699.  
  700.   New = (OBJECT *)Copy(Old);
  701.  
  702.   COOPERATE_0
  703.  
  704.  /*
  705.   * The following copying of OBJECT_FIELDS is redundant if Copy
  706.   * did *New = *Old but we cannot assume it did. It is safe for
  707.   * Copy to do *New = *Old but it should not otherwise
  708.   * touch OBJECT_FIELDS.
  709.   */
  710.  
  711.   New->Methods = Old->Methods;
  712.   New->Type    = Old->Type;
  713.   New->Sibling = Old->Sibling;
  714.   New->Bound   = Old->Bound;
  715.   New->Clip    = Old->Clip;
  716.   New->BBox    = Old->BBox;
  717.   New->Flags   = Old->Flags;
  718.  
  719.   New->Sibling = NULL;  /* Important */
  720.  
  721.   New->Texture = Copy_Textures (Old->Texture);
  722. #ifdef InteriorTexturePatch
  723.   New->Interior_Texture = Copy_Textures (Old->Interior_Texture);/*Chris Huff: Interior Texture patch*/
  724. #endif
  725.  
  726. #ifdef GlowPatch
  727.     if (Old->numOfGlows)    /* YS jan 2001 fix for OS X (zero pointer) */
  728.     {
  729.     New->glowList =(GLOW**) POV_MALLOC((New->numOfGlows+1)*sizeof(GLOW_PTR), "glow pointer array");
  730.     memcpy(New->glowList, Old->glowList, (Old->numOfGlows+1)*sizeof(GLOW_PTR));
  731.     }
  732. #endif
  733.  
  734.   New->Bound   = Copy_Bound_Clip (Old->Bound);
  735.  
  736.   New->Interior = Copy_Interior(Old->Interior);
  737.  
  738.   /* NK 1998 */
  739.   New->UV_Trans = Copy_Transform(Old->UV_Trans);
  740.   /* NK ---- */
  741.  
  742.   /* NK persist */
  743.   if (Old->Label != NULL)
  744.     New->Label = POV_STRDUP(Old->Label);
  745.   /* ---- */
  746.  
  747.   if (Old->Bound != Old->Clip)
  748.   {
  749.     New->Clip  = Copy_Bound_Clip (Old->Clip);
  750.   }
  751.   else
  752.   {
  753.     New->Clip  = New->Bound;
  754.   }
  755.  
  756.   return (New);
  757. }
  758.  
  759.  
  760.  
  761. /*****************************************************************************
  762. *
  763. * FUNCTION
  764. *
  765. *   Destroy_Object
  766. *
  767. * INPUT
  768. *
  769. * OUTPUT
  770. *
  771. * RETURNS
  772. *
  773. * AUTHOR
  774. *
  775. *   POV-Ray Team
  776. *
  777. * DESCRIPTION
  778. *
  779. *   -
  780. *
  781. * CHANGES
  782. *
  783. *   -
  784. *
  785. ******************************************************************************/
  786.  
  787. void Destroy_Single_Object (OBJECT **ObjectPtr)
  788. {
  789.   OBJECT *Object;
  790.  
  791.   Object = *ObjectPtr;
  792.  
  793.   Destroy_Textures(Object->Texture);
  794.  
  795. #ifdef GlowPatch
  796.     if(Object->glowList != NULL)
  797.         POV_FREE(Object->glowList);
  798. #endif
  799.  
  800.   Destroy_Object(Object->Bound);
  801.  
  802.   Destroy_Interior((INTERIOR *)Object->Interior);
  803.  
  804.     /* NK 1998 */
  805.   Destroy_Transform(Object->UV_Trans);
  806.   /* NK ---- */
  807.  
  808.   /* NK persist - Nov 1999 */
  809.   if (Object->Label!=NULL)
  810.     POV_FREE(Object->Label);
  811.   /* NK ---- */
  812.  
  813.   if (Object->Bound != Object->Clip)
  814.   {
  815.     Destroy_Object(Object->Clip);
  816.   }
  817.  
  818.   *ObjectPtr = Object->Sibling;
  819.  
  820.   Destroy(Object);
  821. }
  822.  
  823. void Destroy_Object (OBJECT *Object)
  824. {
  825.   OBJECT *Sib;
  826.  
  827.   while (Object != NULL)
  828.   {
  829.     Destroy_Textures(Object->Texture);
  830. #ifdef InteriorTexturePatch
  831.     Destroy_Textures(Object->Interior_Texture);/*Chris Huff: Interior Texture patch*/
  832. #endif
  833.  
  834. #ifdef GlowPatch
  835.     if(Object->glowList != NULL)
  836.         POV_FREE(Object->glowList);
  837. #endif
  838.     Destroy_Object(Object->Bound);
  839.  
  840.     Destroy_Interior((INTERIOR *)Object->Interior);
  841.  
  842.       /* NK 1998 */
  843.     Destroy_Transform(Object->UV_Trans);
  844.       /* NK ---- */
  845.  
  846.     /* NK persist - Nov 1999 */
  847.     if (Object->Label!=NULL)
  848.       POV_FREE(Object->Label);
  849.     /* NK ---- */
  850.  
  851.     if (Object->Bound != Object->Clip)
  852.     {
  853.       Destroy_Object(Object->Clip);
  854.     }
  855.  
  856.     Sib = Object->Sibling;
  857.  
  858.     Destroy(Object);
  859.  
  860.     Object = Sib;
  861.   }
  862. }
  863.  
  864.  
  865.  
  866. /*****************************************************************************
  867. *
  868. * FUNCTION
  869. *
  870. *   create_istack
  871. *
  872. * INPUT
  873. *
  874. * OUTPUT
  875. *
  876. * RETURNS
  877. *
  878. * AUTHOR
  879. *
  880. *   POV-Ray Team
  881. *
  882. * DESCRIPTION
  883. *
  884. *   -
  885. *
  886. * CHANGES
  887. *
  888. *   -
  889. *
  890. ******************************************************************************/
  891.  
  892. static void create_istack()
  893. {
  894.   ISTACK *New;
  895.  
  896.   New = (ISTACK *)POV_MALLOC(sizeof (ISTACK), "istack");
  897.  
  898.   New->next = free_istack;
  899.  
  900.   free_istack = New;
  901.  
  902.   New->istack = (INTERSECTION *)POV_MALLOC(Max_Intersections * sizeof (INTERSECTION), "istack entries");
  903.  
  904.   Number_of_istacks++;
  905. }
  906.  
  907.  
  908.  
  909.  
  910. /*****************************************************************************
  911. *
  912. * FUNCTION
  913. *
  914. *   Destroy_IStacks
  915. *
  916. * INPUT
  917. *
  918. * OUTPUT
  919. *
  920. * RETURNS
  921. *
  922. * AUTHOR
  923. *
  924. *   POV-Ray Team
  925. *
  926. * DESCRIPTION
  927. *
  928. *   -
  929. *
  930. * CHANGES
  931. *
  932. *   -
  933. *
  934. ******************************************************************************/
  935.  
  936. void Destroy_IStacks()
  937. {
  938.   ISTACK *istk, *temp;
  939.  
  940.   istk = free_istack;
  941.  
  942.   while (istk != NULL)
  943.   {
  944.     temp = istk;
  945.  
  946.     istk = istk->next;
  947.  
  948.     POV_FREE (temp->istack);
  949.  
  950.     POV_FREE (temp);
  951.   }
  952.  
  953.   free_istack = NULL;
  954. }
  955.  
  956.  
  957.  
  958. /*****************************************************************************
  959. *
  960. * FUNCTION
  961. *
  962. *   open_sstack
  963. *
  964. * INPUT
  965. *
  966. * OUTPUT
  967. *
  968. * RETURNS
  969. *
  970. * AUTHOR
  971. *
  972. *   POV-Ray Team
  973. *
  974. * DESCRIPTION
  975. *
  976. *   -
  977. *
  978. * CHANGES
  979. *
  980. *   -
  981. *
  982. ******************************************************************************/
  983.  
  984. ISTACK *open_istack()
  985. {
  986.   ISTACK *istk;
  987.  
  988.   if (free_istack == NULL)
  989.   {
  990.     create_istack ();
  991.   }
  992.  
  993.   istk = free_istack;
  994.  
  995.   free_istack = istk->next;
  996.  
  997.   istk->top_entry = 0;
  998.  
  999.   return (istk);
  1000. }
  1001.  
  1002.  
  1003.  
  1004. /*****************************************************************************
  1005. *
  1006. * FUNCTION
  1007. *
  1008. *   close_istack
  1009. *
  1010. * INPUT
  1011. *
  1012. * OUTPUT
  1013. *
  1014. * RETURNS
  1015. *
  1016. * AUTHOR
  1017. *
  1018. *   POV-Ray Team
  1019. *
  1020. * DESCRIPTION
  1021. *
  1022. *   -
  1023. *
  1024. * CHANGES
  1025. *
  1026. *   -
  1027. *
  1028. ******************************************************************************/
  1029.  
  1030. void close_istack (ISTACK *istk)
  1031. {
  1032.   istk->next = free_istack;
  1033.  
  1034.   free_istack = istk;
  1035. }
  1036.  
  1037.  
  1038.  
  1039. /*****************************************************************************
  1040. *
  1041. * FUNCTION
  1042. *
  1043. *   incstack
  1044. *
  1045. * INPUT
  1046. *
  1047. * OUTPUT
  1048. *
  1049. * RETURNS
  1050. *
  1051. * AUTHOR
  1052. *
  1053. *   POV-Ray Team
  1054. *
  1055. * DESCRIPTION
  1056. *
  1057. *   -
  1058. *
  1059. * CHANGES
  1060. *
  1061. *   -
  1062. *
  1063. ******************************************************************************/
  1064.  
  1065. void incstack(ISTACK *istk)
  1066. {
  1067.   if (++istk->top_entry >= Max_Intersections)
  1068.   {
  1069.     istk->top_entry--;
  1070.  
  1071.     Increase_Counter(stats[Istack_overflows]);
  1072.   }
  1073. }
  1074.  
  1075. /*****************************************************************************
  1076. *
  1077. * FUNCTION
  1078. *
  1079. *   Default_UVCoord
  1080. *
  1081. * INPUT
  1082. *
  1083. *   Object  - Pointer to blob structure
  1084. *   Inter   - Pointer to intersection
  1085. *
  1086. * OUTPUT
  1087. *
  1088. *
  1089. * RETURNS
  1090. *
  1091. * AUTHOR
  1092. *
  1093. *   Nathan Kopp
  1094. *
  1095. * DESCRIPTION
  1096. *   This is used as a default UVCoord function for objects where UVCoordinates
  1097. *   are not defined.  It instead returns the XY coordinates of the intersection.
  1098. *
  1099. * CHANGES
  1100. *
  1101. *
  1102. ******************************************************************************/
  1103.  
  1104. void Default_UVCoord(UV_VECT Result, OBJECT *Object, INTERSECTION *Inter)
  1105. {
  1106.   Result[U] = Inter->IPoint[X];
  1107.   Result[V] = Inter->IPoint[Y];
  1108. }
  1109.  
  1110.