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

quad.c File Reference

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "prm.h"
#include "quad.h"
#include "cd.h"
#include "wd.h"
#include "dsp.h"

Include dependency graph for quad.c:

Include dependency graph

Go to the source code of this file.

Compounds

struct  _quad
 Quadrilateral primitive structure:. More...


Quadrilateral primitive module

Date:
11-Sep-2005
Author:
Luiz F. Martha
Version:
1.0
This file contains the implementation of the quadrilateral primitive module of the current project, which includes the implementation of public and private functions.

See definitions of public data types and public functions in hearder file "quad.h".

For specification see class notes of course CIV-2801 "Fundamentos de Computacao Grafica Aplicada", period 2005.2.

Revisions:

  • On 08-nov-05 by Luiz F. Martha Added functions quadDisplaySolid, quadHighltSolid, and quadDisplayZbuffer. 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 comments). The solution of the second course assignment should be copied to this file. Additional parts should be completed.


void quadPickCode (double x, double y, double xmin, double xmax, double ymin, double ymax, int cod[4])
 This function computes a code vector for a picking point with respect to a window (rectangle given by its limiting coordinates).

int quadPickLine (double x, double y, double pick_tol, double x0, double y0, double x1, double y1)
 This function checks to see whether a given point (x,y) is close to a line (x0, y0, x1, y1).

void quadFaceNormal (Pnt3d *p0, Pnt3d *p1, Pnt3d *p2, Pnt3d *p3, Vec3d *normal)
 This function computes the normal vector of a quadrilateral polygon.

void quadBuildSolidPrm (Quad *quad, double height, Pnt3d *solid_prm)
 This function returns an array of points that represents the solid version of a quadrilateral primitive.

QuadquadCreate (void)
 This function creates a new quadrilateral primitive.

void quadDelete (Quad *quad)
 This function releases memory that is used by a quadrilateral primitive.

void quadRead (Quad *quad, FILE *fd)
 This function reads geometry data of a given quadrilateral primitive (given by its pointer) from a file (given by its pointer) and loads the data into the primitive attributes.

void quadWrite (Quad *quad, FILE *fd)
 This function writes the geometry attribute data of a given quadrilateral primitive (given by its pointer) to a file (given by its pointer).

int quadGetNPts (Quad *quad)
 This function returns (as its value) the number of vertices of the given quadrilateral primitive (given by its pointer).

void quadSetCoords (Quad *quad, int id, double x, double y)
 This function replaces the x and y coordinates of a vertex of the given quadrilateral primitive (given by its pointer) by the given pair of coordinates.

void quadGetCoords (Quad *quad, int id, double *x, double *y)
 This function returns the x and y coordinates of a vertex of the given quadrilateral primitive (given by its pointer).

void quadSet1stPt (Quad *quad, double x, double y)
 This function is used during interactive construction of a quadrilateral primitive.

void quadSet2ndPt (Quad *quad, double x, double y)
 This function is used during interactive construction of a quadrilateral primitive.

int quadPickArea (Quad *quad, double x, double y)
 This function checks whether a given point is inside a given quadrilateral primitive (given by its pointer).

int quadPickVertex (Quad *quad, double x, double y, double tol, int *id)
 This function selects a vertex of a given quadrilateral primitive based on the given point position.

int quadPickSide (Quad *quad, double x, double y, double tol, int *id)
 This function selects a side of a given quadrilateral primitive based on the given point position.

void quadTranslate (Quad *quad, double dx, double dy)
 This function translates the given quadrilateral primitive (given by its pointer).

void quadTranslateVertex (Quad *quad, int id, double dx, double dy)
 This function translates a vertex of a given quadrilateral primitive (given by its pointer) using the given translation factors.

void quadTranslateSide (Quad *quad, int id, double dx, double dy)
 This function translates the two vertices of a side of a given quadrilateral primitive (given by its pointer) using the given translation factors.

void quadGetBox (Quad *quad, double *xmin, double *xmax, double *ymin, double *ymax)
 This function returns the limiting rectangle that involves the given quadrilateral primitive (given by its pointer).

void quadDisplayBoundary (Quad *quad)
 This function displays the boundary of the given quadrilateral primitive (given by its pointer).

void quadDisplayInterior (Quad *quad)
 This function displays the interior of the given quadrilateral primitive (given by its pointer).

void quadDisplaySolid (Quad *quad, double height)
 Function to display a solid version of a quadrilateral primitive.

void quadHighltSolid (Quad *quad, double height)
 Function to highlight a solid version of a quadrilateral primitive.

