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

dsp.c File Reference

#include <stdlib.h>
#include <math.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "iup.h"
#include "cd.h"
#include "prj.h"
#include "prm.h"
#include "dsp.h"
#include "t3d.h"
#include "zbf.h"

Include dependency graph for dsp.c:

Include dependency graph

Go to the source code of this file.

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 comments).
This file contains functions to display primitives of a model in current database. It also contains functions to adjust the window (visible portion of the model) for visualization.

The adopted model data structure is described in header file "prm.h", which also contains code color definitions.

The basic graphics system used to display primitives is OpenGL. Please refer to OpenGL documentation for additional information.

See specification of public functions of this module in hearder file "dsp.h".

Revisions:

  • Report modifications here (including name and date).


#define get_red(_)   ((double)(((_) >> 16) & 0xff) / 255.0)
 Given a long int coded color, get the red component intensity from 0 to 1.

#define get_green(_)   ((double)(((_) >> 8) & 0xff) / 255.0)
 Given a long int coded color, get the green component intensity from 0 to 1.

#define get_blue(_)   ((double)(((_) >> 0) & 0xff) / 255.0)
 Given a long int coded color, get the blue component intensity from 0 to 1.

#define MIN_COLOR_INTENS   0.50
 Macro definition for minimum color intensity.

void dspVecUnit (Vec3d *a, Vec3d *b)
 Function to normalize a 3D vector.

double dspVecDot (Vec3d *a, Vec3d *b)
 Function to compute the dot product between two 3D vectors.

void dspDecodeColor (long int color, unsigned char *red, unsigned char *green, unsigned char *blue)
 Function to decode a long int coded color into the RGB components (in integer values between 0 and 255).

long int dspEncodeColor (unsigned char red, unsigned char green, unsigned char blue)
 Function to encode RGB components (in integer values between 0 and 255) into a long int coded color.

long int dspShadeColor (Vec3d *normal, Vec3d *view, long int color)
 Change color intensity taking into account polygon normal vector orientation with respect to view vector.

void dspInvertMatrix (double mt[4][4], double imt[4][4])
 Function to invert a 4x4 matrix.

void dspGetCamera (double *eyex, double *eyey, double *eyez, double *refx, double *refy, double *refz, double *vupx, double *vupy, double *vupz)
 This function obtains the camera model viewing paramaters (in WC coordinates) from the current OpenGL model view matrix.

int dspGetViewVolume (double *left, double *right, double *bottom, double *top, double *front, double *back)
 This function obtains the view volume limits (in the eye coordinate system) from the current OpenGL projection matrix.

void dspPrm (Prm *prm)
 Function to display a solid version of a primitive with its corresponding color.

void dspHighltPrm (Prm *prm)
 Function to highlight a solid version of a primitive.

void dspInit (void)
 This function initializes the dsp module.

void dspHelp (void)
 This function displays a help list of the possible program actions and their associated keys.

void dspModel (void)
 This function displays all primitives of current model using the OpenGL graphics system.

int dspZbfModel (void *Gzbuffercanvas)
void dspZbfBeginPoly (long int color, double nx, double ny, double nz)
 This function starts to send a new polygon to the zbuffer module to display.

void dspZbfVertex (double x, double y, double z)
 This function project a polygon vertex and send it to the zbuffer module in the process of displaying a face.

void dspZbfEndPoly (void)
 This function finishes the specification of a polygon to be displayed in zbuffer module.

void dspGetPickRay (int x, int y, double *frontx, double *fronty, double *frontz, double *backx, double *backy, double *backz)
 Given a mouse location point in raster canvas coordinates, this function returns the corresponding pick ray in world coordinates (WC).

Vec3d view_vector
 Current view vector.

char * help_cmd []
 Help message commands.

char * help_msg []
 Help message actions.

int font_list_base
 OpenGL font list for text.


Define Documentation

#define get_blue      ((double)(((_) >> 0) & 0xff) / 255.0)
 

Given a long int coded color, get the blue component intensity from 0 to 1.

Definition at line 83 of file dsp.c.

Referenced by dspPrm().

#define get_green      ((double)(((_) >> 8) & 0xff) / 255.0)
 

Given a long int coded color, get the green component intensity from 0 to 1.

Definition at line 79 of file dsp.c.

Referenced by dspPrm().

#define get_red      ((double)(((_) >> 16) & 0xff) / 255.0)
 

Given a long int coded color, get the red component intensity from 0 to 1.

Definition at line 75 of file dsp.c.

Referenced by dspPrm().

#define MIN_COLOR_INTENS   0.50
 

