DraWinQtGL.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 
00032 
00033 #ifndef __DRA_WIN_QT_GL_H_
00034 #define __DRA_WIN_QT_GL_H_
00035 
00036 #include <QtOpenGL/QGLWidget>
00037 #include <QSlider>
00038 #include <QToolBar>
00039 
00040 #include "DraWin.h"
00041 
00042 #include <Option.h>
00043 
00044 using namespace std;
00045 
00046 namespace MipResources{
00048  /* @{ */
00049 
00051 class DraWinGLOptions : public Options {
00052  public:
00053   
00054   IntOption* GLwidth;
00055   IntOption* GLheight;
00056   /*perspective params*/
00057   DecimalOption* GLfov;
00058   DecimalOption* GLaspratio;
00059   DecimalOption* GLzNear;
00060   DecimalOption* GLzFar;
00061   /*lookAt params*/
00062   DecimalOption* GLxEye;
00063   DecimalOption* GLyEye;
00064   DecimalOption* GLzEye;
00065   DecimalOption* GLxCenter;
00066   DecimalOption* GLyCenter;
00067   DecimalOption* GLzCenter;
00068   DecimalOption* GLxUp;
00069   DecimalOption* GLyUp;
00070   DecimalOption* GLzUp;
00071   /*bool params*/
00072   BoolOption* GLactive;
00073   BoolOption* GLmanual;
00074   BoolOption* GLincrementalBB;
00075   BoolOption* GLdisplayMVM;
00076   BoolOption* GLdisplayInfo;
00077   BoolOption* GLdisplayGrid;
00078   BoolOption* GLdisplayAxes;
00079   
00080   DraWinGLOptions();
00081 };
00082 
00084 class DraWinGLPerspective{
00085  public:
00086   Decimal fov;      
00087   Decimal aspratio; 
00088   Decimal zNear;    
00089   Decimal zFar;     
00090 };
00091 
00093 class DraWinGLLookAt{
00094  public:
00095   Decimal xEye;     
00096   Decimal yEye;     
00097   Decimal zEye;     
00098   Decimal xCenter;  
00099   Decimal yCenter;  
00100   Decimal zCenter;  
00101   Decimal xUp;      
00102   Decimal yUp;      
00103   Decimal zUp;   
00104 };
00105 
00107 class DraWinGLButtons{
00108  public:
00109   bool active;    
00110   bool manual;   
00111   bool incrementalBB;  
00112   bool displayMVM;  
00113   bool displayInfo; 
00114   bool displayGrid; 
00115   bool displayAxes; 
00116   DraWinGLButtons(){
00117    active = false;
00118    manual = false;
00119    incrementalBB = false;
00120    displayMVM = false;
00121    displayInfo = false;
00122    displayGrid = false;
00123    displayAxes = false;
00124   }
00125 };
00126 
00128 class DraWinGLVar{
00129  public:
00130   DraWinGLPerspective persp;  
00131   DraWinGLLookAt   lookAt;  
00132   DraWinGLButtons   buttons; 
00133   
00134   Decimal   MVM[16];         /* matrice omegenea della vista, aggiornata dal drawer */
00135   Decimal  actualFPS;       /*reale FPS*/
00136   unsigned int robotId;
00137   
00138   DraWinGLVar(){};
00139 };
00140 
00141 // enum LSRDraw_t{LSR_FILL, LSR_CONTOUR, LSR_CONTOUR_AND_FILL};
00142 
00144 class DraWinGL: public QGLWidget, public DraWin{
00145  Q_OBJECT
00146 
00147  private:
00149   static const ResourcePlate _plate= DW_GL_RES;
00151   void updateBB(DraWinObj* draWinObj);
00153   void setColor(Color c);
00155   void setPose2D(Pose p);
00157   void unsetPose2D();
00158   
00159   void DrawAxes();
00160   
00162   void renderBitmapString(Decimal x, Decimal y, void *font, char *string);
00164   void setOrthographicProjection(int w, int h);
00166   void resetPerspectiveProjection();
00168   void drawModelViewMatrix();
00170   void drawInfo();
00171   
00172  public:
00173   DraWinGLOptions  options; 
00174   DraWinGLVar _var;      
00175   DraWinGLVar _defaultVar;  
00176   //Thread _GLThread;    ///< thread that manages the GLWindow
00177 
00179   DraWinGL(int argc, const char* argv[]);
00180   
00182   ~DraWinGL();
00183   
00185   ResourcePlate getPlate() const {
00186    return _plate;
00187   }
00188 
00190   void getDefaultVar();
00191   
00193   bool drawingCycle(Time timeout);
00194   
00196   void drawObject(DraWinObj* draWinObj);
00197   
00199   bool execCmd(DraWinObj* draWinObj);
00200   
00202   void GLdrawPoint2D(DraWinObj* draWinObj);
00203   
00205   void GLdrawPoints2D(DraWinObj* draWinObj);
00206   
00208   void GLdrawPolygon2D(DraWinObj* draWinObj);
00209   
00211   void GLdrawSeg2D(DraWinObj* draWinObj);
00212   
00214   void GLdrawDisk2D(DraWinObj* draWinObj);
00215   
00217   void GLdrawMobRob2D(DraWinObj* draWinObj);
00218   
00220   void GLdrawHalfLine2D(DraWinObj* draWinObj);
00221 
00223   void GLexecBB2D(DraWinObj* draWinObj);
00224     
00226   void manualModelView();
00227   
00229   void autoModelView();
00230   
00232   void zNearFarControl(void);
00233 
00235   void updateModelViewMatrix();
00236   
00238   void drawText();
00239   
00241   void defaultView(int width, int height);
00242   
00243 //   void resetBB(void);
00244 //   ///
00245 //   void printBB(void);
00246 
00247   QSize minimumSizeHint() const;
00248   QSize sizeHint() const;
00249 
00250  public slots:
00251   void setXRotation(int angle);
00252   void setYRotation(int angle);
00253   void setZRotation(int angle);
00254       
00255   void increaseZ();
00256   void decreaseZ();
00257   void stopZ();
00258   void increaseY();
00259   void decreaseY();
00260   void stopY();
00261   void increaseX();
00262   void decreaseX();
00263   void stopX();
00264   void manual();
00265   void grid();
00266   
00267  signals:
00268    void xRotationChanged(int angle);
00269    void yRotationChanged(int angle);
00270    void zRotationChanged(int angle);
00271 
00272  protected:
00273   void initializeGL();
00274   void paintGL();
00275   void resizeGL(int width, int height);
00276   void mousePressEvent(QMouseEvent *event);
00277   void mouseMoveEvent(QMouseEvent *event);
00278 
00279  private:
00280   GLuint makeObject();
00281   void normalizeAngle(int *angle);
00282 
00283   GLuint object;
00284   int xRot;
00285   int yRot;
00286   int zRot;
00287   QPoint lastPos;
00288   QColor green;
00289   QColor white;
00290 };
00291 
00292 
00294 class DraWinGLWindow : public QWidget{
00295   Q_OBJECT
00296 
00297 public:
00298   DraWinGLWindow(DraWinGL *dGL);
00299   
00300   void fillToolBar(QToolBar *);
00301   
00302   QSize sizeHint() const;
00303 private:
00304   QSlider *createSlider();
00305   QWidget *createButtons();
00306 
00307   DraWinGL *glWidget;
00308   QSlider *xSlider;
00309   QSlider *ySlider;
00310   QSlider *zSlider;
00311   
00312   QWidget *buttons;
00313 };
00314 
00315 
00316  /* @} */
00317  
00318 };// end namespace MipResources{
00319 
00320 
00321 #endif
00322 

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