| 1 | #ifndef GLLANDSCAPE_H
|
|---|
| 2 | #define GLLANDSCAPE_H
|
|---|
| 3 |
|
|---|
| 4 | #include <qgl.h>
|
|---|
| 5 |
|
|---|
| 6 | class GLLandscape : public QGLWidget
|
|---|
| 7 | {
|
|---|
| 8 | Q_OBJECT
|
|---|
| 9 |
|
|---|
| 10 | public:
|
|---|
| 11 | GLLandscape( QWidget * parent = 0, const char * name = 0 );
|
|---|
| 12 | ~GLLandscape();
|
|---|
| 13 |
|
|---|
| 14 | public slots:
|
|---|
| 15 | void rotateX( int );
|
|---|
| 16 | void rotateY( int );
|
|---|
| 17 | void rotateZ( int );
|
|---|
| 18 | void zoom( int );
|
|---|
| 19 | void fractalize();
|
|---|
| 20 | void resetGrid();
|
|---|
| 21 |
|
|---|
| 22 | void setWireframe( int );
|
|---|
| 23 | void setFilled( int );
|
|---|
| 24 | void setSmoothShaded( int );
|
|---|
| 25 | void setLandscape( int );
|
|---|
| 26 | void setGridSize( int );
|
|---|
| 27 |
|
|---|
| 28 | void toggleWaveAnimation( bool );
|
|---|
| 29 |
|
|---|
| 30 | signals:
|
|---|
| 31 | void rotatedX( int );
|
|---|
| 32 | void rotatedY( int );
|
|---|
| 33 | void rotatedZ( int );
|
|---|
| 34 |
|
|---|
| 35 | protected:
|
|---|
| 36 | void paintGL();
|
|---|
| 37 | void initializeGL();
|
|---|
| 38 | void resizeGL( int w, int h );
|
|---|
| 39 | void mousePressEvent( QMouseEvent * );
|
|---|
| 40 | void mouseReleaseEvent( QMouseEvent * );
|
|---|
| 41 | void mouseMoveEvent( QMouseEvent * );
|
|---|
| 42 | void timerEvent( QTimerEvent * );
|
|---|
| 43 | void showEvent( QShowEvent * );
|
|---|
| 44 | void hideEvent( QHideEvent * );
|
|---|
| 45 |
|
|---|
| 46 | void drawWireframe();
|
|---|
| 47 | void drawFilled();
|
|---|
| 48 | void drawSmoothShaded();
|
|---|
| 49 | void drawAxis();
|
|---|
| 50 | void drawCube();
|
|---|
| 51 |
|
|---|
| 52 | private:
|
|---|
| 53 | enum Axis { XAxis, YAxis, ZAxis };
|
|---|
| 54 | enum RenderModes { Wireframe, Filled, SmoothShaded, Landscape };
|
|---|
| 55 | enum Views { DefaultView, CurrentView, AxisView };
|
|---|
| 56 |
|
|---|
| 57 | void rotate( GLfloat deg, Axis axis );
|
|---|
| 58 | void calculateVertexNormals();
|
|---|
| 59 | void averageNormals();
|
|---|
| 60 | void createGrid( int size );
|
|---|
| 61 | void destroyGrid();
|
|---|
| 62 | void initDisplayLists();
|
|---|
| 63 |
|
|---|
| 64 | RenderModes mode;
|
|---|
| 65 |
|
|---|
| 66 | typedef struct grid_normals {
|
|---|
| 67 | double u[3], l[3];
|
|---|
| 68 | } gridNormals;
|
|---|
| 69 |
|
|---|
| 70 | // Structure used to store the vertex normals for the landscape
|
|---|
| 71 | typedef struct avg_normals {
|
|---|
| 72 | double n[3];
|
|---|
| 73 | } avgNormals;
|
|---|
| 74 |
|
|---|
| 75 | typedef struct viewMatrix {
|
|---|
| 76 | GLfloat model[4][4]; // OpenGL model view matrix for the view
|
|---|
| 77 | GLfloat projection[4][4]; // OpenGL projection matrix for the view
|
|---|
| 78 | } viewMatrix;
|
|---|
| 79 |
|
|---|
| 80 | double ** landscape; // Height field data
|
|---|
| 81 | double ** wave; // Wave data
|
|---|
| 82 | double ** wt; // Parameterized wave data
|
|---|
| 83 | gridNormals ** normals;
|
|---|
| 84 | avgNormals ** vertexNormals;
|
|---|
| 85 | viewMatrix views[3];
|
|---|
| 86 |
|
|---|
| 87 | QPoint oldPos;
|
|---|
| 88 | GLfloat oldX, oldY, oldZ;
|
|---|
| 89 | bool initFractals;
|
|---|
| 90 | int gridSize, gridHalf;
|
|---|
| 91 | bool animationRunning;
|
|---|
| 92 | bool mouseButtonDown;
|
|---|
| 93 | int cubeTimer, animTimer;
|
|---|
| 94 | GLfloat cubeRot;
|
|---|
| 95 | GLint axisList, cubeList;
|
|---|
| 96 | };
|
|---|
| 97 |
|
|---|
| 98 | #endif
|
|---|