-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyOpenGLWidget.h
429 lines (355 loc) · 10.6 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
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
/**
* @file MyOpenGLWidget.h
* @author Donal Evans
* @date 25 Jul 2016
* @brief This class provides OpenGL functionalty for drawing to the main window.
*
* Detailed description goes here.
*/
#ifndef MYOPENGLWIDGET_H
#define MYOPENGLWIDGET_H
#include "Vertex.h"
#include "Transform3D.h"
#include "Camera3D.h"
#include <QOpenGLWidget>
#include <QOpenGLBuffer>
#include <QOpenGLFunctions>
#include <QOpenGLShaderProgram>
class MyOpenGLWidget : public QOpenGLWidget
{
Q_OBJECT
public:
/**
* @brief Getter for a reference to the Vertex vector.
* @return A reference to the Vertex vector.
*/
QVector<QVector<Vertex> >& GetVerticesRef();
/**
* @brief Setter for the Vertex data that is to be used in drawing.
* @param vertices A 2-dimensional QVector containing @Vertex objects for
* each time step, for each atom.
*/
void SetVertices(QVector<QVector<Vertex> > vertices);
/**
* @brief Setter for the zoom level.
* @param zoom The zoom factor as a float.
*/
void SetZoom(float zoom);
/**
* @brief Constructor
* @param parent The parent widget to which this object belongs.
*/
MyOpenGLWidget(QWidget* parent);
/**
* @brief Appends a QVector of @Vertex objects to the vertex vector.
* @param vertices The QVector of @Vertex objects to be appended.
*/
void AddVertices(QVector<Vertex> vertices);
/**
* @brief Clears all data currently stored in this object.
*/
void ClearData();
/**
* @brief Loads the vertices required to draw points and paths into the
* GPU memory as a buffer.
*/
void CreateTrajBuffer();
/**
* @brief Convenience function for printint the contents of a 4x4 matrix.
* @param matrix The QMatrix4x4 to be printed.
*/
void PrintMatrix(QMatrix4x4 matrix);
/**
* @brief Sets the size of the bounding box for the data, allowing
* initial camera position to be set.
* @param box a QVector3D represening the boundaries of the simulation
* space.
*/
void SetBoundingBox(QVector3D box);
public slots:
/**
* @brief Resets the position of the diffuse lighting source to the default
* view.
*/
void ResetLighting();
/**
* @brief Resets the camera view to the default view.
*/
void ResetView();
/**
* @brief Setter for the intensity of the ambient lighting.
* @param ambientValue The intensity of the ambient lighting, as an integer
* from 0 - 100.
*/
void SetAmbientValue(int ambientValue);
/**
* @brief Setter for the radius of the circles to be drawn.
* @param radius The radius to be used.
*/
void SetCircleRadius(int radius);
/**
* @brief Setter for whether or not paths will be drawn.
* @param draw If true paths will be drawn, if false, they will not.
*/
void SetDrawPaths(bool draw);
/**
* @brief Setter for whether or not points will be drawn.
* @param draw If true points will be drawn, if false, they will not.
*/
void SetDrawPoints(bool draw);
/**
* @brief Setter for which frame of data will be drawn.
* @param frame The frame number that will be drawn.
*/
void SetFrame(int frame);
/**
* @brief Sets the maximum path length to be drawn, as a percentage of the
* total path length range.
* @param percentage The maxmimum path length to be drawn, as a percentage
* of the total path length.
*/
void SetMaxPathLength(int percentage);
/**
* @brief Sets the minimum path length to be drawn, as a percentage of the
* total path length range.
* @param percentage The minmimum path length to be drawn, as a percentage
* of the total path length.
*/
void SetMinPathLength(int percentage);
protected:
/**
* @brief This function sets up the OpenGL environment and initializes
* the shader programs.
*/
void initializeGL();
/**
* @brief This function handles all the painting to be done by the class.
*/
void paintGL();
/**
* @brief This function handles resizing of the drawing surface.
* @param w The new width of the drawing surface.
* @param h The new height of the drawing surface.
*/
void resizeGL(int w, int h);
private:
/**
* @brief Getter for the far flipping plane.
* @return The distance from the camera to the far clipping plane
* as a float.
*/
float getFar();
/**
* @brief Setter for the far clipping plane.
* @param newFar The distance from the camera to the far clipping plane
* as a float.
*/
void setFar(float newFar);
/**
* @brief Setter for the mouse x position value on mouse click.
* @param LastX The x position of the mouse on mouse click.
*/
void setLastX(float LastX);
/**
* @brief Setter for the mouse y position value on mouse click.
* @param LastY The y position of the mouse on mouse click.
*/
void setLastY(float LastY);
/**
* @brief Setter for if panning is occurring.
* @param panning True if panning, false otherwise.
*/
void setPan(bool panning);
/**
* @brief Setter for if rotation is occurring.
* @param rotating True if rotating, false otherwise.
*/
void setRotate(bool rotating);
/**
* @brief Uses the vertex data stored in the trajectory buffer to draw
* atom paths to the drawing surface.
*/
void drawPaths();
/**
* @brief Uses the vertex data stored in the trajectory buffer to draw
* atom positions as points to the drawing surface.
*/
void drawPoints();
/**
* @brief Handles behaviour on mouse movement.
* @param event The triggering QMouseEvent.
*/
virtual void mouseMoveEvent(QMouseEvent *event);
/**
* @brief Handles behaviour on mouse button press.
* @param event The triggering QMouseEvent.
*/
virtual void mousePressEvent(QMouseEvent *event);
/**
* @brief Handles behaviour on mouse button release.
* @param event The triggering QMouseEvent.
*/
virtual void mouseReleaseEvent(QMouseEvent *event);
/**
* @brief Handles behaviour on mouse wheel scroll.
* @param event The triggering QWheelEvent.
*/
virtual void wheelEvent(QWheelEvent *event);
/**
* @brief The intensity of the ambient lighting, as a float.
*/
float m_AmbientValue = 0.3;
/**
* @brief The number of atoms currently being drawn.
*/
int m_Atoms;
/**
* @brief The camera object.
*/
Camera3D m_Camera;
/**
* @brief The uniform location within the shader files of the camera to
* view transformation matrix.
*/
int m_CameraToView;
/**
* @brief The radius of circles to be drawn, as a float.
*/
float m_CircleRadius;
/**
* @brief Matrix describing the default camera view.
*/
QMatrix4x4 m_DefaultView;
/**
* @brief Flag determining if paths are to be drawn.
*/
bool m_DrawPaths = false;
/**
* @brief Flag determining if postition points are to be drawn.
*/
bool m_DrawPoints = false;
/**
* @brief The distance from the far clipping plane to the camera.
*/
float m_Far = 200;
/**
* @brief The frame of data for which positions are being drawn.
*/
int m_Frame = 0;
/**
* @brief True if panning is occurring, false otherwise.
*/
bool m_IsPanning;
/**
* @brief True if rotation is occurring, false otherwise.
*/
bool m_IsRotating;
/**
* @brief The X position of the mouse at the beginning of a movement event.
*/
float m_LastX;
/**
* @brief The Y position of the mouse at the beginning of a movement event.
*/
float m_LastY;
/**
* @brief The object controling the movement of the diffuse lighting source.
*/
Camera3D m_LightingMatrix;
/**
* @brief The maximum path length to be drawn, as a fraction of total path
* length range.
*/
float m_MaxPathLength = 1;
/**
* @brief The minimum path length to be drawn, as a fraction of total path
* length range.
*/
float m_MinPathLength = 0;
/**
* @brief The uniform location within the shader files of the model to
* world transformation matrix.
*/
int m_ModelToWorld;
/**
* @brief The distance from the camera to the near clipping plane.
*/
float m_Near = 1;
/**
* @brief The shader program used for drawing paths.
*/
QOpenGLShaderProgram* m_PathProgram;
/**
* @brief The shader program used for drawing points.
*/
QOpenGLShaderProgram* m_PointProgram;
/**
* @brief The projection matrix to be used.
*/
QMatrix4x4 m_Projection;
/**
* @brief The total number of frames in the data.
*/
int m_TotalFrames;
/**
* @brief The buffer in which vertices used for drawing points and paths
* are stored.
*/
QOpenGLBuffer m_TrajBuffer;
/**
* @brief The Transform3D object to be used for handling transformations.
*/
Transform3D m_Transform;
/**
* @brief The @Vertex objects for each @Atom at each time step of the data.
*/
QVector<QVector<Vertex> > m_Vertices;
/**
* @brief The uniform location within the shader files of the world to
* camera transformation matrix.
*/
int m_WorldToCamera;
/**
* @brief The zoom to be applied to the image, as a fraction.
*/
float m_Zoom = 1.0;
/**
* @brief A scaling factor used when determining the appropriate far
* clipping plane for the simulation space size.
*/
const int FAR_SCALING = 3;
/**
* @brief The FOV used in gluPerspective(), in radians.
*/
const float FOV = 0.88;
/**
* @brief The number one hundred as an int.
*/
const int HUNDRED = 100;
/**
* @brief A scaling factor used when setting the radius of circles to be
* drawn.
*/
const float RADIUS_SCALING = 10.0;
/**
* @brief Scaling factor influencing the speed at which rotation occurs.
*/
const float ROT_SPEED = 0.5;
/**
* @brief The square root of 3, used in calculating circle vertices.
*/
const float SQRT_THREE = 1.732;
/**
* @brief Scaling factor influencing the speed at which translation occurs.
*/
const float TRANS_SPEED = 0.4;
/**
* @brief The number of spatial dimensions being used.
*/
const int TUPLE_SIZE_3D = 3;
/**
* @brief The rate at which zooming occurs.
*/
const float ZOOM_SPEED = 1.35;
};
#endif // MYOPENGLWIDGET_H