-
Notifications
You must be signed in to change notification settings - Fork 3
/
canvas.h
84 lines (65 loc) · 1.95 KB
/
canvas.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
#ifndef CANVAS_H
#define CANVAS_H
#include <QtOpenGL>
#include <QSurfaceFormat>
#include <QOpenGLShaderProgram>
class GLMesh;
class Mesh;
class Backdrop;
class Canvas : public QOpenGLWidget, protected QOpenGLFunctions
{
Q_OBJECT
public:
explicit Canvas(const QSurfaceFormat& format, QWidget* parent=0);
~Canvas();
void view_orthographic();
void view_perspective();
void draw_shaded();
void draw_wireframe();
enum class RenderMode { Solid, Wireframe };
enum class Direction { Front, Back, Top, Bottom, Left, Right };
public slots:
void set_status(const QString& s);
void clear_status();
void load_mesh(Mesh* m, bool is_reload);
void reset_cam();
void setCameraAngle(const enum Direction direction);
protected:
void paintGL() override;
void initializeGL() override;
void resizeGL(int width, int height) override;
void mousePressEvent(QMouseEvent* event) override;
void mouseReleaseEvent(QMouseEvent* event) override;
void mouseMoveEvent(QMouseEvent* event) override;
void wheelEvent(QWheelEvent* event) override;
void set_perspective(float p);
void set_renderMode(const enum RenderMode);
void view_anim(float v);
private:
void draw_mesh();
void draw_small_axes();
QMatrix4x4 transform_matrix() const;
QMatrix4x4 view_matrix() const;
QOpenGLShaderProgram mesh_shader;
QOpenGLShaderProgram mesh_wireframe_shader;
QOpenGLShaderProgram quad_shader;
QOpenGLShaderProgram small_axes_shader;
QOpenGLVertexArrayObject small_axes_vao;
QOpenGLBuffer small_axes_vertices;
GLMesh* mesh;
Backdrop* backdrop;
QVector3D center;
float scale;
float zoom;
float tilt;
float yaw;
QVector3D meshCenter;
float meshScale;
float perspective;
enum RenderMode mode;
Q_PROPERTY(float perspective MEMBER perspective WRITE set_perspective);
QPropertyAnimation anim;
QPoint mouse_pos;
QString status;
};
#endif // CANVAS_H