]> git.tdb.fi Git - libs/game.git/blob - source/game/camera.cpp
Convert components to buffered where appropriate
[libs/game.git] / source / game / camera.cpp
1 #include "camera.h"
2
3 using namespace std;
4
5 namespace Msp::Game {
6
7 Camera::Camera(Handle<Entity> e, const CameraSetup &s):
8         BufferedComponent<CameraData>(e),
9         setup(s)
10 {
11         CameraData &d = write();
12         d.fov_y = setup.field_of_view_y;
13         d.size = setup.size;
14         d.near_clip = setup.near_clip;
15         d.far_clip = setup.far_clip;
16
17         if(!d.is_orthographic())
18                 d.size = { d.get_aspect(), 1.0f };
19 }
20
21 void Camera::set_field_of_view(Geometry::Angle<float> f, float a)
22 {
23         Data &d = write();
24         if(d.is_orthographic())
25                 throw logic_error("Camera is not perspective");
26
27         d.fov_y = f;
28         d.size = { a, 1.0f };
29 }
30
31 void Camera::set_size(const LinAl::Vector<float, 2> &s)
32 {
33         Data &d = write();
34         if(!d.is_orthographic())
35                 throw logic_error("Camera is not orthographic");
36
37         d.size = s;
38 }
39
40 } // namespace Msp::Game