home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / BSP Tree 1.2 / Sources / Graphics / source / polylist_3d.cp < prev    next >
Encoding:
Text File  |  1995-03-26  |  5.4 KB  |  96 lines  |  [TEXT/MMCC]

  1. //------------------------------------------------------------------------------
  2. //    File:                    polylist.cp
  3. //    Date:                    9/26/94
  4. //    Author:                Bretton Wade
  5. //
  6. //    Description:    this file contains the class methods for a polygon list
  7. //
  8. //------------------------------------------------------------------------------
  9.  
  10. #include "listptr_3d.h"
  11.  
  12. //------------------------------------------------------------------------------
  13. //    constructor
  14. //------------------------------------------------------------------------------
  15. polylist::polylist (void)                                                                                                                //    normal constructor
  16. {                                                                                                                                                                //    begin
  17.     head = 0;                                                                                                                                            //    the list is empty
  18.     ref_count = 0;                                                                                                                                //    start out with no references
  19. }                                                                                                                                                                //    end
  20.  
  21. //------------------------------------------------------------------------------
  22. //    destructor
  23. //------------------------------------------------------------------------------
  24. polylist::~polylist (void)                                                                                                            //    destructor
  25. {                                                                                                                                                                //    begin
  26.     while (head)                                                                                                                                    //    while the list is not empty
  27.     {                                                                                                                                                            //    begin
  28.         node    *kill = head;                                                                                                                    //    save the head element for a moment
  29.         head = head->next;                                                                                                                    //    advance the head element
  30.         delete kill;                                                                                                                                //    kill the former head
  31.     }                                                                                                                                                            //    end
  32. }                                                                                                                                                                //    end
  33.  
  34. //------------------------------------------------------------------------------
  35. //    add to list
  36. //------------------------------------------------------------------------------
  37. void        polylist::AddToList (polyptr &poly)                                                                            //    add a polygon to the list
  38. {                                                                                                                                                                //    begin
  39.     node    *add = new node;                                                                                                                //    create a new node
  40.     add->ptr = poly;                                                                                                                            //    copy the polygon pointer
  41.     add->next = head;                                                                                                                            //    set the new node at the head of the list
  42.     head = add;                                                                                                                                        //    install the new head
  43.     for (int i = 0; i < poly->Count (); i++)                                                                            //    take each vertex of the polygon
  44.         box += poly->Vertex (i);                                                                                                        //    and add it into the bounding box for the list
  45. }                                                                                                                                                                //    end
  46.  
  47. //------------------------------------------------------------------------------
  48. //    add to list
  49. //------------------------------------------------------------------------------
  50. void        polylist::Append (listptr &list)                                                                                //    append the contents of list to this list
  51. {                                                                                                                                                                //    begin
  52.     while (list->head)                                                                                                                        //    while there are elements in in the appending list
  53.         AddToList (list->Pop ());                                                                                                        //    pop them off and add them to this list
  54. }                                                                                                                                                                //    end
  55.  
  56. //------------------------------------------------------------------------------
  57. //    pop the head element
  58. //------------------------------------------------------------------------------
  59. polyptr    polylist::Pop (void)                                                                                                        //    pop the head from the list
  60. {                                                                                                                                                                //    begin
  61.     if (head)                                                                                                                                            //    if there is an entry in the list
  62.     {                                                                                                                                                            //    begin
  63.         polyptr    poly = head->ptr;                                                                                                        //    get the polygon pointer from the head element
  64.         node        *kill = head;                                                                                                                //    save the head element for a moment
  65.         head = head->next;                                                                                                                    //    advance the head to the next node
  66.         delete kill;                                                                                                                                //    kill the former head
  67.         return poly;                                                                                                                                //    return the polygon pointer
  68.     }                                                                                                                                                            //    end
  69.     else                                                                                                                                                    //    otherwise. there are no entries
  70.         return polyptr ();                                                                                                                    //    return a null polygon
  71. }                                                                                                                                                                //    end
  72.  
  73. //------------------------------------------------------------------------------
  74. //    test the list for emptiness
  75. //------------------------------------------------------------------------------
  76. bool        polylist::Empty (void) const                                                                                        //    return whether or not the list is empty
  77. {                                                                                                                                                                //    begin
  78.     return bool (head == 0);                                                                                                            //    return whether the head is a valid pointer
  79. }                                                                                                                                                                //    end
  80.  
  81. //------------------------------------------------------------------------------
  82. //    draw all the polygons in the list
  83. //------------------------------------------------------------------------------
  84. void        polylist::Draw (void) const                                                                                            //    draw the polygons in the list
  85. {                                                                                                                                                                //    begin
  86.     node    *current = head;                                                                                                                //    start at the top
  87.     while (current)                                                                                                                                //    while there are more items in the list
  88.     {                                                                                                                                                            //    begin
  89.         extern    void    DrawPolygon (polyptr);
  90.         DrawPolygon (current->ptr);                                                                                                    //    draw the polygon
  91.         current = current->next;                                                                                                        //    advance to the next list entry
  92.     }                                                                                                                                                            //    end
  93. }                                                                                                                                                                //    end
  94.  
  95. //------------------------------------------------------------------------------
  96.