GOpenGLFrame.h

00001 /***************************************************************************
00002  *   Copyright (C) 2004 - 2006 by Raphael Langerhorst                      *
00003  *   raphael-langerhorst@gmx.at                                            *
00004  *                                                                         *
00005  *   Permission is hereby granted, free of charge, to any person obtaining *
00006  *   a copy of this software and associated documentation files (the       *
00007  *   "Software"), to deal in the Software without restriction, including   *
00008  *   without limitation the rights to use, copy, modify, merge, publish,   *
00009  *   distribute, sublicense, and/or sell copies of the Software, and to    *
00010  *   permit persons to whom the Software is furnished to do so, subject to *
00011  *   the following conditions:                                             *
00012  *                                                                         *
00013  *   The above copyright notice and this permission notice shall be        *
00014  *   included in all copies or substantial portions of the Software.       *
00015  *                                                                         *
00016  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       *
00017  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    *
00018  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*
00019  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR     *
00020  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
00021  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
00022  *   OTHER DEALINGS IN THE SOFTWARE.                                       *
00023  ***************************************************************************/
00024 
00025 
00026 #ifndef OPENGLFRAMEH
00027 #define OPENGLFRAMEH
00028 
00029 //GCE includes
00030 namespace X3DTK
00031 {
00032   class SimpleX3DGLScene;
00033 }
00034 
00035 //G includes
00036 #include <GForm.h>
00037 #include <GVector3.h>
00038 #include <GElementID.h>
00039 #include <GElement.h>
00040 
00041 
00042 //Qt includes
00043 #include <qgl.h>
00044 #include <QMutex>
00045 #include <QMap>
00046 #include <QThread>
00047 #include <QList>
00048 #include <QTimer>
00049 
00050 namespace GWE
00051 {
00052   class GInformationInterface;
00053 }
00054 
00055 
00056 //this belongs to the client engine
00057 namespace GCE
00058 {
00059 
00060 class GScene;
00061 
00062 
00068 class GViewProperties
00069 {
00070   public:
00071   
00072     GViewProperties()
00073     : ViewPosition(0,0,-1),
00074       ViewTarget(0,0,0),
00075       ViewUp(0,1,0),
00076       fov(90),
00077       NearClippingPlane(0.01),
00078       FarClippingPlane(10),
00079       width(768),
00080       height(1024),
00081       CameraElement(0)
00082     {
00083     }
00084   
00085     GCS::GVector3 ViewPosition;
00086     GCS::GVector3 ViewTarget;
00087     GCS::GVector3 ViewUp;
00088     double fov;
00089     double NearClippingPlane;
00090     double FarClippingPlane;
00091     
00092     int width, height;
00093     
00101     GCS::GElementID CameraElement;
00102     
00103     void update()
00104     {
00105       glViewport(0,0,width,height);
00106       glMatrixMode(GL_PROJECTION);
00107       glLoadIdentity();
00108       gluPerspective(fov,(double)width/(double)height,NearClippingPlane,FarClippingPlane);
00109       glMatrixMode(GL_MODELVIEW);
00110       glLoadIdentity();
00111     }
00112 };
00113 
00124 class GOpenGLFrame : public QGLWidget, public QMutex
00125 {
00126   Q_OBJECT
00127   private:
00128     
00132     const GWE::GInformationInterface* WorldData;
00133     
00137     GScene* Scene;
00138     
00143     GCS::GElementID CameraParent;
00144     
00150     QList<double> RenderingPeriods;
00151     
00155     double FramesPerSecond;
00156     
00162     double TimeSinceFpsUpdate;
00163     
00167     QTime FpsTimer;
00168     
00169   protected:
00170   
00174 //     void renderElement(const GCS::GElement* element);
00175     
00176   protected:
00177     
00182 //     void transform(const GCS::GForm* form) const;
00183     
00188 //     void render(const GCS::GForm* form, float* RGBA);
00189   
00194     QTimer RedrawTimer;
00195   
00201     bool StopRendering;
00202   
00207     int RedrawSleepTime_ms;
00208   
00209   public:
00210     
00214     GViewProperties ViewProperties;
00215 
00217     GOpenGLFrame(const GWE::GInformationInterface* WorldData, GScene* scene, QWidget* parent = 0);
00218 
00220     ~GOpenGLFrame();
00221     
00226     GScene* getScene();
00227     
00228   public slots:
00229     
00235     virtual void startRendering(int sleep_ms_between_updates_min = 20);
00236     
00240     virtual void setTimeBetweenRendering(int milliseconds);
00241     
00246     virtual void stopRendering();
00247     
00249     virtual void initializeGL();
00250     
00252     virtual void resizeGL(int w, int h);
00253     
00255     virtual void paintGL();
00256     
00257   signals:
00258     
00263     void beforeRendering();
00264     
00268     void afterRendering();
00269 
00270 };
00271 
00272 }
00273 
00274 #endif

Generated on Thu Nov 16 07:49:12 2006 for G System by  doxygen 1.4.7