home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / rec / games / programm / 5515 < prev    next >
Encoding:
Text File  |  1993-01-25  |  4.0 KB  |  119 lines

  1. Newsgroups: rec.games.programmer
  2. Path: sparky!uunet!van-bc!chrisp
  3. From: chrisp@wimsey.bc.ca (Chris Phillips)
  4. Subject: Re: blocking out walls
  5. Organization: Wimsey Information Services
  6. Date: Mon, 25 Jan 1993 11:22:42 GMT
  7. Message-ID: <C1Eq9v.2M6@wimsey.bc.ca>
  8. X-Newsreader: Tin 1.1 PL5
  9. References: <727768927.0@njackn.njackn.uucp>
  10. Lines: 106
  11.  
  12. :         To add yet another question about Wolf3d games: Has anyone got a good algoritm for eliminating walls that you couldn't see(wall behind other walls). I have tried having it check the tiles in a line between you and the tile in question and haven't had very much success. It may be because I had some errors in my algorith, but I wanted to see if anyone else had a better idea. Also about those pesky wall sections that you can only see part of, is it easiest just to print ther closer one last or is th
  13. er
  14.  
  15.  
  16.     What you need is whats called an Extent list.
  17.  
  18.     First order of business is to create a list of all walls you want
  19. to draw in order(front to back).
  20.  
  21.     Next you need an array with 1 bit for every pixel wide your
  22. screen is. So if your screen or view window is 320 you need 320 bits(or bytes
  23. for speed) in your array.
  24.     
  25.     Next go through the list front(closest wall to you) to back (wall
  26. furthest away). For each wall fill in the bits in the array that corespond
  27. to the minimum and maximum x value of the wall. If you set any bits in this
  28. step the wall is visible and must be drawn. When all bits in the array are
  29. filled you can stop looking.
  30.  
  31.     Here is some code that should give you the idea.
  32.  
  33. NOTE: This code is completly un-tested. It is provided as an example only
  34. and proably contains many typing and other errors.
  35.  
  36. char extent_list[VIEWPORT_WIDTH];
  37.  
  38. void clear_extent_list()
  39. {
  40. int i;
  41. for(i=0;i<VIEWPORT_WIDTH;i++)
  42.     extent_list[i]=0;
  43.  
  44. }
  45. /*************************************************/
  46. /* This function returns TRUE if the wall is     */
  47. /* visible and must be drawn. This funtion also  */
  48. /* fills in the extent list.                     */
  49. /* Called with: Projected view port coord's for  */
  50. /* the min and max x value of a wall             */
  51. /*************************************************/
  52. char check_wall_against_extent(int x1,int x2)
  53. {
  54. int i;
  55. char flag=0;     /*assume no draw*/
  56. for(i=x1;i<x2;i++)    /*go from left to right*/
  57.     {
  58.     if(extent_list[i]==0)    /*if no wall already here*/ 
  59.         flag=TRUE;        /*set flag to draw wall*/
  60.     extent_list[i]=1;    /*fill in extent list for this wall*/
  61.     }
  62. return(flag);
  63. }
  64. /***********************************************/
  65. /* This funtion will go through a list of      */
  66. /* walls and mark the visible ones as drawable */
  67. /* This function assumes a global array of     */
  68. /* structures as follows                       */
  69. /* 1. wall.x1,wall.y1 .... wall.x4,wall.y4     */
  70. /* the 4 corners of the wall to draw in        */
  71. /* in clock-wise order starting with upper     */
  72. /* left.                                       */
  73. /* 2. wall.draw                                */
  74. /* Flag to set if wall is visible              */
  75. /* NOTE: This array must be sorted so the      */
  76. /* the wall closest to you is element 0        */
  77. /* and the wall furthest from the viewer is    */
  78. /* element number "num_walls_to_render"        */
  79. /***********************************************/*
  80. void check_extent_list()
  81. {
  82. clear_extent_list();
  83. for(i=0;i<num_walls_to_render;i++)
  84.     {
  85.     wall[i].draw=FALSE; /*assume no draw*/
  86.     if(check_wall_against_extent(wall[i].x1,wall[i].x2))
  87.         wall[i].draw=TRUE;   /*mark wall to draw*/
  88.     }
  89. }
  90. /**********************************************/
  91. /* your main will proably look somthing like  */
  92. /* this.                      */
  93. /**********************************************/
  94. void my_main()
  95. {
  96. int i;
  97. num_walls_to_render=build_list_of_all_walls_in_visible_range();
  98. sort_all_walls_front_to_back();
  99. project_and_rotate_points_to_create_polygons_of_walls();
  100. clip_all_walls_to_view_port();
  101. check_extent_list();
  102. for(i=num_walls_to_render;i>=0;i--) /*NOTE: draw walls back to front*/    
  103.     if(wall[i].draw)
  104.         draw_wall(&wall);
  105. }
  106.  
  107. If anything in this mess isn't clear I'll be happy to answer any questions.
  108.  
  109.     Good Luck
  110.         Chris
  111.         chrisp@wimsey.bc.ca
  112.  
  113.  
  114.         
  115.  
  116.  
  117.  
  118.