-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathqglviewer.h
95 lines (66 loc) · 1.82 KB
/
qglviewer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef QGLVIEWER_H
#define QGLVIEWER_H
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include <QOpenGLVertexArrayObject>
#include <QOpenGLBuffer>
#include <QMatrix4x4>
#include "gldata.h"
QT_FORWARD_DECLARE_CLASS(QOpenGLShaderProgram)
QT_FORWARD_DECLARE_CLASS(Camera)
struct GridConfig {
GridConfig();
int minX, maxX; // draw the grid from minX to maxX
int minY, maxY; // ...and from minY to maxY
int step;
QVector3D color; // grid color
};
struct AxesConfig {
AxesConfig();
float length;
float arrowSize;
QVector3D colorX, colorY, colorZ;
};
class QGLViewer : public QOpenGLWidget, protected QOpenGLFunctions
{
Q_OBJECT
public:
QGLViewer(QWidget *parent = nullptr);
~QGLViewer() override;
QSize minimumSizeHint() const override;
QSize sizeHint() const override;
Camera *camera() const { return m_camera; }
void setData(const GLData &data);
void setGridConfig(const GridConfig &grid);
void setAxesConfig(const AxesConfig &axes);
protected:
void initializeGL() override;
void paintGL() override;
void resizeGL(int width, int height) override;
void keyPressEvent(QKeyEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void wheelEvent(QWheelEvent *event) override;
private:
void initializeGridAndAxes();
void setupGL();
void setupVertexAttribs();
QPoint m_lastPos;
GLData m_data;
// draw as triangles
QOpenGLVertexArrayObject m_trisVao;
QOpenGLBuffer m_trisVbo;
// draw as lines: grid and axes
QOpenGLVertexArrayObject m_linesVao;
QOpenGLBuffer m_linesVbo;
bool m_drawGrid;
int m_gridVertexIdx;
GridConfig m_gridConfig;
bool m_drawAxes;
int m_axesVertexIdx;
AxesConfig m_axesConfig;
QOpenGLShaderProgram *m_program;
Camera *m_camera;
int m_mvpMatrixLoc;
};
#endif