forked from kenygia/MooseEdit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGlContextWidget.h
128 lines (108 loc) · 3.17 KB
/
GlContextWidget.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
#ifndef GLCONTEXTWIDGET_H
#define GLCONTEXTWIDGET_H
#include <QTimer>
#include "zgranny.h"
#include "GlShaderProgram.h"
#include <QGLWidget>
#include <QMessageBox>
#include <QKeyEvent>
#include <cmath>
#include <QElapsedTimer>
#include <glm/glm.hpp>
class GlContextWidget : public QGLWidget
{
Q_OBJECT
public:
explicit GlContextWidget(QWidget *parent = 0);
void initializeGL();
void resizeGL(int w, int h);
void paintGL();
//ZGrannyScene *getGrannyScene() const;
//void setGrannyScene(ZGrannyScene *value);
void addGrannyScene(ZGrannyScene *scene, std::vector<GLuint> &textures);
void addGrannyScene(ZGrannyScene *scene, std::vector<GLuint> &textures, VertexRGB *vertexRgb, VertexRGB *vertexRgb2, VertexRGB *vertexRgb3, VertexRGB *vertexRgb4, VertexRGB *vertexRgb5, GlShaderProgram *shaderProgram, MeshAttachmentPoint *attachment);
bool removeGrannyScene(ZGrannyScene *scene);
void keyPressEvent(QKeyEvent* e);
void keyReleaseEvent(QKeyEvent* e);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent* event);
void wheelEvent(QWheelEvent *event);
void showEvent(QShowEvent *event);
void hideEvent(QHideEvent *event);
void closeEvent(QCloseEvent *);
void cleanup();
void cleanupScene(ZGrannyScene *scene, bool cleanupProgram = false);
void pauseRendering();
void resumeRendering();
int getSceneCount();
signals:
public slots:
private:
void addAngle(double *angle, double toAdd, bool restricted) {
*angle += toAdd;
if (restricted) {
*angle = fmod(*angle + 360.0, 360.0);
if (*angle < 180.0) {
*angle += 180.0;
}
}
else {
*angle = fmod(*angle + 360.0, 360.0);
}
}
double d2r(double degrees) {
return degrees * 3.1415926535897932385 / 180.0;
}
double r2d(double radians) {
return radians * 180.0 / 3.1415926535897932385;
}
void polarToCartesian() {
double r_inclination = d2r(inclination);
double r_azimuth = d2r(azimuth);
posX = radius * sin(r_inclination) * cos(r_azimuth);
posZ = radius * sin(r_inclination) * sin(r_azimuth);
posY = radius * cos(r_inclination);
}
void cartesianToPolar() {
radius = sqrt(posX*posX + posY*posY + posZ*posZ);
inclination = 0;
addAngle(&inclination, r2d(acos(posY/radius)), true);
azimuth = 0;
addAngle(&azimuth, r2d(atan2(posZ, posX)), false);
}
QPoint lastMousePos = QPoint(-1, -1);
const long framesPerSecond = 60;
QTimer frameTimer;
QElapsedTimer elapsedTime;
std::vector<ZGrannyScene *> grannyScenes;
std::vector<std::vector<GLuint> > textureIds;
std::vector<VertexRGB *> vertexRGBs;
std::vector<VertexRGB *> vertexRGB2s;
std::vector<VertexRGB *> vertexRGB3s;
std::vector<VertexRGB *> vertexRGB4s;
std::vector<VertexRGB *> vertexRGB5s;
std::vector<GlShaderProgram *> shaderPrograms;
std::vector<MeshAttachmentPoint *> attachments;
bool timerConnected = false;
glm::mat4 model;
glm::mat4 view;
glm::mat4 projection;
float farPlane;
float nearPlane;
float screenWidth;
float screenHeight;
double posX;
double posY;
double posZ;
double addX;
double addY;
double addZ;
double radius;
double inclination;
double azimuth;
double lookatX;
double lookatY;
double lookatZ;
};
#endif // GLCONTEXTWIDGET_H