-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlatCamera.cpp
More file actions
65 lines (51 loc) · 1.15 KB
/
FlatCamera.cpp
File metadata and controls
65 lines (51 loc) · 1.15 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
#include "FlatCamera.h"
#include <glm/gtx/euler_angles.hpp>
#include <iostream>
FlatCamera::FlatCamera()
{
Reset();
AspectRatio(1.0f);
UpdateProjection();
}
FlatCamera::FlatCamera(const float &ar)
{
Reset();
AspectRatio(ar);
UpdateProjection();
}
FlatCamera::FlatCamera(const unsigned &w, const unsigned &h)
{
Reset();
AspectRatio(w, h);
UpdateProjection();
}
void FlatCamera::Reset()
{
scale = 1.0f;
rotation = 0.0f;
position[0] = 0.0f;
position[1] = 0.0f;
nearp = 1.0f;
farp = -1.0f;
aspectratio = 1.0f;
top = 0.70710678118654752440084436210485f;
right = 0.70710678118654752440084436210485f;
}
void FlatCamera::AspectRatio(const float &ar)
{
aspectratio = ar;
top = sqrt(1.0f / (aspectratio + 1.0f));
right = aspectratio * top;
}
void FlatCamera::AspectRatio(const unsigned &w, const unsigned &h)
{
aspectratio = (float)w / h;
top = sqrt(1.0f / (aspectratio + 1.0f));
right = aspectratio * top;
}
void FlatCamera::UpdateProjection()
{
lastm = projm;
projm = ortho(-right * scale + position[0], right * scale + position[0], -top * scale + position[1], top * scale + position[1], nearp, farp);
projm = projm * eulerAngleZ(rotation);
}