glview.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           glview.h  -  description
00003                              -------------------
00004     begin                : Fri Nov 5 2004
00005     copyright            : (C) 2004-2006 by Ben Swerts
00006     email                : bswerts@users.sourceforge.net
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00020 
00021 #ifndef GLVIEW_H
00022 #define GLVIEW_H
00023 
00025 
00026 // Qt forward class declarations
00027 class QPoint;
00028 class QTimer;
00029 
00030 // Xbrabo forward class declarations
00031 #include <glbaseparameters.h>  // struct GLBaseParameters can't be declared forward
00032 template <class T> class Quaternion;
00033 
00034 // Base class header file
00035 #include <qgl.h>
00036 
00038 class GLView : public QGLWidget
00039 {
00040   Q_OBJECT
00041   
00042   public:
00044     GLView(QWidget *parent=0, const char *name=0);// constructor
00045     virtual ~GLView();                          // destructor
00046 
00048     bool isModified() const;            // returns whether the scene needs to be saved
00049     bool isAnimating() const;           // returns whether the scene is animating
00050     unsigned int calculateFPS();        // returns the maximum framerate for the current parameters
00051 
00053     static void setParameters(GLBaseParameters params);     // sets new OpenGL parameters
00054 
00055   signals:
00056     void modified();                    // is emitted when the status changes from non-modified to modified
00057     void changed();                     // is emitted everytime something changes
00058 
00059   public slots:
00060     void setModified(const bool status = true);   // sets the 'modified' status of the scene
00061     void toggleAnimation();             // turns animation on/off
00062     void centerView(const bool update = true);    // centers the scene (through xPos and yPos)
00063     void resetOrientation(const bool update = true);        // resets the orientation
00064     void zoomFit(const bool update = true);      // zooms so the scene fits the window
00065     void resetView(const bool update = true);     // resets translation/orientation/zoom
00066     void saveImage();           // saves the current view to an image
00067 
00068   protected:
00070     void initializeGL();                // called once upon initialization
00071     void resizeGL(int w, int h);        // called when the widget is resized
00072     void paintGL();                     // called when the widget has to be repainted
00073     void mousePressEvent(QMouseEvent* e);         // event which takes place when a mouse button is pressed
00074     void mouseMoveEvent(QMouseEvent* e);// event which takes place when the mouse is moved while a mousebutton is pressed
00075     void mouseReleaseEvent(QMouseEvent* e);       // event which takes place when a mouse button was released on the widget
00076     void keyPressEvent(QKeyEvent* e);   // event which takes place when a key was pressed
00077     void wheelEvent(QWheelEvent* e);    // event which takes place when the scrollwheel of the mouse is used
00078     virtual void drawScene() = 0;       // should contain the actual OpenGL drawing code for the scene
00079     void translateZ(const int amount);    // handles Z-direction translations
00080     void translateXY(const int amountX, const int amountY);   // handles X- and Y-direction translations
00081     virtual void clicked(const QPoint&);// handles left-mouse clicks at position
00082     virtual void updateGLSettings();    // updates the GL View according to parameters
00083     virtual float boundingSphereRadius() = 0;     // calculates the radius of the bounding sphere needed for zoomFit
00084     void updateFog(const float radius); // updates the fog parameters
00085     void updateProjection();            // does the necessary updating when the projection type changes
00086     void setPerspective();              // sets the perspective
00087     
00089     GLfloat xPos;                       
00090     GLfloat yPos;                       
00091     GLfloat zPos;                       
00092     Quaternion<float>* orientationQuaternion;     
00093     //GLfloat aspectRatio;                ///< Needed in resizeGL and selectEntity.
00094     QPoint mousePosition;               
00095 
00097     static const int redrawWait;                  
00098     static const float fieldOfView;               
00099     static GLBaseParameters baseParameters;       
00100     
00101   private:
00102     
00104     GLfloat xRot;                       
00105     GLfloat yRot;                       
00106     GLfloat zRot;                       
00107     QTimer* timer;                      
00108     bool animation;                     
00109     int updateIndex;                    
00110     bool viewModified;                  
00111     bool startingClick;                 
00112     float maxRadius;                    
00113     bool currentPerspectiveProjection;  
00114 
00116     static int staticUpdateIndex;       
00117 };
00118 
00119 #endif
00120 

Generated on Fri May 19 14:31:54 2006 for Brabosphere by  doxygen 1.4.6-NO