-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera2d.h
executable file
·66 lines (57 loc) · 1.2 KB
/
camera2d.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
#ifndef CAMERA2D_H
#define CAMERA2D_H
#include <glm/mat4x4.hpp>
#include <glm/vec2.hpp>
#include <GL/glew.h>
#include <iostream>
class Camera2D
{
private:
bool _matrixChanged;
GLuint _width;
GLuint _height;
GLfloat _scale;
glm::vec2 _position;
glm::mat4 _cameraMatrix;
glm::mat4 _orthoMatrix;
public:
Camera2D();
void init(GLuint width, GLuint height);
void update();
glm::vec2 convertScreenToWorld(glm::vec2 screenCoords);
void addPosition(const glm::vec2& position)
{
_position += position;
_matrixChanged = true;
}
void addScale(float scale);
// setters
void setPosition(const glm::vec2& position)
{
_position = position;
_matrixChanged = true;
}
void setScale(float scale)
{
_scale = scale;
_matrixChanged = true;
}
// getters
const glm::vec2& getPosition() const
{
return _position;
}
float getScale() const
{
return _scale;
}
const glm::mat4& getCameraMatrix() const
{
return _cameraMatrix;
}
float getAspectRatio() const
{
return (float)_width / (float)_height;
}
};
#endif // CAMERA2D_H