void quadDisplayZbuffer (Quad *quad, double height, long int color)
 Function to send a solid version of a quadrilateral primitive to the zbuffer module to be projected and displayed.


Function Documentation

void quadBuildSolidPrm Quad   quad,
double    height,
Pnt3d   solid_prm
[static]
 

This function returns an array of points that represents the solid version of a quadrilateral primitive.

The solid version is a prism that has the 2D primitive as its base and height equal to the primitive height. The solid prism is built in such a way that each of its base faces has a normal vector pointing outwards the prism when traversing its vertices in counter-clockwise order and following the right-hand rule.

Parameters:
quad  - pointer to target 2D primitive (in)
height  - height of primitive (in)
solid_prm  - array of solid primitive points (out)

Definition at line 240 of file quad.c.

References _quad::p, quadFaceNormal(), _Coord::x, pnt3d::x, _Coord::y, pnt3d::y, and pnt3d::z.

Referenced by quadDisplayZbuffer().

Quad* quadCreate void   
 

This function creates a new quadrilateral primitive.

It only allocates memory for a quadrilateral primitive, sets its default vertex coordinates and returns a pointer to the allocated quadrilateral primitive.

The quadrilateral vertices are ordered in the following order:

(id = 3) (id = 1) +--------+ | | | | | | | | +--------+ (id = 0) (id = 2)

Default vertex coordinates: id = 0 ==> (x0 = 0.0, y0 = 0.0) id = 1 ==> (x1 = 1.0, y1 = 1.0) id = 2 ==> (x2 = 1.0, y2 = 0.0) id = 3 ==> (x3 = 0.0, y3 = 1.0)

Returns:
The function returns a pointer to the created primitive, or a null pointer if the primitive could not be created.

Definition at line 309 of file quad.c.

References _quad::p, _Coord::x, and _Coord::y.

Referenced by prmCreateBack(), and prmCreateFront().

void quadDelete Quad   quad
 

This function releases memory that is used by a quadrilateral primitive.

It is assumed that the given pointer is really a valid pointer to an existing quadrilateral primitive.

Parameters:
quad  - pointer to primitive to delete (in)

Definition at line 335 of file quad.c.

Referenced by prmDelete().

void quadDisplayBoundary Quad   quad
 

This function displays the boundary of the given quadrilateral primitive (given by its pointer).

Straight lines are used used to display the primitive edges and marks are used to display its vertices. The Canvas Draw (CD) graphics library is used to display the boundary of the primitive. Please refer to CD documentation for additional information. The function only deals with the geometric attributes of the primitive. This means that other attributes such as foreground color, line style, or mark type are specified outside this function. It is assumed that the given pointer is really a valid pointer to an existing quadrilateral primitive.

Parameters:
quad  - pointer to target quadrilateral primitive(in)

Definition at line 492 of file quad.c.

Referenced by prmDisplayBoundary().

void quadDisplayInterior Quad   quad
 

This function displays the interior of the given quadrilateral primitive (given by its pointer).

The interior area is filled with the currently specified background color. The Canvas Draw (CD) graphics library is used to display the boundary of the primitive. Please refer to CD documentation for additional information. The function only deals with the geometric attributes of the primitive. This means that other attributes such as background color or interior style are specified outside this function. It is assumed that the given pointer is really a valid pointer to an existing quadrilateral primitive.

Parameters:
quad  - pointer to target quadrilateral primitive(in)

Definition at line 499 of file quad.c.

Referenced by prmDisplayInterior().

void quadDisplaySolid Quad   quad,
double    height
 

Function to display a solid version of a quadrilateral primitive.

The solid version is a prism that has the 2D primitive as its base and height equal to the primitive height. This function fills the quadrilateral shape of the solid prism faces with the current color. It uses OpenGL display functions.

Parameters:
quad  - pointer to target quadrilateral primitive(in)
height  - primitive height (in)

Definition at line 506 of file quad.c.

Referenced by prmDisplaySolid().

void quadDisplayZbuffer Quad   quad,
double    height,
long int    color
 

Function to send a solid version of a quadrilateral primitive to the zbuffer module to be projected and displayed.

The solid version is a prism that has the 2D primitive as its base and height equal to the primitive height.

Parameters:
quad  - pointer to target quadrilateral primitive(in)
height  - primitive height (in)
color  - primitive coded color (in)

Definition at line 523 of file quad.c.

