DraWinGL.h

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 //
00003 // $Id$
00004 //
00005 // Copyright 2008, 2009, 2010, 2011, 2012  Antonio Franchi and Paolo Stegagno    
00006 //
00007 // This file is part of MIP.
00008 //
00009 // MIP is free software: you can redistribute it and/or modify
00010 // it under the terms of the GNU General Public License as published by
00011 // the Free Software Foundation, either version 3 of the License, or
00012 // (at your option) any later version.
00013 //
00014 // MIP is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with MIP. If not, see <http://www.gnu.org/licenses/>.
00021 //
00022 // Contact info: antonio.franchi@tuebingen.mpg.de stegagno@diag.uniroma1.it
00023 //
00024 // ----------------------------------------------------------------------------
00025 
00026 
00027 
00033 
00034 #ifndef __DRA_WIN_GL_H_
00035 #define __DRA_WIN_GL_H_
00036 
00037 #ifdef FOUND_GLUT_LIBS
00038  #include <GL/glut.h>
00039 #endif
00040 
00041 #include "DraWin.h"
00042 
00043 #include <Option.h>
00044 
00045 using namespace std;
00046 
00047 
00048 namespace MipResources{
00050  /* @{ */
00051 
00052 
00055 class DraWinGLOptions : public Options {
00056  public:
00057   
00058   IntOption* GLwidth;
00059   IntOption* GLheight;
00060   /*perspective params*/
00061   DecimalOption* GLfov;
00062   DecimalOption* GLaspratio;
00063   DecimalOption* GLzNear;
00064   DecimalOption* GLzFar;
00065   /*lookAt params*/
00066   DecimalOption* GLxEye;
00067   DecimalOption* GLyEye;
00068   DecimalOption* GLzEye;
00069   DecimalOption* GLxCenter;
00070   DecimalOption* GLyCenter;
00071   DecimalOption* GLzCenter;
00072   DecimalOption* GLxUp;
00073   DecimalOption* GLyUp;
00074   DecimalOption* GLzUp;
00075   /*bool params*/
00076   BoolOption* GLactive;
00077   BoolOption* GLmanual;
00078   BoolOption* GLincrementalBB;
00079   BoolOption* GLdisplayMVM;
00080   BoolOption* GLdisplayInfo;
00081   BoolOption* GLdisplayGrid;
00082   BoolOption* GLdisplayAxes;
00083   DraWinGLOptions(){
00084 
00085    GLwidth  = createIntOption(string("GLwidth"),string("GL Windows width"),400);
00086    GLheight = createIntOption(string("GLheight"),string("GL Windows height"),400);
00087    GLfov    = createDecimalOption(string("GLfov"),string("GL Field of view"),45.0);
00088    GLaspratio = createDecimalOption(string("GLaspratio"),string("GL aspect ratio"),1.0);
00089    GLzNear   = createDecimalOption(string("GLzNear"),string("GLzNear"),0.05);
00090    GLzFar   = createDecimalOption(string("GLzFar"),string("GLzFar"),100.0);
00091    GLxEye   = createDecimalOption(string("GLxEye"),string("GLxEye"),0.0);
00092    GLyEye   = createDecimalOption(string("GLyEye"),string("GLyEye"),0.0);
00093    GLzEye   = createDecimalOption(string("GLzEye"),string("GLzEye"),2.0);
00094    GLxCenter  = createDecimalOption(string("GLxCenter"),string("GLxCenter"),0.0);
00095    GLyCenter  = createDecimalOption(string("GLyCenter"),string("GLyCenter"),0.0);
00096    GLzCenter  = createDecimalOption(string("GLzCenter"),string("GLzCenter"),0.0);
00097    GLxUp    = createDecimalOption(string("GLxUp"),string("GLxUp"),0.0);
00098    GLyUp    = createDecimalOption(string("GLyUp"),string("GLyUp"),1.0);
00099    GLzUp    = createDecimalOption(string("GLzUp"),string("GLzUp"),0.0);
00100    GLactive    = createBoolOption(string("GLactive"),string("GLactive"),true);
00101    GLmanual    = createBoolOption(string("GLmanual"),string("GLmanual"),false);
00102    GLincrementalBB = createBoolOption(string("GLincrementalBB"),string("GLincrementalBB"),false);
00103    GLdisplayMVM  = createBoolOption(string("GLdisplayMVM"),string("GLdisplayMVM"),false);
00104    GLdisplayInfo  = createBoolOption(string("GLdisplayInfo"),string("GLdisplayInfo"),false);
00105    GLdisplayGrid  = createBoolOption(string("GLdisplayGrid"),string("GLdisplayGrid"),false);
00106    GLdisplayAxes  = createBoolOption(string("GLdisplayAxes"),string("GLdisplayAxes"),false);
00107    
00108    updateValues();
00109 
00110   }
00111 
00112   string getObjectName() const {
00113    return "DraWinGLOptions";
00114   }
00115 };
00116 
00119 class DraWinGLPerspective{
00120  public:
00121   Decimal fov;      
00122   Decimal aspratio; 
00123   Decimal zNear;    
00124   Decimal zFar;     
00125 };
00126 
00129 class DraWinGLLookAt{
00130  public:
00131   Decimal xEye;     
00132   Decimal yEye;     
00133   Decimal zEye;     
00134   Decimal xCenter;  
00135   Decimal yCenter;  
00136   Decimal zCenter;  
00137   Decimal xUp;      
00138   Decimal yUp;      
00139   Decimal zUp;   
00140 };
00141 
00144 class DraWinGLButtons{
00145  public:
00146   bool active;    
00147   bool manual;   
00148   bool incrementalBB;  
00149   bool displayMVM;  
00150   bool displayInfo; 
00151   bool displayGrid; 
00152   bool displayAxes; 
00153   DraWinGLButtons(){
00154    active = false;
00155    manual = false;
00156    incrementalBB = false;
00157    displayMVM = false;
00158    displayInfo = false;
00159    displayGrid = false;
00160    displayAxes = false;
00161   }
00162 };
00163 
00166 class DraWinGLVar{  
00167  public:
00168   DraWinGLPerspective persp;  
00169   DraWinGLLookAt   lookAt;  
00170   DraWinGLButtons   buttons; 
00171   
00172   Decimal   MVM[16];         /* matrice omegenea della vista, aggiornata dal drawer */
00173   Decimal  actualFPS;       /*reale FPS*/
00174   unsigned int robotId;
00175   
00176   DraWinGLVar(){};
00177 };
00178 
00179 // enum LSRDraw_t{LSR_FILL, LSR_CONTOUR, LSR_CONTOUR_AND_FILL};
00180 
00181 class DraWinGL: public DraWin{
00182  private:
00184   static const ResourcePlate _plate= DW_GL_RES;
00186   void updateBB(DraWinObj* draWinObj);
00188   void setColor(Color c);
00190   void setPose2D(Pose p);
00192   void unsetPose2D();
00193   
00195   void renderBitmapString(Decimal x, Decimal y, void *font, char *string);
00197   void setOrthographicProjection(int w, int h);
00199   void resetPerspectiveProjection();
00201   void drawModelViewMatrix();
00203   void drawInfo();
00204   
00205  public:
00206   DraWinGLOptions  options; 
00207   DraWinGLVar _var;     
00208   DraWinGLVar _defaultVar; 
00209   Thread _GLThread;    
00210 
00212   DraWinGL(int argc, const char* argv[]);
00214   ~DraWinGL();
00216   ResourcePlate getPlate() const {
00217    return _plate;
00218   }
00219 
00221   void getDefaultVar();
00222   
00224   bool drawingCycle(Time timeout);
00226   void drawObject(DraWinObj* draWinObj);
00228   bool execCmd(DraWinObj* draWinObj);
00230   void GLdrawPoint2D(DraWinObj* draWinObj);
00232   void GLdrawPoints2D(DraWinObj* draWinObj);
00234   void GLdrawPolygon2D(DraWinObj* draWinObj);
00236   void GLdrawSeg2D(DraWinObj* draWinObj);
00238   void GLdrawDisk2D(DraWinObj* draWinObj);
00240   void GLdrawMobRob2D(DraWinObj* draWinObj);
00242   void GLdrawKhepera2D(DraWinObj* draWinObj);
00244   void GLdrawQuad3D(DraWinObj* draWinObj);
00246   void GLdrawPar3D(DraWinObj* draWinObj);
00248   void GLdrawHalfLine2D(DraWinObj* draWinObj);
00250   void GLdrawCovEllipse2D(DraWinObj* draWinObj);
00251 
00253   void GLexecBB2D(DraWinObj* draWinObj);
00254     
00256   void autoModelView();
00257 
00259   void updateModelViewMatrix();
00261   void drawText();
00263   void drawPar3D(double x0, double x1, double y0, double y1,double z0, double z1, double red=0, double green=0, double blue=0);
00265 //   void resetBB(void);
00266 //   ///
00267 //   void printBB(void);
00268 };
00269 
00270  /* @} */
00271  
00272 };// end namespace MipResources{
00273 
00274 
00275 #endif
00276 

Generated on Mon Feb 20 07:01:07 2017 for MIP by  doxygen 1.5.6