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

dsp.c

Go to the documentation of this file.
00001 /*
00002 ** ---------------------------------------------------------------
00003 ** dsp.c -  Display module.
00004 **
00005 ** ---------------------------------------------------------------
00006 */
00007 
00039 /*
00040 ** ---------------------------------------------------------------
00041 ** Global variables and symbols:
00042 */
00043 #ifdef _WIN32
00044 #include <windows.h>
00045 #endif
00046 #include <stdlib.h>
00047 #include <math.h>
00048 #include <GL/gl.h>
00049 #include <GL/glu.h>
00050 
00051 #include "iup.h"   /* IupGetAttribute */
00052 #include "cd.h"
00053 
00054 #include "prj.h"   /* Odatascreen */
00055 #include "prm.h"
00056 #include "dsp.h"
00057 #include "t3d.h"
00058 #include "zbf.h"
00059 
00060 /*
00061 ** ---------------------------------------------------------------
00062 ** Local variables and symbols:
00063 */
00064 
00065 #ifndef ABS
00066 #define ABS(x) (((x) < 0.0)? -(x): (x))
00067 #endif
00068 
00071 static Vec3d view_vector;
00072 
00075 #define get_red(_)   ((double)(((_) >> 16) & 0xff) / 255.0)
00076 
00079 #define get_green(_) ((double)(((_) >>  8) & 0xff) / 255.0)
00080 
00083 #define get_blue(_)  ((double)(((_) >>  0) & 0xff) / 255.0)
00084 
00087 #define MIN_COLOR_INTENS  0.50
00088 
00091 static char *help_cmd[] =
00092   {
00093    "Tecle:",
00094    "H (de Help)",
00095    "Ctrl+Q (de Quit)",
00096    "Ctrl+I (de Info)",
00097    "Ctrl+O (de Open)",
00098    "Ctrl+S (de Snap shot)",
00099    "R (de Reset view)",
00100    "F (de Fit)" ,
00101    "P (de Perspec.)",
00102    "O (de Ortogr.)",
00103    "X (de Proj. X)",
00104    "Y (de Proj. Y)",
00105    "Z (de Proj. Z)",
00106    "Ctrl+M (de Manip.)",
00107    "Ctrl+N (de Naveg.)",
00108    "Ctrl+Z (de Zoom)"
00109   };
00110 
00113 static char *help_msg[] =
00114   { 
00115    " ",
00116    "==> Exibe este help",
00117    "==> Sai do programa",
00118    "==> Informacoes sobre o programa",
00119    "==> Abre modelo de arquivo",
00120    "==> Desenha o modelo usando CD",
00121    "==> Inicializa projecao",
00122    "==> Ajusta modelo na janela" ,
00123    "==> Projecao conica",
00124    "==> Projecao cilindrica",
00125    "==> Projecao ortografica no plano X",
00126    "==> Projecao ortografica no plano Y",
00127    "==> Projecao ortografica no plano Z",
00128    "==> Mouse manipula modelo",
00129    "==> Mouse controla navegacao",
00130    "==> Mouse controla zoom"
00131   };
00132 
00135 static int font_list_base;
00136 
00137 /*
00138 ** ---------------------------------------------------------------
00139 ** Private functions:
00140 */
00141 
00142 /*=========================  dspVecUnit  =========================*/
00146 static void dspVecUnit( Vec3d *a, Vec3d *b )
00147 {
00148  double len = sqrt(a->x*a->x + a->y*a->y + a->z*a->z);
00149 
00150  if( len != 0.0 )
00151  {
00152   b->x = a->x / len; 
00153   b->y = a->y / len;
00154   b->z = a->z / len;
00155  }
00156 }
00157  
00158 /*=========================  zbfVecDot  ==========================*/
00162 static double dspVecDot( Vec3d *a, Vec3d *b )
00163 { 
00164  return( a->x*b->x + a->y*b->y + a->z*b->z );
00165 }
00166 
00167 /*=======================  dspDecodeColor  =======================*/
00172 static void dspDecodeColor( long int color, unsigned char *red,
00173                                             unsigned char *green, 
00174                                             unsigned char *blue )
00175 {
00176  *red   = (unsigned char)(((color) >> 16) & 0xff);
00177  *green = (unsigned char)(((color) >>  8) & 0xff);
00178  *blue  = (unsigned char)(((color) >>  0) & 0xff);
00179 }
00180 
00181 /*=======================  dspEncodeColor  =======================*/
00186 static long int dspEncodeColor( unsigned char red, 
00187                                 unsigned char green,
00188                                 unsigned char blue )
00189 {
00190  return( ((unsigned long)(red)   << 16) |
00191          ((unsigned long)(green) <<  8) |
00192          ((unsigned long)(blue)  <<  0) );
00193 }
00194 
00195 /*=======================  dspShadeColor  ========================*/
00201 static long int dspShadeColor( Vec3d *normal, Vec3d *view, long int color )
00202 {
00203  unsigned char red;
00204  unsigned char green;
00205  unsigned char blue;
00206  double        fac;    /* intensity factor */
00207 
00208  dspDecodeColor( color, &red, &green, &blue );
00209 
00210  fac = dspVecDot( normal, view );
00211  fac = ABS( fac );
00212 
00213  fac = MIN_COLOR_INTENS + (1.0 - MIN_COLOR_INTENS) * fac;
00214 
00215  if( fac < 0.0 )
00216   fac = 0.0;
00217  else if( fac > 1.0 )
00218   fac = 1.0;
00219 
00220  red   = (unsigned char)(fac * (double)red);
00221  green = (unsigned char)(fac * (double)green);
00222  blue  = (unsigned char)(fac * (double)blue);
00223 
00224  return( dspEncodeColor( red, green, blue ) );
00225 }
00226 
00227 /*=======================  dspInvertMatrix  ======================*/
00231 static void dspInvertMatrix( double mt[4][4], double imt[4][4] )
00232 {
00233  double det;
00234 
00235  det =
00236   mt[0][3]*mt[1][2]*mt[2][1]*mt[3][0] - mt[0][2]*mt[1][3]*mt[2][1]*mt[3][0] -
00237   mt[0][3]*mt[1][1]*mt[2][2]*mt[3][0] + mt[0][1]*mt[1][3]*mt[2][2]*mt[3][0] +
00238   mt[0][2]*mt[1][1]*mt[2][3]*mt[3][0] - mt[0][1]*mt[1][2]*mt[2][3]*mt[3][0] -
00239   mt[0][3]*mt[1][2]*mt[2][0]*mt[3][1] + mt[0][2]*mt[1][3]*mt[2][0]*mt[3][1] +
00240   mt[0][3]*mt[1][0]*mt[2][2]*mt[3][1] - mt[0][0]*mt[1][3]*mt[2][2]*mt[3][1] -
00241   mt[0][2]*mt[1][0]*mt[2][3]*mt[3][1] + mt[0][0]*mt[1][2]*mt[2][3]*mt[3][1] +
00242   mt[0][3]*mt[1][1]*mt[2][0]*mt[3][2] - mt[0][1]*mt[1][3]*mt[2][0]*mt[3][2] -
00243   mt[0][3]*mt[1][0]*mt[2][1]*mt[3][2] + mt[0][0]*mt[1][3]*mt[2][1]*mt[3][2] +
00244   mt[0][1]*mt[1][0]*mt[2][3]*mt[3][2] - mt[0][0]*mt[1][1]*mt[2][3]*mt[3][2] -
00245   mt[0][2]*mt[1][1]*mt[2][0]*mt[3][3] + mt[0][1]*mt[1][2]*mt[2][0]*mt[3][3] +
00246   mt[0][2]*mt[1][0]*mt[2][1]*mt[3][3] - mt[0][0]*mt[1][2]*mt[2][1]*mt[3][3] -
00247   mt[0][1]*mt[1][0]*mt[2][2]*mt[3][3] + mt[0][0]*mt[1][1]*mt[2][2]*mt[3][3];
00248 
00249 
00250  imt[0][0] = (-mt[1][3]*mt[2][2]*mt[3][1] + mt[1][2]*mt[2][3]*mt[3][1] +
00251                mt[1][3]*mt[2][1]*mt[3][2] - mt[1][1]*mt[2][3]*mt[3][2] -
00252                mt[1][2]*mt[2][1]*mt[3][3] + mt[1][1]*mt[2][2]*mt[3][3] )
00253             / det;
00254 
00255  imt[0][1] = ( mt[0][3]*mt[2][2]*mt[3][1] - mt[0][2]*mt[2][3]*mt[3][1] -
00256                mt[0][3]*mt[2][1]*mt[3][2] + mt[0][1]*mt[2][3]*mt[3][2] +
00257                mt[0][2]*mt[2][1]*mt[3][3] - mt[0][1]*mt[2][2]*mt[3][3] )
00258             / det;
00259 
00260  imt[0][2] = (-mt[0][3]*mt[1][2]*mt[3][1] + mt[0][2]*mt[1][3]*mt[3][1] +
00261                mt[0][3]*mt[1][1]*mt[3][2] - mt[0][1]*mt[1][3]*mt[3][2] -
00262                mt[0][2]*mt[1][1]*mt[3][3] + mt[0][1]*mt[1][2]*mt[3][3] )
00263             / det;
00264 
00265  imt[0][3] = ( mt[0][3]*mt[1][2]*mt[2][1] - mt[0][2]*mt[1][3]*mt[2][1] -
00266                mt[0][3]*mt[1][1]*mt[2][2] + mt[0][1]*mt[1][3]*mt[2][2] +
00267                mt[0][2]*mt[1][1]*mt[2][3] - mt[0][1]*mt[1][2]*mt[2][3] )
00268             / det;
00269 
00270  imt[1][0] = ( mt[1][3]*mt[2][2]*mt[3][0] - mt[1][2]*mt[2][3]*mt[3][0] -
00271                mt[1][3]*mt[2][0]*mt[3][2] + mt[1][0]*mt[2][3]*mt[3][2] +
00272                mt[1][2]*mt[2][0]*mt[3][3] - mt[1][0]*mt[2][2]*mt[3][3] )
00273             / det;
00274 
00275  imt[1][1] = (-mt[0][3]*mt[2][2]*mt[3][0] + mt[0][2]*mt[2][3]*mt[3][0] +
00276                mt[0][3]*mt[2][0]*mt[3][2] - mt[0][0]*mt[2][3]*mt[3][2] -
00277                mt[0][2]*mt[2][0]*mt[3][3] + mt[0][0]*mt[2][2]*mt[3][3] )
00278             / det;
00279 
00280  imt[1][2] = ( mt[0][3]*mt[1][2]*mt[3][0] - mt[0][2]*mt[1][3]*mt[3][0] -
00281                mt[0][3]*mt[1][0]*mt[3][2] + mt[0][0]*mt[1][3]*mt[3][2] +
00282                mt[0][2]*mt[1][0]*mt[3][3] - mt[0][0]*mt[1][2]*mt[3][3] )
00283             / det;
00284 
00285  imt[1][3] = (-mt[0][3]*mt[1][2]*mt[2][0] + mt[0][2]*mt[1][3]*mt[2][0] +
00286                mt[0][3]*mt[1][0]*mt[2][2] - mt[0][0]*mt[1][3]*mt[2][2] -
00287                mt[0][2]*mt[1][0]*mt[2][3] + mt[0][0]*mt[1][2]*mt[2][3] )
00288             / det;
00289 
00290  imt[2][0] = (-mt[1][3]*mt[2][1]*mt[3][0] + mt[1][1]*mt[2][3]*mt[3][0] +
00291                mt[1][3]*mt[2][0]*mt[3][1] - mt[1][0]*mt[2][3]*mt[3][1] -
00292                mt[1][1]*mt[2][0]*mt[3][3] + mt[1][0]*mt[2][1]*mt[3][3] )
00293             / det;
00294 
00295  imt[2][1] = ( mt[0][3]*mt[2][1]*mt[3][0] - mt[0][1]*mt[2][3]*mt[3][0] -
00296                mt[0][3]*mt[2][0]*mt[3][1] + mt[0][0]*mt[2][3]*mt[3][1] +
00297                mt[0][1]*mt[2][0]*mt[3][3] - mt[0][0]*mt[2][1]*mt[3][3] )
00298             / det;
00299 
00300  imt[2][2] = (-mt[0][3]*mt[1][1]*mt[3][0] + mt[0][1]*mt[1][3]*mt[3][0] +
00301                mt[0][3]*mt[1][0]*mt[3][1] - mt[0][0]*mt[1][3]*mt[3][1] -
00302                mt[0][1]*mt[1][0]*mt[3][3] + mt[0][0]*mt[1][1]*mt[3][3] )
00303             / det;
00304 
00305  imt[2][3] = ( mt[0][3]*mt[1][1]*mt[2][0] - mt[0][1]*mt[1][3]*mt[2][0] -
00306                mt[0][3]*mt[1][0]*mt[2][1] + mt[0][0]*mt[1][3]*mt[2][1] +
00307                mt[0][1]*mt[1][0]*mt[2][3] - mt[0][0]*mt[1][1]*mt[2][3] )
00308             / det;
00309 
00310  imt[3][0] = ( mt[1][2]*mt[2][1]*mt[3][0] - mt[1][1]*mt[2][2]*mt[3][0] -
00311                mt[1][2]*mt[2][0]*mt[3][1] + mt[1][0]*mt[2][2]*mt[3][1] +
00312                mt[1][1]*mt[2][0]*mt[3][2] - mt[1][0]*mt[2][1]*mt[3][2] )
00313             / det;
00314 
00315  imt[3][1] = (-mt[0][2]*mt[2][1]*mt[3][0] + mt[0][1]*mt[2][2]*mt[3][0] +
00316                mt[0][2]*mt[2][0]*mt[3][1] - mt[0][0]*mt[2][2]*mt[3][1] -
00317                mt[0][1]*mt[2][0]*mt[3][2] + mt[0][0]*mt[2][1]*mt[3][2] )
00318             / det;
00319 
00320  imt[3][2] = ( mt[0][2]*mt[1][1]*mt[3][0] - mt[0][1]*mt[1][2]*mt[3][0] -
00321                mt[0][2]*mt[1][0]*mt[3][1] + mt[0][0]*mt[1][2]*mt[3][1] +
00322                mt[0][1]*mt[1][0]*mt[3][2] - mt[0][0]*mt[1][1]*mt[3][2] )
00323             / det;
00324 
00325  imt[3][3] = (-mt[0][2]*mt[1][1]*mt[2][0] + mt[0][1]*mt[1][2]*mt[2][0] +
00326                mt[0][2]*mt[1][0]*mt[2][1] - mt[0][0]*mt[1][2]*mt[2][1] -
00327                mt[0][1]*mt[1][0]*mt[2][2] + mt[0][0]*mt[1][1]*mt[2][2] )
00328             / det;
00329 }
00330 
00331 /*========================  dspGetCamera  ========================*/
00336 static void dspGetCamera( double *eyex, double *eyey, double *eyez,
00337                           double *refx, double *refy, double *refz,
00338                           double *vupx, double *vupy, double *vupz )
00339 {
00340  double mt[4][4];           /* model view matrix */
00341  double im[4][4];           /* inverse model view matrix */
00342  double zex, zey, zez;      /* eye normalized z vector */
00343 
00344  glGetDoublev( GL_MODELVIEW_MATRIX, (double *)mt );
00345 
00346 /* Get eye z and y normalized vectors (consider vup equal to eye y).
00347  * Note that OpenGL stores the model view matrix in column major order.
00348  */
00349  zex   = mt[0][2]; zey   = mt[1][2]; zez   = mt[2][2];
00350  *vupx = mt[0][1]; *vupy = mt[1][1]; *vupz = mt[2][1];
00351 
00352 /* Invert model view matrix and compute eye location.
00353  */
00354  dspInvertMatrix( mt, im );
00355  *eyex = im[3][0] / im[3][3];
00356  *eyey = im[3][1] / im[3][3];
00357  *eyez = im[3][2] / im[3][3];
00358 
00359 /* Compute a reference point at a unit distance from eye 
00360  * along view direction at the negative z side.
00361  */
00362  *refx = *eyex - zex;
00363  *refy = *eyey - zey;
00364  *refz = *eyez - zez;
00365 }
00366 
00367 /*======================  dspGetViewVolume  ======================*/
00424 static int dspGetViewVolume( double *left,   double *right,
00425                              double *bottom, double *top,
00426                              double *front,  double *back )
00427 {
00428  double projmt[4][4];       /* projection matrix */
00429  int    persp;              /* if true (1), doing perspective projection */
00430 
00431  glGetDoublev( GL_PROJECTION_MATRIX, (double *)projmt );
00432 
00433  if( projmt[2][3] != 0.0 )
00434   persp = 1;
00435  else
00436   persp = 0;
00437 
00438 /* Get view volume according to type of projection.
00439  * Note that OpenGL stores the projection matrix in column-major order.
00440  */
00441  if( persp )      /* perspective projection */
00442  {
00443   *front  = projmt[3][2] / (projmt[2][2]-1.0);
00444   *back   = projmt[3][2] / (projmt[2][2]+1.0);
00445   *left   = (*front * (projmt[2][0]-1.0)) / projmt[0][0];
00446   *right  = (*front * (projmt[2][0]+1.0)) / projmt[0][0];
00447   *bottom = (*front * (projmt[2][1]-1.0)) / projmt[1][1];
00448   *top    = (*front * (projmt[2][1]+1.0)) / projmt[1][1];
00449  }
00450  else             /* orthographic projection */
00451  {
00452   *front  =  (projmt[3][2]+1.0) / projmt[2][2];
00453   *back   =  (projmt[3][2]-1.0) / projmt[2][2];
00454   *left   = -(1.0+projmt[3][0]) / projmt[0][0];
00455   *right  =  (1.0-projmt[3][0]) / projmt[0][0];
00456   *bottom = -(1.0+projmt[3][1]) / projmt[1][1];
00457   *top    =  (1.0-projmt[3][1]) / projmt[1][1];
00458  }
00459 
00460  return( persp );
00461 }
00462 
00463 /*============================  dspPrm  ==========================*/
00472 static void dspPrm( Prm *prm )
00473 {
00474  glColor3d( get_red( prmGetColor( prm) ),
00475             get_green( prmGetColor( prm) ),
00476             get_blue( prmGetColor( prm) ) );
00477 
00478 /*** COMPLETE HERE: 43 ***/
00479 }
00480 
00481 /*========================  dspHighltPrm  ========================*/
00491 static void dspHighltPrm( Prm *prm )
00492 {
00493  glColor3d( 1.0, 0.0, 0.0 );   /* red color */
00494 
00495  glDisable( GL_LIGHTING );
00496 /*** COMPLETE HERE: 44 ***/
00497  glEnable( GL_LIGHTING );
00498 }
00499 
00500 
00501 /*
00502 ** ---------------------------------------------------------------
00503 ** Public functions:
00504 */
00505 
00506 /*===========================  dspInit  ==========================*/
00507 
00508 void dspInit( void )
00509 {
00510  GLfloat ambienteLight[] = { 0.35f, 0.35f, 0.35f, 1.0f };
00511  GLfloat diffuseLight[] = { 0.3f, 0.3f, 0.3f, 1.0f };
00512  HWND hwnd;
00513  HDC  hdc;
00514 
00515 /* Initialize some OpenGL parameters.
00516  */
00517  glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE );
00518  glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambienteLight );
00519  glLightfv( GL_LIGHT0, GL_AMBIENT, ambienteLight );
00520  glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuseLight );
00521  glEnable( GL_LIGHT0 );
00522  glEnable( GL_LIGHTING );
00523  glEnable( GL_COLOR_MATERIAL );
00524  glEnable( GL_DEPTH_TEST );
00525  glPointSize( 4.0 );
00526 
00527 /* This is stuff for displaying help text on the data canvas.
00528  */
00529  hwnd = (HWND)IupGetAttribute( Odatascreen, IUP_WID );
00530  hdc  = GetDC( hwnd );
00531  if(hdc == 0)
00532    return;
00533  font_list_base = glGenLists( 256 );
00534  if( font_list_base == 0 )
00535   return;
00536  if( !wglUseFontBitmaps( hdc, 0, 255, font_list_base ) )
00537   return;
00538 }
00539 
00540 /*===========================  dspHelp  ===========================*/
00541 
00542 void dspHelp( void )
00543 {
00544  double win_xmin_help, win_xmax_help, win_ymin_help, win_ymax_help;
00545 
00546  win_xmin_help =  0.0;
00547  win_xmax_help = 10.0;
00548  win_ymin_help = -0.5;
00549  win_ymax_help = 10.0;
00550 
00551  glClearColor( 0.0, 0.0, 0.0, 1.0 );
00552  glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
00553  glMatrixMode( GL_PROJECTION );
00554  glLoadIdentity( );
00555 
00556  glOrtho( (GLdouble)win_xmin_help, (GLdouble)win_xmax_help,
00557           (GLdouble)win_ymin_help, (GLdouble)win_ymax_help,   0.0, 1.0 );
00558  glMatrixMode( GL_MODELVIEW );
00559  glLoadIdentity( );
00560 
00561  glDisable( GL_LIGHTING );
00562  glDisable( GL_LIGHT0);
00563 
00564  glColor3d( 0.0, 1.0, 0.0 );
00565  glListBase( font_list_base );
00566 
00567  glRasterPos2d( 0.5,  9.0 );
00568  glCallLists( (GLsizei)strlen( help_cmd[ 0] ), GL_UNSIGNED_BYTE, help_cmd[ 0] );
00569  glRasterPos2d( 0.5,  8.0 );
00570  glCallLists( (GLsizei)strlen( help_cmd[ 1] ), GL_UNSIGNED_BYTE, help_cmd[ 1] );
00571  glRasterPos2d( 0.5,  7.5 );
00572  glCallLists( (GLsizei)strlen( help_cmd[ 2] ), GL_UNSIGNED_BYTE, help_cmd[ 2] );
00573  glRasterPos2d( 0.5,  7.0 );
00574  glCallLists( (GLsizei)strlen( help_cmd[ 3] ), GL_UNSIGNED_BYTE, help_cmd[ 3] );
00575  glRasterPos2d( 0.5,  6.5 );
00576  glCallLists( (GLsizei)strlen( help_cmd[ 4] ), GL_UNSIGNED_BYTE, help_cmd[ 4] );
00577  glRasterPos2d( 0.5,  6.0 );
00578  glCallLists( (GLsizei)strlen( help_cmd[ 5] ), GL_UNSIGNED_BYTE, help_cmd[ 5] );
00579  glRasterPos2d( 0.5,  5.0 );
00580  glCallLists( (GLsizei)strlen( help_cmd[ 6] ), GL_UNSIGNED_BYTE, help_cmd[ 6] );
00581  glRasterPos2d( 0.5,  4.5 );
00582  glCallLists( (GLsizei)strlen( help_cmd[ 7] ), GL_UNSIGNED_BYTE, help_cmd[ 7] );
00583  glRasterPos2d( 0.5,  4.0 );
00584  glCallLists( (GLsizei)strlen( help_cmd[ 8] ), GL_UNSIGNED_BYTE, help_cmd[ 8] );
00585  glRasterPos2d( 0.5,  3.5 );
00586  glCallLists( (GLsizei)strlen( help_cmd[ 9] ), GL_UNSIGNED_BYTE, help_cmd[ 9] );
00587  glRasterPos2d( 0.5,  3.0 );
00588  glCallLists( (GLsizei)strlen( help_cmd[10] ), GL_UNSIGNED_BYTE, help_cmd[10] );
00589  glRasterPos2d( 0.5,  2.5 );
00590  glCallLists( (GLsizei)strlen( help_cmd[11] ), GL_UNSIGNED_BYTE, help_cmd[11] );
00591  glRasterPos2d( 0.5,  2.0 );
00592  glCallLists( (GLsizei)strlen( help_cmd[12] ), GL_UNSIGNED_BYTE, help_cmd[12] );
00593  glRasterPos2d( 0.5,  1.0 );
00594  glCallLists( (GLsizei)strlen( help_cmd[13] ), GL_UNSIGNED_BYTE, help_cmd[13] );
00595  glRasterPos2d( 0.5,  0.5 );
00596  glCallLists( (GLsizei)strlen( help_cmd[14] ), GL_UNSIGNED_BYTE, help_cmd[14] );
00597  glRasterPos2d( 0.5,  0.0 );
00598  glCallLists( (GLsizei)strlen( help_cmd[15] ), GL_UNSIGNED_BYTE, help_cmd[15] );
00599 
00600  glRasterPos2d( 4.0,  9.0 );
00601  glCallLists( (GLsizei)strlen( help_msg[ 0] ), GL_UNSIGNED_BYTE, help_msg[ 0] );
00602  glRasterPos2d( 4.0,  8.0 );
00603  glCallLists( (GLsizei)strlen( help_msg[ 1] ), GL_UNSIGNED_BYTE, help_msg[ 1] );
00604  glRasterPos2d( 4.0,  7.5 );
00605  glCallLists( (GLsizei)strlen( help_msg[ 2] ), GL_UNSIGNED_BYTE, help_msg[ 2] );
00606  glRasterPos2d( 4.0,  7.0 );
00607  glCallLists( (GLsizei)strlen( help_msg[ 3] ), GL_UNSIGNED_BYTE, help_msg[ 3] );
00608  glRasterPos2d( 4.0,  6.5 );
00609  glCallLists( (GLsizei)strlen( help_msg[ 4] ), GL_UNSIGNED_BYTE, help_msg[ 4] );
00610  glRasterPos2d( 4.0,  6.0 );
00611  glCallLists( (GLsizei)strlen( help_msg[ 5] ), GL_UNSIGNED_BYTE, help_msg[ 5] );
00612  glRasterPos2d( 4.0,  5.0 );
00613  glCallLists( (GLsizei)strlen( help_msg[ 6] ), GL_UNSIGNED_BYTE, help_msg[ 6] );
00614  glRasterPos2d( 4.0,  4.5 );
00615  glCallLists( (GLsizei)strlen( help_msg[ 7] ), GL_UNSIGNED_BYTE, help_msg[ 7] );
00616  glRasterPos2d( 4.0,  4.0 );
00617  glCallLists( (GLsizei)strlen( help_msg[ 8] ), GL_UNSIGNED_BYTE, help_msg[ 8] );
00618  glRasterPos2d( 4.0,  3.5 );
00619  glCallLists( (GLsizei)strlen( help_msg[ 9] ), GL_UNSIGNED_BYTE, help_msg[ 9] );
00620  glRasterPos2d( 4.0,  3.0 );
00621  glCallLists( (GLsizei)strlen( help_msg[10] ), GL_UNSIGNED_BYTE, help_msg[10] );
00622  glRasterPos2d( 4.0,  2.5 );
00623  glCallLists( (GLsizei)strlen( help_msg[11] ), GL_UNSIGNED_BYTE, help_msg[11] );
00624  glRasterPos2d( 4.0,  2.0 );
00625  glCallLists( (GLsizei)strlen( help_msg[12] ), GL_UNSIGNED_BYTE, help_msg[12] );
00626  glRasterPos2d( 4.0,  1.0 );
00627  glCallLists( (GLsizei)strlen( help_msg[13] ), GL_UNSIGNED_BYTE, help_msg[13] );
00628  glRasterPos2d( 4.0,  0.5 );
00629  glCallLists( (GLsizei)strlen( help_msg[14] ), GL_UNSIGNED_BYTE, help_msg[14] );
00630  glRasterPos2d( 4.0,  0.0 );
00631  glCallLists( (GLsizei)strlen( help_msg[15] ), GL_UNSIGNED_BYTE, help_msg[15] );
00632 
00633  glEnable( GL_LIGHTING );
00634 }
00635 
00636 /*==========================  dspModel  ==========================*/
00637 
00638 void dspModel( void ) 
00639 {
00640  Prm *prm;
00641 
00642  for( prm = prmFirst( ); prm != NULL; prm = prmNext( prm ) )
00643  {
00644   if( prmCheckSelected( prm ) )
00645   {
00646    glEnable( GL_POLYGON_OFFSET_FILL );
00647    glPolygonOffset( 1.0, 1.0 );
00648    dspPrm( prm );
00649    glDisable( GL_POLYGON_OFFSET_FILL );
00650    dspHighltPrm( prm );
00651   }
00652   else
00653   {
00654    dspPrm( prm );
00655   }
00656  }
00657 }
00658 
00659 /*=========================  dspZbfModel  ========================*/
00660 
00661 int dspZbfModel( void *Gzbuffercanvas )
00662 {
00663  int    width, height;      /* zbuffer sizes */
00664  double eyex, eyey, eyez;   /* camera parameters */
00665  double refx, refy, refz;
00666  double vupx, vupy, vupz;
00667  double left, right;        /* view volume parameters */
00668  double bottom, top;
00669  double front, back;
00670  int    persp;              /* if true (1), doing perspective projection */
00671  Prm    *prm;
00672  unsigned char gray_intensity;
00673 
00674  cdActivate( Gzbuffercanvas );
00675  cdGetCanvasSize( &width, &height, 0L, 0L );
00676 
00677 /* Set gray background color and clear canvas.
00678  */
00679  gray_intensity = (unsigned char)(0.75 * 255.0);
00680  cdBackground( dspEncodeColor(gray_intensity, gray_intensity, gray_intensity) );
00681  cdClear( );
00682 
00683 /* Get camera and view volume parameters.
00684  */
00685  dspGetCamera( &eyex, &eyey, &eyez, &refx, &refy, &refz, &vupx, &vupy, &vupz );
00686  persp = dspGetViewVolume( &left, &right, &bottom, &top, &front, &back );
00687 
00688 /* Compute normalized view vector.
00689  */
00690  view_vector.x = refx - eyex;
00691  view_vector.y = refy - eyey;
00692  view_vector.z = refz - eyez;
00693  dspVecUnit( &view_vector, &view_vector );
00694 
00695 /* Build a 3D transformation that transforms from world (object)
00696  * coordinates to normalized screen coordinates (the view frustum
00697  * is transformed into a cube of size 2 and center at origin).
00698  * For perspective projection, place the projection plane at
00699  * the front view volume plane (OpenGL does this way).
00700  */
00701 /*** COMPLETE HERE: 45 ***/
00702 
00703 /* Display the model in the zbuffer canvas.
00704  */
00705 /*** COMPLETE HERE: 46 ***/
00706 
00707  return( 1 );
00708 }
00709 
00710 /*=======================  dspZbfBeginPoly  ======================*/
00711 
00712 void dspZbfBeginPoly( long int color, double nx, double ny, double nz )
00713 {
00714  Vec3d normal;          /* face normal vector */
00715  long int shaded_color; /* face color with modified intensity */
00716 
00717  normal.x = nx;
00718  normal.y = ny;
00719  normal.z = nz;
00720  shaded_color = dspShadeColor( &normal, &view_vector, color );
00721  zbfBeginPoly( shaded_color );
00722 }
00723 
00724 /*=========================  dspZbfVertex  =======================*/
00725 
00726 void dspZbfVertex( double x, double y, double z )
00727 {
00728  t3dTransform( &x, &y, &z );
00729  zbfVertex( x, y, z );
00730 }
00731 
00732 /*========================  dspZbfEndPoly  =======================*/
00733 
00734 void dspZbfEndPoly( void )
00735 {
00736  zbfEndPoly( );
00737 }
00738 
00739 /*=======================  dspGetPickRay  ========================*/
00740 
00741 void dspGetPickRay( int x, int y,
00742                     double *frontx, double *fronty, double *frontz,
00743                     double *backx,  double *backy,  double *backz )
00744 {
00745  double modelMatrix[16];
00746  double projMatrix[16];
00747  int    viewport[4];
00748  int    h;
00749  double winx, winy, winz;
00750 
00751  glGetDoublev( GL_MODELVIEW_MATRIX, modelMatrix );
00752  glGetDoublev( GL_PROJECTION_MATRIX, projMatrix );
00753  glGetIntegerv( GL_VIEWPORT, viewport );
00754 
00755 /* Transform from mouse raster position in canvas to 
00756  * GL viewport position.  It is assumed that the GL 
00757  * viewport takes the entire canvas.
00758  */
00759  h = viewport[3];
00760  winx = (double)x;
00761  winy = (double)y;
00762 
00763 /* Find ray point in object space at front (near) plane.
00764  */
00765  winz = 0.0;
00766  gluUnProject( winx, winy, winz, modelMatrix, projMatrix,
00767                viewport, frontx, fronty, frontz );
00768 
00769 /* Find ray point in object space at back (far) plane.
00770  */
00771  winz = 1.0;
00772  gluUnProject( winx, winy, winz, modelMatrix, projMatrix,
00773                viewport, backx, backy, backz );
00774 }
00775 
00777  double winx, winy, winz;
00778 
00779  glGetDoublev( GL_MODELVIEW_MATRIX, modelMatrix );
00780  glGetDoublev( GL_PROJECTION_MATRIX, projMatrix );
00781  glGetIntegerv( GL_VIEWPORT, viewport );
00782 
00783 /* Transform from mouse raster position in canvas to 
00784  * GL viewport position.  It is assumed that the GL 
00785  * viewport takes the entire canvas.
00786  */
00787  h = viewport[3];
00788  winx = (double)x;
00789  winy = (double)y;
00790 
00791 /* Find ray point in object space at front (near) plane.
00792  */
00793  winz = 0.0;
00794  gluUnProject( winx, winy, winz, modelMatrix, projMatrix,
00795                viewport, frontx, fronty, frontz );
00796 
00797 /* Find ray point in object space at back (far) plane.
00798  */
00799  winz = 1.0;
00800  gluUnProject( winx, winy, winz, modelMatrix, projMatrix,
00801                viewport, backx, backy, backz );
00802 }
00803 

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