-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoglmanager.h
118 lines (91 loc) · 2.76 KB
/
oglmanager.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
#ifndef OGLMANAGER_H
#define OGLMANAGER_H
#include <QOpenGLWidget>
#include <QKeyEvent>
#include <QOpenGLFunctions_3_3_Core>
#include <QTime>
#include <QMouseEvent>
#include <QMainWindow>
#include "camera.h"
#include "model.h"
#include "air.h"
static const int FPS = 60;
class MainWindow;
class OGLManager : public QOpenGLWidget{
public:
explicit OGLManager(QWidget *parent = 0);
~OGLManager();
void handleKeyPressEvent(QKeyEvent *event);
void handleKeyReleaseEvent(QKeyEvent *event);
void changeObjModel(QString fileName);
void setModelScale();
GLfloat modelScaling;// obj scale
GLboolean keys[1024];//multi-key press
GLboolean isOpenLighting;
GLboolean isLineMode;
// for animation
void AddKeyFrame(int frame);
void RuntheAnimation();
void SetFrame(int frame);
std::vector<QMatrix4x4> frame_matrixs;
std::vector<QMatrix4x4> temp_translate_matrixs;
std::vector<QMatrix4x4> temp_rotate_matrixs;
std::vector<QMatrix4x4> temp_scale_matrixs;
std::vector<int> key_frame_indices;
GLboolean run_animation_flag = false;
GLboolean has_run_animation = false;
int frame_num = 100;
int current_frame = 0;
int m_fps = FPS;
GLfloat m_deltatime = 0.0f;
MainWindow *window;
protected:
void mouseMoveEvent(QMouseEvent *event);
void wheelEvent(QWheelEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
virtual void initializeGL();
virtual void resizeGL(int w, int h);
virtual void paintGL();
private:
void processInput(GLfloat dt);//handle input
void updateGL();
// for animation
QVector3D _translationMat2Vec3(QMatrix4x4 m);
QMatrix4x4 _translationVec32Mat(QVector3D v);
QOpenGLFunctions_3_3_Core *core;
GLboolean isFirstMouse;
GLboolean isLeftMousePress;
GLboolean isRightMousePress;
GLint lastX;
GLint lastY;
QTime time;
GLfloat deltaTime;
GLfloat lastFrame;
Camera *camera;
};
struct Quaternion
{
float w, x, y, z;
Quaternion()
{
w=0;x=0;y=0;z=0;
}
Quaternion(float _w, float _x, float _y, float _z)
{
w = _w; x=_x;y=_y;z=_z;
}
// This constructor use 'injects' a QVector3D into the imaginary part of the Quaternion (i.e. x, y, z values)
Quaternion(float _w, QVector3D v)
{
w=_w, x=v.x(), y=v.y(), z=v.z();
}
};
// SLERP(Spherical linear interpolation) moves a point from one position to another over time
Quaternion Slerp(Quaternion a, Quaternion b, double t);
// Returns a Matrix4D used for rotation
QMatrix4x4 RotationMatrix4D(Quaternion q);
Quaternion Matrix4D2Quaternion(QMatrix4x4 m);
float Norm(Quaternion q);
Quaternion Normalize(Quaternion q);
#endif // OGLMANAGER_H