#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "cd.h"
#include "zbf.h"
Include dependency graph for zbf.c:
Go to the source code of this file.
Compounds | |
struct | Edge |
Polygon edge. More... | |
struct | NscPnt |
3D point in normalized screen coordinates More... | |
struct | Pixel |
Pixel point. More... | |
Z-buffer display module | |
See class notes of courses CIV-2801 Fundamentos de Computacao Grafica Aplicada, 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 public functions specification, see header file "zbf.h".
--------------------------------------------------------------- Revisions: Created: 08-Nov-2005 Luiz Fernando Martha Stolen from g3dcdrnd.c and and modified. | |
#define | UINT_MAX 0xffffffff |
#define | MAX(a, b) (((a)>(b))?(a):(b)) |
#define | MIN(a, b) (((a)<(b))?(a):(b)) |
void | zbfNSCtoRaster (double xnsc, double ynsc, double znsc, int *xr, int *yr, unsigned *zr) |
Convert from normalized screen coordinates (NSC) to raster (image) coordinates. | |
void | zbfOrderIntersections (Pixel *vtx, int left, int right) |
void | zbfScanLine (Pixel *vtx_lft, Pixel *vtx_rgt, int ys) |
Paints a horizontal line on canvas (image). | |
int | zbfMountEdges (Edge *edge, int *ymin, int *ymax, int npoints, NscPnt *poly) |
Calculate maximum and minimum y coordinate and mount edge vector. | |
int | zbfMountInt (Pixel *vtx, Edge *edge, int *nedges, int ys) |
Mount intersection vector. | |
void | zbfFillPoly (int npoints, NscPnt *poly) |
This function fills a closed polygon with the current color. | |
void | zbfRelease (void) |
int | zbfAlloc (void) |
int | zbfInit (int w, int h) |
This function initializes a zbuffer for displaying. | |
void | zbfClose (void) |
This function closes a zbuffer. | |
void | zbfBeginPoly (long int color) |
This function starts the display of a new polygon in this module. | |
void | zbfVertex (double x, double y, double z) |
This function receives a vertex of the current polygon being displayed in this module. | |
void | zbfEndPoly (void) |
This function finishes the specification of a polygon to be displayed in this module. | |
NscPnt * | zbf_poly = NULL |
Current polygon being displayed. | |
int | sizepoly = 0 |
Size of zbf_poly array. | |
int | npolyverts = 0 |
Number of polygon vertices. | |
Edge * | poly_edge = NULL |
Edge vector. | |
Pixel * | scanline_vtx = NULL |
Intersection vector. | |
long int | curr_color |
Current fill color. | |
int | cv_width |
Current z-buffer (canvas) horizontal size. | |
int | cv_height |
Current z-buffer (canvas) vertical size. | |
unsigned * | zbuff |
|
|
|
Definition at line 71 of file zbf.c. Referenced by zbfMountEdges(). |
|
Definition at line 63 of file zbf.c. Referenced by zbfNSCtoRaster(). |
|
Definition at line 421 of file zbf.c. References cv_height, cv_width, sizepoly, zbfRelease(), and zbuff. Referenced by zbfInit(). |
|
This function starts the display of a new polygon in this module. The polygon is filled with the given color.
Definition at line 470 of file zbf.c. References curr_color, npolyverts, and zbuff. Referenced by dspZbfBeginPoly(). |
|
This function closes a zbuffer. It releases the memory used by the current allocated zbuffer. Definition at line 461 of file zbf.c. References cv_height, cv_width, and zbfRelease(). |
|
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 502 of file zbf.c. References npolyverts, NscPnt::x, NscPnt::y, NscPnt::z, and zbfFillPoly(). Referenced by dspZbfEndPoly(). |
|
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 354 of file zbf.c. References Pixel::x, zbfMountEdges(), zbfMountInt(), zbfOrderIntersections(), and zbfScanLine(). Referenced by zbfEndPoly(). |
|
This function initializes a zbuffer for displaying. It allocate memory for the zbuffer array and for local variables.
Definition at line 445 of file zbf.c. References cv_height, cv_width, zbfAlloc(), and zbuff. Referenced by prjZbufferSnapShot(). |
|
Calculate maximum and minimum y coordinate and mount edge vector.
Definition at line 267 of file zbf.c. References Edge::dxs, Edge::dzs, MAX, MIN, Edge::xs, Edge::y_max, Edge::y_min, zbfNSCtoRaster(), and Edge::zs. Referenced by zbfFillPoly(). |
|
Mount intersection vector.
Definition at line 318 of file zbf.c. References Edge::dxs, Edge::dzs, Pixel::x, Edge::xs, Edge::y_max, Edge::y_min, Pixel::z, and Edge::zs. Referenced by zbfFillPoly(). |
|
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 163 of file zbf.c. References cv_height, cv_width, and UINT_MAX. Referenced by zbfMountEdges(). |
|
Definition at line 182 of file zbf.c. References Pixel::x. Referenced by zbfFillPoly(). |
|
Definition at line 406 of file zbf.c. References npolyverts, sizepoly, and zbuff. Referenced by zbfAlloc(), and zbfClose(). |
|
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 223 of file zbf.c. References curr_color, cv_width, Pixel::x, Pixel::z, and zbuff. Referenced by zbfFillPoly(). |
|
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 483 of file zbf.c. References npolyverts, sizepoly, and zbuff. Referenced by dspZbfVertex(). |
|
Current fill color.
Definition at line 128 of file zbf.c. Referenced by zbfBeginPoly(), and zbfScanLine(). |
|
Current z-buffer (canvas) vertical size.
Definition at line 134 of file zbf.c. Referenced by zbfAlloc(), zbfClose(), zbfInit(), and zbfNSCtoRaster(). |
|
Current z-buffer (canvas) horizontal size.
Definition at line 131 of file zbf.c. Referenced by zbfAlloc(), zbfClose(), zbfInit(), zbfNSCtoRaster(), and zbfScanLine(). |
|
Number of polygon vertices.
Definition at line 90 of file zbf.c. Referenced by zbfBeginPoly(), zbfEndPoly(), zbfRelease(), and zbfVertex(). |
|
Edge vector.
|
|
Intersection vector.
|
|
Size of zbf_poly array.
Definition at line 86 of file zbf.c. Referenced by zbfAlloc(), zbfRelease(), and zbfVertex(). |
|
Current polygon being displayed.
|
|
Definition at line 137 of file zbf.c. Referenced by zbfAlloc(), zbfBeginPoly(), zbfInit(), zbfRelease(), zbfScanLine(), and zbfVertex(). |