References dspZbfBeginPoly(), dspZbfEndPoly(), dspZbfVertex(), _quad::p, quadBuildSolidPrm(), quadFaceNormal(), _Coord::x, pnt3d::x, _Coord::y, pnt3d::y, and pnt3d::z.

Referenced by prmDisplayZbuffer().

void quadFaceNormal Pnt3d   p0,
Pnt3d   p1,
Pnt3d   p2,
Pnt3d   p3,
Vec3d   normal
[static]
 

This function computes the normal vector of a quadrilateral polygon.

It uses the cross product of the polygon edges.

Parameters:
p0  - first quadrilateral point (in)
p1  - second quadrilateral point (in)
p2  - third quadrilateral point (in)
p4  - fourth quadrilateral point (in)
normal  - quadrilateral normalized normal vector (out)

Definition at line 193 of file quad.c.

References pnt3d::x, pnt3d::y, and pnt3d::z.

Referenced by quadBuildSolidPrm(), and quadDisplayZbuffer().

void quadGetBox Quad   quad,
double *    xmin,
double *    xmax,
double *    ymin,
double *    ymax
 

This function returns the limiting rectangle that involves the given quadrilateral primitive (given by its pointer).

This rectangle is the primitive bounding box, which is parallel to the x and y axes, with the minimum and maximum x and y coordinates of the primitive's vertices. It is assumed that the given pointer is really a valid pointer to an existing quadrilateral primitive.

Parameters:
quad  - pointer to target quadrilateral primitive(in)
xmin, xmax  - limiting x coordinates of primitive (out)
ymin, ymax  - limiting y coordinates of primitive (out)

Definition at line 484 of file quad.c.

Referenced by prmGetBox().

void quadGetCoords Quad   quad,
int    id,
double *    x,
double *    y
 

This function returns the x and y coordinates of a vertex of the given quadrilateral primitive (given by its pointer).

The vertex is indicated by an index between 0 and 3. Nothing will happen if the given index is outside this range. It is assumed that the given pointer is really a valid pointer to an existing quadrilateral primitive.

The quadrilateral vertices are ordered in counter-clockwise order:

(id = 3) (id = 2) +-------------------+ | | | | | | | | +-------------------+ (id = 0) (id = 1)

Parameters:
quad  - pointer to target quadrilateral primitive(in)
id  - index of target vertex in primitive (in)
x  - vertex x coordinate (out)
y  - vertex y coordinate (out)

Definition at line 370 of file quad.c.

Referenced by prmGetCoords(), and quadPickArea().

int quadGetNPts Quad   quad
 

This function returns (as its value) the number of vertices of the given quadrilateral primitive (given by its pointer).

It is assumed that the given pointer is really a valid pointer to an existing quadrilateral primitive.

Parameters:
quad  - pointer to target primitive (in)
Returns:
The number of vertices of quadrilateral: 4.

Definition at line 356 of file quad.c.

Referenced by prmGetNPts().

void quadHighltSolid Quad   quad,
double    height
 

Function to highlight a solid version of a quadrilateral primitive.

The solid version is a prism that has the 2D primitive as its base and height equal to the primitive height. This function displays the edges of the prism and draws marks at its vertices, all with the current color. It uses OpenGL display functions.

Parameters:
quad  - pointer to target quadrilateral primitive(in)
height  - primitive height (in)

Definition at line 515 of file quad.c.

Referenced by prmHighltSolid().

int quadPickArea Quad   quad,
double    x,
double    y
 

This function checks whether a given point is inside a given quadrilateral primitive (given by its pointer).

The adopted algorithm is the so called semi-infinite ray algorithm that starts at the given point and goes in the horizontal direction to positive infinity. If the number of intersections of the ray with the polygon boundary is odd, the point is inside the polygon. If the number of intersections is even, the point is outside. Please refer to class notes of course CIV 2801 - Fundamentos de Computacao Grafica Aplicada - PUC-Rio. It is assumed that the given pointer is really a valid pointer to an existing quadrilateral primitive.

Parameters:
quad  - pointer to target quadrilateral primitive(in)
x  - x coordinate of given point (in)
y  - y coordinate of given point (in)
Returns:
In case the given point is inside the given primitive, a true (1) status is returned. Otherwise, a false (0) status is returned.

Definition at line 391 of file quad.c.

References quadGetCoords().

Referenced by prmPickArea().

void quadPickCode double    x,
double    y,
double    xmin,
double    xmax,
double    ymin,
double    ymax,
int    cod[4]
[static]
 

This function computes a code vector for a picking point with respect to a window (rectangle given by its limiting coordinates).

