[4] | 1 | #ifndef _QGLVIEWERWIDGET_H_ |
---|
| 2 | #define _QGLVIEWERWIDGET_H_ |
---|
| 3 | |
---|
| 4 | #include <QtXml> |
---|
| 5 | #include <QGLWidget> |
---|
| 6 | #include <QTimer> |
---|
| 7 | #include <QTime> |
---|
| 8 | |
---|
| 9 | #pragma warning(disable: 4003) |
---|
| 10 | #include "gmtl/gmtl.h" |
---|
| 11 | |
---|
| 12 | class QGLViewerWidget : public QGLWidget |
---|
| 13 | { |
---|
| 14 | Q_OBJECT |
---|
| 15 | |
---|
| 16 | public: |
---|
| 17 | |
---|
| 18 | QGLViewerWidget(QWidget* pParent=0, const QGLWidget* pShareWidget=0, Qt::WindowFlags f=0); |
---|
| 19 | |
---|
| 20 | void setClearColor(const QColor& color) { m_clearColor = color; } |
---|
| 21 | QColor clearColor() const { return m_clearColor; } |
---|
| 22 | |
---|
| 23 | void setView(const gmtl::Vec3f& center, const gmtl::Quatf& rot, float distance); |
---|
| 24 | |
---|
| 25 | void setPerspective(bool bPerspective) { m_bPerspective = bPerspective; } |
---|
| 26 | bool isPerspective() const { return m_bPerspective; } |
---|
| 27 | |
---|
| 28 | void setFovy(float fovy) { m_fovy = fovy; } |
---|
| 29 | float fovy() const { return m_fovy; } |
---|
| 30 | |
---|
| 31 | void setZNear(float znear) { m_znear = znear; } |
---|
| 32 | float znear() const { return m_znear; } |
---|
| 33 | |
---|
| 34 | void setZFar(float zfar) { m_zfar = zfar; } |
---|
| 35 | float zfar() const { return m_zfar; } |
---|
| 36 | |
---|
| 37 | void setGridVisible(bool bVisible) { if (bVisible != m_bGridVisible) { m_bGridVisible = bVisible; emit gridVisibilityChanged(bVisible); } } |
---|
| 38 | bool isGridVisible() const { return m_bGridVisible; } |
---|
| 39 | |
---|
| 40 | void setAxisVisible(bool bVisible) { if (bVisible != m_bAxisVisible) { m_bAxisVisible = bVisible; emit axisVisibilityChanged(bVisible); } } |
---|
| 41 | bool isAxisVisible() const { return m_bAxisVisible; } |
---|
| 42 | |
---|
| 43 | void setSceneSize(float sceneSize) { m_sceneSize = sceneSize; } |
---|
| 44 | float sceneSize() const { return m_sceneSize; } |
---|
| 45 | |
---|
| 46 | void setGridSize(float gridSize) { m_gridSize = gridSize; } |
---|
| 47 | float gridSize() const { return m_gridSize; } |
---|
| 48 | |
---|
| 49 | void setGridSubdivision(int subdiv) { m_gridSubdiv = subdiv; } |
---|
| 50 | float gridSubdivision() const { return m_gridSubdiv; } |
---|
| 51 | |
---|
| 52 | void centerView(); |
---|
| 53 | void viewAll(); |
---|
| 54 | void stop(); |
---|
| 55 | |
---|
| 56 | void setInertia(bool bInertia) { m_bInertia = bInertia; if (!m_bInertia) stop(); } |
---|
| 57 | bool isInertia() const { return m_bInertia; } |
---|
| 58 | |
---|
| 59 | bool isAnimating() const { return m_bAnimating; } |
---|
| 60 | |
---|
| 61 | void initFromDOMElement(const QDomElement& element); |
---|
| 62 | QDomElement domElement(const QString& name, QDomDocument& doc) const; |
---|
| 63 | |
---|
| 64 | protected: |
---|
| 65 | |
---|
| 66 | virtual void init(); |
---|
| 67 | virtual void draw(); |
---|
| 68 | virtual void idle(); |
---|
| 69 | |
---|
| 70 | virtual void initializeGL(); |
---|
| 71 | virtual void paintGL(); |
---|
| 72 | virtual void mousePressEvent(QMouseEvent* pEvent); |
---|
| 73 | virtual void mouseMoveEvent(QMouseEvent* pEvent); |
---|
| 74 | virtual void mouseReleaseEvent(QMouseEvent* pEvent); |
---|
| 75 | virtual void wheelEvent(QWheelEvent* pEvent); |
---|
| 76 | virtual void keyReleaseEvent(QKeyEvent* pEvent); |
---|
| 77 | |
---|
| 78 | void drawGrid(); |
---|
| 79 | void drawAxis(); |
---|
| 80 | |
---|
| 81 | protected slots: |
---|
| 82 | |
---|
| 83 | void timeout(); |
---|
| 84 | |
---|
| 85 | signals: |
---|
| 86 | |
---|
| 87 | void cameraChanged(const gmtl::Vec3f& center, const gmtl::Quatf& rot, float distance); |
---|
| 88 | void axisVisibilityChanged(bool bVisible); |
---|
| 89 | void gridVisibilityChanged(bool bVisible); |
---|
| 90 | |
---|
| 91 | protected: |
---|
| 92 | |
---|
| 93 | QColor m_clearColor; |
---|
| 94 | |
---|
| 95 | gmtl::Matrix44f m_matrix; |
---|
| 96 | gmtl::Vec3f m_center; |
---|
| 97 | gmtl::Quatf m_rot; |
---|
| 98 | float m_distance; |
---|
| 99 | float m_orthoScale; |
---|
| 100 | |
---|
| 101 | gmtl::Vec3f m_pivotCenter; |
---|
| 102 | gmtl::Quatf m_pivotRot; |
---|
| 103 | float m_pivotDistance; |
---|
| 104 | float m_pivotOrthoScale; |
---|
| 105 | |
---|
| 106 | bool m_bPerspective; |
---|
| 107 | float m_fovy; |
---|
| 108 | float m_znear; |
---|
| 109 | float m_zfar; |
---|
| 110 | |
---|
| 111 | QPoint m_lastMousePos; |
---|
| 112 | QTime m_lastTime; |
---|
| 113 | |
---|
| 114 | bool m_bInertia; |
---|
| 115 | float m_animX; |
---|
| 116 | float m_animY; |
---|
| 117 | bool m_bAnimating; |
---|
| 118 | |
---|
| 119 | bool m_bGridVisible; |
---|
| 120 | bool m_bAxisVisible; |
---|
| 121 | |
---|
| 122 | float m_sceneSize; |
---|
| 123 | float m_gridSize; |
---|
| 124 | int m_gridSubdiv; |
---|
| 125 | |
---|
| 126 | QTimer m_timer; |
---|
| 127 | }; |
---|
| 128 | |
---|
| 129 | #endif // _QGLVIEWERWIDGET_H_ |
---|