summaryrefslogtreecommitdiff
path: root/engine/src/Camera.cpp
blob: 4a95ad890f2d64d56cb12de20c1fea92008624d2 (plain)
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
#include <kurator/engine/Camera.h>

#include <raylib.h>

#include <kurator/engine/Point.h>


namespace kurator
{
namespace engine
{


static auto viewport() -> Point;


Point
Camera::to_world(const Point& screen) const
{
	return (screen - viewport().scale(0.5)).scale(1.0 / scale) + offset;
}


Point
Camera::to_screen(const Point& world) const
{
	return (world - offset).scale(scale) + viewport().scale(0.5);
}


Point
Camera::top_left() const
{
	return to_world({0.0, 0.0});
}


Point
Camera::center() const
{
	return to_world(viewport().scale(0.5));
}


Point
Camera::bottom_right() const
{
	return to_world(viewport());
}


Point
viewport()
{
	return {static_cast<double>(GetScreenWidth()), static_cast<double>(GetScreenHeight())};
}


}  // namespace engine
}  // namespace kurator