#include <zbf.h>
Collaboration diagram for Zbf:
See class notes of courses CIV-2802 Sistemas Graficos para Engenharia, Departamento de Engenharia Civil, PUC-Rio. --------------------------------------------------------------- Description: This is a simple graphics package containing a z-buffer algorithm for filling polygon areas with a given color. For functions specification, see header file "zbf.h". --------------------------------------------------------------- Revisions:
| |
static int | Init (cdCanvas *cv) |
This function initializes a zbuffer for displaying. | |
static void | Close (void) |
This function closes a zbuffer. | |
static void | BeginPoly (long int color) |
This function starts the display of a new polygon in this module. | |
static void | Vertex (double x, double y, double z) |
This function receives a vertex of the current polygon being displayed in this module. | |
static void | EndPoly (void) |
This function finishes the specification of a polygon to be displayed in this module. | |
static void | NSCtoRaster (double xnsc, double ynsc, double znsc, int *xr, int *yr, unsigned int *zr) |
Convert from normalized screen coordinates (NSC) to raster (image) coordinates. | |
static void | OrderIntersections (Pixel *vtx, int left, int right) |
Order intesections of a scan line with polygon edges from left to right. | |
static void | ScanLine (Pixel *vtx_lft, Pixel *vtx_rgt, int ys) |
Paints a horizontal line on canvas (image). | |
static int | MountEdges (Edge *edge, int *ymin, int *ymax, int npoints, NscPnt *poly) |
Calculate maximum and minimum y coordinate and mount edge vector. | |
static int | MountInt (Pixel *vtx, Edge *edge, int *nedges, int ys) |
Mount intersection vector. | |
static void | FillPoly (int npoints, NscPnt *poly) |
This function fills a closed polygon with the current color. | |
static void | Release (void) |
Release memory used by z-buffer and polygon. | |
static int | Alloc (void) |
Allocate memory used by z-buffer and polygon. | |
static cdCanvas * | canvas = NULL |
CD handle of canvas for displaying zbuffer snap shot image. | |
static NscPnt * | poly = NULL |
Current polygon being displayed. | |
static int | sizepoly = 0 |
Size of poly array. | |
static int | npolyverts = 0 |
Number of polygon vertices. | |
static Edge * | poly_edge = NULL |
Edge vector. | |
static Pixel * | scanline_vtx = NULL |
Intersection vector. | |
static long int | curr_color = 0x0L |
Current fill color. | |
static int | cv_width = 100 |
Current z-buffer (canvas) horizontal size. | |
static int | cv_height = 100 |
Current z-buffer (canvas) vertical size. | |
static unsigned int * | zbuff = NULL |
Static Private Member Functions | |
static int | MAX (int a, int b) |
This function returns the maximum value between two integers. | |
static int | MIN (int a, int b) |
This function returns the minumum value between two integers. | |
Classes | |
struct | Edge |
Polygon edge. More... | |
struct | NscPnt |
3D point in normalized screen coordinates More... | |
struct | Pixel |
Pixel point. More... |
|
Allocate memory used by z-buffer and polygon.
Definition at line 348 of file zbf.cpp. References cv_height, cv_width, poly, Release(), sizepoly, and zbuff. Referenced by Init(). |
|
This function starts the display of a new polygon in this module. The polygon is filled with the given color.
Definition at line 399 of file zbf.cpp. References canvas, curr_color, npolyverts, and zbuff. Referenced by Dsp::ZbfBeginPoly(). |
|
This function closes a zbuffer. It releases the memory used by the current allocated zbuffer. |
|
This function finishes the specification of a polygon to be displayed in this module. It displays the polygon using the z-buffer algorithm. Definition at line 431 of file zbf.cpp. References FillPoly(), npolyverts, poly, Zbf::NscPnt::x, Zbf::NscPnt::y, and Zbf::NscPnt::z. Referenced by Dsp::ZbfEndPoly(). |
|
This function fills a closed polygon with the current color. Each pixel of the polygon is tested against the zbuffer. A pixel is displayed only if its z value is less then the current value of that pixel in the zbuffer (which is then updated). Definition at line 281 of file zbf.cpp. References MountEdges(), MountInt(), OrderIntersections(), poly_edge, ScanLine(), scanline_vtx, and Zbf::Pixel::x. Referenced by EndPoly(). |
|
This function initializes a zbuffer for displaying. It allocate memory for the zbuffer array and for local variables.
Definition at line 372 of file zbf.cpp. References Alloc(), canvas, cv_height, cv_width, and zbuff. Referenced by Prj::DspRotateView(), and Prj::DspZbufferCanvas(). |
|
This function returns the maximum value between two integers.
Definition at line 133 of file zbf.h. Referenced by MountEdges(). |
|
This function returns the minumum value between two integers.
Definition at line 141 of file zbf.h. Referenced by MountEdges(). |
|
Calculate maximum and minimum y coordinate and mount edge vector.
Definition at line 201 of file zbf.cpp. References Zbf::Edge::dxs, Zbf::Edge::dzs, MAX(), MIN(), NSCtoRaster(), Zbf::Edge::xs, Zbf::Edge::y_max, Zbf::Edge::y_min, and Zbf::Edge::zs. Referenced by FillPoly(). |
|
Mount intersection vector.
Definition at line 250 of file zbf.cpp. References Zbf::Edge::dxs, Zbf::Edge::dzs, Zbf::Pixel::x, Zbf::Edge::xs, Zbf::Edge::y_max, Zbf::Edge::y_min, Zbf::Pixel::z, and Zbf::Edge::zs. Referenced by FillPoly(). |
|
Convert from normalized screen coordinates (NSC) to raster (image) coordinates. The view volume in NSC ranges from -1 to +1 in the three axes. In NSC, the front (near) clipping plane has znsc = -1 and the back (far) clipping plane has znsc = +1. In raster coordinates, the front plane has zr = UINT_MAX (maximum unsigned int value) and the back plane has zr = 0. Therefore, the conversions of the limiting planes of the view volume from NSC to raster are as follows: left: xnsc = -1.0 ---> xr = 0 right: xnsc = +1.0 ---> xr = cv_width-1 bottom: ynsc = -1.0 ---> yr = 0 top: ynsc = +1.0 ---> yr = cv_height-1 front: znsc = -1.0 ---> zr = UINT_MAX back: znsc = +1.0 ---> zr = 0 Definition at line 102 of file zbf.cpp. References cv_height, and cv_width. Referenced by MountEdges(). |
|
Order intesections of a scan line with polygon edges from left to right.
Definition at line 124 of file zbf.cpp. References Zbf::Pixel::x. Referenced by FillPoly(). |
|
Release memory used by z-buffer and polygon.
Definition at line 333 of file zbf.cpp. References npolyverts, poly, sizepoly, and zbuff. |
|
Paints a horizontal line on canvas (image). Each pixel of the scan line is tested against the zbuffer. A pixel is displayed only if its z value is less then the current value of that pixel in the zbuffer (which is then updated). Definition at line 159 of file zbf.cpp. References canvas, curr_color, cv_width, Zbf::Pixel::x, Zbf::Pixel::z, and zbuff. Referenced by FillPoly(). |
|
This function receives a vertex of the current polygon being displayed in this module. It is assumed that the vertex is given in normalized screen coordinates (NSC). The view volume in NSC ranges from -1 to +1 in the three axes. In NSC, the front (near) clipping plane has z = -1 and the back (far) clipping plane has z = +1.
Definition at line 412 of file zbf.cpp. References npolyverts, poly, sizepoly, Zbf::NscPnt::x, Zbf::NscPnt::y, Zbf::NscPnt::z, and zbuff. Referenced by Dsp::ZbfVertex(). |
|
CD handle of canvas for displaying zbuffer snap shot image.
Definition at line 61 of file zbf.cpp. Referenced by BeginPoly(), Init(), and ScanLine(). |
|
Current fill color.
Definition at line 85 of file zbf.cpp. Referenced by BeginPoly(), and ScanLine(). |
|
Current z-buffer (canvas) vertical size.
Definition at line 91 of file zbf.cpp. Referenced by Alloc(), Close(), Init(), and NSCtoRaster(). |
|
Current z-buffer (canvas) horizontal size.
Definition at line 88 of file zbf.cpp. Referenced by Alloc(), Close(), Init(), NSCtoRaster(), and ScanLine(). |
|
Number of polygon vertices.
Definition at line 73 of file zbf.cpp. Referenced by BeginPoly(), EndPoly(), Release(), and Vertex(). |
|
Current polygon being displayed.
|
|
Edge vector.
Definition at line 77 of file zbf.cpp. Referenced by FillPoly(). |
|
Intersection vector.
Definition at line 81 of file zbf.cpp. Referenced by FillPoly(). |
|
Size of poly array.
|
|
Definition at line 94 of file zbf.cpp. Referenced by Alloc(), BeginPoly(), Init(), Release(), ScanLine(), and Vertex(). |