OpenGlRenderer.cpp

Go to the documentation of this file.
00001 /* ****************************************************************** **
00002 **    OpenSees - Open System for Earthquake Engineering Simulation    **
00003 **          Pacific Earthquake Engineering Research Center            **
00004 **                                                                    **
00005 **                                                                    **
00006 ** (C) Copyright 1999, The Regents of the University of California    **
00007 ** All Rights Reserved.                                               **
00008 **                                                                    **
00009 ** Commercial use of this program without express permission of the   **
00010 ** University of California, Berkeley, is strictly prohibited.  See   **
00011 ** file 'COPYRIGHT'  in main directory for information on usage and   **
00012 ** redistribution,  and for a DISCLAIMER OF ALL WARRANTIES.           **
00013 **                                                                    **
00014 ** Developed by:                                                      **
00015 **   Frank McKenna (fmckenna@ce.berkeley.edu)                         **
00016 **   Gregory L. Fenves (fenves@ce.berkeley.edu)                       **
00017 **   Filip C. Filippou (filippou@ce.berkeley.edu)                     **
00018 **                                                                    **
00019 ** ****************************************************************** */
00020                                                                         
00021 // $Revision: 1.18 $
00022 // $Date: 2006/01/10 22:52:53 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/renderer/OpenGlRenderer.cpp,v $
00024                                                                         
00025                                                                         
00026 // Written: fmk 
00027 // Revision: A
00028 //
00029 // Description: This file contains the class definition for OpenGLRenderer.
00030 // OpenGLRenderer is an class which diplays using X11 or openGL.
00031 //
00032 // What: "@(#) OpenGLRenderer.h, revA"
00033 
00034 #include <OpenGLRenderer.h>
00035 #include <ColorMap.h>
00036 #include <stdio.h>
00037 #include <stdlib.h>
00038 #include <Matrix.h>
00039 #include <iomanip>
00040 using std::ios;
00041 
00042 #ifdef _WGL
00043 #include <windows.h>
00044 #include <GL/glaux.h>
00045 #include <GL/glu.h>
00046 #include <GL/gl.h>
00047 
00048 #elif _GLX
00049 
00050 #include <GL/glu.h>
00051 
00052 #endif
00053 
00054 #define PARALLEL_MODE 0
00055 #define PERSPECTIVE_MODE 1
00056 
00057 #define WIRE_MODE 0
00058 #define FILL_MODE 1
00059 
00060 //#include <db.H>
00061 #include <Vector.h>
00062 
00063 OpenGLRenderer::OpenGLRenderer(const char *_title, int _xLoc, int _yLoc, 
00064                                int _width, int _height, 
00065                                ColorMap &_theMap)
00066   :Renderer(_title, _theMap),  
00067   windowTitle(0), height(_height), width(_width), xLoc(_xLoc), yLoc(_yLoc),
00068   count(-1), theOutputFileName(0), 
00069   theDevice(0),
00070   vrp(3), vuv(3), vpn(3), cop(3), ViewMat(4,4), 
00071   projectionMode(0), vpWindow(4), ProjMat(4,4),
00072   portWindow(4)
00073 {
00074 
00075   // set the WindowDevices title, height, wdth, xLoc and yLoc
00076   windowTitle = new char [strlen(_title)+1];
00077   strcpy(windowTitle, _title);
00078 
00079   fillMode = WIRE_MODE;
00080   projectionMode = PARALLEL_MODE;
00081   portWindow(0) = -1.0; portWindow(1) = 1.0;
00082   portWindow(2) = -1.0;  portWindow(3) = 1.0;
00083 
00084   theDevice = new OpenGlDevice();
00085   theDevice->WINOPEN(_title, _xLoc, _yLoc, _width, _height);
00086 
00087   theDevice->CLEAR();
00088   glClearColor(1.0f,1.0f,1.0f,1.0f);
00089 
00090   glEnable(GL_DEPTH_TEST);
00091   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00092 
00093   glFlush();
00094   theDevice->ENDIMAGE();
00095 }
00096 
00097 
00098 
00099 
00100 OpenGLRenderer::OpenGLRenderer(const char *_title, int _xLoc, int _yLoc, 
00101                                int _width, int _height, 
00102                                ColorMap &_theMap, 
00103                                const char *outputFileName, 
00104                                const char *bitmapFileName)
00105   :Renderer(_title, _theMap),  
00106   windowTitle(0), height(_height), width(_width), xLoc(_xLoc), yLoc(_yLoc),
00107   count(-1), theOutputFileName(0), 
00108   theDevice(0),
00109   vrp(3), vuv(3), vpn(3), cop(3), ViewMat(4,4), 
00110   projectionMode(0), vpWindow(4), ProjMat(4,4),
00111   portWindow(4)
00112 {
00113   // set the WindowDevices title, height, wdth, xLoc and yLoc
00114   windowTitle = new char [strlen(_title)+1];
00115   strcpy(windowTitle, _title);
00116 
00117   fillMode = WIRE_MODE;
00118   projectionMode = PARALLEL_MODE;
00119   portWindow(0) = -1.0; portWindow(1) = 1.0;
00120   portWindow(2) = -1.0;  portWindow(3) = 1.0;
00121 
00122   theDevice = new OpenGlDevice();
00123   if (bitmapFileName != 0) {
00124                 opserr << "OpenGLRenderer:;OpenGlRenderer - feature to save image only to BMP removed\n";
00125   }
00126   theDevice->WINOPEN(_title, _xLoc, _yLoc, _width, _height);;
00127   
00128   theDevice->CLEAR();
00129 
00130 
00131   // open the file for  making the movie
00132   if (outputFileName != 0) {
00133     windowTitle = new char [strlen(_title)+1];
00134     theOutputFileName = new char [strlen(outputFileName)+1];
00135 
00136     strcpy(windowTitle, _title);
00137     strcpy(theOutputFileName, outputFileName);
00138     theFile.open(theOutputFileName, ios::out);
00139     if (theFile.bad()) {
00140       opserr << "WARNING - OpenGLRenderer::OpenGLRenderer() - could not open file: " << outputFileName << endln;
00141       theOutputFileName = 0;
00142     } else {
00143       theFile << windowTitle << endln;
00144       theFile << 1.0*xLoc << " " << 1.0*yLoc << " " << 1.0*width << " " << 1.0*height << endln;
00145     }
00146   }
00147 
00148   theDevice->CLEAR();
00149   glClearColor(1.0f,1.0f,1.0f,1.0f);
00150 
00151   glEnable(GL_DEPTH_TEST);
00152   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00153 
00154   glFlush();
00155   theDevice->ENDIMAGE();
00156 }
00157 
00158 OpenGLRenderer::~OpenGLRenderer()
00159 {
00160   if (theDevice != 0)
00161     delete theDevice;
00162 
00163   if (windowTitle != 0)
00164     delete [] windowTitle;
00165 
00166   if (theOutputFileName != 0) {
00167     theFile.close();
00168     delete [] theOutputFileName;
00169   }
00170 }
00171 
00172 
00173 int 
00174 OpenGLRenderer::clearImage(void)
00175 {
00176   theDevice->CLEAR();
00177   glClearColor(1.0f,1.0f,1.0f,1.0f);
00178 
00179   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00180  
00181   glFlush();
00182  
00183 #ifdef _UNIX
00184   theDevice->ENDIMAGE();
00185 #endif
00186 
00187   return 0;
00188 }
00189 
00190 int 
00191 OpenGLRenderer::saveImage(const char *imageName)
00192 {
00193   return theDevice->saveImage(imageName, 0);
00194 }
00195 
00196 
00197 int 
00198 OpenGLRenderer::startImage(void)
00199 {
00200   theMap->startImage();
00201 
00202   theDevice->STARTIMAGE();
00203 
00204   if (fillMode == WIRE_MODE) {
00205     glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
00206   } else {
00207     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
00208   }
00209 
00210   // glEnable(GL_BLEND);
00211   // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00212   // glEnable(GL_LINE_SMOOTH);
00213   // glEnable(GL_POINT_SMOOTH);
00214   // glEnable(GL_POLYGON_SMOOTH);
00215 
00216     //
00217     // set up the viewing transformation
00218     //
00219     static Vector u(3), v(3), n(3);
00220 
00221     // vpnCopy used to store vpn, if no vpn yet specified vpn = VRP-PRP
00222     static Vector vpnCopy(3);
00223 
00224     if (vpn(0) == 0.0 && vpn(1) == 0.0 && vpn(2) == 0.0) {
00225       vpnCopy(0) = cop(0) - vrp(0);
00226       vpnCopy(1) = cop(1) - vrp(1);
00227       vpnCopy(2) = cop(2) - vrp(2);
00228     } else {
00229       vpnCopy(0) = vpn(0);
00230       vpnCopy(1) = vpn(1);
00231       vpnCopy(2) = vpn(2);
00232     }
00233 
00234     for (int i=0; i<3; i++) {
00235         n(i) = vpnCopy(i);
00236         v(i) = vuv(i);
00237     }
00238 
00239     if (n.Normalize() != 0) {
00240         opserr << "View::update() - VPN cannot have zero length\n";
00241         return -1;
00242     }
00243 
00244     // u = v % n;
00245     u(0) = v(1)*n(2) - v(2)*n(1) ;
00246     u(1) = v(2)*n(0) - v(0)*n(2) ;
00247     u(2) = v(0)*n(1) - v(1)*n(0) ;
00248 
00249     if (u.Normalize() != 0) {
00250         opserr << "View::update() - VUV X VPN cannot have zero length\n";
00251         return -1;
00252     }
00253 
00254     //v = n % u;
00255     v(0) = n(1)*u(2) - n(2)*u(1) ;
00256     v(1) = n(2)*u(0) - n(0)*u(2) ;
00257     v(2) = n(0)*u(1) - n(1)*u(0) ;
00258 
00259     v.Normalize();
00260     
00261     ViewMat(0,0) = u(0); ViewMat(0,1) = u(1); ViewMat(0,2) = u(2); ViewMat(0,3) = -(vrp^u);
00262     ViewMat(1,0) = v(0); ViewMat(1,1) = v(1); ViewMat(1,2) = v(2); ViewMat(1,3) = -(vrp^v);
00263     ViewMat(2,0) = n(0); ViewMat(2,1) = n(1); ViewMat(2,2) = n(2); ViewMat(2,3) = -(vrp^n);
00264     ViewMat(3,0) =  0.0; ViewMat(3,1) =  0.0; ViewMat(3,2) = 0.0;  ViewMat(3,3) =  1.0;
00265 
00266     for (int j=0; j<4; j++)
00267         for (int k=0; k<4; k++)
00268             viewData[j+k*4] = ViewMat(j,k);
00269     
00270     glMatrixMode(GL_MODELVIEW);
00271     glLoadMatrixf(viewData);
00272 
00273    //
00274    // set up the projection transformation
00275    //
00276 
00277     float midU, midV, dopU, dopV, dopN, shU, shV, F, B;
00278     midU = (vpWindow(0) + vpWindow(1))/2;
00279     midV = (vpWindow(2) + vpWindow(3))/2;
00280 
00281     // PRP (COP) in viewing system
00282     float PRPu = u(0)*cop(0) + u(1)*cop(1) + u(2)*cop(2) + ViewMat(0,3);
00283     float PRPv = v(0)*cop(0) + v(1)*cop(1) + v(2)*cop(2) + ViewMat(1,3);
00284     float PRPn = n(0)*cop(0) + n(1)*cop(1) + n(2)*cop(2) + ViewMat(2,3);
00285 
00286     float diffU, diffV;// prpN;
00287         
00288     diffU = vpWindow(1)-vpWindow(0);
00289     diffV = vpWindow(3)-vpWindow(2);      
00290 
00291     dopU = midU - PRPu;
00292     dopV = midV - PRPv;
00293     dopN = -PRPn;
00294 
00295     shU = dopU/dopN;
00296     shV = dopV/dopN;
00297     F = clippingPlanes[0];
00298     B = clippingPlanes[1];
00299 
00300     /******* the equiv of the viewData transformation using glu **************
00301     glLoadIdentity();
00302     gluLookAt(cop[0),cop[1),cop[2),vrp[0),vrp[1),vrp[2),vuv[0),vuv[1),vuv[2));
00303     glTranslatef(0.0, 0.0, PRPn);  // note the PRPn transformation here
00304     **************************************************************************/
00305 
00306     if (projectionMode == PARALLEL_MODE) {
00307 
00308       ProjMat(0,0) = 2.0/diffU; ProjMat(0,1) = 0.0; ProjMat(0,2) = 2.0*shU/diffU; 
00309       ProjMat(0,3) = -2*midU/diffU,
00310 
00311         ProjMat(1,0) = 0.0; ProjMat(1,1) = 2/diffV; ProjMat(1,2) = 2*shV/diffV; 
00312         ProjMat(1,3) = -2*midV/diffV;
00313 
00314         ProjMat(2,0) =  0.0; ProjMat(2,1) =  0.0; ProjMat(2,2) = 1.0;  ProjMat(2,3) =  0.0;
00315         ProjMat(3,0) =  0.0; ProjMat(3,1) =  0.0; ProjMat(3,2) = 0.0;  ProjMat(3,3) =  1.0;
00316       
00317         for (int jj=0; jj<4; jj++)
00318           for (int kk=0; kk<4; kk++)
00319             projData[jj+kk*4] = ProjMat(jj,kk);
00320 
00321         glMatrixMode(GL_PROJECTION);
00322         glLoadMatrixf(projData);
00323         glOrtho(-1.0, 1.0, -1.0, 1.0, -F, -B);
00324 
00325     } else { // perspective projection
00326 
00327         double VRPn = -PRPn;  // VRP after T(-PRP)
00328         float near2 = PRPn-F;
00329         float far2  = PRPn-B;
00330         float zMin = near2/far2;
00331 
00332         /**************** Having trouble with the following transformation ******
00333         float a,b,c,e,f,g,h;
00334 
00335         a = 2.0*PRPn/(diffU * far);
00336         b = 2.0*PRPn/(diffV * far);
00337         c = -1.0/far;
00338 
00339         e = 1/(1-zMin);
00340         f = -zMin * e;
00341         
00342         g = PRPu - shU * PRPn;
00343         h = PRPv - shV * PRPn;
00344 
00345         ProjMat.Set(     a,   0.0,         0.0,    0.0,
00346                        0.0,     b,         0.0,    0.0,
00347                      a*shU, b*shV,         e*c,     -c,
00348                        -a*g,  -b*h, e*c*PRPn+f, -c*PRPn);  
00349 
00350         for (int jj=0; jj<4; jj++)
00351           for (int kk=0; kk<4; kk++)
00352             projData[jj*4+kk) = ProjMat.m(jj)[kk);
00353 
00354         glMatrixMode(GL_PROJECTION);
00355         glLoadMatrixf(projData);
00356         ******* so in the meantime use the following - NO SHEARING  **************/
00357 
00358         glMatrixMode(GL_MODELVIEW);
00359         glLoadIdentity();
00360         gluLookAt(cop(0),cop(1),cop(2),vrp(0),vrp(1),vrp(2),vuv(0),vuv(1),vuv(2));
00361 
00362         glMatrixMode(GL_PROJECTION);
00363         float left = near2*diffU/VRPn/2;
00364         float bottom = near2*diffV/VRPn/2;
00365         float right = -left;
00366         float top = -bottom;
00367         glLoadIdentity();
00368         glFrustum(left,right,bottom,top,near2,far2);    
00369 
00370     }
00371 
00372     int xMin = floor((portWindow(0)+1) * width/2.0);
00373     int xDiff = floor((portWindow(1)-portWindow(0)) * width/2.0);
00374     int yMin = floor((portWindow(2)+1) * height/2.0);
00375     int yDiff = floor((portWindow(3)-portWindow(2)) * height/2.0);
00376 
00377     glViewport((GLsizei) xMin, (GLsizei) yMin, (GLsizei) xDiff, (GLsizei) yDiff);
00378 
00379     if (theOutputFileName != 0) {
00380         theFile << "StartImage\n";
00381         theFile << "VRP " << vrp(0) << " " << vrp(1) << " " 
00382             << vrp(2) << " " << endln;
00383         theFile << "VPN " << vpn(0) << " " << vpn(1) << " " 
00384             << vpn(2) << " " << endln;
00385         theFile << "VUV " << vuv(0) << " " << vuv(1) << " " 
00386             << vuv(2) << " " << endln;
00387         theFile << "COP " << cop(0) << " " << cop(1) << " " 
00388             << cop(2) << " " << endln;
00389         
00390         theFile << "PROJECTIONMODE " << 1.0*projectionMode << endln;
00391         theFile << "VPWINDOW " << vpWindow(0) << " " << vpWindow(1) << " "
00392             << vpWindow(2) << " " << vpWindow(3) << " " << endln;
00393         theFile << "PLANES " << clippingPlanes[0] << " " << clippingPlanes[1] << "\n";
00394         theFile << "PORTWINDOW " << portWindow(0) << " " << portWindow(1) << " "
00395             << portWindow(2) << " " << portWindow(3) << " " << endln;
00396     } 
00397  
00398     // done
00399     return 0;
00400 }
00401 
00402 
00403 int 
00404 OpenGLRenderer::doneImage(void)
00405 {
00406   if (theOutputFileName != 0) {
00407     theFile << "DoneImage\n";
00408   }
00409     
00410   if (count != -1) {
00411     count++;
00412   }
00413 
00414   theDevice->ENDIMAGE();    
00415   return 0;
00416 }
00417 
00418 int 
00419 OpenGLRenderer::drawPoint(const Vector &pos1, float V1, int numPixels)
00420 {
00421     glPointSize(numPixels);
00422 
00423     glBegin(GL_POINTS);
00424     float r, g, b;
00425 
00426     theMap->getRGB(V1, r, g, b);
00427     glColor3f(r,g,b);
00428     glVertex3f(pos1(0),pos1(1),pos1(2));
00429     
00430     if (theOutputFileName != 0) {
00431         theFile << "Point\n" << pos1(0) << " " << pos1(1) << " " << pos1(2) 
00432             << " " << r << " " << g << " " << b << " " << endln;
00433     }
00434 
00435     glEnd();
00436 
00437     return 0;  
00438 }
00439 
00440 
00441 int 
00442 OpenGLRenderer::drawPoint(const Vector &pos1, const Vector &rgb, int numPixels)
00443 {
00444     glPointSize(numPixels);
00445 
00446     glBegin(GL_POINTS);
00447     float r, g, b;
00448     r = rgb(0);
00449     g = rgb(1);
00450     b = rgb(2);
00451 
00452     glColor3f(r,g,b);
00453     glVertex3f(pos1(0),pos1(1),pos1(2));
00454     
00455     if (theOutputFileName != 0) {
00456         theFile << "Point\n" << pos1(0) << " " << pos1(1) << " " << pos1(2) 
00457             << " " << r << " " << g << " " << b << " " << endln;
00458     }
00459 
00460     glEnd();
00461 
00462     return 0;  
00463 }
00464 
00465 
00466 
00467 int 
00468 OpenGLRenderer::drawLine(const Vector &pos1, const Vector &pos2, 
00469                          float V1, float V2, int width, int style)
00470 {
00471     // open gl does a divide by zero error if points are the same - so check
00472     if (pos1(0) == pos2(0) && pos1(1) == pos2(1) && pos1(2) == pos2(2))
00473       return 0;
00474 
00475     glLineWidth(width);
00476 
00477     glBegin(GL_LINES);
00478     float r, g, b;
00479 
00480     theMap->getRGB(V1, r, g, b);
00481     glColor3f(r,g,b);
00482 
00483     glVertex3f(pos1(0),pos1(1),pos1(2));
00484     
00485     if (theOutputFileName != 0) {
00486         theFile << "Line\n" << pos1(0) << " " << pos1(1) << " " << pos1(2) 
00487             << " " << r << " " << g << " " << b << " " << endln;
00488     }
00489 
00490     theMap->getRGB(V2, r, g, b);
00491     glColor3f(r,g,b);
00492 
00493     glVertex3f(pos2(0),pos2(1),pos2(2));
00494     glEnd();
00495 
00496     if (theOutputFileName != 0) {
00497         theFile << pos2(0) << " " << pos2(1) << " " << pos2(2) << " " << r 
00498             << " " << g << " " << b << " " << endln;
00499     }
00500 
00501     return 0;  
00502 }
00503 
00504 
00505 
00506 int 
00507 OpenGLRenderer::drawLine(const Vector &end1, const Vector &end2, 
00508                          const Vector &rgb1, const Vector &rgb2,
00509                          int width, int style)
00510 {
00511     // open gl does a divide by zero error if points are the same
00512     if (end1(0) == end2(0) && end1(1) == end2(1) && end1(2) == end2(2))
00513       return 0;
00514 
00515     glLineWidth(width);
00516 
00517     glBegin(GL_LINES);
00518     float r, g, b;
00519     r = rgb1(0);
00520     g = rgb1(1);
00521     b = rgb1(2);
00522   
00523     if (theOutputFileName != 0) {
00524         theFile << "Line\n" << end1(0) << " " << end1(1) << " " << end1(2) 
00525             << " " << r << " " << g << " " << b << " " << endln;
00526     }
00527     glColor3f(r,g,b);
00528     glVertex3f(end1(0),end1(1),end1(2));
00529 
00530     r = rgb2(0);
00531     g = rgb2(1);
00532     b = rgb2(2);
00533   
00534     if (theOutputFileName != 0) {
00535         theFile << end2(0) << " " << end2(1) << " " << end2(2) << " " << r 
00536             << " " << g << " " << b << " " << endln;
00537     }
00538     glColor3f(r,g,b);
00539 
00540     glVertex3f(end2(0),end2(1),end2(2));
00541     glEnd();
00542 
00543     return 0;
00544 }
00545 
00546 
00547 
00548 int 
00549 OpenGLRenderer::drawPolygon(const Matrix &pos, const Vector &data)
00550 
00551 {
00552 #ifdef _G3DEBUG
00553   if (pos.noCols() != 3) {
00554     opserr << "OpenGLRenderer::drawPolygon - matrix needs 3 cols\n";
00555     return -1;
00556   }
00557   if (pos.noRows() != data.Size()) {
00558     opserr << "OpenGLRenderer::drawPolygon - matrix & vector incompatable\n";
00559     return -1;
00560   }
00561 #endif
00562 
00563   double posX, posY, posZ, value;
00564   float r,g,b;
00565 
00566     glBegin(GL_POLYGON);
00567     int numRows = pos.noRows();
00568     for (int i=0; i<numRows; i++) {
00569       posX = pos(i,0);
00570       posY = pos(i,1);
00571       posZ = pos(i,2);
00572       value = data(i);
00573       theMap->getRGB(value, r, g, b);
00574 
00575     if (theOutputFileName != 0) {
00576         theFile << posX << " " << posY << " " << posZ << " " << r 
00577             << " " << g << " " << b << " " << endln;
00578     }
00579       glColor3f(r,g,b);
00580       glVertex3f(posX, posY, posZ);
00581     }
00582 
00583     glEnd();
00584 
00585     return 0;
00586 }
00587 
00588 
00589 int 
00590 OpenGLRenderer::drawPolygon(const Matrix &pos, const Matrix &rgbData)
00591 
00592 {
00593 #ifdef _G3DEBUG
00594   if (pos.noCols() != 3 || rgbData.noCols() != 3) {
00595     opserr << "OpenGLRenderer::drawPolygon - matrix needs 3 cols\n";
00596     return -1;
00597   }
00598   if (pos.noRows() != rgbData.noRows()) {
00599     opserr << "OpenGLRenderer::drawPolygon - matrix & vector incompatable\n";
00600     return -1;
00601   }
00602 #endif
00603 
00604   double posX, posY, posZ;
00605   float r,g,b;
00606 
00607     glBegin(GL_POLYGON);
00608     int numRows = pos.noRows();
00609     for (int i=0; i<numRows; i++) {
00610       posX = pos(i,0);
00611       posY = pos(i,1);
00612       posZ = pos(i,2);
00613       r = rgbData(i,0);
00614       g = rgbData(i,1);
00615       b = rgbData(i,2);
00616 
00617     if (theOutputFileName != 0) {
00618         theFile << posX << " " << posY << " " << posZ << " " << r 
00619             << " " << g << " " << b << " " << endln;
00620     }
00621       glColor3f(r,g,b);
00622       glVertex3f(posX, posY, posZ);
00623     }
00624 
00625     glEnd();
00626 
00627     return 0;
00628 }
00629 
00630 
00631 
00632 int 
00633 OpenGLRenderer::drawText(const Vector &pos, char *text, int length,
00634                          char horizontalJustify, char verticalJustify)
00635 {
00636     // add POINTs to the FACE  
00637     int size = pos.Size();
00638     float x,y,z;
00639     if (size == 1) {
00640         x = pos(0);
00641         y = 0;
00642         z = 0;
00643     } else if (size == 2) {
00644         x = pos(0);
00645         y = pos(1);
00646         z = 0;
00647     } else {
00648         x = pos(0);
00649         y = pos(1);
00650         z = pos(2);
00651     }  
00652 
00653     theDevice->drawText(x,y,z, text, length, horizontalJustify, verticalJustify);
00654 
00655     return 0;
00656 }
00657 
00658 int 
00659 OpenGLRenderer::setVRP(float x, float y, float z)
00660 {
00661   vrp(0) = x;
00662   vrp(1) = y;
00663   vrp(2) = z;
00664 
00665   return 0;
00666 }
00667 
00668 int 
00669 OpenGLRenderer::setVPN(float x, float y, float z)
00670 {
00671   vpn(0) = x;
00672   vpn(1) = y;
00673   vpn(2) = z;
00674 
00675   return 0;
00676 }
00677 
00678 int 
00679 OpenGLRenderer::setVUP(float x, float y, float z)
00680 {
00681   vuv(0) = x;
00682   vuv(1) = y;
00683   vuv(2) = z;
00684 
00685   return 0;
00686 }
00687 
00688 int 
00689 OpenGLRenderer::setViewWindow(float umin, float umax, float vmin, float vmax)
00690 {
00691   if (umin > umax || vmin > vmax) {
00692       opserr << "OpenGLRenderer::setViewWindow() - invalid window ";
00693       opserr << umin << " "<< umax << " "<< vmin << " "<< vmax << endln;
00694       return -1;
00695   }
00696 
00697   vpWindow(0) = umin;
00698   vpWindow(1) = umax;
00699   vpWindow(2) = vmin;
00700   vpWindow(3) = vmax;
00701 
00702   return 0;
00703 }
00704 
00705 int 
00706 OpenGLRenderer::setPlaneDist(float anear, float afar) 
00707 {
00708   if ((anear < afar)) {
00709       opserr << "OpenGLRenderer::setClippingPlanes() - invalid planes";
00710       opserr << anear << " " << afar << endln;
00711       return -1;
00712   }
00713 
00714   clippingPlanes[0] = anear;
00715   clippingPlanes[1] = afar;
00716 
00717   return 0;
00718 }
00719 
00720 int 
00721 OpenGLRenderer::setProjectionMode(const char *newMode)
00722 {
00723   if ((strcmp(newMode, "parallel") == 0) || (strcmp(newMode, "Parallel") == 0))
00724     projectionMode = PARALLEL_MODE;
00725   else if ((strcmp(newMode, "perspective") == 0) || (strcmp(newMode, "Perspective") == 0))
00726     projectionMode = PERSPECTIVE_MODE;
00727   return 0;
00728 }
00729 
00730 int 
00731 OpenGLRenderer::setFillMode(const char *newMode)
00732 {
00733   if ((strcmp(newMode, "wire") == 0) || (strcmp(newMode, "Wire") == 0))
00734     fillMode = WIRE_MODE;
00735   else if ((strcmp(newMode, "fill") == 0) || (strcmp(newMode, "Fill") == 0))
00736     fillMode = FILL_MODE;
00737 
00738   return 0;
00739 }
00740 
00741 // eye location
00742 int 
00743 OpenGLRenderer::setPRP(float u, float v, float n){
00744   cop(0) = u;
00745   cop(1) = v;
00746   cop(2) = n;
00747 
00748   return 0;
00749 }
00750     
00751 int 
00752 OpenGLRenderer::setPortWindow(float left, float right, 
00753                              float bottom, float top)
00754 {
00755   if (left < -1 || right > 1 || bottom < -1 || top > 1
00756       || left > right || bottom > top) {
00757       
00758       opserr << "OpenGLRenderer::setPortWindow() - bounds invalid ";
00759       opserr << left << " "<< right << " "<< bottom << " "<< top << endln;
00760       return -1;
00761   }
00762 
00763   portWindow(0) = left;
00764   portWindow(1) = right;
00765   portWindow(2) = bottom;
00766   portWindow(3) = top;
00767 
00768   return 0;
00769 }
00770 

Generated on Mon Oct 23 15:05:27 2006 for OpenSees by doxygen 1.5.0