Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

dsp.cpp

Go to the documentation of this file.
00001 /*
00002 ** ---------------------------------------------------------------
00003 ** dsp.cpp -  Display class.
00004 **
00005 ** ---------------------------------------------------------------
00006 */
00007 
00037 /*
00038 ** ---------------------------------------------------------------
00039 ** Global variables and symbols:
00040 */
00041 #ifdef _WIN32
00042 #include <windows.h>
00043 #endif
00044 #include <stdlib.h>
00045 #include <math.h>
00046 #include <GL/glew.h>
00047 #include <GL/gl.h>
00048 #include <GL/glu.h>
00049 
00050 #include "iup.h"   /* IupGetAttribute */
00051 #include "cd.h"
00052 
00053 #include "prj.h"   /* Odatascreen */
00054 #include "prm.h"
00055 #include "dsp.h"
00056 #include "t3d.h"
00057 #include "zbf.h"
00058 
00059 /*
00060 ** ---------------------------------------------------------------
00061 ** Initialization of class variables:
00062 */
00065 double Dsp::MIN_COLOR_INTENS = 0.50;
00066 
00069 Dsp::Vec Dsp::view_vector = {0.0, 0.0, 0.0};
00070 
00073 char* Dsp::help_cmd[] =
00074   {
00075    "Tecle:",
00076    "H (de Help)",
00077    "Ctrl+Q (de Quit)",
00078    "Ctrl+I (de Info)",
00079    "Ctrl+O (de Open)",
00080    "Ctrl+S (de Snap shot)",
00081    "R (de Reset view)",
00082    "F (de Fit)" ,
00083    "P (de Perspec.)",
00084    "O (de Ortogr.)",
00085    "X (de Proj. X)",
00086    "Y (de Proj. Y)",
00087    "Z (de Proj. Z)",
00088    "Ctrl+M (de Manip.)",
00089    "Ctrl+N (de Naveg.)",
00090    "Ctrl+Z (de Zoom)"
00091   };
00092 
00095 char* Dsp::help_msg[] =
00096   {
00097    " ",
00098    "==> Exibe este help",
00099    "==> Sai do programa",
00100    "==> Informacoes sobre o programa",
00101    "==> Abre modelo de arquivo",
00102    "==> Desenha o modelo usando CD",
00103    "==> Inicializa projecao",
00104    "==> Ajusta modelo na janela" ,
00105    "==> Projecao conica",
00106    "==> Projecao cilindrica",
00107    "==> Projecao ortografica no plano X",
00108    "==> Projecao ortografica no plano Y",
00109    "==> Projecao ortografica no plano Z",
00110    "==> Mouse manipula modelo",
00111    "==> Mouse controla navegacao",
00112    "==> Mouse controla zoom"
00113   };
00114 
00117 int Dsp::font_list_base = 0;
00118 
00119 /*
00120 ** ---------------------------------------------------------------
00121 ** Private class functions:
00122 */
00123 /*=======================  Dsp::ShadeColor  ========================*/
00124 
00125 long int Dsp::ShadeColor( Vec* normal, Vec* view, long int color )
00126 {
00127  unsigned char red;
00128  unsigned char green;
00129  unsigned char blue;
00130  double        fac;    /* intensity factor */
00131 
00132  DecodeColor( color, &red, &green, &blue );
00133 
00134  fac = VecDot( normal, view );
00135  fac = Prm::ABS( fac );
00136 
00137  fac = MIN_COLOR_INTENS + (1.0 - MIN_COLOR_INTENS) * fac;
00138 
00139  if( fac < 0.0 )
00140   fac = 0.0;
00141  else if( fac > 1.0 )
00142   fac = 1.0;
00143 
00144  red   = (unsigned char)(fac * (double)red);
00145  green = (unsigned char)(fac * (double)green);
00146  blue  = (unsigned char)(fac * (double)blue);
00147 
00148  return( EncodeColor( red, green, blue ) );
00149 }
00150 
00151 /*=======================  Dsp::InvertMatrix  ======================*/
00152 
00153 void Dsp::InvertMatrix( double mt[4][4], double imt[4][4] )
00154 {
00155  double det;
00156 
00157  det =
00158   mt[0][3]*mt[1][2]*mt[2][1]*mt[3][0] - mt[0][2]*mt[1][3]*mt[2][1]*mt[3][0] -
00159   mt[0][3]*mt[1][1]*mt[2][2]*mt[3][0] + mt[0][1]*mt[1][3]*mt[2][2]*mt[3][0] +
00160   mt[0][2]*mt[1][1]*mt[2][3]*mt[3][0] - mt[0][1]*mt[1][2]*mt[2][3]*mt[3][0] -
00161   mt[0][3]*mt[1][2]*mt[2][0]*mt[3][1] + mt[0][2]*mt[1][3]*mt[2][0]*mt[3][1] +
00162   mt[0][3]*mt[1][0]*mt[2][2]*mt[3][1] - mt[0][0]*mt[1][3]*mt[2][2]*mt[3][1] -
00163   mt[0][2]*mt[1][0]*mt[2][3]*mt[3][1] + mt[0][0]*mt[1][2]*mt[2][3]*mt[3][1] +
00164   mt[0][3]*mt[1][1]*mt[2][0]*mt[3][2] - mt[0][1]*mt[1][3]*mt[2][0]*mt[3][2] -
00165   mt[0][3]*mt[1][0]*mt[2][1]*mt[3][2] + mt[0][0]*mt[1][3]*mt[2][1]*mt[3][2] +
00166   mt[0][1]*mt[1][0]*mt[2][3]*mt[3][2] - mt[0][0]*mt[1][1]*mt[2][3]*mt[3][2] -
00167   mt[0][2]*mt[1][1]*mt[2][0]*mt[3][3] + mt[0][1]*mt[1][2]*mt[2][0]*mt[3][3] +
00168   mt[0][2]*mt[1][0]*mt[2][1]*mt[3][3] - mt[0][0]*mt[1][2]*mt[2][1]*mt[3][3] -
00169   mt[0][1]*mt[1][0]*mt[2][2]*mt[3][3] + mt[0][0]*mt[1][1]*mt[2][2]*mt[3][3];
00170 
00171 
00172  imt[0][0] = (-mt[1][3]*mt[2][2]*mt[3][1] + mt[1][2]*mt[2][3]*mt[3][1] +
00173                mt[1][3]*mt[2][1]*mt[3][2] - mt[1][1]*mt[2][3]*mt[3][2] -
00174                mt[1][2]*mt[2][1]*mt[3][3] + mt[1][1]*mt[2][2]*mt[3][3] )
00175             / det;
00176 
00177  imt[0][1] = ( mt[0][3]*mt[2][2]*mt[3][1] - mt[0][2]*mt[2][3]*mt[3][1] -
00178                mt[0][3]*mt[2][1]*mt[3][2] + mt[0][1]*mt[2][3]*mt[3][2] +
00179                mt[0][2]*mt[2][1]*mt[3][3] - mt[0][1]*mt[2][2]*mt[3][3] )
00180             / det;
00181 
00182  imt[0][2] = (-mt[0][3]*mt[1][2]*mt[3][1] + mt[0][2]*mt[1][3]*mt[3][1] +
00183                mt[0][3]*mt[1][1]*mt[3][2] - mt[0][1]*mt[1][3]*mt[3][2] -
00184                mt[0][2]*mt[1][1]*mt[3][3] + mt[0][1]*mt[1][2]*mt[3][3] )
00185             / det;
00186 
00187  imt[0][3] = ( mt[0][3]*mt[1][2]*mt[2][1] - mt[0][2]*mt[1][3]*mt[2][1] -
00188                mt[0][3]*mt[1][1]*mt[2][2] + mt[0][1]*mt[1][3]*mt[2][2] +
00189                mt[0][2]*mt[1][1]*mt[2][3] - mt[0][1]*mt[1][2]*mt[2][3] )
00190             / det;
00191 
00192  imt[1][0] = ( mt[1][3]*mt[2][2]*mt[3][0] - mt[1][2]*mt[2][3]*mt[3][0] -
00193                mt[1][3]*mt[2][0]*mt[3][2] + mt[1][0]*mt[2][3]*mt[3][2] +
00194                mt[1][2]*mt[2][0]*mt[3][3] - mt[1][0]*mt[2][2]*mt[3][3] )
00195             / det;
00196 
00197  imt[1][1] = (-mt[0][3]*mt[2][2]*mt[3][0] + mt[0][2]*mt[2][3]*mt[3][0] +
00198                mt[0][3]*mt[2][0]*mt[3][2] - mt[0][0]*mt[2][3]*mt[3][2] -
00199                mt[0][2]*mt[2][0]*mt[3][3] + mt[0][0]*mt[2][2]*mt[3][3] )
00200             / det;
00201 
00202  imt[1][2] = ( mt[0][3]*mt[1][2]*mt[3][0] - mt[0][2]*mt[1][3]*mt[3][0] -
00203                mt[0][3]*mt[1][0]*mt[3][2] + mt[0][0]*mt[1][3]*mt[3][2] +
00204                mt[0][2]*mt[1][0]*mt[3][3] - mt[0][0]*mt[1][2]*mt[3][3] )
00205             / det;
00206 
00207  imt[1][3] = (-mt[0][3]*mt[1][2]*mt[2][0] + mt[0][2]*mt[1][3]*mt[2][0] +
00208                mt[0][3]*mt[1][0]*mt[2][2] - mt[0][0]*mt[1][3]*mt[2][2] -
00209                mt[0][2]*mt[1][0]*mt[2][3] + mt[0][0]*mt[1][2]*mt[2][3] )
00210             / det;
00211 
00212  imt[2][0] = (-mt[1][3]*mt[2][1]*mt[3][0] + mt[1][1]*mt[2][3]*mt[3][0] +
00213                mt[1][3]*mt[2][0]*mt[3][1] - mt[1][0]*mt[2][3]*mt[3][1] -
00214                mt[1][1]*mt[2][0]*mt[3][3] + mt[1][0]*mt[2][1]*mt[3][3] )
00215             / det;
00216 
00217  imt[2][1] = ( mt[0][3]*mt[2][1]*mt[3][0] - mt[0][1]*mt[2][3]*mt[3][0] -
00218                mt[0][3]*mt[2][0]*mt[3][1] + mt[0][0]*mt[2][3]*mt[3][1] +
00219                mt[0][1]*mt[2][0]*mt[3][3] - mt[0][0]*mt[2][1]*mt[3][3] )
00220             / det;
00221 
00222  imt[2][2] = (-mt[0][3]*mt[1][1]*mt[3][0] + mt[0][1]*mt[1][3]*mt[3][0] +
00223                mt[0][3]*mt[1][0]*mt[3][1] - mt[0][0]*mt[1][3]*mt[3][1] -
00224                mt[0][1]*mt[1][0]*mt[3][3] + mt[0][0]*mt[1][1]*mt[3][3] )
00225             / det;
00226 
00227  imt[2][3] = ( mt[0][3]*mt[1][1]*mt[2][0] - mt[0][1]*mt[1][3]*mt[2][0] -
00228                mt[0][3]*mt[1][0]*mt[2][1] + mt[0][0]*mt[1][3]*mt[2][1] +
00229                mt[0][1]*mt[1][0]*mt[2][3] - mt[0][0]*mt[1][1]*mt[2][3] )
00230             / det;
00231 
00232  imt[3][0] = ( mt[1][2]*mt[2][1]*mt[3][0] - mt[1][1]*mt[2][2]*mt[3][0] -
00233                mt[1][2]*mt[2][0]*mt[3][1] + mt[1][0]*mt[2][2]*mt[3][1] +
00234                mt[1][1]*mt[2][0]*mt[3][2] - mt[1][0]*mt[2][1]*mt[3][2] )
00235             / det;
00236 
00237  imt[3][1] = (-mt[0][2]*mt[2][1]*mt[3][0] + mt[0][1]*mt[2][2]*mt[3][0] +
00238                mt[0][2]*mt[2][0]*mt[3][1] - mt[0][0]*mt[2][2]*mt[3][1] -
00239                mt[0][1]*mt[2][0]*mt[3][2] + mt[0][0]*mt[2][1]*mt[3][2] )
00240             / det;
00241 
00242  imt[3][2] = ( mt[0][2]*mt[1][1]*mt[3][0] - mt[0][1]*mt[1][2]*mt[3][0] -
00243                mt[0][2]*mt[1][0]*mt[3][1] + mt[0][0]*mt[1][2]*mt[3][1] +
00244                mt[0][1]*mt[1][0]*mt[3][2] - mt[0][0]*mt[1][1]*mt[3][2] )
00245             / det;
00246 
00247  imt[3][3] = (-mt[0][2]*mt[1][1]*mt[2][0] + mt[0][1]*mt[1][2]*mt[2][0] +
00248                mt[0][2]*mt[1][0]*mt[2][1] - mt[0][0]*mt[1][2]*mt[2][1] -
00249                mt[0][1]*mt[1][0]*mt[2][2] + mt[0][0]*mt[1][1]*mt[2][2] )
00250             / det;
00251 }
00252 
00253 /*========================  Dsp::GetCamera  ========================*/
00254 
00255 void Dsp::GetCamera( double* eyex, double* eyey, double* eyez,
00256                      double* refx, double* refy, double* refz,
00257                      double* vupx, double* vupy, double* vupz )
00258 {
00259  double mt[4][4];           /* model view matrix */
00260  double im[4][4];           /* inverse model view matrix */
00261  double zex, zey, zez;      /* eye normalized z vector */
00262 
00263  glGetDoublev( GL_MODELVIEW_MATRIX, (double *)mt );
00264 
00265 /* Get eye z and y normalized vectors (consider vup equal to eye y).
00266  * Note that OpenGL stores the model view matrix in column major order.
00267  */
00268  zex   = mt[0][2]; zey   = mt[1][2]; zez   = mt[2][2];
00269  *vupx = mt[0][1]; *vupy = mt[1][1]; *vupz = mt[2][1];
00270 
00271 /* Invert model view matrix and compute eye location.
00272  */
00273  InvertMatrix( mt, im );
00274  *eyex = im[3][0] / im[3][3];
00275  *eyey = im[3][1] / im[3][3];
00276  *eyez = im[3][2] / im[3][3];
00277 
00278 /* Compute a reference point at a unit distance from eye 
00279  * along view direction at the negative z side.
00280  */
00281  *refx = *eyex - zex;
00282  *refy = *eyey - zey;
00283  *refz = *eyez - zez;
00284 }
00285 
00286 /*======================  Dsp::GetViewVolume  ======================*/
00287 
00288 int Dsp::GetViewVolume( double* left,   double* right,
00289                         double* bottom, double* top,
00290                         double* front,  double* back )
00291 {
00292  double projmt[4][4];       /* projection matrix */
00293  int    persp;              /* if true (1), doing perspective projection */
00294 
00295  glGetDoublev( GL_PROJECTION_MATRIX, (double *)projmt );
00296 
00297  if( projmt[2][3] != 0.0 )
00298   persp = 1;
00299  else
00300   persp = 0;
00301 
00302 /* Get view volume according to type of projection.
00303  * Note that OpenGL stores the projection matrix in column-major order.
00304  */
00305  if( persp )      /* perspective projection */
00306  {
00307   *front  = projmt[3][2] / (projmt[2][2]-1.0);
00308   *back   = projmt[3][2] / (projmt[2][2]+1.0);
00309   *left   = (*front * (projmt[2][0]-1.0)) / projmt[0][0];
00310   *right  = (*front * (projmt[2][0]+1.0)) / projmt[0][0];
00311   *bottom = (*front * (projmt[2][1]-1.0)) / projmt[1][1];
00312   *top    = (*front * (projmt[2][1]+1.0)) / projmt[1][1];
00313  }
00314  else             /* orthographic projection */
00315  {
00316   *front  =  (projmt[3][2]+1.0) / projmt[2][2];
00317   *back   =  (projmt[3][2]-1.0) / projmt[2][2];
00318   *left   = -(1.0+projmt[3][0]) / projmt[0][0];
00319   *right  =  (1.0-projmt[3][0]) / projmt[0][0];
00320   *bottom = -(1.0+projmt[3][1]) / projmt[1][1];
00321   *top    =  (1.0-projmt[3][1]) / projmt[1][1];
00322  }
00323 
00324  return( persp );
00325 }
00326 
00327 /*========================  Dsp::DisplayPrm  =======================*/
00328 
00329 void Dsp::DisplayPrm( Prm* prm )
00330 {
00331  glColor3d( get_red( prm->GetColor( ) ),
00332             get_green( prm->GetColor( ) ),
00333             get_blue( prm->GetColor( ) ) );
00334 
00335 /*** COMPLETE HERE: 16 ***/
00336
00337 /*** COMPLETE HERE: 16 ***/
00338 }
00339 
00340 /*========================  Dsp::HighltPrm  ========================*/
00341 
00342 void Dsp::HighltPrm( Prm* prm )
00343 {
00344  glColor3d( 1.0, 0.0, 0.0 );   /* red color */
00345 
00346  glDisable( GL_LIGHTING );
00347 /*** COMPLETE HERE: 17 ***/
00348
00349 /*** COMPLETE HERE: 17 ***/
00350  glEnable( GL_LIGHTING );
00351 }
00352 
00353 
00354 /*
00355 ** ---------------------------------------------------------------
00356 ** Public class functions:
00357 */
00358 
00359 /*===========================  Dsp::Init  ==========================*/
00360 
00361 void Dsp::Init( void )
00362 {
00363  GLfloat ambienteLight[] = { 0.35f, 0.35f, 0.35f, 1.0f };
00364  GLfloat diffuseLight[] = { 0.3f, 0.3f, 0.3f, 1.0f };
00365  HWND hwnd;
00366  HDC  hdc;
00367 
00368 /* Initialize some OpenGL parameters.
00369  */
00370  glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE );
00371  glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambienteLight );
00372  glLightfv( GL_LIGHT0, GL_AMBIENT, ambienteLight );
00373  glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuseLight );
00374  glEnable( GL_LIGHT0 );
00375  glEnable( GL_LIGHTING );
00376  glEnable( GL_COLOR_MATERIAL );
00377  glEnable( GL_DEPTH_TEST );
00378  glPointSize( 4.0 );
00379 
00380 /* This is stuff for displaying help text on the data canvas.
00381  */
00382  hwnd = (HWND)IupGetAttribute( Prj::Odatascreen, IUP_WID );
00383  hdc  = GetDC( hwnd );
00384  if(hdc == 0)
00385    return;
00386  font_list_base = glGenLists( 256 );
00387  if( font_list_base == 0 )
00388   return;
00389  if( !wglUseFontBitmaps( hdc, 0, 255, font_list_base ) )
00390   return;
00391 }
00392 
00393 /*===========================  Dsp::Help  ===========================*/
00394 
00395 void Dsp::Help( void )
00396 {
00397  double win_xmin_help, win_xmax_help, win_ymin_help, win_ymax_help;
00398 
00399  win_xmin_help =  0.0;
00400  win_xmax_help = 10.0;
00401  win_ymin_help = -0.5;
00402  win_ymax_help = 10.0;
00403 
00404  glClearColor( 0.0, 0.0, 0.0, 1.0 );
00405  glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
00406  glMatrixMode( GL_PROJECTION );
00407  glLoadIdentity( );
00408 
00409  glOrtho( (GLdouble)win_xmin_help, (GLdouble)win_xmax_help,
00410           (GLdouble)win_ymin_help, (GLdouble)win_ymax_help,   0.0, 1.0 );
00411  glMatrixMode( GL_MODELVIEW );
00412  glLoadIdentity( );
00413 
00414  glDisable( GL_LIGHTING );
00415  glDisable( GL_LIGHT0);
00416 
00417  glColor3d( 0.0, 1.0, 0.0 );
00418  glListBase( font_list_base );
00419 
00420  glRasterPos2d( 0.5,  9.0 );
00421  glCallLists( (GLsizei)strlen( help_cmd[ 0] ), GL_UNSIGNED_BYTE, help_cmd[ 0] );
00422  glRasterPos2d( 0.5,  8.0 );
00423  glCallLists( (GLsizei)strlen( help_cmd[ 1] ), GL_UNSIGNED_BYTE, help_cmd[ 1] );
00424  glRasterPos2d( 0.5,  7.5 );
00425  glCallLists( (GLsizei)strlen( help_cmd[ 2] ), GL_UNSIGNED_BYTE, help_cmd[ 2] );
00426  glRasterPos2d( 0.5,  7.0 );
00427  glCallLists( (GLsizei)strlen( help_cmd[ 3] ), GL_UNSIGNED_BYTE, help_cmd[ 3] );
00428  glRasterPos2d( 0.5,  6.5 );
00429  glCallLists( (GLsizei)strlen( help_cmd[ 4] ), GL_UNSIGNED_BYTE, help_cmd[ 4] );
00430  glRasterPos2d( 0.5,  6.0 );
00431  glCallLists( (GLsizei)strlen( help_cmd[ 5] ), GL_UNSIGNED_BYTE, help_cmd[ 5] );
00432  glRasterPos2d( 0.5,  5.0 );
00433  glCallLists( (GLsizei)strlen( help_cmd[ 6] ), GL_UNSIGNED_BYTE, help_cmd[ 6] );
00434  glRasterPos2d( 0.5,  4.5 );
00435  glCallLists( (GLsizei)strlen( help_cmd[ 7] ), GL_UNSIGNED_BYTE, help_cmd[ 7] );
00436  glRasterPos2d( 0.5,  4.0 );
00437  glCallLists( (GLsizei)strlen( help_cmd[ 8] ), GL_UNSIGNED_BYTE, help_cmd[ 8] );
00438  glRasterPos2d( 0.5,  3.5 );
00439  glCallLists( (GLsizei)strlen( help_cmd[ 9] ), GL_UNSIGNED_BYTE, help_cmd[ 9] );
00440  glRasterPos2d( 0.5,  3.0 );
00441  glCallLists( (GLsizei)strlen( help_cmd[10] ), GL_UNSIGNED_BYTE, help_cmd[10] );
00442  glRasterPos2d( 0.5,  2.5 );
00443  glCallLists( (GLsizei)strlen( help_cmd[11] ), GL_UNSIGNED_BYTE, help_cmd[11] );
00444  glRasterPos2d( 0.5,  2.0 );
00445  glCallLists( (GLsizei)strlen( help_cmd[12] ), GL_UNSIGNED_BYTE, help_cmd[12] );
00446  glRasterPos2d( 0.5,  1.0 );
00447  glCallLists( (GLsizei)strlen( help_cmd[13] ), GL_UNSIGNED_BYTE, help_cmd[13] );
00448  glRasterPos2d( 0.5,  0.5 );
00449  glCallLists( (GLsizei)strlen( help_cmd[14] ), GL_UNSIGNED_BYTE, help_cmd[14] );
00450  glRasterPos2d( 0.5,  0.0 );
00451  glCallLists( (GLsizei)strlen( help_cmd[15] ), GL_UNSIGNED_BYTE, help_cmd[15] );
00452 
00453  glRasterPos2d( 4.0,  9.0 );
00454  glCallLists( (GLsizei)strlen( help_msg[ 0] ), GL_UNSIGNED_BYTE, help_msg[ 0] );
00455  glRasterPos2d( 4.0,  8.0 );
00456  glCallLists( (GLsizei)strlen( help_msg[ 1] ), GL_UNSIGNED_BYTE, help_msg[ 1] );
00457  glRasterPos2d( 4.0,  7.5 );
00458  glCallLists( (GLsizei)strlen( help_msg[ 2] ), GL_UNSIGNED_BYTE, help_msg[ 2] );
00459  glRasterPos2d( 4.0,  7.0 );
00460  glCallLists( (GLsizei)strlen( help_msg[ 3] ), GL_UNSIGNED_BYTE, help_msg[ 3] );
00461  glRasterPos2d( 4.0,  6.5 );
00462  glCallLists( (GLsizei)strlen( help_msg[ 4] ), GL_UNSIGNED_BYTE, help_msg[ 4] );
00463  glRasterPos2d( 4.0,  6.0 );
00464  glCallLists( (GLsizei)strlen( help_msg[ 5] ), GL_UNSIGNED_BYTE, help_msg[ 5] );
00465  glRasterPos2d( 4.0,  5.0 );
00466  glCallLists( (GLsizei)strlen( help_msg[ 6] ), GL_UNSIGNED_BYTE, help_msg[ 6] );
00467  glRasterPos2d( 4.0,  4.5 );
00468  glCallLists( (GLsizei)strlen( help_msg[ 7] ), GL_UNSIGNED_BYTE, help_msg[ 7] );
00469  glRasterPos2d( 4.0,  4.0 );
00470  glCallLists( (GLsizei)strlen( help_msg[ 8] ), GL_UNSIGNED_BYTE, help_msg[ 8] );
00471  glRasterPos2d( 4.0,  3.5 );
00472  glCallLists( (GLsizei)strlen( help_msg[ 9] ), GL_UNSIGNED_BYTE, help_msg[ 9] );
00473  glRasterPos2d( 4.0,  3.0 );
00474  glCallLists( (GLsizei)strlen( help_msg[10] ), GL_UNSIGNED_BYTE, help_msg[10] );
00475  glRasterPos2d( 4.0,  2.5 );
00476  glCallLists( (GLsizei)strlen( help_msg[11] ), GL_UNSIGNED_BYTE, help_msg[11] );
00477  glRasterPos2d( 4.0,  2.0 );
00478  glCallLists( (GLsizei)strlen( help_msg[12] ), GL_UNSIGNED_BYTE, help_msg[12] );
00479  glRasterPos2d( 4.0,  1.0 );
00480  glCallLists( (GLsizei)strlen( help_msg[13] ), GL_UNSIGNED_BYTE, help_msg[13] );
00481  glRasterPos2d( 4.0,  0.5 );
00482  glCallLists( (GLsizei)strlen( help_msg[14] ), GL_UNSIGNED_BYTE, help_msg[14] );
00483  glRasterPos2d( 4.0,  0.0 );
00484  glCallLists( (GLsizei)strlen( help_msg[15] ), GL_UNSIGNED_BYTE, help_msg[15] );
00485 
00486  glEnable( GL_LIGHTING );
00487 }
00488 
00489 /*==========================  Dsp::Model  ==========================*/
00490 
00491 void Dsp::Model( void )
00492 {
00493  Prm* prm;
00494 
00495  for( prm = Prm::First( ); prm != NULL; prm = prm->Next( ) )
00496  {
00497   if( prm->CheckSelected( ) )
00498   {
00499    glEnable( GL_POLYGON_OFFSET_FILL );
00500    glPolygonOffset( 1.0, 1.0 );
00501    DisplayPrm( prm );
00502    glDisable( GL_POLYGON_OFFSET_FILL );
00503    HighltPrm( prm );
00504   }
00505   else
00506   {
00507    DisplayPrm( prm );
00508   }
00509  }
00510 }
00511 
00512 /*=========================  Dsp::ZbfModel  ========================*/
00513 
00514 int Dsp::ZbfModel( void* Gzbuffercanvas )
00515 {
00516  int    width, height;      /* zbuffer sizes */
00517  double eyex, eyey, eyez;   /* camera parameters */
00518  double refx, refy, refz;
00519  double vupx, vupy, vupz;
00520  double left, right;        /* view volume parameters */
00521  double bottom, top;
00522  double front, back;
00523  int    persp;              /* if true (1), doing perspective projection */
00524  Prm*   prm;
00525  unsigned char gray_intensity;
00526 
00527  cdActivate( (cdCanvas*)Gzbuffercanvas );
00528  cdGetCanvasSize( &width, &height, 0L, 0L );
00529 
00530 /* Set gray background color and clear canvas.
00531  */
00532  gray_intensity = (unsigned char)(0.75 * 255.0);
00533  cdBackground( EncodeColor(gray_intensity, gray_intensity, gray_intensity) );
00534  cdClear( );
00535 
00536 /* Get camera and view volume parameters.
00537  */
00538  GetCamera( &eyex, &eyey, &eyez, &refx, &refy, &refz, &vupx, &vupy, &vupz );
00539  persp = GetViewVolume( &left, &right, &bottom, &top, &front, &back );
00540 
00541 /* Compute normalized view vector.
00542  */
00543  view_vector.x = refx - eyex;
00544  view_vector.y = refy - eyey;
00545  view_vector.z = refz - eyez;
00546  VecUnit( &view_vector, &view_vector );
00547 
00548 /* Build a 3D transformation that transforms from world (object)
00549  * coordinates to normalized screen coordinates (the view frustum
00550  * is transformed into a cube of size 2 and center at origin).
00551  * For perspective projection, place the projection plane at
00552  * the front view volume plane (OpenGL does this way).
00553  */
00554 /*** COMPLETE HERE: 18 ***/
00555
00556
00557
00558
00559
00560 /*** COMPLETE HERE: 18 ***/
00561 
00562 /* Display the model in the zbuffer canvas.
00563  */
00564 /*** COMPLETE HERE: 19 ***/
00565
00566
00567
00568
00569 /*** COMPLETE HERE: 19 ***/
00570 
00571  return( 1 );
00572 }
00573 
00574 /*=======================  Dsp::ZbfBeginPoly  ======================*/
00575 
00576 void Dsp::ZbfBeginPoly( long int color, double nx, double ny, double nz )
00577 {
00578  Vec normal;            /* face normal vector */
00579  long int shaded_color; /* face color with modified intensity */
00580 
00581  normal.x = nx;
00582  normal.y = ny;
00583  normal.z = nz;
00584  shaded_color = ShadeColor( &normal, &view_vector, color );
00585  Zbf::BeginPoly( shaded_color );
00586 }
00587 
00588 /*=========================  Dsp::ZbfVertex  =======================*/
00589 
00590 void Dsp::ZbfVertex( double x, double y, double z )
00591 {
00592  T3d::Transform( &x, &y, &z );
00593  Zbf::Vertex( x, y, z );
00594 }
00595 
00596 /*========================  Dsp::ZbfEndPoly  =======================*/
00597 
00598 void Dsp::ZbfEndPoly( void )
00599 {
00600  Zbf::EndPoly( );
00601 }
00602 
00603 /*=======================  Dsp::GetPickRay  ========================*/
00604 
00605 void Dsp::GetPickRay( int x, int y,
00606                       double* frontx, double* fronty, double* frontz,
00607                       double* backx,  double* backy,  double* backz )
00608 {
00609  double modelMatrix[16];
00610  double projMatrix[16];
00611  int    viewport[4];
00612  int    h;
00613  double winx, winy, winz;
00614 
00615  glGetDoublev( GL_MODELVIEW_MATRIX, modelMatrix );
00616  glGetDoublev( GL_PROJECTION_MATRIX, projMatrix );
00617  glGetIntegerv( GL_VIEWPORT, viewport );
00618 
00619 /* Transform from mouse raster position in canvas to 
00620  * GL viewport position.  It is assumed that the GL 
00621  * viewport takes the entire canvas.
00622  */
00623  h = viewport[3];
00624  winx = (double)x;
00625  winy = (double)y;
00626 
00627 /* Find ray point in object space at front (near) plane.
00628  */
00629  winz = 0.0;
00630  gluUnProject( winx, winy, winz, modelMatrix, projMatrix,
00631                viewport, frontx, fronty, frontz );
00632 
00633 /* Find ray point in object space at back (far) plane.
00634  */
00635  winz = 1.0;
00636  gluUnProject( winx, winy, winz, modelMatrix, projMatrix,
00637                viewport, backx, backy, backz );
00638 }
00639 

Generated on Mon Jun 21 12:45:12 2010 for Trab4 by  doxygen 1.4.2-20050421