-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcamera.cpp
More file actions
79 lines (62 loc) · 1.61 KB
/
camera.cpp
File metadata and controls
79 lines (62 loc) · 1.61 KB
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
#include <fea/rendering/camera.hpp>
namespace fea
{
Camera::Camera() : mPosition(glm::vec2(0.0f, 0.0f)), mZoom(glm::vec2(1.0f, 1.0f)), mRotation(0.0f)
{
}
Camera::Camera(glm::vec2 p, glm::vec2 z) : mPosition(p), mZoom(z), mRotation(0.0f)
{
}
void Camera::setPosition(glm::vec2 p)
{
mPosition = p;
}
const glm::vec2& Camera::getPosition() const
{
return mPosition;
}
void Camera::translate(glm::vec2 p)
{
mPosition += p;
}
void Camera::setZoom(glm::vec2 z)
{
mZoom = z;
}
const glm::vec2& Camera::getZoom() const
{
return mZoom;
}
void Camera::zoom(glm::vec2 zoom)
{
mZoom *= zoom;
}
void Camera::setRotation(float radians)
{
mRotation = radians;
}
float Camera::getRotation() const
{
return mRotation;
}
void Camera::rotate(float radians)
{
mRotation += radians;
}
glm::mat2x2 Camera::getRotationMatrix() const
{
glm::mat2x2 result;
float sin = glm::sin(mRotation);
float cos = glm::cos(mRotation);
glm::mat2x2 rot = glm::mat2x2(cos, sin, -sin, cos);
return result * rot;
}
glm::vec2 Camera::transformPoint(const glm::vec2 point) const
{
return getRotationMatrix() * (getZoom() * (point - getPosition()));
}
glm::vec2 Camera::untransformPoint(const glm::vec2 point) const
{
return (1.0f/getZoom()) * (glm::inverse(getRotationMatrix()) * (point)) + getPosition();
}
}