Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

qglvuwidget.h

00001 #ifndef __QGLVUWIDGET_H__
00002 #define __QGLVUWIDGET_H__
00003 
00004 #include <qgl.h>
00005 #include <sys/timeb.h> // for frame timing
00006 
00007 // GLVU includes
00008 #include <camera.hpp>
00009 
00011 
00034 class QGLVUWidget : public QGLWidget
00035 {
00036   Q_OBJECT
00037 public: // Constants
00038   
00040   enum WorldNavMode 
00041   {
00042     NAV_MODE_TRACKBALL, 
00043     NAV_MODE_HYPERBALL,
00044     NAV_MODE_DRIVE, 
00045     NAV_MODE_TRANSLATE, 
00046     NAV_MODE_LOOK,
00047     NAV_MODE_NUM_MODES
00048   };
00049   
00051   enum CameraID
00052   {
00053     CAMERA_ONE,
00054     CAMERA_TWO,
00055     CAMERA_THREE,
00056     CAMERA_FOUR,
00057     CAMERA_NUM_CAMS
00058   };
00059   
00060 public: // Methods
00061   QGLVUWidget(QGLFormat &format = QGLFormat::defaultFormat(), 
00062               QWidget* parent = 0, 
00063               const char* name = 0 );
00064   virtual ~QGLVUWidget();
00065   
00066   virtual void        DoneCurrent();
00067   void                MakeContextCurrent();
00068                       
00069   virtual void        BeginFrame();
00070   virtual void        EndFrame();
00071                       
00072   inline void         SetCurrentCam(Camera *pNewCam);     
00073   inline Camera*      GetCurrentCam();
00074   inline Camera*      GetCam(int whichCam);
00075   
00076   void                SetOrigCam(Camera *pCam);
00077   
00078   void                SetAllCams(Vec3f worldMin, Vec3f worldMax, Vec3f eye, 
00079                                  Vec3f lookAtCntr, Vec3f viewup,
00080                                  float yFOV, float aspect, 
00081                                  float nearFactor, float farFactor);
00082                       
00083   void                AllCamsPerspectiveChange(float yFOV, float aspect, 
00084                                                float nearDist, float farDist);
00085   void                AllCamsPerspectiveAspectChange(float aspect);
00086                       
00087   float*              GetModelviewMatrix(float* pMatrix) const;
00088   float*              GetProjectionMatrix(float* pMatrix) const;                                                      
00089                       
00090   inline bool         GetInOutMode() const;
00091   inline void         SetInOutMode(bool bMode);
00092                       
00093   inline int          GetWorldNavMode() const;
00094   
00095   inline const Vec3f& GetViewUp() const;
00096   inline const Vec3f& GetWorldCenter() const;
00097   inline float        GetWorldRadius() const;
00098   inline void         SetViewUp(Vec3f viewup);
00099   inline void         SetWorldCenter(const Vec3f& center);
00100   inline void         SetWorldRadius(float newRadius);
00101   
00102   inline bool         GetCamDisplayOn(int whichCam) const;
00103   
00104   inline bool         GetInertiaOn() const;
00105   inline bool         GetInertiaEnabled() const;
00106   inline int          GetInertiaDelay() const;
00107   void                SetInertiaOn( bool bEnable );
00108   inline void         SetInertiaEnabled( bool bEnable);  
00109   inline void         SetInertiaDelay(int iMilliseconds);
00110   inline int          GetInertiaMinMove() const;    
00111   inline void         SetInertiaMinMove( int iAmount );
00112   
00113   inline void         StartFPSClock();
00114   inline void         StopFPSClock(); 
00115   inline float        GetFPS() const;
00116   inline void         SetFPSIntegrateInterval(float rInterval);
00117 
00118   // use only if you do not call QGLVUWidget::BeginFrame()
00119   void                UpdateFPS();                         
00120   
00121   inline ButtonState  GetButtonState() const;
00122   inline void         GetMousePos(int &ix, int &iy) const;
00123   
00124   //           Movement functions
00125   void                TranslateX(int iOldX, int iNewX, int iWW);
00126   void                TranslateY(int iOldY, int iNewY, int iWH);
00127   void                DriveY(int iOldY, int iNewY, int iWH);
00128   void                LookX(int iOldX, int iNewX, int iWW);
00129   void                LookY(int iOldY, int iNewY, int iWH);
00130   void                TrackBallX(int iOldX, int iNewX, int iWW);
00131   void                TrackBallY(int iOldY, int iNewY, int iWH);
00132   void                HyperBall( int iOldX, int iOldY, 
00133                                  int iNewX, int iNewY,
00134                                  int iWW, int iWH);
00135   
00136   void                SnapShot();
00137   void                ReportGLError(char *msg);
00138   QPixmap*            CreateQGLVUPixmap() const;
00139                       
00140   //                  Path Recording and playback.
00141   void                SetPathFilename(const char *pFilename);
00142   void                StartRecording();
00143   void                EndRecording();
00144   void                StartPlayback();
00145   void                EndPlayback();
00146   void                StopRecordingPlayback();
00147                     
00148   //                  Replace default GL methods
00149   void                SetInitializeGL(void (*f)(QGLVUWidget*));
00150   void                SetResizeGL(void (*f)(QGLVUWidget*, int, int));
00151   void                SetPaintGL(void (*f)(QGLVUWidget*));
00152   
00153   // Default implementations.  Can be replaced with Set*GL() methods
00154   static void         DefaultInitializeGL(QGLVUWidget* pGLVU);
00155   static void         DefaultResizeGL(QGLVUWidget* pGLVU, int iw, int ih );
00156   static void         DefaultPaintGL(QGLVUWidget* pGLVU);
00157                       
00158 public slots:         
00159   inline void         SelectCam( int whichCam ); 
00160   void                AllCamsResetToOrig();
00161   void                CyclePolygonMode();
00162   inline int          SetWorldNavMode(WorldNavMode mode);
00163   bool                ToggleCamDisplay( int whichCam );           
00164   bool                ToggleInOutMode();
00165   bool                ToggleFaceCulling();
00166   bool                ToggleLighting();
00167   bool                ToggleMaterials();
00168   bool                ToggleSmoothShading();
00169   void                ToggleCullFace();
00170   
00171 signals:
00172   void                FPSUpdate(float rFPS);
00173 
00174 protected: // Methods
00175   virtual void        initializeGL();
00176   virtual void        resizeGL( int iw, int ih );
00177   virtual void        paintGL();
00178   
00179 
00180 protected: // Events
00181   
00182   // These are inherited from QWidget.  Can override in a subclass.
00183   virtual void        mousePressEvent( QMouseEvent *pEvent );
00184   virtual void        mouseReleaseEvent( QMouseEvent *pEvent ); 
00185   virtual void        mouseDoubleClickEvent( QMouseEvent *pEvent );
00186   virtual void        mouseMoveEvent( QMouseEvent *pEvent );
00187   virtual void        wheelEvent( QWheelEvent *pEvent );
00188   virtual void        keyPressEvent( QKeyEvent *pEvent ); 
00189   virtual void        keyReleaseEvent( QKeyEvent *pEvent ); 
00190                       
00191   virtual void        timerEvent(QTimerEvent *pEvent);
00192   // end inherited protected methods from QWidget
00193   
00194   bool                _DoInertia();
00195   virtual void        _Inertia( int x, int y);
00196                       
00197   void                _DoRecordAndPlayback();
00198   
00199 protected:     // Data
00200   Camera       _pCams[CAMERA_NUM_CAMS];          // array of 4 viewer cams
00201   Camera       *_pCam;                           // current cam ptr (default=0)
00202   Camera       _origCam;                         // orig. view for resetting
00203   bool         _pbCamDisplayOn[CAMERA_NUM_CAMS]; // display flag for each cam
00204   
00205   Vec3f        _worldCenter;                     // world bound-sphere center
00206   float        _rWorldRadius;                    // world bound-sphere radius
00207   Vec3f        _viewUp;                          // the world up-vector
00208   
00209   bool         _bInsideLookingOutMode;           // nav. mode (in->out/out->in)
00210   WorldNavMode _eWorldNavMode;                   // world navigation mode
00211   
00212   // Mouse State
00213   int          _iOldX, _iOldY, _iNewX, _iNewY;   // old and new mouse pos.
00214   float        _rMoveSpeed;
00215   ButtonState  _buttonState;
00216   
00217   bool         _bInertiaOn;
00218   bool         _bInertiaEnabled;
00219   int          _iInertiaDelay;
00220   int          _iInertiaTimerID;
00221   int          _iInertiaMinMove;
00222   
00223   // Path Recording and Playback
00224   char         *_pPathFilename;
00225   bool         _bRecordingOn;
00226   bool         _bPlaybackOn;
00227   FILE         *_pPathFP;
00228   
00229   struct timeb _lastFPSClock;
00230   bool         _bCalcFPS;
00231   float        _rLastFPS;
00232   int          _iLastFPSCount;
00233   int          _iFPSDelay;
00234   int          _iFPSTimerID;
00235   float        _rFPSIntegrateInterval; // minimum secs to integrate frame-rate.
00236 
00237   
00238 protected:    // function pointers
00239   void        (*_pfInitializeGL)(QGLVUWidget*);
00240   void        (*_pfResizeGL)(QGLVUWidget*, int, int);
00241   void        (*_pfPaintGL)(QGLVUWidget*);
00242 };
00243 
00244 // BEGIN INLINE METHODS
00245 
00252 inline void QGLVUWidget::SetCurrentCam(Camera *pNewCam)
00253 { 
00254   _pCam = pNewCam;                  
00255 }     
00256 
00260 inline Camera* QGLVUWidget::GetCurrentCam()                      
00261 { 
00262   return(_pCam);                    
00263 }     
00264 
00268 inline Camera* QGLVUWidget::GetCam(int whichCam)
00269 { 
00270   return(&_pCams[whichCam]);        
00271 }
00272    
00278 inline bool QGLVUWidget::GetInOutMode() const                 
00279 { 
00280   return _bInsideLookingOutMode;    
00281 }
00282 
00287 inline void QGLVUWidget::SetInOutMode(bool bMode)           
00288 { 
00289   _bInsideLookingOutMode = bMode;   
00290 }
00291 
00295 inline int QGLVUWidget::GetWorldNavMode() const              
00296 { 
00297   return _eWorldNavMode;            
00298 }
00299 
00303 inline const Vec3f& QGLVUWidget::GetViewUp() const                    
00304 { 
00305   return _viewUp;                   
00306 }
00307 
00312 inline const Vec3f& QGLVUWidget::GetWorldCenter() const               
00313 { 
00314   return _worldCenter;              
00315 }
00316 
00321 inline float QGLVUWidget::GetWorldRadius() const               
00322 { 
00323   return _rWorldRadius;             
00324 }
00325 
00329 inline void QGLVUWidget::SetViewUp(Vec3f viewup)
00330 { 
00331   _viewUp = viewup;
00332 }
00333  
00337 inline void QGLVUWidget::SetWorldCenter(const Vec3f& center) 
00338 { 
00339   _worldCenter = center;            
00340 }
00341 
00345 inline void QGLVUWidget::SetWorldRadius(float newRadius)
00346 { 
00347   _rWorldRadius = newRadius;
00348 }
00349   
00353 inline bool QGLVUWidget::GetCamDisplayOn(int whichCam) const  
00354 { 
00355   return _pbCamDisplayOn[whichCam]; 
00356 }
00357   
00362 inline bool QGLVUWidget::GetInertiaOn() const
00363 { 
00364   return _bInertiaOn;
00365 } 
00366   
00371 inline bool QGLVUWidget::GetInertiaEnabled() const
00372 { 
00373   return _bInertiaEnabled;
00374 }
00375 
00380 inline int QGLVUWidget::GetInertiaDelay() const
00381 { 
00382   return _iInertiaDelay;
00383 } 
00384 
00388 inline void QGLVUWidget::SetInertiaEnabled( bool bEnable)
00389 { 
00390   _bInertiaEnabled = bEnable;
00391 }
00392 
00396 inline void QGLVUWidget::SetInertiaDelay(int iMilliseconds)
00397 { 
00398   _iInertiaDelay = iMilliseconds;
00399 }
00400 
00405 inline int QGLVUWidget::GetInertiaMinMove() const
00406 { 
00407   return _iInertiaMinMove;
00408 }
00409 
00414 inline void QGLVUWidget::SetInertiaMinMove( int iAmount )
00415 { 
00416   _iInertiaMinMove = iAmount;
00417 }
00418 
00422 inline void QGLVUWidget::StartFPSClock()
00423 { 
00424   _bCalcFPS = 1; 
00425   ftime(&_lastFPSClock); 
00426   _iLastFPSCount=0;
00427 }
00428 
00432 inline void QGLVUWidget::StopFPSClock()  
00433 { 
00434   _bCalcFPS = 0; 
00435 }
00436 
00440 inline float QGLVUWidget::GetFPS() const
00441 { 
00442   return _rLastFPS; 
00443 }
00444 
00449 inline void QGLVUWidget::SetFPSIntegrateInterval(float rInterval)
00450 {
00451   _rFPSIntegrateInterval = rInterval;
00452 }
00453 
00458 inline Qt::ButtonState QGLVUWidget::GetButtonState() const
00459 { 
00460   return _buttonState;
00461 }
00462 
00468 inline void QGLVUWidget::GetMousePos(int &ix, int &iy) const
00469 { 
00470   ix = _iOldX;
00471   iy = _iOldY;
00472 }
00473 
00477 inline void QGLVUWidget::SelectCam( int whichCam )
00478 { 
00479   _pCam = &_pCams[whichCam]; 
00480   repaint(); 
00481 } 
00482 
00496 inline int QGLVUWidget::SetWorldNavMode(WorldNavMode mode)
00497 { 
00498   return (_eWorldNavMode = mode);
00499 }
00500 
00501 
00502   
00503 #endif //__QGLVUWIDGET_H__

Generated at Fri Oct 12 15:12:21 2001 for GLVU by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001