Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

OpenGLFrame.h

00001 /***************************************************************************
00002  *   Copyright (C) 2004 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 //GBE includes
00030 #include <GOpenGLForm.h>
00031 
00032 //G includes
00033 #include <GVector3.h>
00034 #include <GElementID.h>
00035 #include <GElement.h>
00036 
00037 #include <GWEInterface.h>
00038 
00039 //Qt includes
00040 #include <qgl.h>
00041 #include <qmutex.h>
00042 #include <qthread.h>
00043 #include <qvaluelist.h>
00044 
00045 //use G Core System classes
00046 using namespace GCS;
00047 
00048 //basic element classes
00049 using namespace GBE;
00050 
00051 //for the G world engine
00052 using namespace GWE;
00053 
00054 //this belongs to the client engine
00055 namespace GCE
00056 {
00057 
00064 class CViewProperties
00065 {
00066   public:
00067   
00068     CViewProperties()
00069     : ViewPosition(0,0,-1),
00070       ViewTarget(0,0,0),
00071       ViewUp(0,1,0),
00072       fov(90),
00073       NearClippingPlane(0.01),
00074       FarClippingPlane(10),
00075       width(768),
00076       height(1024),
00077       CameraElement(0)
00078     {
00079     }
00080   
00081     GVector3 ViewPosition;
00082     GVector3 ViewTarget;
00083     GVector3 ViewUp;
00084     double fov;
00085     double NearClippingPlane;
00086     double FarClippingPlane;
00087     
00088     int width, height;
00089     
00097     GElementID CameraElement;
00098     
00099     void update()
00100     {          
00101       glViewport(0,0,width,height);
00102       glMatrixMode(GL_PROJECTION);
00103       glLoadIdentity();
00104       gluPerspective(fov,(double)width/(double)height,NearClippingPlane,FarClippingPlane);
00105       glMatrixMode(GL_MODELVIEW);
00106       glLoadIdentity();
00107     }
00108 };
00109 
00120 class OpenGLFrame : public QGLWidget, protected QThread, public QMutex
00121 {
00122   Q_OBJECT
00123   private:
00124     
00125     const GWEInterface* Gwe;
00126     
00127     QValueList<GElementID> TopElements;
00128     
00129     void renderChildren(const GElement* element);
00130     
00131   protected:
00132   
00133     bool stop_rendering;
00134   
00135     int sleep_time_ms;
00136   
00137     virtual void run();
00138     
00139     
00140   public:
00141     
00142     CViewProperties ViewProperties;
00143 
00144     OpenGLFrame(const GWEInterface* gwe, QWidget* parent = 0, const char* name = 0);
00145 
00146     ~OpenGLFrame()
00147     {}
00148     
00149   public slots:
00150     
00156     virtual void startRendering(int sleep_ms_between_updates_min = 20);
00157     
00158     virtual void stopRendering();
00159     
00160     virtual void initializeGL();
00161     
00162     virtual void resizeGL(int w, int h);
00163     
00164     virtual void paintGL();
00165     
00166     virtual void addTopElement(const GElementID& element);
00167     
00168     virtual void removeTopElement(const GElementID& element);
00169 
00170 };
00171 
00172 }
00173 
00174 #endif

Generated on Thu Oct 21 21:18:03 2004 for G System by doxygen 1.3.6