include/GLWindow.h
Go to the documentation of this file.
00001 #ifndef __GL_WINDOW_H__
00002 #define __GL_WINDOW_H__
00003 
00004 #include <ngl/Camera.h>
00005 #include <QtOpenGL>
00006 #include <ngl/TransformStack.h>
00007 #include <ngl/Vec3.h>
00008 #include <ngl/Obj.h>
00009 #include <ngl/VAOPrimitives.h>
00010 #include <ngl/Text.h>
00011 #include <ngl/Material.h>
00012 
00013 
00014 #include "SmokeSystem.h"
00015 
00017 //----------------------------------------------------------------------------------------------------------------------
00018 const static float INCREMENT=0.05;
00019 //----------------------------------------------------------------------------------------------------------------------
00021 //----------------------------------------------------------------------------------------------------------------------
00022 const static float ZOOM=1.0;
00023 
00034 class GLWindow : public QGLWidget
00035 {
00036 Q_OBJECT        // must include this if you use Qt signals/slots
00037 public :
00040   GLWindow(
00041            QWidget *_parent
00042           );
00044         ~GLWindow();
00045 
00046   //----------------------------------------------------------------------------------------------------------------------
00048   //----------------------------------------------------------------------------------------------------------------------
00049   inline void decTime(){m_time-=m_timeStep;}
00050   //----------------------------------------------------------------------------------------------------------------------
00052   //----------------------------------------------------------------------------------------------------------------------
00053   void displayScreenText();
00054   //----------------------------------------------------------------------------------------------------------------------
00056   //----------------------------------------------------------------------------------------------------------------------
00057   void drawInWireframe();
00058   //----------------------------------------------------------------------------------------------------------------------
00060   //----------------------------------------------------------------------------------------------------------------------
00061   void drawSmokeSprites();
00062   //----------------------------------------------------------------------------------------------------------------------
00064   //----------------------------------------------------------------------------------------------------------------------
00065   void drawVelocityField();
00066   //----------------------------------------------------------------------------------------------------------------------
00068   //----------------------------------------------------------------------------------------------------------------------
00069   void drawVoxelGrid();
00070   //----------------------------------------------------------------------------------------------------------------------
00072   //----------------------------------------------------------------------------------------------------------------------
00073   void drawObstacle();
00074   //----------------------------------------------------------------------------------------------------------------------
00077   //----------------------------------------------------------------------------------------------------------------------
00078   inline SmokeSystem* getSmokeSystem() { return m_smokeSystem; }
00079   //----------------------------------------------------------------------------------------------------------------------
00081   //----------------------------------------------------------------------------------------------------------------------
00082   inline void incTime(){m_time+=m_timeStep;}
00083   //----------------------------------------------------------------------------------------------------------------------
00085   //----------------------------------------------------------------------------------------------------------------------
00086   void initLight();
00087   //----------------------------------------------------------------------------------------------------------------------
00090   //----------------------------------------------------------------------------------------------------------------------
00091   void initPhongShader(
00092                         ngl::Material & _m
00093                       );
00094   //----------------------------------------------------------------------------------------------------------------------
00096   //----------------------------------------------------------------------------------------------------------------------
00097   void initPointSpriteShader();
00098   //----------------------------------------------------------------------------------------------------------------------
00100   //----------------------------------------------------------------------------------------------------------------------
00101   void initTextureShader();
00102   //----------------------------------------------------------------------------------------------------------------------
00104   //----------------------------------------------------------------------------------------------------------------------
00105   void moveEmitter();
00106   //----------------------------------------------------------------------------------------------------------------------
00110   //----------------------------------------------------------------------------------------------------------------------
00111   void processKeyDown(
00112                       QKeyEvent *_event
00113                      );
00114   //----------------------------------------------------------------------------------------------------------------------
00118   //----------------------------------------------------------------------------------------------------------------------
00119   void processKeyUp(
00120                     QKeyEvent *_event
00121                     );
00122   //----------------------------------------------------------------------------------------------------------------------
00124   //----------------------------------------------------------------------------------------------------------------------
00125   inline void resetTime(){m_time=0.0;}
00126   //----------------------------------------------------------------------------------------------------------------------
00128   //----------------------------------------------------------------------------------------------------------------------
00129   inline void toggleAnimation(){m_animate^=true;}
00130   //----------------------------------------------------------------------------------------------------------------------
00132   //----------------------------------------------------------------------------------------------------------------------
00133   void updateTransformStack();
00134   //----------------------------------------------------------------------------------------------------------------------
00136   //----------------------------------------------------------------------------------------------------------------------
00137   void updateUI();
00138 
00139 public slots :
00140   //----------------------------------------------------------------------------------------------------------------------
00142   //----------------------------------------------------------------------------------------------------------------------
00143   inline void reset() { m_smokeSystem->reset(); }
00144   //----------------------------------------------------------------------------------------------------------------------
00146   //----------------------------------------------------------------------------------------------------------------------
00147   void resetToDefaultValues();
00148   //---------------------------------------------------------------------------------------------------------------------
00151   //----------------------------------------------------------------------------------------------------------------------
00152   inline void setAbsoluteTolerance(
00153                                       double _val
00154                                      ) { m_smokeSystem->setAbsoluteTolerance(_val); }
00155   //----------------------------------------------------------------------------------------------------------------------
00158   //----------------------------------------------------------------------------------------------------------------------
00159   void setBoundaryCondition(
00160                             int _mode
00161                            );
00162   //---------------------------------------------------------------------------------------------------------------------
00165   //----------------------------------------------------------------------------------------------------------------------
00166   inline void setEmitDensityRate(
00167                                   double _val
00168                                  ) { m_smokeSystem->getEmitter()->setEmitDensityRate(_val); }
00169   //---------------------------------------------------------------------------------------------------------------------
00172   //----------------------------------------------------------------------------------------------------------------------
00173   inline void setEmitTemperatureRate(
00174                                       double _val
00175                                      ) { m_smokeSystem->getEmitter()->setEmitTemperatureRate(_val); }
00176   //---------------------------------------------------------------------------------------------------------------------
00179   //----------------------------------------------------------------------------------------------------------------------
00180   void setEmitterSize(
00181                       double _val
00182                      );
00183   //---------------------------------------------------------------------------------------------------------------------
00186   //----------------------------------------------------------------------------------------------------------------------
00187   void setEmitterSize(
00188                       int _val
00189                      );
00190   //----------------------------------------------------------------------------------------------------------------------
00193   //----------------------------------------------------------------------------------------------------------------------
00194   inline void setGravity(
00195                           double _val
00196                          ) { m_smokeSystem->setGravity(_val); }
00197   //----------------------------------------------------------------------------------------------------------------------
00200   //----------------------------------------------------------------------------------------------------------------------
00201   void setGridBaseRes(
00202                       int _res
00203                      );
00204   //----------------------------------------------------------------------------------------------------------------------
00207   //----------------------------------------------------------------------------------------------------------------------
00208   void setGridLengthX(
00209                       double _length
00210                      );
00211   //----------------------------------------------------------------------------------------------------------------------
00214   //----------------------------------------------------------------------------------------------------------------------
00215   void setGridLengthY(
00216                       double _length
00217                      );
00218   //----------------------------------------------------------------------------------------------------------------------
00221   //----------------------------------------------------------------------------------------------------------------------
00222   void setGridLengthZ(
00223                       double _length
00224                      );
00225   //----------------------------------------------------------------------------------------------------------------------
00228   //----------------------------------------------------------------------------------------------------------------------
00229   inline void setH(
00230                     double _val
00231                    ) { m_smokeSystem->setH(_val); }
00232   //---------------------------------------------------------------------------------------------------------------------
00235   //----------------------------------------------------------------------------------------------------------------------
00236   inline void setKDensityDiss(
00237                               double _val
00238                              ) { m_smokeSystem->setKDensityDiss(_val); }
00239   //----------------------------------------------------------------------------------------------------------------------
00242   //----------------------------------------------------------------------------------------------------------------------
00243   inline void setKFall(
00244                         double _val
00245                        ) { m_smokeSystem->setKFall(_val); }
00246   //----------------------------------------------------------------------------------------------------------------------
00249   //----------------------------------------------------------------------------------------------------------------------
00250   inline void setKRise(
00251                         double _val
00252                        ) { m_smokeSystem->setKRise(_val); }
00253   //----------------------------------------------------------------------------------------------------------------------
00256   //----------------------------------------------------------------------------------------------------------------------
00257   inline void setKTemperDiss(
00258                               double _val
00259                              ) { m_smokeSystem->setKTemperDiss(_val); }
00260   //----------------------------------------------------------------------------------------------------------------------
00263   //----------------------------------------------------------------------------------------------------------------------
00264   inline void setKVorticity(
00265                             double _val
00266                            ) { m_smokeSystem->setKVorticity(_val); }
00267   //----------------------------------------------------------------------------------------------------------------------
00270   //----------------------------------------------------------------------------------------------------------------------
00271   inline void setMaxFPS(
00272                         double _fps
00273                        ) { setTimeStep(1.0/_fps); }
00274   //----------------------------------------------------------------------------------------------------------------------
00277   //----------------------------------------------------------------------------------------------------------------------
00278   inline void setNoiseFrequency(
00279                                 double _val
00280                                ) { m_smokeSystem->getNoiseModule()->SetFrequency(_val); }
00281   //----------------------------------------------------------------------------------------------------------------------
00284   //----------------------------------------------------------------------------------------------------------------------
00285   inline void setNoiseMagnitude(
00286                                 double _val
00287                                ) { m_smokeSystem->setNoiseMagnitude(_val); }
00288   //----------------------------------------------------------------------------------------------------------------------
00291   //----------------------------------------------------------------------------------------------------------------------
00292   inline void setNoiseOctaveCount(
00293                                   double _val
00294                                  ) { m_smokeSystem->getNoiseModule()->SetOctaveCount(_val); }
00295   //----------------------------------------------------------------------------------------------------------------------
00298   //----------------------------------------------------------------------------------------------------------------------
00299   inline void setNoisePersistence(
00300                                   double _val
00301                                  ) { m_smokeSystem->getNoiseModule()->SetPersistence(_val); }
00302   //----------------------------------------------------------------------------------------------------------------------
00305   //----------------------------------------------------------------------------------------------------------------------
00306   inline void setNoiseSpeed(
00307                             double _val
00308                            ) { m_smokeSystem->setNoiseSpeed(_val); }
00309   //----------------------------------------------------------------------------------------------------------------------
00312   //----------------------------------------------------------------------------------------------------------------------
00313   void setObstacle(
00314                     int _mode
00315                    );
00316   //----------------------------------------------------------------------------------------------------------------------
00319   //----------------------------------------------------------------------------------------------------------------------
00320   inline void setOpacityStrength(
00321                                  int _val
00322                                 ) { m_smokeSystem->setOpacityStrength((float)_val); }
00323   //----------------------------------------------------------------------------------------------------------------------
00326   //----------------------------------------------------------------------------------------------------------------------
00327   inline void setPrecisionX(
00328                             int _precision
00329                            ) { m_smokeSystem->setPrecisionX(_precision); }
00330   //----------------------------------------------------------------------------------------------------------------------
00333   //----------------------------------------------------------------------------------------------------------------------
00334   inline void setPrecisionY(
00335                             int _precision
00336                            ) { m_smokeSystem->setPrecisionY(_precision); }
00337   //----------------------------------------------------------------------------------------------------------------------
00340   //----------------------------------------------------------------------------------------------------------------------
00341   inline void setPrecisionZ(
00342                             int _precision
00343                            ) { m_smokeSystem->setPrecisionZ(_precision); }
00344   //---------------------------------------------------------------------------------------------------------------------
00347   //----------------------------------------------------------------------------------------------------------------------
00348   inline void setRelaxationRate(
00349                                 double _val
00350                                ) { m_smokeSystem->setRelaxationRate(_val); }
00351   //----------------------------------------------------------------------------------------------------------------------
00354   //----------------------------------------------------------------------------------------------------------------------
00355   inline void setShadowStrength(
00356                                  int _val
00357                                 ) { m_smokeSystem->setShadowStrength((float)_val); }
00358   //----------------------------------------------------------------------------------------------------------------------
00361   //----------------------------------------------------------------------------------------------------------------------
00362   inline void setSpriteSize(
00363                              int _size
00364                            ) { m_spriteSize = _size; }
00365   //----------------------------------------------------------------------------------------------------------------------
00368   //----------------------------------------------------------------------------------------------------------------------
00369   void setTimeStep(
00370                     double _dt
00371                    );
00372   //----------------------------------------------------------------------------------------------------------------------
00375   //----------------------------------------------------------------------------------------------------------------------
00376   inline void setViscosity(
00377                             double _val
00378                            ) { m_smokeSystem->setViscosity(_val); }
00379   //----------------------------------------------------------------------------------------------------------------------
00382   //----------------------------------------------------------------------------------------------------------------------
00383   inline void toggleDepthTest(
00384                                bool _mode
00385                               ) { m_depthTestEnabled = _mode; }
00386   //----------------------------------------------------------------------------------------------------------------------
00389   //----------------------------------------------------------------------------------------------------------------------
00390   inline void toggleTemperature(
00391                                  bool _mode
00392                                 ) { m_showTemperature = _mode; }
00393   //----------------------------------------------------------------------------------------------------------------------
00396   //----------------------------------------------------------------------------------------------------------------------
00397   inline void toggleVelocityArrows(
00398                                    bool _mode
00399                                   ) { m_showVelocityArrows = _mode; }
00400   //----------------------------------------------------------------------------------------------------------------------
00403   //----------------------------------------------------------------------------------------------------------------------
00404   inline void toggleVoxelGrid(
00405                                bool _mode
00406                               ) { m_showVoxelGrid = _mode; }
00407   //----------------------------------------------------------------------------------------------------------------------
00410   //----------------------------------------------------------------------------------------------------------------------
00411   inline void toggleWireframe(
00412                                bool _mode
00413                               ){ m_wireframe=_mode; }
00414 signals:
00415 
00416   //----------------------------------------------------------------------------------------------------------------------
00420   //----------------------------------------------------------------------------------------------------------------------
00421   void setUIBuoyancyValues(
00422                             float _kRise,
00423                             float _kFall
00424                           );
00425   //----------------------------------------------------------------------------------------------------------------------
00429   //----------------------------------------------------------------------------------------------------------------------
00430   void setUIDissipationValues(
00431                               float _kDensityDiss,
00432                               float _kTemperDiss
00433                             );
00434   //----------------------------------------------------------------------------------------------------------------------
00440   //----------------------------------------------------------------------------------------------------------------------
00441   void setUIEmitterValues(
00442                             ngl::Vec3 _emitterLoc,
00443                             float _emitterSize,
00444                             float _emitDensityRate,
00445                             float _emitTemperatureRate
00446                           );
00447   //----------------------------------------------------------------------------------------------------------------------
00452   //----------------------------------------------------------------------------------------------------------------------
00453   void setUIFluidValues(
00454                         float _viscosity,
00455                         float _gravity,
00456                         float _kVorticity
00457                       );
00458   //----------------------------------------------------------------------------------------------------------------------
00460   //----------------------------------------------------------------------------------------------------------------------
00461   void setUIObstacleValues();
00462   //----------------------------------------------------------------------------------------------------------------------
00469   //----------------------------------------------------------------------------------------------------------------------
00470   void setUINoiseValues(
00471                           float _frequency,
00472                           float _octaveCount,
00473                           float _persistence,
00474                           float _speed,
00475                           float _magnitude
00476                         );
00477   //----------------------------------------------------------------------------------------------------------------------
00481   //----------------------------------------------------------------------------------------------------------------------
00482   void setUIPressureValues(
00483                             float _absoluteTolerance,
00484                             float _relaxationRate
00485                           );
00486   //----------------------------------------------------------------------------------------------------------------------
00491   //----------------------------------------------------------------------------------------------------------------------
00492   void setUISpriteValues(
00493                             int _spriteSize,
00494                             float _opacityStrength,
00495                             float _shadowStrength
00496                           );
00497   //----------------------------------------------------------------------------------------------------------------------
00501   //----------------------------------------------------------------------------------------------------------------------
00502   void setUITimeValues(
00503                         float _timeStep,
00504                         float _maxFPS
00505                       );
00506   //----------------------------------------------------------------------------------------------------------------------
00517   //----------------------------------------------------------------------------------------------------------------------
00518   void setUIVoxelGridValues(
00519                             float _gridLengthX,
00520                             float _gridLengthY,
00521                             float _gridLengthZ,
00522                             int _gridBaseRes,
00523                             int _gridPrecisionX,
00524                             int _gridPrecisionY,
00525                             int _gridPrecisionZ,
00526                             float _h,
00527                             BOUNDARYCONDITION _condition
00528                           );
00529 
00530 
00531 
00532 private :
00533   //----------------------------------------------------------------------------------------------------------------------
00535   //----------------------------------------------------------------------------------------------------------------------
00536   bool m_animate;
00537   //----------------------------------------------------------------------------------------------------------------------
00539   //----------------------------------------------------------------------------------------------------------------------
00540   bool m_depthTestEnabled;
00541   //----------------------------------------------------------------------------------------------------------------------
00543   //----------------------------------------------------------------------------------------------------------------------
00544   QTime m_currentTime;
00545   //----------------------------------------------------------------------------------------------------------------------
00547   //----------------------------------------------------------------------------------------------------------------------
00548   int m_gridBaseRes;
00549   //----------------------------------------------------------------------------------------------------------------------
00551   //----------------------------------------------------------------------------------------------------------------------
00552   float m_gridLengthX;
00553   //----------------------------------------------------------------------------------------------------------------------
00555   //----------------------------------------------------------------------------------------------------------------------
00556   float m_gridLengthY;
00557   //----------------------------------------------------------------------------------------------------------------------
00559   //----------------------------------------------------------------------------------------------------------------------
00560   float m_gridLengthZ;
00561   //----------------------------------------------------------------------------------------------------------------------
00563   //----------------------------------------------------------------------------------------------------------------------
00564   QSet<Qt::Key> m_keysPressed;
00565   //----------------------------------------------------------------------------------------------------------------------
00567   //----------------------------------------------------------------------------------------------------------------------
00568   ngl::Vec3 m_modelPos;
00569   //----------------------------------------------------------------------------------------------------------------------
00571   //----------------------------------------------------------------------------------------------------------------------
00572   int m_origX;
00573   //----------------------------------------------------------------------------------------------------------------------
00575   //----------------------------------------------------------------------------------------------------------------------
00576   int m_origXPos;
00577   //----------------------------------------------------------------------------------------------------------------------
00579   //----------------------------------------------------------------------------------------------------------------------
00580   int m_origY;
00581   //----------------------------------------------------------------------------------------------------------------------
00583   //----------------------------------------------------------------------------------------------------------------------
00584   int m_origYPos;
00585   //----------------------------------------------------------------------------------------------------------------------
00587   //----------------------------------------------------------------------------------------------------------------------
00588   int m_precisionX;
00589   //----------------------------------------------------------------------------------------------------------------------
00591   //----------------------------------------------------------------------------------------------------------------------
00592   int m_precisionY;
00593   //----------------------------------------------------------------------------------------------------------------------
00595   //----------------------------------------------------------------------------------------------------------------------
00596   int m_precisionZ;
00597   //----------------------------------------------------------------------------------------------------------------------
00599   //----------------------------------------------------------------------------------------------------------------------
00600   bool m_rotate;
00601   //----------------------------------------------------------------------------------------------------------------------
00603   //----------------------------------------------------------------------------------------------------------------------
00604   float m_scale;
00605   //----------------------------------------------------------------------------------------------------------------------
00607   //----------------------------------------------------------------------------------------------------------------------
00608   SmokeSystem* m_smokeSystem;
00609   //----------------------------------------------------------------------------------------------------------------------
00611   //----------------------------------------------------------------------------------------------------------------------
00612   int m_spinXFace;
00613   //----------------------------------------------------------------------------------------------------------------------
00615   //----------------------------------------------------------------------------------------------------------------------
00616   int m_spinYFace;
00617   //----------------------------------------------------------------------------------------------------------------------
00619   //----------------------------------------------------------------------------------------------------------------------
00620   bool m_showTemperature;
00621   //----------------------------------------------------------------------------------------------------------------------
00623   //----------------------------------------------------------------------------------------------------------------------
00624   bool m_showVelocityArrows;
00625   //----------------------------------------------------------------------------------------------------------------------
00627   //----------------------------------------------------------------------------------------------------------------------
00628   bool m_showVoxelGrid;
00629   //----------------------------------------------------------------------------------------------------------------------
00631   //----------------------------------------------------------------------------------------------------------------------
00632   int m_spriteSize;
00633   //----------------------------------------------------------------------------------------------------------------------
00635   //----------------------------------------------------------------------------------------------------------------------
00636   ngl::Text *m_text;
00637   //----------------------------------------------------------------------------------------------------------------------
00639   //----------------------------------------------------------------------------------------------------------------------
00640   float m_time;
00641   //----------------------------------------------------------------------------------------------------------------------
00643   //----------------------------------------------------------------------------------------------------------------------
00644   float m_timeStep;
00645   //----------------------------------------------------------------------------------------------------------------------
00647   //----------------------------------------------------------------------------------------------------------------------
00648   int m_timer;
00649   //----------------------------------------------------------------------------------------------------------------------
00651   //----------------------------------------------------------------------------------------------------------------------
00652   float m_timerVal;
00653   //----------------------------------------------------------------------------------------------------------------------
00655   //----------------------------------------------------------------------------------------------------------------------
00656   bool m_translate;
00657   //----------------------------------------------------------------------------------------------------------------------
00659   //----------------------------------------------------------------------------------------------------------------------
00660   bool m_wireframe;
00661 
00662 protected:
00663 
00666   void initializeGL();
00667 
00671   void resizeGL(
00672                 const int _w,
00673                 const int _h
00674                );
00676   // be re-drawn
00677   void paintGL();
00678 
00680         ngl::Camera *m_camera;
00682         ngl::TransformStack m_transformStack;
00683 private :
00686 
00687   void mouseMoveEvent (
00688                        QMouseEvent * _event
00689                       );
00693 
00694   void mousePressEvent (
00695                         QMouseEvent *_event
00696                        );
00697 
00701   void mouseReleaseEvent (
00702                           QMouseEvent *_event
00703                          );
00704 
00705   //----------------------------------------------------------------------------------------------------------------------
00709   //----------------------------------------------------------------------------------------------------------------------
00710   void wheelEvent(
00711                     QWheelEvent *_event
00712                  );
00713 
00714   //----------------------------------------------------------------------------------------------------------------------
00718   //----------------------------------------------------------------------------------------------------------------------
00719   void timerEvent(
00720                     QTimerEvent *
00721                  );
00722 
00723   void loadMatricesToShader(
00724                              ngl::TransformStack &_tx
00725                            );
00726 
00727 
00728 };
00729 
00730 #endif
 All Classes Files Functions Variables