home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / alt / sources / 2611 / draw_bsp_xgl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-23  |  2.7 KB  |  135 lines

  1. #ifndef lint
  2. static    char    sccsid[] = "@(#)draw_bsp_xgl.c 1.1 92/05/28 SMI" ;
  3.     /* from draw_bsp_xgl.c 1.1 90/07/23 SMI */
  4. #endif
  5.  
  6. /*
  7.  * Copyright (c) 1986 by Sun Microsystems, Inc.
  8.  */
  9.  
  10. /*
  11.  * this file draws a bsp_tree object
  12.  */
  13.  
  14.  
  15.  
  16. #include <stdio.h>
  17. #include <math.h>
  18. #include "graphics.h"
  19. #include "dstar.h"
  20. #include "bsp_object.h"
  21.  
  22. extern    int    debug_level ;
  23.  
  24. #define    MAX_VECS    50
  25.  
  26. static    Pt3d    Pointzero = {0.0, 0.0, 0.0} ;
  27.  
  28. static    int    current_color ;
  29. static    int    current_pg_color ;
  30. static    Xgl_color    pg_color ;
  31.  
  32.  
  33. #define    bsp_color_line(color) if(color != current_color)    \
  34.         Set_color(Main_gfx, current_color = color) ;
  35.  
  36. #define    bsp_color_pg(color) if(color != current_pg_color){    \
  37.         pg_color.index = dbmap[current_pg_color = color] ;    \
  38.         xgl_object_set(Main_gfx,                \
  39.         XGL_CTX_SURF_FRONT_COLOR, &pg_color, 0) ; }
  40.  
  41.  
  42.  
  43. int
  44. draw_object_bsp(desc, viewer)
  45.     Object_Desc    *desc ;
  46.     Pt3d    *viewer;
  47. {
  48.     Bsp_Node    *top ;
  49. static    void        fill_vec() ;
  50. static    void        draw_node() ;
  51.  
  52.     top = (Bsp_Node *)desc->first ;
  53.     current_color = -1 ;
  54.     draw_node(top, viewer) ;
  55. }
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62. static    void
  63. draw_node(node, viewer)
  64. register Bsp_Node    *node ;
  65.      Pt3d    *viewer;
  66. {
  67.     Pt3d    vector ;
  68.     int    i,j ;
  69.     Xgl_pt_list    pl[BSP_MAX_LOOP] ;
  70.  
  71.  
  72.     vector = *viewer ;
  73.     vector.x -= node->vertices->x ;
  74.     vector.y -= node->vertices->y ;
  75.     vector.z -= node->vertices->z ;
  76.  
  77.     if ((vector.x*node->normal.x +
  78.          vector.y*node->normal.y +
  79.          vector.z*node->normal.z ) < 0.0)    /* back face */
  80.     {
  81.       if(node->front_child)
  82.         draw_node(node->front_child, viewer) ;
  83.       if(node->flags & BSP_BACK_VIEW)
  84.       {
  85.         for(i=0, j=0; i<node->nloop; ++i)
  86.         {
  87.           pl[i].pt_type = XGL_PT_F3D ;
  88.           pl[i].bbox = NULL ;
  89.           pl[i].num_pts = node->loops[i] ;
  90.           pl[i].pts.f3d = &node->vertices[j] ;
  91.           j += node->loops[i] ;
  92.         }
  93.  
  94.         if(node->color)
  95.         {
  96.           bsp_color_pg(node->color) ;
  97.           xgl_polygon(Main_gfx,XGL_FACET_NONE,NULL,NULL, node->nloop, pl);
  98.         }
  99.         if(node->trimcolor)
  100.         {
  101.           bsp_color_line(node->trimcolor) ;
  102.           xgl_multipolyline(Main_gfx, NULL, node->nloop, pl) ;
  103.         }
  104.       }
  105.       if(node->back_child)
  106.         draw_node(node->back_child, viewer) ;
  107.     }
  108.     else                /* front face */
  109.     {
  110.       if(node->back_child)
  111.         draw_node(node->back_child, viewer) ;
  112.       for(i=0, j=0; i<node->nloop; ++i)
  113.       {
  114.         pl[i].pt_type = XGL_PT_F3D ;
  115.         pl[i].bbox = NULL ;
  116.         pl[i].num_pts = node->loops[i] ;
  117.         pl[i].pts.f3d = &node->vertices[j] ;
  118.         j += node->loops[i] ;
  119.       }
  120.  
  121.       if(node->color)
  122.       {
  123.         bsp_color_pg(node->color) ;
  124.         xgl_polygon(Main_gfx,XGL_FACET_NONE,NULL,NULL, node->nloop, pl);
  125.       }
  126.       if(node->trimcolor)
  127.       {
  128.         bsp_color_line(node->trimcolor) ;
  129.         xgl_multipolyline(Main_gfx, NULL, node->nloop, pl) ;
  130.       }
  131.       if(node->front_child)
  132.         draw_node(node->front_child, viewer) ;
  133.     }
  134. }
  135.