00001 #ifndef __GL_WINDOW_H__ 00002 #define __GL_WINDOW_H__ 00003 00004 00005 #include <ngl/Camera.h> 00006 #include <ngl/Colour.h> 00007 #include <ngl/TransformStack.h> 00008 #include "Cloth.h" 00009 // must be included after our stuff becuase GLEW needs to be first 00010 #include <QtOpenGL> 00011 #include "Environment.h" 00012 #include "FilesManager.h" 00013 #include <ngl/Light.h> 00014 #include "QStringList" 00015 #include "QFileDialog" 00016 #include "QString" 00017 00018 00019 00020 //---------------------------------------------------------------------------------------------------------------------- 00031 //---------------------------------------------------------------------------------------------------------------------- 00032 class GLWindow : public QGLWidget 00033 { 00034 Q_OBJECT // must include this if you use Qt signals/slots 00035 public : 00036 //---------------------------------------------------------------------------------------------------------------------- 00040 //---------------------------------------------------------------------------------------------------------------------- 00041 GLWindow( 00042 int _timer, 00043 QWidget *_parent 00044 ); 00045 //---------------------------------------------------------------------------------------------------------------------- 00047 //---------------------------------------------------------------------------------------------------------------------- 00048 ~GLWindow(); 00049 00050 void CreateLights(); 00052 ngl::Light m_LightList[3]; 00053 00055 inline void resetPos(){ m_modelPos.set(0,0,0,1);} 00056 00057 //---------------------------------------------------------------------------------------------------------------------- 00059 //---------------------------------------------------------------------------------------------------------------------- 00060 void startSimTimer(); 00061 //---------------------------------------------------------------------------------------------------------------------- 00063 //---------------------------------------------------------------------------------------------------------------------- 00064 void stopSimTimer(); 00065 //---------------------------------------------------------------------------------------------------------------------- 00069 //---------------------------------------------------------------------------------------------------------------------- 00070 std::string resetScene(float _size, 00071 int _massesNum, 00072 float _damping, 00073 float _sprinDamping, 00074 float _timeStep, 00075 float _gravity, 00076 float _stiffeness, 00077 float _criticalDistance, 00078 float _friction, 00079 float _bumpiness 00080 ); 00081 00082 //---------------------------------------------------------------------------------------------------------------------- 00085 void createCube( 00086 GLfloat _scale 00087 ); 00088 void loadTexture(); 00089 00090 00091 Environment* m_environment; 00092 FilesManager* m_fileManager; 00093 00094 bool activeMassIsSet; 00095 00096 //---------------------------------------------------------------------------------------------------------------------- 00098 //---------------------------------------------------------------------------------------------------------------------- 00099 std::string loadFile(); 00100 00101 00102 //---------------------------------------------------------------------------------------------------------------------- 00104 //---------------------------------------------------------------------------------------------------------------------- 00105 std::string loadAnimation(); 00106 00107 void clearAll(); 00108 00109 00110 00111 public slots : 00112 //---------------------------------------------------------------------------------------------------------------------- 00115 //---------------------------------------------------------------------------------------------------------------------- 00116 inline void setTimerDuration(int _v){m_timerValue=_v;} 00117 00120 void IntegrationMethodChanged(QString _integrationMethod); 00121 00122 //---------------------------------------------------------------------------------------------------------------------- 00125 //---------------------------------------------------------------------------------------------------------------------- 00126 void setDamping(int _damping); 00127 00128 //---------------------------------------------------------------------------------------------------------------------- 00131 //---------------------------------------------------------------------------------------------------------------------- 00132 void setSpringDamping(int _damping); 00133 00134 //---------------------------------------------------------------------------------------------------------------------- 00137 //---------------------------------------------------------------------------------------------------------------------- 00138 void setIsEuler(bool _isEuler); 00139 00140 //---------------------------------------------------------------------------------------------------------------------- 00143 //---------------------------------------------------------------------------------------------------------------------- 00144 void setConstraint1Active(bool _isActive); 00145 //---------------------------------------------------------------------------------------------------------------------- 00148 //---------------------------------------------------------------------------------------------------------------------- 00149 void setConstraint4Active(bool _isActive); 00150 //---------------------------------------------------------------------------------------------------------------------- 00153 //---------------------------------------------------------------------------------------------------------------------- 00154 void setConstraint3Active(bool _isActive); 00155 //---------------------------------------------------------------------------------------------------------------------- 00158 //---------------------------------------------------------------------------------------------------------------------- 00159 void setConstraint2Active(bool _isActive); 00160 00161 //---------------------------------------------------------------------------------------------------------------------- 00164 //---------------------------------------------------------------------------------------------------------------------- 00165 void setIsVerlet(bool _isVerlet); 00166 00167 //---------------------------------------------------------------------------------------------------------------------- 00170 //---------------------------------------------------------------------------------------------------------------------- 00171 void setTimeStep(int _timeStep); 00172 00173 //---------------------------------------------------------------------------------------------------------------------- 00176 //---------------------------------------------------------------------------------------------------------------------- 00177 void setCriticalDistanse(int _criticalDistanse); 00178 00179 //---------------------------------------------------------------------------------------------------------------------- 00182 //---------------------------------------------------------------------------------------------------------------------- 00183 void setFriction(int _friction); 00184 00185 //---------------------------------------------------------------------------------------------------------------------- 00188 //---------------------------------------------------------------------------------------------------------------------- 00189 void setBumpiness(int _bumpiness); 00190 00191 //---------------------------------------------------------------------------------------------------------------------- 00194 //---------------------------------------------------------------------------------------------------------------------- 00195 void setStiffeness(int _stiffeness); 00196 00197 //---------------------------------------------------------------------------------------------------------------------- 00200 //---------------------------------------------------------------------------------------------------------------------- 00201 void setGravity(int _gravity); 00202 00203 //---------------------------------------------------------------------------------------------------------------------- 00206 void tableExists(bool flag){ table = flag;} 00207 00208 //---------------------------------------------------------------------------------------------------------------------- 00211 void windExists(bool activated); 00212 00213 //---------------------------------------------------------------------------------------------------------------------- 00216 void floorExists(bool flag){ floor = flag;} 00217 00218 //---------------------------------------------------------------------------------------------------------------------- 00221 void movingBallExists(bool flag){ movingBall = flag;} 00222 00223 void saveAnimation(); 00224 00225 void stopRecording(); 00226 00227 00228 00229 00230 00231 private : 00232 GLuint m_vaoID; 00233 00235 ngl::Vector m_modelPos; 00237 int m_fpsTimer; 00239 int m_texTimer; 00240 //---------------------------------------------------------------------------------------------------------------------- 00242 //---------------------------------------------------------------------------------------------------------------------- 00243 int m_timer; 00244 00245 std::vector<std::string> m_filesNames; 00246 int animationFileNumber; 00247 //---------------------------------------------------------------------------------------------------------------------- 00249 //---------------------------------------------------------------------------------------------------------------------- 00250 int m_animationTimer; 00251 //---------------------------------------------------------------------------------------------------------------------- 00253 //---------------------------------------------------------------------------------------------------------------------- 00254 int m_spinXFace; 00255 //---------------------------------------------------------------------------------------------------------------------- 00257 //---------------------------------------------------------------------------------------------------------------------- 00258 int m_spinYFace; 00259 //---------------------------------------------------------------------------------------------------------------------- 00261 //---------------------------------------------------------------------------------------------------------------------- 00262 bool m_rotate; 00263 //---------------------------------------------------------------------------------------------------------------------- 00265 //---------------------------------------------------------------------------------------------------------------------- 00266 int m_origX; 00267 //---------------------------------------------------------------------------------------------------------------------- 00269 //---------------------------------------------------------------------------------------------------------------------- 00271 bool m_translate; 00272 00274 bool m_applyForce; 00275 00277 ngl::Vector userForce; 00278 00280 int m_origXPos; 00281 00283 int m_origYPos; 00284 00286 int m_origMassXPos; 00287 00289 int m_origMassYPos; 00290 00291 int m_origY; 00292 //---------------------------------------------------------------------------------------------------------------------- 00294 //---------------------------------------------------------------------------------------------------------------------- 00295 ngl::Camera *m_cam; 00296 //---------------------------------------------------------------------------------------------------------------------- 00298 //---------------------------------------------------------------------------------------------------------------------- 00300 //---------------------------------------------------------------------------------------------------------------------- 00301 ngl::TransformStack m_transformStack; 00302 00303 //---------------------------------------------------------------------------------------------------------------------- 00305 //---------------------------------------------------------------------------------------------------------------------- 00306 int m_timerValue; 00307 //---------------------------------------------------------------------------------------------------------------------- 00309 //---------------------------------------------------------------------------------------------------------------------- 00310 float ball_time; // counter for used to calculate the z position of the ball below 00311 00312 //---------------------------------------------------------------------------------------------------------------------- 00314 //---------------------------------------------------------------------------------------------------------------------- 00315 ngl::Vector ball_pos; // the center of our one ball 00316 00317 //---------------------------------------------------------------------------------------------------------------------- 00319 //---------------------------------------------------------------------------------------------------------------------- 00320 float ball_radius; // the radius of our one ball 00321 00322 //---------------------------------------------------------------------------------------------------------------------- 00324 //---------------------------------------------------------------------------------------------------------------------- 00325 ngl::Vector box_pos; // the center of our one table 00326 00327 //---------------------------------------------------------------------------------------------------------------------- 00329 //---------------------------------------------------------------------------------------------------------------------- 00330 float box_radius; // the radius of our one table 00331 //---------------------------------------------------------------------------------------------------------------------- 00333 //---------------------------------------------------------------------------------------------------------------------- 00334 bool table; 00335 //---------------------------------------------------------------------------------------------------------------------- 00337 //---------------------------------------------------------------------------------------------------------------------- 00338 bool movingBall; 00339 //---------------------------------------------------------------------------------------------------------------------- 00341 //---------------------------------------------------------------------------------------------------------------------- 00342 bool floor; 00343 //---------------------------------------------------------------------------------------------------------------------- 00345 //---------------------------------------------------------------------------------------------------------------------- 00346 bool isWind; 00347 00348 //---------------------------------------------------------------------------------------------------------------------- 00350 bool tableExists(){ return table;} 00351 00352 00353 //---------------------------------------------------------------------------------------------------------------------- 00355 bool windExists(){ return isWind;} 00356 00357 //---------------------------------------------------------------------------------------------------------------------- 00359 bool floorExists(){ return floor;} 00360 00361 //---------------------------------------------------------------------------------------------------------------------- 00363 bool movingBallExists(){ return movingBall;} 00364 00365 void saveSimulationToFile(); 00366 00367 std::string createFileName(); 00368 00369 bool m_recordAnimation; 00370 00371 std::string m_animationFilePath; 00372 00373 protected: 00374 00375 //---------------------------------------------------------------------------------------------------------------------- 00378 //---------------------------------------------------------------------------------------------------------------------- 00379 void initializeGL(); 00380 00381 //---------------------------------------------------------------------------------------------------------------------- 00385 //---------------------------------------------------------------------------------------------------------------------- 00386 void resizeGL( 00387 const int _w, 00388 const int _h 00389 ); 00390 //---------------------------------------------------------------------------------------------------------------------- 00393 //---------------------------------------------------------------------------------------------------------------------- 00394 void paintGL(); 00395 00396 00397 private : 00398 00399 00400 //---------------------------------------------------------------------------------------------------------------------- 00403 //---------------------------------------------------------------------------------------------------------------------- 00404 void mouseMoveEvent ( 00405 QMouseEvent * _event 00406 ); 00407 //---------------------------------------------------------------------------------------------------------------------- 00411 //---------------------------------------------------------------------------------------------------------------------- 00412 00413 void mousePressEvent ( 00414 QMouseEvent *_event 00415 ); 00416 00417 //---------------------------------------------------------------------------------------------------------------------- 00421 //---------------------------------------------------------------------------------------------------------------------- 00422 void mouseReleaseEvent ( 00423 QMouseEvent *_event 00424 ); 00425 00426 //---------------------------------------------------------------------------------------------------------------------- 00430 //---------------------------------------------------------------------------------------------------------------------- 00431 void keyPressEvent( 00432 QKeyEvent *_event 00433 ); 00434 //---------------------------------------------------------------------------------------------------------------------- 00436 //---------------------------------------------------------------------------------------------------------------------- 00437 void timerEvent( 00438 QTimerEvent *_event 00439 ); 00440 00441 // @brief this method is called everytime the mouse wheel is moved 00444 void wheelEvent( 00445 QWheelEvent *_event 00446 ); 00447 00448 }; 00449 00450 #endif