Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members  

zbf.c File Reference

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "cd.h"
#include "zbf.h"

Include dependency graph for zbf.c:

Include dependency graph

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

Date:
08-Nov-2005
Author:
Luiz F. Martha
Version:
1.0
  • Incomplete source code file. Part of the objectives of the third course assignment is to complete the source code in this file (see COMPLETE HERE: XX comment).
--------------------------------------------------------------- Reference:

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.

NscPntzbf_poly = NULL
 Current polygon being displayed.

int sizepoly = 0
 Size of zbf_poly array.

int npolyverts = 0
 Number of polygon vertices.

Edgepoly_edge = NULL
 Edge vector.

Pixelscanline_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


Define Documentation

#define MAX a,
     (((a)>(b))?(a):(b))
 

Definition at line 67 of file zbf.c.

#define MIN a,
     (((a)<(b))?(a):(b))
 

Definition at line 71 of file zbf.c.

Referenced by zbfMountEdges().

#define UINT_MAX   0xffffffff
 

Definition at line 63 of file zbf.c.

Referenced by zbfNSCtoRaster().


Function Documentation

int zbfAlloc void    [static]
 

Definition at line 421 of file zbf.c.

References cv_height, cv_width, sizepoly, zbfRelease(), and zbuff.

Referenced by zbfInit().

void zbfBeginPoly long int    color
 

This function starts the display of a new polygon in this module.

The polygon is filled with the given color.

Parameters:
color  - coded color of polygon (in)

Definition at line 470 of file zbf.c.

References curr_color, npolyverts, and zbuff.

Referenced by dspZbfBeginPoly().

void zbfClose void   
 

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().

void zbfEndPoly void   
 

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().

void zbfFillPoly int    npoints,
NscPnt   poly
[static]
 

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().

int zbfInit int    width,
int    height
 

This function initializes a zbuffer for displaying.

It allocate memory for the zbuffer array and for local variables.

Parameters:
width, height  - sizes of new zbuffer (in)

Definition at line 445 of file zbf.c.

References cv_height, cv_width, zbfAlloc(), and zbuff.

Referenced by prjZbufferSnapShot().

int zbfMountEdges Edge   edge,
int *    ymin,
int *    ymax,
int    npoints,
NscPnt   poly
[static]
 

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().

int zbfMountInt Pixel   vtx,
Edge   edge,
int *    nedges,
int    ys
[static]
 

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().

void zbfNSCtoRaster double    xnsc,
double    ynsc,
double    znsc,
int *    xr,
int *    yr,
unsigned *    zr
 

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().

void zbfOrderIntersections Pixel   vtx,
int    left,
int    right
[static]
 

Definition at line 182 of file zbf.c.

References Pixel::x.

Referenced by zbfFillPoly().

void zbfRelease void    [static]
 

Definition at line 406 of file zbf.c.

References npolyverts, sizepoly, and zbuff.

Referenced by zbfAlloc(), and zbfClose().

void zbfScanLine Pixel   vtx_lft,
Pixel   vtx_rgt,
int    ys
[static]
 

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().

void zbfVertex double    x,
double    y,
double    z
 

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.

Parameters:
x, y, z  - polygon vertex in normalized screen coords. (in)

Definition at line 483 of file zbf.c.

References npolyverts, sizepoly, and zbuff.

Referenced by dspZbfVertex().


Variable Documentation

long int curr_color [static]
 

Current fill color.

Definition at line 128 of file zbf.c.

Referenced by zbfBeginPoly(), and zbfScanLine().

int cv_height [static]
 

Current z-buffer (canvas) vertical size.

Definition at line 134 of file zbf.c.

Referenced by zbfAlloc(), zbfClose(), zbfInit(), and zbfNSCtoRaster().

int cv_width [static]
 

Current z-buffer (canvas) horizontal size.

Definition at line 131 of file zbf.c.

Referenced by zbfAlloc(), zbfClose(), zbfInit(), zbfNSCtoRaster(), and zbfScanLine().

int npolyverts = 0 [static]
 

Number of polygon vertices.

Definition at line 90 of file zbf.c.

Referenced by zbfBeginPoly(), zbfEndPoly(), zbfRelease(), and zbfVertex().

Edge* poly_edge = NULL [static]
 

Edge vector.

Definition at line 111 of file zbf.c.

Pixel* scanline_vtx = NULL [static]
 

Intersection vector.

Definition at line 124 of file zbf.c.

int sizepoly = 0 [static]
 

Size of zbf_poly array.

Definition at line 86 of file zbf.c.

Referenced by zbfAlloc(), zbfRelease(), and zbfVertex().

NscPnt* zbf_poly = NULL [static]
 

Current polygon being displayed.

Definition at line 82 of file zbf.c.

unsigned* zbuff [static]
 

Definition at line 137 of file zbf.c.

Referenced by zbfAlloc(), zbfBeginPoly(), zbfInit(), zbfRelease(), zbfScanLine(), and zbfVertex().


Generated on Tue Nov 8 10:58:10 2005 for Trab3 by doxygen1.2.18