This code vector is used in function quadPickLine below.

Parameters:
x  - x coordinate of given point (in)
y  - y coordinate of given point (in)
xmin  - left limit of window (in)
xmax  - right limit of window (in)
ymin  - bottom limit of window (in)
ymax  - top limit of window (in)
cod  - returned code vector (out)

Definition at line 96 of file quad.c.

Referenced by quadPickLine().

int quadPickLine double    x,
double    y,
double    pick_tol,
double    x0,
double    y0,
double    x1,
double    y1
[static]
 

This function checks to see whether a given point (x,y) is close to a line (x0, y0, x1, y1).

The adopted algorithm is based on clipping the given line by a tolerance window that is defined by the given point and the current tolerance value. Please refer to class notes of course CIV 2801 - Fundamentos de Computacao Grafica Aplicada - PUC-Rio.

Parameters:
x  - x coordinate of given point (in)
y  - y coordinate of given point (in)
pick_tol  - tolerance value for check proximity (in)
x0  - x coordinate of first line vertex (in)
y0  - y coordinate of first line vertex (in)
x1  - x coordinate of second line vertex (in)
y1  - y coordinate of second line vertex (in)
Returns:
Status: true (1) if point is close to line; false (0) if not.

Definition at line 126 of file quad.c.

References quadPickCode().

int quadPickSide Quad   quad,
double    x,
double    y,
double    tol,
int *    id
 

This function selects a side of a given quadrilateral primitive based on the given point position.

The target side is indicated by an index, which has a value between 0 and 3.

The quadrilateral sides are ordered in counter-clockwise order:

(id = 2) +-------------------+ | | (id = 3) | | (id = 1) | | | | +-------------------+ (id = 0)

Parameters:
quad  - pointer to target quadrilateral primitive(in)
x  - x coordinate of given point (in)
y  - y coordinate of given point (in)
tol  - tolerance value to check proximity (in)
id  - returned primitive side index (out)
Returns:
In case the given point is close to a side of the target primitive, the function returns a true (1) status and the index of the selected side is returned as a parameter. In case no side if found close to the given point, the function returns a false (0) status.

Definition at line 453 of file quad.c.

Referenced by prmPickSide().

int quadPickVertex Quad   quad,
double    x,
double    y,
double    tol,
int *    id
 

This function selects a vertex of a given quadrilateral primitive based on the given point position.

In case the given point is close to a vertex of the primitive, the index of the found vertex is returned. The index is a value between 0 and 3.

The quadrilateral vertices are ordered in counter-clockwise order:

(id = 3) (id = 2) +-------------------+ | | | | | | | | +-------------------+ (id = 0) (id = 1)

Parameters:
quad  - pointer to target quadrilateral primitive(in)
x  - x coordinate of given point (in)
y  - y coordinate of given point (in)
tol  - tolerance value to check proximity (in)
id  - returned primitive vertex index (out)
Returns:
In case the given point is close to a vertex of the target primitive, the function returns a true (1) status and the index of the selected vertex is returned as a parameter. In case no vertex if found close to the given point, the function returns a false (0) status.

Definition at line 443 of file quad.c.

Referenced by prmPickVertex().

void quadRead Quad   quad,
FILE *    fd
 

This function reads geometry data of a given quadrilateral primitive (given by its pointer) from a file (given by its pointer) and loads the data into the primitive attributes.

It is assumed that the given pointer is really a valid pointer to an existing quadrilateral primitive.

Parameters:
quad  - pointer to target primitive (in)
fd  - ponter to file descriptor (in)

Definition at line 342 of file quad.c.

Referenced by prmRead().

void quadSet1stPt Quad   quad,
double    x,
double    y
 

This function is used during interactive construction of a quadrilateral primitive.

It sets the x and y coordinates of the first construction point of the given quadrilateral primitive (given by its pointer) by the given pair of coordinates. The first construction point corresponds to the first corner vertex of the quadrilateral primitive (with id = 0). It is assumed that the given pointer is really a valid pointer to an existing quadrilateral primitive.

The quadrilateral vertices are ordered in counter-clockwise order:

(id = 3) (id = 2) +-------------------+ | | | | | | | | +-------------------+ (id = 0) (id = 1)

The coordinates of vertices with id = 1 and id = 3 are set in such a way the quadrilateral will have horizontal and vertical sides. That is, the following is set: x0 = x3 = x and y0 = y1 = y.

Parameters:
quad  - pointer to target quadrilateral primitive(in)
x  - first point x coordinate (in)
y  - first point y coordinate (in)

