]> git.tdb.fi Git - libs/game.git/blob - source/game/camera.cpp
Add a view sub-library, including a Camera component
[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         Component(e),
9         setup(s),
10         fov_y(setup.field_of_view_y),
11         size(setup.size),
12         near_clip(setup.near_clip),
13         far_clip(setup.far_clip)
14 {
15         if(!is_orthographic())
16                 size = { get_aspect(), 1.0f };
17 }
18
19 void Camera::set_field_of_view(Geometry::Angle<float> f, float a)
20 {
21         if(is_orthographic())
22                 throw logic_error("Camera is not perspective");
23
24         fov_y = f;
25         size = { a, 1.0f };
26 }
27
28 void Camera::set_size(const LinAl::Vector<float, 2> &s)
29 {
30         if(!is_orthographic())
31                 throw logic_error("Camera is not orthographic");
32
33         size = s;
34 }
35
36 } // namespace Msp::Game