home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_09_12
/
9n12042a
< prev
next >
Wrap
Text File
|
1991-10-14
|
2KB
|
42 lines
#include "solid.h"
void draw_polygon(struct solid_obj *obj_ptr,
struct facet *facet_ptr)
/* draws a polygon representing a facet */
{
struct vertex *vertex_ptr;
int x_first, y_first; /* screen coordinates for
first vertex of facet */
int vertex_ref_index;
float screen_x, screen_y; /* display screen
coordinates */
float x_normal, y_normal, z_normal; /* surface
normal vector */
for (vertex_ref_index = 0; vertex_ref_index <
facet_ptr->vertex_count; ++vertex_ref_index) {
/* loop for each vertex of this facet */
vertex_ptr = obj_ptr->vertex_first +
facet_ptr->vertex_index[vertex_ref_index];
screen_x = proj_d * vertex_ptr->coord[0] /
proj_z;
screen_y = proj_d * vertex_ptr->coord[1] /
proj_z;
if (vertex_ref_index == 0) /* first vertex */
moveto(x_first = (int)(((screen_x -
screen_x_min) / (screen_x_max -
screen_x_min)) * maxx), y_first = (int)
(((screen_y - screen_y_min) /
(screen_y_max - screen_y_min)) *
maxy));
else /* subsequent vertex */
lineto((int)(((screen_x - screen_x_min) /
(screen_x_max - screen_x_min)) * maxx),
(int)(((screen_y - screen_y_min) /
(screen_y_max - screen_y_min)) *
maxy));
}
lineto(x_first, y_first); /* back to 1st vertex */
return;
}