home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_12 / 9n12040a < prev    next >
Text File  |  1991-10-14  |  3KB  |  71 lines

  1. #include "solid.h"
  2.  
  3. void display_facet(struct solid_obj *obj_ptr, struct
  4.     facet *facet_ptr, int display_opt, int is_visible)
  5. /*  Projects facet onto 2-dimensional screen.  */
  6. {
  7.     struct vertex *vertex_ptr;
  8.     int x_first, y_first; /* screen coordinates for
  9.         first vertex of facet */
  10.     int vertex_ref_index;
  11.     float screen_x, screen_y; /* screen coords */
  12.     float x_normal, y_normal, z_normal; /* surface
  13.         normal vector */
  14.  
  15.     if ((disp_hidden == LINE_NOSHOW  || render_opt) &&
  16.         !is_visible) return; /* nothing to do */
  17.     if (display_opt && render_opt) {
  18.         render_facet(obj_ptr, facet_ptr);
  19.         return;
  20.     }
  21.     if (!display_opt) { /* don't display; just compute
  22.         screen coordinates */
  23.         for (vertex_ref_index = 0; vertex_ref_index <
  24.             facet_ptr->vertex_count;
  25.             ++vertex_ref_index) { /* loop for each
  26.             vertex of this facet */
  27.             vertex_ptr = obj_ptr->vertex_first +
  28.                 facet_ptr->vertex_index
  29.                 [vertex_ref_index];
  30.             screen_x = proj_d * vertex_ptr->coord[0] /
  31.                 proj_z;
  32.             screen_y = proj_d * vertex_ptr->coord[1] /
  33.                 proj_z;
  34.             if (!init_screen) { /* first vertex;
  35.                 initialize minimum and maximum */
  36.                 screen_x_min = screen_x_max = screen_x;
  37.                 screen_y_min = screen_y_max = screen_y;
  38.                 init_screen = TRUE;
  39.             }
  40.             else { /* subsequent vertex; compare to
  41.                 minimum and maximum */
  42.                 if (screen_x < screen_x_min)
  43.                     screen_x_min = screen_x;
  44.                 if (screen_x > screen_x_max)
  45.                     screen_x_max = screen_x;
  46.                 if (screen_y < screen_y_min)
  47.                     screen_y_min = screen_y;
  48.                 if (screen_y > screen_y_max)
  49.                     screen_y_max = screen_y;
  50.             }
  51.             continue;
  52.         }
  53.     }
  54.     else { /* display option is on */
  55.         if (!is_visible && (disp_hidden ==
  56.             LINE_BROKEN))
  57.             setlinestyle(DASHED_LINE, 0, NORM_WIDTH);
  58.         if (!is_visible && (color_visible !=
  59.             color_hidden))
  60.             setcolor(color_hidden);
  61.         draw_polygon(obj_ptr, facet_ptr);
  62.         if (!is_visible && (disp_hidden ==
  63.             LINE_BROKEN))
  64.             setlinestyle(SOLID_LINE, 0, NORM_WIDTH);
  65.         if (!is_visible && (color_visible !=
  66.             color_hidden))
  67.             setcolor(color_visible);
  68.     }
  69.     return;
  70. }
  71.