-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyopenglwidget.h
executable file
·109 lines (80 loc) · 2.83 KB
/
myopenglwidget.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#ifndef MYOPENGLWIDGET_H
#define MYOPENGLWIDGET_H
#include <QOpenGLWidget>
#include <QOpenGLFunctions_4_0_Core>
#include <QSurfaceFormat>
#include <QOpenGLBuffer>
#include <QOpenGLVertexArrayObject>
#include <QOpenGLShader>
#include <QOpenGLShaderProgram>
#include <QMouseEvent>
#include <QWidget>
#include <iostream>
#include "mode.h"
#include <mgl_node.h>
class MyOpenGLWidget : public QOpenGLWidget, public QOpenGLFunctions_4_0_Core
{
Q_OBJECT
public:
MyOpenGLWidget(QWidget *parent=nullptr);
~MyOpenGLWidget() override;
void refresh();
void newNode(); // creates new node and selects it
void deleteSelected();
void makeParentOf();
void clearObjects();
void activateKeyboard(bool);
bool keyboardIsActivated() {return keyboardActivated;}
void setMouseMode(int mode);
void setKeyboardMode(int mode);
void setAxis(int axis);
void swapTransformOrder(int order);
void swapAxisOrder(int order);
void resetCamera();
void selectParent();
void selectNext();
void selectPrevious();
// interface for transforming the world
void genericTriangle();
void translateWorld(float,float,float);
protected:
void initializeGL() override;
void paintGL() override;
void resizeGL(int w, int h) override;
void mousePressEvent(QMouseEvent *ev) override;
void mouseReleaseEvent(QMouseEvent *ev) override;
// uses saved mouse click values
void setNextVertex();
float mouseDistanceY();
void calculateCameraMatrix();
private:
// raytracing functions
QMatrix4x4 matCamera, matPerspective;
QVector3D eye, center, up;
int nearclip = 1, farclip = 20;
// empty TObject to manage user-created objects
// all newly created objects are children of worldObject
MGL_Node *world;
std::list<MGL_Node *>::iterator selected, aux;
// essentially a mutex for UI controls
bool keyboardActivated = false;
// when true, selected is red and aux (if it points to a child) is dark blue
bool colorSetting = false;
// rendering
QOpenGLVertexArrayObject *pVao;
QOpenGLBuffer *pBuffer;
QOpenGLShader *pVertexShader, *pFragmentShader;
QOpenGLShaderProgram *pShaderProgram;
void renderTree(MGL_Node *node, const QMatrix4x4 &transform, const QVector4D &color);
int widgetX1,widgetY1, // mousePressEvent coordinates
widgetX2,widgetY2; // mouseReleaseEvent coordinates
// UI-related components
int viewportCoordinatesX[3], viewportCoordinatesY[3]; // holds each each vertex for the next triangle to be drawn
QVector4D qvertices[3];
int numVerticesChosen = 0;
int axis = 0;
// helper functions
bool canAddVertex();
int mouseMode, keyboardMode;
};
#endif // MYOPENGLWIDGET_H