Macro definition for minimum color intensity.

Definition at line 87 of file dsp.c.

Referenced by dspShadeColor().


Function Documentation

void dspDecodeColor long int    color,
unsigned char *    red,
unsigned char *    green,
unsigned char *    blue
[static]
 

Function to decode a long int coded color into the RGB components (in integer values between 0 and 255).

Definition at line 172 of file dsp.c.

Referenced by dspShadeColor().

long int dspEncodeColor unsigned char    red,
unsigned char    green,
unsigned char    blue
[static]
 

Function to encode RGB components (in integer values between 0 and 255) into a long int coded color.

Definition at line 186 of file dsp.c.

Referenced by dspShadeColor(), and dspZbfModel().

void dspGetCamera double *    eyex,
double *    eyey,
double *    eyez,
double *    refx,
double *    refy,
double *    refz,
double *    vupx,
double *    vupy,
double *    vupz
[static]
 

This function obtains the camera model viewing paramaters (in WC coordinates) from the current OpenGL model view matrix.

Definition at line 336 of file dsp.c.

References dspInvertMatrix().

Referenced by dspZbfModel().

void dspGetPickRay int    x,
int    y,
double *    frontx,
double *    fronty,
double *    frontz,
double *    backx,
double *    backy,
double *    backz
 

Given a mouse location point in raster canvas coordinates, this function returns the corresponding pick ray in world coordinates (WC).

A pick ray is a line between a point on the front (near) plane and a point on the back (far) plane. These two points correspond to the given point location in raster coordinates.

Parameters:
x  - x coordindate of raster point on canvas (in)
y  - y coordindate of raster point on canvas (in)
frontx  - x coord. of point in WC at front plane (out)
fronty  - y coord. of point in WC at front plane (out)
frontz  - z coord. of point in WC at front plane (out)
backx  - x coord. of point in WC at back plane (out)
backy  - y coord. of point in WC at back plane (out)
backz  - z coord. of point in WC at back plane (out)

Definition at line 741 of file dsp.c.

Referenced by prjRaster2WorldXY().

int dspGetViewVolume double *    left,
double *    right,
double *    bottom,
double *    top,
double *    front,
double *    back
[static]
 

This function obtains the view volume limits (in the eye coordinate system) from the current OpenGL projection matrix.

It assumes that the projection matrix has the following forms for orthographic and perspective projections:

  • - | 2 r + l | | ----- 0 0 - ----- | | r - l r - l | | | | 2 t + b | | 0 ----- 0 - ----- | | t - b t - b | [Ortho] = | | | 2 f + n | | 0 0 - ----- - ----- | | f - n f - n | | | | | | 0 0 0 1 | | |
  • -
  • - | 2n r + l | | ----- 0 ----- 0 | | r - l r - l | | | | 2n t + b | | 0 ----- ----- 0 | | t - b t - b | [Persp] = | | | f + n fn | | 0 0 - ----- - ----- | | f - n f - n | | | | | | 0 0 -1 0 | | |
  • -
Where:

l = left r = right b = bottom t = top n = near (front) f = far (back)

The function return value is a flag indicating the type of projection. In case of perspective projection, a true (1) status is returned. In case of orthographic projection, a false (0) status is returned.

Definition at line 424 of file dsp.c.

Referenced by dspZbfModel().

void dspHelp void   
 

This function displays a help list of the possible program actions and their associated keys.

Definition at line 542 of file dsp.c.

References font_list_base, help_cmd, and help_msg.

Referenced by prjHelp().

void dspHighltPrm Prm   prm [static]
 

Function to highlight a solid version of a 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 in red and draws red marks at its vertices.

Parameters:
prm  - pointer to target primitive (in)

Definition at line 491 of file dsp.c.

Referenced by dspModel().

void dspInit void   
 

This function initializes the dsp module.

It initializes some OpenGL parameters.

Definition at line 508 of file dsp.c.

References font_list_base, and Odatascreen.

Referenced by prjResize().

void dspInvertMatrix double    mt[4][4],
double    imt[4][4]
[static]
 

Function to invert a 4x4 matrix.

Definition at line 231 of file dsp.c.

Referenced by dspGetCamera().

void dspModel void   
 

This function displays all primitives of current model using the OpenGL graphics system.

Definition at line 638 of file dsp.c.

References dspHighltPrm(), dspPrm(), prmCheckSelected(), prmFirst(), and prmNext().

Referenced by prjBuildDisplayList().

void dspPrm Prm   prm [static]
 

Function to display a solid version of a primitive with its corresponding color.

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

