| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information (qt-info@nokia.com)
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the demonstration applications of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at qt-sales@nokia.com.
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #ifndef SCENE_H
|
|---|
| 43 | #define SCENE_H
|
|---|
| 44 |
|
|---|
| 45 | //#include <GL/glew.h>
|
|---|
| 46 | #include "glextensions.h"
|
|---|
| 47 |
|
|---|
| 48 | #include <QtGui>
|
|---|
| 49 | #include <QtOpenGL>
|
|---|
| 50 |
|
|---|
| 51 | #include "roundedbox.h"
|
|---|
| 52 | #include "gltrianglemesh.h"
|
|---|
| 53 | #include "vector.h"
|
|---|
| 54 | #include "trackball.h"
|
|---|
| 55 | #include "glbuffers.h"
|
|---|
| 56 | #include "glshaders.h"
|
|---|
| 57 | #include "qtbox.h"
|
|---|
| 58 |
|
|---|
| 59 | #define PI 3.14159265358979
|
|---|
| 60 |
|
|---|
| 61 | class ParameterEdit : public QWidget
|
|---|
| 62 | {
|
|---|
| 63 | public:
|
|---|
| 64 | virtual void emitChange() = 0;
|
|---|
| 65 | };
|
|---|
| 66 |
|
|---|
| 67 | class ColorEdit : public ParameterEdit
|
|---|
| 68 | {
|
|---|
| 69 | Q_OBJECT
|
|---|
| 70 | public:
|
|---|
| 71 | ColorEdit(QRgb initialColor, int id);
|
|---|
| 72 | QRgb color() const {return m_color;}
|
|---|
| 73 | virtual void emitChange() {emit colorChanged(m_color, m_id);}
|
|---|
| 74 | public slots:
|
|---|
| 75 | void editDone();
|
|---|
| 76 | signals:
|
|---|
| 77 | void colorChanged(QRgb color, int id);
|
|---|
| 78 | protected:
|
|---|
| 79 | virtual void mousePressEvent(QMouseEvent *event);
|
|---|
| 80 | void setColor(QRgb color); // also emits colorChanged()
|
|---|
| 81 | private:
|
|---|
| 82 | QGraphicsScene *m_dialogParentScene;
|
|---|
| 83 | QLineEdit *m_lineEdit;
|
|---|
| 84 | QFrame *m_button;
|
|---|
| 85 | QRgb m_color;
|
|---|
| 86 | int m_id;
|
|---|
| 87 | };
|
|---|
| 88 |
|
|---|
| 89 | class FloatEdit : public ParameterEdit
|
|---|
| 90 | {
|
|---|
| 91 | Q_OBJECT
|
|---|
| 92 | public:
|
|---|
| 93 | FloatEdit(float initialValue, int id);
|
|---|
| 94 | float value() const {return m_value;}
|
|---|
| 95 | virtual void emitChange() {emit valueChanged(m_value, m_id);}
|
|---|
| 96 | public slots:
|
|---|
| 97 | void editDone();
|
|---|
| 98 | signals:
|
|---|
| 99 | void valueChanged(float value, int id);
|
|---|
| 100 | private:
|
|---|
| 101 | QGraphicsScene *m_dialogParentScene;
|
|---|
| 102 | QLineEdit *m_lineEdit;
|
|---|
| 103 | float m_value;
|
|---|
| 104 | int m_id;
|
|---|
| 105 | };
|
|---|
| 106 |
|
|---|
| 107 | class GraphicsWidget : public QGraphicsProxyWidget
|
|---|
| 108 | {
|
|---|
| 109 | protected:
|
|---|
| 110 | virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
|---|
| 111 | virtual void resizeEvent(QGraphicsSceneResizeEvent *event);
|
|---|
| 112 | virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
|---|
| 113 | };
|
|---|
| 114 |
|
|---|
| 115 | class TwoSidedGraphicsWidget : public QObject
|
|---|
| 116 | {
|
|---|
| 117 | Q_OBJECT
|
|---|
| 118 | public:
|
|---|
| 119 | TwoSidedGraphicsWidget(QGraphicsScene *scene);
|
|---|
| 120 | void setWidget(int index, QWidget *widget);
|
|---|
| 121 | QWidget *widget(int index);
|
|---|
| 122 | public slots:
|
|---|
| 123 | void flip();
|
|---|
| 124 | protected slots:
|
|---|
| 125 | void animateFlip();
|
|---|
| 126 | private:
|
|---|
| 127 | GraphicsWidget *m_proxyWidgets[2];
|
|---|
| 128 | int m_current;
|
|---|
| 129 | int m_angle; // angle in degrees
|
|---|
| 130 | int m_delta;
|
|---|
| 131 | };
|
|---|
| 132 |
|
|---|
| 133 | class RenderOptionsDialog : public QDialog
|
|---|
| 134 | {
|
|---|
| 135 | Q_OBJECT
|
|---|
| 136 | public:
|
|---|
| 137 | RenderOptionsDialog();
|
|---|
| 138 | int addTexture(const QString &name);
|
|---|
| 139 | int addShader(const QString &name);
|
|---|
| 140 | void emitParameterChanged();
|
|---|
| 141 | protected slots:
|
|---|
| 142 | void setColorParameter(QRgb color, int id);
|
|---|
| 143 | void setFloatParameter(float value, int id);
|
|---|
| 144 | signals:
|
|---|
| 145 | void dynamicCubemapToggled(int);
|
|---|
| 146 | void colorParameterChanged(const QString &, QRgb);
|
|---|
| 147 | void floatParameterChanged(const QString &, float);
|
|---|
| 148 | void textureChanged(int);
|
|---|
| 149 | void shaderChanged(int);
|
|---|
| 150 | void doubleClicked();
|
|---|
| 151 | protected:
|
|---|
| 152 | virtual void mouseDoubleClickEvent(QMouseEvent *event);
|
|---|
| 153 |
|
|---|
| 154 | QVector<QByteArray> m_parameterNames;
|
|---|
| 155 | QComboBox *m_textureCombo;
|
|---|
| 156 | QComboBox *m_shaderCombo;
|
|---|
| 157 | QVector<ParameterEdit *> m_parameterEdits;
|
|---|
| 158 | };
|
|---|
| 159 |
|
|---|
| 160 | class ItemDialog : public QDialog
|
|---|
| 161 | {
|
|---|
| 162 | Q_OBJECT
|
|---|
| 163 | public:
|
|---|
| 164 | enum ItemType {
|
|---|
| 165 | QtBoxItem,
|
|---|
| 166 | CircleItem,
|
|---|
| 167 | SquareItem,
|
|---|
| 168 | };
|
|---|
| 169 |
|
|---|
| 170 | ItemDialog();
|
|---|
| 171 | public slots:
|
|---|
| 172 | void triggerNewQtBox();
|
|---|
| 173 | void triggerNewCircleItem();
|
|---|
| 174 | void triggerNewSquareItem();
|
|---|
| 175 | signals:
|
|---|
| 176 | void doubleClicked();
|
|---|
| 177 | void newItemTriggered(ItemDialog::ItemType type);
|
|---|
| 178 | protected:
|
|---|
| 179 | virtual void mouseDoubleClickEvent(QMouseEvent *event);
|
|---|
| 180 | };
|
|---|
| 181 |
|
|---|
| 182 | class Scene : public QGraphicsScene
|
|---|
| 183 | {
|
|---|
| 184 | Q_OBJECT
|
|---|
| 185 | public:
|
|---|
| 186 | Scene(int width, int height, int maxTextureSize);
|
|---|
| 187 | ~Scene();
|
|---|
| 188 | virtual void drawBackground(QPainter *painter, const QRectF &rect);
|
|---|
| 189 |
|
|---|
| 190 | public slots:
|
|---|
| 191 | void setShader(int index);
|
|---|
| 192 | void setTexture(int index);
|
|---|
| 193 | void toggleDynamicCubemap(int state);
|
|---|
| 194 | void setColorParameter(const QString &name, QRgb color);
|
|---|
| 195 | void setFloatParameter(const QString &name, float value);
|
|---|
| 196 | void newItem(ItemDialog::ItemType type);
|
|---|
| 197 | protected:
|
|---|
| 198 | void renderBoxes(const gfx::Matrix4x4f &view, int excludeBox = -2);
|
|---|
| 199 | void setStates();
|
|---|
| 200 | void setLights();
|
|---|
| 201 | void defaultStates();
|
|---|
| 202 | void renderCubemaps();
|
|---|
| 203 |
|
|---|
| 204 | virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
|---|
| 205 | virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
|---|
| 206 | virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
|---|
| 207 | virtual void wheelEvent(QGraphicsSceneWheelEvent * event);
|
|---|
| 208 | private:
|
|---|
| 209 | void initGL();
|
|---|
| 210 | QPointF pixelPosToViewPos(const QPointF& p);
|
|---|
| 211 |
|
|---|
| 212 | QTime m_time;
|
|---|
| 213 | int m_lastTime;
|
|---|
| 214 | int m_mouseEventTime;
|
|---|
| 215 | int m_distExp;
|
|---|
| 216 | int m_frame;
|
|---|
| 217 | int m_maxTextureSize;
|
|---|
| 218 |
|
|---|
| 219 | int m_currentShader;
|
|---|
| 220 | int m_currentTexture;
|
|---|
| 221 | bool m_dynamicCubemap;
|
|---|
| 222 | bool m_updateAllCubemaps;
|
|---|
| 223 |
|
|---|
| 224 | RenderOptionsDialog *m_renderOptions;
|
|---|
| 225 | ItemDialog *m_itemDialog;
|
|---|
| 226 | QTimer *m_timer;
|
|---|
| 227 | GLRoundedBox *m_box;
|
|---|
| 228 | TrackBall m_trackBalls[3];
|
|---|
| 229 | QVector<GLTexture *> m_textures;
|
|---|
| 230 | GLTextureCube *m_environment;
|
|---|
| 231 | GLTexture3D *m_noise;
|
|---|
| 232 | GLRenderTargetCube *m_mainCubemap;
|
|---|
| 233 | QVector<GLRenderTargetCube *> m_cubemaps;
|
|---|
| 234 | QVector<GLProgram *> m_programs;
|
|---|
| 235 | GLVertexShader *m_vertexShader;
|
|---|
| 236 | QVector<GLFragmentShader *> m_fragmentShaders;
|
|---|
| 237 | GLFragmentShader *m_environmentShader;
|
|---|
| 238 | GLProgram *m_environmentProgram;
|
|---|
| 239 | };
|
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 | #endif
|
|---|