QtGLViewer.h
Go to the documentation of this file.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
00027 #ifndef SOFA_GUI_QGLVIEWER_QTVIEWER_H
00028 #define SOFA_GUI_QGLVIEWER_QTVIEWER_H
00029
00030 #include <sofa/helper/system/gl.h>
00031 #include <qgl.h>
00032 #include <qtimer.h>
00033 #include <math.h>
00034 #include <stdlib.h>
00035 #include <stdio.h>
00036 #include <string.h>
00037 #include <fstream>
00038
00039 #include <viewer/SofaViewer.h>
00040 #include <sofa/defaulttype/Vec.h>
00041 #include <sofa/defaulttype/Quat.h>
00042 #include <sofa/helper/gl/Transformation.h>
00043 #include <sofa/helper/gl/Trackball.h>
00044 #include <sofa/helper/gl/Texture.h>
00045 #include <sofa/helper/system/thread/CTime.h>
00046 #include <sofa/simulation/tree/xml/Element.h>
00047
00048
00049
00050 #include <QGLViewer/qglviewer.h>
00051
00052 namespace sofa
00053 {
00054
00055 namespace gui
00056 {
00057
00058 namespace qt
00059 {
00060
00061 namespace viewer
00062 {
00063
00064 namespace qgl
00065 {
00066 using namespace sofa::defaulttype;
00067 using namespace sofa::helper::gl;
00068 using namespace sofa::helper::system::thread;
00069 using namespace sofa::component::collision;
00070
00071
00072 class QtGLViewer :public QGLViewer, public sofa::gui::qt::viewer::SofaViewer
00073 {
00074 typedef Vector3::value_type Real;
00075 Q_OBJECT
00076 private:
00077
00078 QTimer* timerAnimate;
00079 int _W, _H;
00080 int _clearBuffer;
00081 bool _lightModelTwoSides;
00082 float _lightPosition[4];
00083
00084
00085 double lastProjectionMatrix[16];
00086 double lastModelviewMatrix[16];
00087 GLint lastViewport[4];
00088
00089
00090
00091
00092
00093
00094
00095 GLUquadricObj* _arrow;
00096 GLUquadricObj* _tube;
00097 GLUquadricObj* _sphere;
00098 GLUquadricObj* _disk;
00099 GLuint _numOBJmodels;
00100 GLuint _materialMode;
00101 GLboolean _facetNormal;
00102
00103 int _renderingMode;
00104
00105 Texture *texLogo;
00106
00107
00108 ctime_t _beginTime;
00109
00110
00111 bool _waitForRender;
00112
00113
00114 Vector3 sceneMinBBox;
00115 Vector3 sceneMaxBBox;
00116
00117 public:
00118
00122 static int EnableViewer();
00123
00127 static int DisableViewer();
00128
00129 QtGLViewer( QWidget* parent, const char* name="" );
00130 ~QtGLViewer();
00131
00132 QWidget* getQWidget() { return this; }
00133
00134 protected:
00135
00136
00137 void init();
00138 virtual void draw();
00139 void viewAll();
00140 void resizeGL( int w, int h );
00141 void ApplyShadowMap();
00142 void CreateRenderTexture(GLuint& textureID, int sizeX, int sizeY, int channels, int type);
00143 void StoreLightMatrices();
00144
00145 public:
00146
00147
00148
00149
00150 int GetWidth()
00151 {
00152 return _W;
00153 };
00154 int GetHeight()
00155 {
00156 return _H;
00157 };
00158 bool ready(){return _waitForRender;};
00159 void wait(){_waitForRender = true;};
00160
00161 void UpdateOBJ(void);
00162
00163 void moveRayPickInteractor(int eventX, int eventY);
00164
00165
00166
00167
00168 QString helpString();
00169
00170 private:
00171
00172 void InitGFX(void);
00173 void PrintString(void* font, char* string);
00174 void Display3DText(float x, float y, float z, char* string);
00175 void DrawAxis(double xpos, double ypos, double zpos, double arrowSize);
00176 void DrawBox(Real* minBBox, Real* maxBBox, Real r=0.0);
00177 void DrawXYPlane(double zo, double xmin, double xmax, double ymin,
00178 double ymax, double step);
00179 void DrawYZPlane(double xo, double ymin, double ymax, double zmin,
00180 double zmax, double step);
00181 void DrawXZPlane(double yo, double xmin, double xmax, double zmin,
00182 double zmax, double step);
00183 void CreateOBJmodelDisplayList(int material_mode);
00184
00185
00186 void DrawLogo(void);
00187 void DisplayOBJs(bool shadowPass = false);
00188 void DisplayMenu(void);
00189 void DrawScene();
00190
00191
00192
00193
00194 protected:
00195
00196 virtual void keyPressEvent ( QKeyEvent * e );
00197 virtual void keyReleaseEvent ( QKeyEvent * e );
00198 virtual void mousePressEvent ( QMouseEvent * e );
00199 virtual void mouseReleaseEvent ( QMouseEvent * e );
00200 virtual void mouseMoveEvent ( QMouseEvent * e );
00201 virtual void wheelEvent(QWheelEvent* e);
00202 bool mouseEvent( QMouseEvent * e );
00203
00204
00205
00206
00207 public slots:
00208 void resetView();
00209 void saveView();
00210 void setSizeW(int);
00211 void setSizeH(int);
00212
00213 signals:
00214 void redrawn();
00215 void resizeW( int );
00216 void resizeH( int );
00217 };
00218
00219 }
00220
00221 }
00222
00223 }
00224
00225 }
00226
00227 }
00228
00229 #endif
00230
00231