-
Notifications
You must be signed in to change notification settings - Fork 8
/
openglwidget.h
87 lines (61 loc) · 1.72 KB
/
openglwidget.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
#ifndef OPENGLWIDGET_H
#define OPENGLWIDGET_H
#include <QDateTime>
#include <QDebug>
#include <QMatrix4x4>
#include <QMouseEvent>
#include <QOpenGLBuffer>
#include <QOpenGLFunctions>
#include <QOpenGLShaderProgram>
#include <QOpenGLVertexArrayObject>
#include <QOpenGLWidget>
#include <QTime>
#include <QtMath>
// 引入GDAL头文件
#include "ogrsf_frmts.h"
#include "renderlayer.h"
class OpenGLWidget : public QOpenGLWidget, protected QOpenGLFunctions {
Q_OBJECT
public:
explicit OpenGLWidget(QWidget *parent);
void initializeGL() override;
void paintGL() override;
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void wheelEvent(QWheelEvent *event);
void keyPressEvent(QKeyEvent *event);
void mouseMoveEvent(QMouseEvent *event);
QVector<RenderLayer *> layers;
QRectF *boundary;
bool displayMode = false;
float displaySpeed = 1;
bool gameMode = false;
void rotate(bool checked);
float rotateHeight = 0;
private:
QOpenGLBuffer m_vertex;
QOpenGLVertexArrayObject m_object;
QOpenGLShaderProgram *m_program;
QVector4D pressVec4;
QVector4D lastVec4;
QMatrix4x4 projection;
QMatrix4x4 rotateVec;
QMatrix4x4 camera;
QVector3D cameraPos;
QVector3D cameraTarget;
float pitch = .0f;
float yaw = -90.0f;
float span = 0;
QVector3D worldUp;
QVector3D front;
QVector3D right;
QVector3D up;
QMatrix4x4 perspective;
QMatrix4x4 moveMatrix;
QVector4D cursorToView(QMouseEvent *event);
void cursorToViewBoundary(QMouseEvent *event, QVector4D *leftTop,
QVector4D *rightBottom, float offset = 2);
QVector4D cursorToView(QWheelEvent *event);
QVector4D viewToWorld(QVector4D point);
};
#endif // OPENGLWIDGET_H