-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcamera.h
More file actions
38 lines (30 loc) · 750 Bytes
/
camera.h
File metadata and controls
38 lines (30 loc) · 750 Bytes
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
#pragma once
#include "libs/glm/glm.hpp"
#include "libs/glm/ext/matrix_transform.hpp"
class Camera {
public:
Camera(float fov, float width, float height) {
projection = glm::perspective(fov/2.0f, width / height, 0.1f, 1000.0f);
view = glm::mat4(1.0f);
position = glm::vec3(0.0f);
update();
}
glm::mat4 getViewProj() {
return viewProj;
}
glm::mat4 getView() {
return view;
}
virtual void update() {
viewProj = projection * view;
}
virtual void translate(glm::vec3 v) {
position += v;
view = glm::translate(view, v*-1.0f);
}
protected:
glm::vec3 position;
glm::mat4 projection;
glm::mat4 view;
glm::mat4 viewProj;
};