Parameters:
prm  - pointer to target primitive (in)

Definition at line 472 of file dsp.c.

References get_blue, get_green, get_red, and prmGetColor().

Referenced by dspModel().

long int dspShadeColor Vec3d   normal,
Vec3d   view,
long int    color
[static]
 

Change color intensity taking into account polygon normal vector orientation with respect to view vector.

All computations should be performed in object coordinates.

Definition at line 201 of file dsp.c.

References ABS, dspDecodeColor(), dspEncodeColor(), dspVecDot(), and MIN_COLOR_INTENS.

Referenced by dspZbfBeginPoly().

double dspVecDot Vec3d   a,
Vec3d   b
[static]
 

Function to compute the dot product between two 3D vectors.

Definition at line 162 of file dsp.c.

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

Referenced by dspShadeColor().

void dspVecUnit Vec3d   a,
Vec3d   b
[static]
 

Function to normalize a 3D vector.

Definition at line 146 of file dsp.c.

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

Referenced by dspZbfModel().

void dspZbfBeginPoly long int    color,
double    nx,
double    ny,
double    nz
 

This function starts to send a new polygon to the zbuffer module to display.

It displays with the given coded color and changes the color intensity taking into account the given polygon normal vector orientation with respect to view vector.

Parameters:
color  - polygon coded color (in)
nx  - x component to polygon normal (in)
ny  - y component to polygon normal (in)
nz  - z component to polygon normal (in)

Definition at line 712 of file dsp.c.

References dspShadeColor(), pnt3d::x, pnt3d::y, pnt3d::z, and zbfBeginPoly().

Referenced by circDisplayZbuffer(), and quadDisplayZbuffer().

void dspZbfEndPoly void   
 

This function finishes the specification of a polygon to be displayed in zbuffer module.

Definition at line 734 of file dsp.c.

References zbfEndPoly().

Referenced by circDisplayZbuffer(), and quadDisplayZbuffer().

int dspZbfModel void *    Gzbuffercanvas
 

Definition at line 661 of file dsp.c.

References dspEncodeColor(), dspGetCamera(), dspGetViewVolume(), dspVecUnit(), pnt3d::x, pnt3d::y, and pnt3d::z.

Referenced by prjDspZbufferCanvas().

void dspZbfVertex double    x,
double    y,
double    z
 

This function project a polygon vertex and send it to the zbuffer module in the process of displaying a face.

To project a vertex means to transform it from modeling (object) coordinates to normalized screen coordinates.

Parameters:
x  - x coordinate of polygon vertex (in)
y  - y coordinate of polygon vertex (in)
z  - z coordinate of polygon vertex (in)

Definition at line 726 of file dsp.c.

References t3dTransform(), and zbfVertex().

Referenced by circDisplayZbuffer(), and quadDisplayZbuffer().


Variable Documentation

int font_list_base [static]
 

OpenGL font list for text.

Definition at line 135 of file dsp.c.

Referenced by dspHelp(), and dspInit().

char* help_cmd[] [static]
 

Initial value:

  {
   "Tecle:",
   "H (de Help)",
   "Ctrl+Q (de Quit)",
   "Ctrl+I (de Info)",
   "Ctrl+O (de Open)",
   "Ctrl+S (de Snap shot)",
   "R (de Reset view)",
   "F (de Fit)" ,
   "P (de Perspec.)",
   "O (de Ortogr.)",
   "X (de Proj. X)",
   "Y (de Proj. Y)",
   "Z (de Proj. Z)",
   "Ctrl+M (de Manip.)",
   "Ctrl+N (de Naveg.)",
   "Ctrl+Z (de Zoom)"
  }
Help message commands.

Definition at line 91 of file dsp.c.

Referenced by dspHelp().

char* help_msg[] [static]
 

Initial value:

  { 
   " ",
   "==> Exibe este help",
   "==> Sai do programa",
   "==> Informacoes sobre o programa",
   "==> Abre modelo de arquivo",
   "==> Desenha o modelo usando CD",
   "==> Inicializa projecao",
   "==> Ajusta modelo na janela" ,
   "==> Projecao conica",
   "==> Projecao cilindrica",
   "==> Projecao ortografica no plano X",
   "==> Projecao ortografica no plano Y",
   "==> Projecao ortografica no plano Z",
   "==> Mouse manipula modelo",
   "==> Mouse controla navegacao",
   "==> Mouse controla zoom"
  }
Help message actions.

Definition at line 113 of file dsp.c.

Referenced by dspHelp().

Vec3d view_vector [static]
 

Current view vector.

Definition at line 71 of file dsp.c.


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