Eulerian Smoke Simulation on the GPU
|
00001 #ifndef __GL_WINDOW_H__ 00002 #define __GL_WINDOW_H__ 00003 00004 //----------------------------------------------------------- 00007 //----------------------------------------------------------- 00008 00009 #include <ngl/Camera.h> 00010 #include <ngl/Colour.h> 00011 #include <ngl/Light.h> 00012 #include <ngl/Material.h> 00013 #include <ngl/TransformStack.h> 00014 #include <ngl/Vector.h> 00015 00016 #include "FluidEngine.h" 00017 00018 // must be declared last 00019 #include <QtOpenGL> 00020 00028 class GLWindow : public QGLWidget 00029 { 00030 Q_OBJECT 00031 00032 public: 00033 00035 enum FieldToRender{ 00036 VELOCITY, 00037 PRESSURE, 00038 TEMPERATURE, 00039 DENSITY 00040 }; 00041 00043 enum BackgroundType{ 00044 LIGHT, 00045 DARK 00046 }; 00047 00050 GLWindow( 00051 QWidget *_parent 00052 ); 00054 ~GLWindow(); 00055 00056 public slots: 00059 void setIsoLevel( 00060 float _isoLevel 00061 ); 00062 00065 void setSamplingChannel( 00066 int _channelIndex 00067 ); 00068 00071 void setMeshingMethod( 00072 int _method 00073 ); 00074 00076 void toggleSimulation(); 00077 00080 void toggleMesh( 00081 bool _displayMesh 00082 ); 00083 00086 void setMeshField( 00087 int _meshField 00088 ); 00089 00092 void toggleObstacles( 00093 bool _displayObstacles 00094 ); 00095 00098 void setObstacleGeometry( 00099 int _geoIndex 00100 ); 00101 00104 void toggleGridPlane( 00105 bool _displayGridPlane 00106 ); 00107 00110 void toggleContainer( 00111 bool _displayContainer 00112 ); 00113 00116 void toggleLightIcon( 00117 bool _displayLightIcon 00118 ); 00119 00124 void setLightPosition( 00125 float _posX, 00126 float _posY, 00127 float _posZ 00128 ); 00129 00134 void setLightAttenuation( 00135 float _constant, 00136 float _linear, 00137 float _quadratic 00138 ); 00139 00144 void setLightColour( 00145 float _r, 00146 float _g, 00147 float _b 00148 ); 00149 00154 void setLightSpecColour( 00155 float _r, 00156 float _g, 00157 float _b 00158 ); 00159 00162 void toggleSlice( 00163 bool _displaySlice 00164 ); 00165 00168 void setSliceField( 00169 int _sliceField 00170 ); 00171 00174 void setSliceOpacity( 00175 double _opacity 00176 ); 00177 00180 void setSlicePos( 00181 int _slicePos 00182 ); 00183 00186 void setBGType( 00187 int _bgType 00188 ); 00189 00194 void setMeshColour( 00195 float _r, 00196 float _g, 00197 float _b 00198 ); 00199 00202 void setMeshMaterial( 00203 int _materialIndex 00204 ); 00205 00208 inline void setCellSize( 00209 double _cellSize 00210 ) 00211 { 00212 m_fluidEngine->setCellSize(_cellSize); 00213 } 00214 00217 inline void setSplatRadius( 00218 double _splatRadius 00219 ) 00220 { 00221 m_fluidEngine->setSplatRadius(_splatRadius); 00222 } 00223 00226 inline void setAmbientTemperature( 00227 double _ambientTemperature 00228 ) 00229 { 00230 m_fluidEngine->setAmbientTemperature(_ambientTemperature); 00231 } 00232 00235 inline void setImpulseTemperature( 00236 double _impulseTemperature 00237 ) 00238 { 00239 m_fluidEngine->setImpulseTemperature(_impulseTemperature); 00240 } 00241 00244 inline void setImpulseDensity( 00245 double _impulseDensity 00246 ) 00247 { 00248 m_fluidEngine->setImpulseDensity(_impulseDensity); 00249 } 00250 00255 inline void setImpulsePosition( 00256 double _posX, 00257 double _posY, 00258 double _posZ 00259 ) 00260 { 00261 m_fluidEngine->setImpulsePosition(_posX, _posY, _posZ); 00262 } 00263 00266 inline void setPoissonIterations( 00267 int _numPoissonIterations 00268 ) 00269 { 00270 m_fluidEngine->setPoissonIterations(_numPoissonIterations); 00271 } 00272 00275 inline void setTimestep( 00276 double _timestep 00277 ) 00278 { 00279 m_fluidEngine->setTimestep(_timestep); 00280 } 00281 00284 inline void setBuoyancyLift( 00285 double _buoyancyLift 00286 ) 00287 { 00288 m_fluidEngine->setBuoyancyLift(_buoyancyLift); 00289 } 00290 00293 inline void setGasWeight( 00294 double _gasWeight 00295 ) 00296 { 00297 m_fluidEngine->setGasWeight(_gasWeight); 00298 } 00299 00304 inline void setBuoyancyDirection( 00305 float _dirX, 00306 float _dirY, 00307 float _dirZ 00308 ) 00309 { 00310 m_fluidEngine->setBuoyancyDirection(_dirX, _dirY, _dirZ); 00311 updateGL(); 00312 } 00313 00316 inline void togglePeriodicNoise( 00317 bool _enablePeriodicNoise 00318 ) 00319 { 00320 m_fluidEngine->togglePeriodicNoise(_enablePeriodicNoise); 00321 updateGL(); 00322 } 00323 00328 inline void setNoiseVariance( 00329 float _noiseVarianceX, 00330 float _noiseVarianceY, 00331 float _noiseVarianceZ 00332 ) 00333 { 00334 m_fluidEngine->setNoiseVariance( 00335 _noiseVarianceX, 00336 _noiseVarianceY, 00337 _noiseVarianceZ 00338 ); 00339 updateGL(); 00340 } 00345 inline void setNoiseDrivingFunc( 00346 int _funcIndexX, 00347 int _funcIndexY, 00348 int _funcIndexZ 00349 ) 00350 { 00351 m_fluidEngine->setNoiseDrivingFunc( 00352 _funcIndexX, 00353 _funcIndexY, 00354 _funcIndexZ 00355 ); 00356 } 00357 00358 00361 inline void setTemperatureDissipation( 00362 double _temperatureDissipation 00363 ) 00364 { 00365 m_fluidEngine->setTemperatureDissipation(_temperatureDissipation); 00366 } 00367 00370 inline void setDensityDissipation( 00371 double _densityDissipation 00372 ) 00373 { 00374 m_fluidEngine->setDensityDissipation(_densityDissipation); 00375 } 00376 00379 inline void setVelocityDissipation( 00380 double _velocityDissipation 00381 ) 00382 { 00383 m_fluidEngine->setVelocityDissipation(_velocityDissipation); 00384 } 00385 00386 private: 00388 int m_spinXFace; 00390 int m_spinYFace; 00392 bool m_cameraOrbit; 00394 bool m_cameraPan; 00395 00397 int m_origX; 00399 int m_origY; 00401 int m_origXPos; 00403 int m_origYPos; 00404 00406 ngl::Camera* m_camera; 00407 00409 ngl::TransformStack m_transformStack; 00410 00412 ngl::Material* m_meshMaterial; 00414 ngl::Light* m_light; 00416 ngl::Vector* m_lightIconPos; 00418 ngl::Colour* m_lightIconColour; 00419 00420 00422 FluidEngine* m_fluidEngine; 00423 00425 int m_simRes; 00426 00428 bool m_simulate; 00429 00431 bool m_displayMesh; 00433 bool m_displayObstacles; 00435 bool m_displaySlice; 00437 bool m_displayGridPlane; 00439 bool m_displayContainer; 00441 bool m_displayLightIcon; 00442 00444 FieldToRender m_sliceField; 00445 00447 FieldToRender m_meshField; 00448 00450 BackgroundType m_bgType; 00451 00452 protected: 00455 void initializeGL(); 00456 00460 void resizeGL( 00461 const int _w, 00462 const int _h 00463 ); 00466 void paintGL(); 00467 00468 private: 00469 //------------------------------ MOUSE INTERACTION EVENTS ----------------------------------- 00473 void mouseMoveEvent( 00474 QMouseEvent * _event 00475 ); 00479 00480 void mousePressEvent( 00481 QMouseEvent *_event 00482 ); 00483 00487 void mouseReleaseEvent( 00488 QMouseEvent *_event 00489 ); 00493 void wheelEvent( 00494 QWheelEvent *_event 00495 ); 00496 00497 //------------------------------ END MOUSE INTERACTION EVENTS ------------------------------- 00498 00501 void timerEvent( 00502 QTimerEvent *_event 00503 ); 00504 }; 00505 00506 #endif // __GL_WINDOW_H__ 00507