Definition at line 377 of file quad.c.

Referenced by prmSet1stPt().

void quadSet2ndPt Quad   quad,
double    x,
double    y
 

This function is used during interactive construction of a quadrilateral primitive.

It sets the x and y coordinates of the second construction point of the given quadrilateral primitive (given by its pointer) by the given pair of coordinates. The second construction point corresponds to the third corner vertex of the quadrilateral primitive (with id = 2). It is assumed that the given pointer is really a valid pointer to an existing quadrilateral primitive.

The quadrilateral vertices are ordered in counter-clockwise order:

(id = 3) (id = 2) +-------------------+ | | | | | | | | +-------------------+ (id = 0) (id = 1)

The coordinates of vertices with id = 1 and id = 3 are set in such a way the quadrilateral will have horizontal and vertical sides. That is, the following is set: x2 = x1 = x and y2 = y3 = y.

Parameters:
quad  - pointer to target quadrilateral primitive(in)
x  - second point x coordinate (in)
y  - second point y coordinate (in)

Definition at line 384 of file quad.c.

Referenced by prmSet2ndPt().

void quadSetCoords Quad   quad,
int    id,
double    x,
double    y
 

This function replaces the x and y coordinates of a vertex of the given quadrilateral primitive (given by its pointer) by the given pair of coordinates.

The vertex is indicated by an index between 0 and 3. Nothing will happen if the given index is outside this range. It is assumed that the given pointer is really a valid pointer to an existing quadrilateral primitive.

The quadrilateral vertices are ordered in counter-clockwise order:

(id = 3) (id = 2) +-------------------+ | | | | | | | | +-------------------+ (id = 0) (id = 1)

Parameters:
quad  - pointer to target quadrilateral primitive(in)
id  - index of target vertex in primitive (in)
x  - new vertex x coordinate (in)
y  - new vertex y coordinate (in)

Definition at line 363 of file quad.c.

Referenced by prmSetCoords().

void quadTranslate Quad   quad,
double    dx,
double    dy
 

This function translates the given quadrilateral primitive (given by its pointer).

All the vertices of the primitive are translated by the given translation factors. It is assumed that the given pointer is really a valid pointer to an existing quadrilateral primitive.

Parameters:
quad  - pointer to target quadrilateral primitive(in)
dx, dy  - translation factors in x & y directions (in)

Definition at line 463 of file quad.c.

Referenced by prmTranslate().

void quadTranslateSide Quad   quad,
int    id,
double    dx,
double    dy
 

This function translates the two vertices of a side of a given quadrilateral primitive (given by its pointer) using the given translation factors.

The target side is indicated by an index, which should have a value between 0 and 3. Nothing will happen if the given index is outside this range. The index of a side corresponds to the index of its first vertex. It is assumed that the given pointer is really a valid pointer to an existing quadrilateral primitive.

The quadrilateral sides are ordered in counter-clockwise order:

(id = 2) +-------------------+ | | (id = 3) | | (id = 1) | | | | +-------------------+ (id = 0)

Parameters:
quad  - pointer to target quadrilateral primitive(in)
id  - index of side to translate (0..3) (in)
dx, dy  - translation factors in x & y directions (in)

Definition at line 477 of file quad.c.

Referenced by prmTranslateSide().

void quadTranslateVertex Quad   quad,
int    id,
double    dx,
double    dy
 

This function translates a vertex of a given quadrilateral primitive (given by its pointer) using the given translation factors.

The target vertex is indicated by an index between 0 and 3. Nothing will happen if the given index is outside this range. It is assumed that the given pointer is really a valid pointer to an existing quadrilateral primitive.

The quadrilateral vertices are ordered in counter-clockwise order:

(id = 3) (id = 2) +-------------------+ | | | | | | | | +-------------------+ (id = 0) (id = 1)

Parameters:
quad  - pointer to target quadrilateral primitive(in)
id  - index of vertex to translate (0..3) (in)
dx, dy  - translation factors in x & y directions (in)

Definition at line 470 of file quad.c.

Referenced by prmTranslateVertex().

void quadWrite Quad   quad,
FILE *    fd
 

This function writes the geometry attribute data of a given quadrilateral primitive (given by its pointer) to a file (given by its pointer).

It is assumed that the given pointer is really a valid pointer to an existing quadrilateral primitive.

Parameters:
quad  - pointer to target primitive (in)
fd  - ponter to file descriptor (in)

Definition at line 349 of file quad.c.

Referenced by prmWrite().


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