00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef OPENGLFRAMEH
00027 #define OPENGLFRAMEH
00028
00029
00030 namespace X3DTK
00031 {
00032 class SimpleX3DGLScene;
00033 }
00034
00035
00036 #include <GForm.h>
00037 #include <GVector3.h>
00038 #include <GElementID.h>
00039 #include <GElement.h>
00040
00041
00042
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
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
00175
00176 protected:
00177
00182
00183
00188
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