-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera.h
67 lines (54 loc) · 1.64 KB
/
camera.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
#ifndef CAMERA_H
#define CAMERA_H
#include <QVector3D>
#include <QMatrix4x4>
#include <QKeyEvent>
#include <QOpenGLShader>//为了glfloat 这些变量,所以引进这个头文件
#include <QDebug>
#include <QtMath>
enum Camera_Movement {
FORWARD,
BACKWARD,
LEFT,
RIGHT,
UP,
DOWN
};
//使用这些宏,可以很方便的修改初始化数据
const GLfloat YAW = -90.0f;
const GLfloat PITCH = 0.0f;
const GLfloat SPEED = 0.25;
const GLfloat SENSITIVITY = 0.1f;
const GLfloat ZOOM = 45.0f;
class Camera {
public:
Camera(QVector3D position = QVector3D(0.0f, 0.0f, 0.0f), QVector3D up = QVector3D(0.0f, 1.0f, 0.0f),
GLfloat yaw = YAW, GLfloat pitch = PITCH): front(QVector3D(0.0f, 0.0f, -1.0f)), movementSpeed(SPEED),
mouseSensitivity(SENSITIVITY), zoom(ZOOM){
this->position = position;
this->worldUp = up;
this->yaw = yaw;
this->picth = pitch;
this->updateCameraVectors();
}
QMatrix4x4 getViewMatrix(); //返回lookat函数
void processMouseMovement(GLfloat xoffset, GLfloat yoffset, GLboolean constraintPitch = true); //相应鼠标操作函数
void processMouseScroll(GLfloat yoffset);//鼠标滚轮事件
void processKeyboard(Camera_Movement direction, GLfloat deltaTime);//键盘处理事件函数
//void processInput(GLfloat dt);//键盘循环函数
QVector3D position;
QVector3D worldUp;
QVector3D front;
QVector3D up; //view坐标系 的上方向
QVector3D right; // view坐标系的 右方向
//Eular Angles
GLfloat picth;
GLfloat yaw;
//Camera options
GLfloat movementSpeed;
GLfloat mouseSensitivity;
GLfloat zoom;
private:
void updateCameraVectors();
};
#endif // CAMERA_H