-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy path3Plot.h
263 lines (197 loc) · 5.4 KB
/
3Plot.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#ifndef H3PLOT_H
#define H3PLOT_H
#include <QtQuick/QQuickFramebufferObject>
#include <QtGui/qvector3d.h>
#include <QtGui/qmatrix4x4.h>
//#include <QtGui/qopenglshaderprogram.h>
#include <QtGui/qopenglfunctions.h>
#include <QObject>
#include <qdebug.h>
#include <QTime>
#include <QVector>
#include <memory>
class Scene3D : public QObject, protected QOpenGLFunctions
{
Q_OBJECT
public:
Scene3D();
~Scene3D();
void render();
void initialize();
void scale(float sc) {
m_fScale = sc;
}
void modelScale(float scale) {
_modelScaleZ = scale;
}
void size(QVector2D sz) {
_size = sz;
}
void setRightMouseButtonPressed(bool pressed){
mIsRightMouseButtonPressed = pressed;
}
void mouse(QVector2D m) {
_mouse = m;
}
QMatrix4x4 modelMatrix() const {
return mModel;
}
QMatrix4x4 projectionMatrix() const {
return mProjection;
}
QMatrix4x4 viewMatrix() const {
return mView;
}
QVector3D acrball(QVector2D m);
void setCameraView(QVector3D eye, QVector3D lookat, QVector3D camup) {
_eye = eye;
_lookat = lookat;
_camup = camup;
updateView();
}
QVector3D getViewDir() const { return QVector3D(-_view.column(2)[0],-_view.column(2)[1],-_view.column(2)[2]); }
QVector3D getRight() const { return QVector3D(_view.column(0)[0],_view.column(0)[1],_view.column(0)[2]); }
void rotationFlag(bool is_rotation) { _isRotation = is_rotation; }
private:
float _modelScaleZ = 1.0f;
qreal m_fScale = 1;
QVector2D _size;
QVector2D _rotAngle;
QVector3D _posCenter;
QVector2D _lastMouse;
QVector2D _mouse;
QVector3D _eye;
QVector3D _lookat;
QVector3D _camup;
QMatrix4x4 _view;
QVector<QVector3D> _testPonts;
bool _isRotation;
void updateView() {
_view = QMatrix4x4();
_view.lookAt(_eye, _lookat, _camup);
}
void paintScene();
void createGeometry();
void mash(QVector<qreal> z);
void mashAlign();
void line(qreal x, qreal y, qreal z);
QVector<QVector3D> vLines;
QVector<QVector3D> vTriangle;
QVector<QVector3D> _gridXY;
QVector<QVector<QVector3D>> vQuads;
int vertexAttr1;
int normalAttr1;
int matrixUniform1;
int projectionUniform1;
QVector<qreal> _mashZ;
qreal _mashStep = 0.05;
QQuaternion q;
QMatrix4x4 mModel;
QMatrix4x4 mView;
QMatrix4x4 mProjection;
float mMaxZ = 0.0f;
float mMinZ = 0.0f;
void displayTest();
void displayRays();
void displayPoint(const QVector3D& p);
bool mIsRightMouseButtonPressed = false;
QVector2D mMousePos;
QSize mSceneSize;
};
class FboInSGRenderer : public QQuickFramebufferObject
{
Q_OBJECT
QML_NAMED_ELEMENT(Renderer)
public:
Renderer *createRenderer() const;
QVector<QVector3D> lines() {
return _bottomTrack;
}
//void setSceneObjectsListModel(std::shared_ptr <SceneObjectsListModel> sceneObjectsListModel);
void updateBottomTrack(QVector<QVector3D> p) {
_bottomTrack = p;
// update();
}
bool isRightMouseButtonPressed() const {
return mIsRightMouseButtonPressed;
};
bool isLeftMouseButtonPressed() const {
return mIsLeftMouseButtonPressed;
}
QVector2D mousePos() const {
return mMousePos;
}
public slots:
void scaleDelta(float delta) {
qDebug() << "delta: " << delta;
if(delta > 100.0f) {
delta = 100.0f;
} else if(delta < -100.0f) {
delta = -100.0f;
}
float coef = 1.0f - abs(delta)/400.0;
if(delta > 0) {
_scale /= coef;
if(_scale > 120.0) {
_scale = 120.0;
}
} else if(delta < 0){
_scale *= coef;
if(_scale < 0.1) {
_scale = 0.1;
}
}
// update();
}
void scale(float scale) {
_scale = scale;
// update();
}
float scaleDelta() { return _scale; }
void mouse(int x, int y, bool rotation_flag) {
_lastMouseX = x;
_lastMouseY = y;
_rotationFlag = rotation_flag;
// update();
}
void mousePressed(int modifier){
switch(modifier){
case Qt::LeftButton:
mIsLeftMouseButtonPressed = true;
break;
case Qt::RightButton:
mIsRightMouseButtonPressed = true;
break;
}
// update();
};
void mouseReleased(int modifier){
switch(modifier){
case Qt::LeftButton:
mIsLeftMouseButtonPressed = false;
break;
case Qt::RightButton:
mIsRightMouseButtonPressed = false;
break;
}
// update();
};
void mouseMoved(int x, int y){
mMousePos = QVector2D(x,y);
// update();
};
QVector2D mouse() { return QVector2D(_lastMouseX, _lastMouseY); }
bool isRotation() { return _rotationFlag; }
private:
QVector<QVector3D> _bottomTrack;
float _scale = 30.0;
float _modelScaleZ = 1.0f;
int _lastMouseX = -1, _lastMouseY = -1;
bool _rotationFlag = false;
Renderer* mpRenderer;
//std::shared_ptr <SceneObjectsListModel> mpSceneObjectsListModel;
bool mIsRightMouseButtonPressed = false;
bool mIsLeftMouseButtonPressed = false;
QVector2D mMousePos = {0.0f, 0.0f};
};
#endif // H3PLOT_H